Skip to content

Commit

Permalink
updated sorting in recursive_alignement clusters
Browse files Browse the repository at this point in the history
  • Loading branch information
weiju committed Jul 1, 2024
1 parent 065b500 commit d266539
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
10 changes: 5 additions & 5 deletions miner/miner.py
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,7 @@ def remix(df,frequencyClusters):
minGenes = max(4,cut*len(cluster))
keepers = list(sliceDf.columns[np.where(sumSlice>=minGenes)[0]])
keepers = list(set(keepers)|set(cluster))
finalClusters.append(keepers)
finalClusters.append(sorted(keepers))
finalClusters.sort(key = lambda s: -len(s))
return finalClusters

Expand Down Expand Up @@ -951,7 +951,7 @@ def combineClusters(axes,clusters,threshold=0.925):
revisedClusters = {}
combinedKeys = decomposeDictionaryToLists(combineAxes)
for keyList in combinedKeys:
genes = list(set(np.hstack([clusters[i] for i in keyList])))
genes = sorted(set(np.hstack([clusters[i] for i in keyList])))
revisedClusters[len(revisedClusters)] = genes

return revisedClusters
Expand All @@ -966,8 +966,8 @@ def reconstruction(decomposedList,expressionData, random_state, threshold=0.925)

clusters = {i:decomposedList[i] for i in range(len(decomposedList))}
axes = get_axes(clusters, expressionData, random_state)
recombine = combineClusters(axes,clusters,threshold)
return recombine
return combineClusters(axes,clusters,threshold)


def recursive_alignment(geneset,expressionData,minNumberGenes=6,
pct_threshold=80, random_state=12):
Expand All @@ -976,7 +976,7 @@ def recursive_alignment(geneset,expressionData,minNumberGenes=6,
return []

reconstructed = reconstruction(recDecomp,expressionData, random_state)
reconstructedList = [reconstructed[i] for i in list(reconstructed.keys()) if len(reconstructed[i])>minNumberGenes]
reconstructedList = [reconstructed[i] for i in list(reconstructed.keys()) if len(reconstructed[i]) > minNumberGenes]
reconstructedList.sort(key = lambda s: -len(s))
return reconstructedList

Expand Down
4 changes: 3 additions & 1 deletion test/mechinf_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ def test_recursive_alignment():
ref_recalign.append(line.strip().split(" "))

rec_align = miner.recursive_alignment(cluster, exp, 6, 80)
assert(ref_recalign == rec_align)
#with open("ref_recalign.txt", "w") as outfile:
# outfile.write("%s" % ' '.join(sorted(rec_align[0])))
assert(ref_recalign[0] == rec_align[0])


def test_revise_initial_clusters():
Expand Down
2 changes: 1 addition & 1 deletion testdata/ref_recalign.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ENSG00000006756 ENSG00000040487 ENSG00000101605 ENSG00000175556 ENSG00000179820 ENSG00000198799 ENSG00000166484 ENSG00000019995 ENSG00000092148
ENSG00000006756 ENSG00000019995 ENSG00000040487 ENSG00000092148 ENSG00000101605 ENSG00000166484 ENSG00000175556 ENSG00000179820 ENSG00000198799

0 comments on commit d266539

Please sign in to comment.