Skip to content

Commit

Permalink
should be cartesian product instead of combination (#312)
Browse files Browse the repository at this point in the history
* should be cartesian product

* Update _tools.py

* Update _plotting.py

* Update _plotting.py

* Update 4_dandelion_visualization-10x_data.ipynb
  • Loading branch information
zktuong committed Sep 12, 2023
1 parent 0471248 commit b0a094c
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 91 deletions.
21 changes: 13 additions & 8 deletions dandelion/plotting/_plotting.py
Expand Up @@ -6,7 +6,7 @@
import seaborn as sns

from anndata import AnnData
from itertools import combinations, cycle
from itertools import product, cycle
from matplotlib.axes import Axes
from matplotlib.figure import Figure
import networkx as nx
Expand Down Expand Up @@ -929,23 +929,24 @@ def clone_overlap(
edges[x] = [
y + ({str(clone_): x},)
for y in list(
combinations(
product(
[
i
for i in overlap.loc[x][
overlap.loc[x] > 0
].index
],
2,
repeat=2,
)
)
]
else:
tmp_overlap = overlap.astype(bool).sum(axis=1)
combis = {
x: list(
combinations(
[i for i in overlap.loc[x][overlap.loc[x] > 0].index], 2
product(
[i for i in overlap.loc[x][overlap.loc[x] > 0].index],
repeat=2,
)
)
for x in tmp_overlap.index
Expand All @@ -972,18 +973,20 @@ def clone_overlap(
+ (
{
str(clone_): x,
"weight": tmp_edge_weight_dict[y],
"weight": tmp_edge_weight_dict[y]
if not isinstance(tmp_edge_weight_dict[y], list)
else 0,
},
)
for y in list(
combinations(
product(
[
i
for i in overlap.loc[x][
overlap.loc[x] > 0
].index
],
2,
repeat=2,
)
)
]
Expand Down Expand Up @@ -1064,6 +1067,8 @@ def clone_overlap(
if return_heatmap_data:
return hm
else:
# remove self loops
G.remove_edges_from(nx.selfloop_edges(G))
ax = nxv.circos(
G,
group_by=colorby,
Expand Down
8 changes: 4 additions & 4 deletions dandelion/tools/_tools.py
Expand Up @@ -13,7 +13,7 @@
from changeo.Gene import getGene
from collections import defaultdict, Counter
from distance import hamming
from itertools import combinations
from itertools import product
from scanpy import logging as logg
from scipy.sparse import csr_matrix
from scipy.spatial.distance import pdist, squareform
Expand Down Expand Up @@ -1675,19 +1675,19 @@ def clustering(distance_dict, threshold, sequences_dict):
(i1, i2): distance_dict[(i1, i2)] <= threshold
if (i1, i2) in distance_dict
else False
for i1, i2 in combinations(i_unique, 2)
for i1, i2 in product(i_unique, repeat=2)
}
i_pair_d.update(
{
(i2, i1): distance_dict[(i2, i1)] <= threshold
if (i2, i1) in distance_dict
else False
for i1, i2 in combinations(i_unique, 2)
for i1, i2 in product(i_unique, repeat=2)
}
)
# so which indices should not be part of a clone?
canbetogether = defaultdict(list)
for ii1, ii2 in combinations(i_unique, 2):
for ii1, ii2 in product(i_unique, repeat=2):
if i_pair_d[(ii1, ii2)] or i_pair_d[(ii2, ii1)]:
if (ii1, ii2) in distance_dict:
canbetogether[ii1].append((ii1, ii2))
Expand Down
147 changes: 68 additions & 79 deletions docs/notebooks/4_dandelion_visualization-10x_data.ipynb

Large diffs are not rendered by default.

0 comments on commit b0a094c

Please sign in to comment.