Skip to content

Commit

Permalink
Merge pull request #91 from kundajelab/hitscoring
Browse files Browse the repository at this point in the history
v0.5.14.1 Nicer API for the density-adaptive hit scoring
  • Loading branch information
AvantiShri committed Apr 29, 2021
2 parents e4028e1 + e9b6db7 commit d3985db
Show file tree
Hide file tree
Showing 10 changed files with 4,198 additions and 3,910 deletions.

This file was deleted.

3,821 changes: 3,821 additions & 0 deletions examples/simulated_TAL_GATA_deeplearning/TF_MoDISco_TAL_GATA.ipynb

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions modisco.egg-info/SOURCES.txt
Expand Up @@ -9,6 +9,7 @@ modisco/core.py
modisco/gammamix.py
modisco/metaclusterers.py
modisco/nearest_neighbors.py
modisco/pattern_filterer.py
modisco/util.py
modisco/value_provider.py
modisco.egg-info/PKG-INFO
Expand Down Expand Up @@ -39,6 +40,7 @@ modisco/cluster/phenograph/louvain/osx-hierarchy
modisco/clusterinit/__init__.py
modisco/clusterinit/memeinit.py
modisco/hit_scoring/__init__.py
modisco/hit_scoring/densityadapted_hitscoring.py
modisco/hit_scoring/exemplar_based_hitscoring.py
modisco/hit_scoring/fast_hit_scoring.py
modisco/seqlet_embedding/__init__.py
Expand Down
19 changes: 15 additions & 4 deletions modisco/cluster/core.py
Expand Up @@ -186,6 +186,14 @@ def run_leiden(fileprefix, use_initclusters, n_vertices,
if line.startswith("Membership:"):
parse_membership = True

if (parse_membership==False):
raise RuntimeError("----\nERROR:\n"
+err.decode()
+"\n----\nSTDOUT:\n"
+out.decode()
+"\n---\nARGS:\n"
+str(args))

return quality, np.array(membership)


Expand Down Expand Up @@ -234,10 +242,13 @@ def __call__(self, orig_affinity_mat, initclusters):

#if an initclustering is specified, we would want to try the Leiden
# both with and without that initialization and take the one that
# gets the best modularity
initclusters_to_try_list = [False]
if (initclusters is not None):
initclusters_to_try_list.append(True)
# gets the best modularity. EXCEPT when refinement is also specified.
if (self.refine):
initclusters_to_try_list = [True]
else:
initclusters_to_try_list = [False]
if (initclusters is not None):
initclusters_to_try_list.append(True)


#write out the contents of affinity_mat and initclusters if applicable
Expand Down
35 changes: 22 additions & 13 deletions modisco/cluster/run_leiden
Expand Up @@ -14,8 +14,8 @@ def get_igraph(sources_idxs_file, targets_idxs_file, weights_file, n_vertices):
weights = np.load(weights_file)
g = ig.Graph(directed=None)
g.add_vertices(n_vertices) # this adds adjacency.shap[0] vertices
g.add_edges(list(zip(sources, targets)))
g.es['weight'] = list(weights)
g.add_edges(list(zip(sources.tolist(), targets.tolist())))
g.es['weight'] = weights.tolist()
if g.vcount() != n_vertices:
print('WARNING: The constructed graph has only '
+str(g.vcount())+' nodes. '
Expand Down Expand Up @@ -50,7 +50,8 @@ if __name__ == "__main__":
else np.load(args.initial_membership_file).tolist())
seed = args.seed

weights = np.array(the_graph.es['weight']).astype(np.float64).tolist()
#weights = np.array(the_graph.es['weight']).astype(np.float64).tolist()
weights = (np.array(the_graph.es['weight']).astype(np.float64)).tolist()

if (args.refine==False):
partition = leidenalg.find_partition(
Expand Down Expand Up @@ -78,21 +79,29 @@ if __name__ == "__main__":
#Github issue discussing things is here: https://github.com/vtraag/leidenalg/issues/61
#move_nodes is what is used in the original louvain
# (as per https://leidenalg.readthedocs.io/en/stable/advanced.html#optimiser)
#with move nodes
optimiser = leidenalg.Optimiser()
optimiser.set_rng_seed(seed)
optimiser.move_nodes_constrained(refined_partition_movenodes,
constraining_partition)
#merge nodes is used for the refinement step of Leiden

#Due to segfault bug, I'm not doing move nodes:
# https://github.com/vtraag/leidenalg/issues/68

##with move nodes
#optimiser = leidenalg.Optimiser()
#optimiser.set_rng_seed(seed)
#optimiser.move_nodes_constrained(refined_partition_movenodes,
# constraining_partition)

#with merge nodes
optimiser = leidenalg.Optimiser()
optimiser.set_rng_seed(seed)
optimiser.merge_nodes_constrained(refined_partition_mergenodes,
constraining_partition)
#take the partition with the best quality
partition = (refined_partition_movenodes if (
refined_partition_movenodes.quality() >
refined_partition_mergenodes.quality())
else refined_partition_mergenodes)
partition = refined_partition_mergenodes

##take the partition with the best quality
#partition = (refined_partition_movenodes if (
# refined_partition_movenodes.quality() >
# refined_partition_mergenodes.quality())
# else refined_partition_mergenodes)

quality = partition.quality()
print("########################")
Expand Down
2 changes: 1 addition & 1 deletion modisco/coordproducers.py
Expand Up @@ -630,7 +630,7 @@ def __call__(self, score_track, null_track, tnt_results=None):
val_transformer=precision_transformer)

else:
precision_transformer = tnt_results.precision_transformer
precision_transformer = tnt_results.val_transformer
(precisiontransformed_score_track,
precisiontransformed_bestwindowsizeidxs) =\
precision_transformer.transform_score_track(
Expand Down

0 comments on commit d3985db

Please sign in to comment.