Skip to content

Commit

Permalink
scenicplus works
Browse files Browse the repository at this point in the history
  • Loading branch information
janursa committed Oct 4, 2024
1 parent 4097e24 commit 885a27d
Show file tree
Hide file tree
Showing 13 changed files with 2,959 additions and 1,414 deletions.
1,247 changes: 1,247 additions & 0 deletions api_examples.ipynb

Large diffs are not rendered by default.

1,386 changes: 784 additions & 602 deletions runs.ipynb

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions src/control_methods/pearson/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
parser.add_argument('--tf_all', type=str, help='Path to the tf_all')
parser.add_argument('--num_workers', type=str, help='Number of cores')
parser.add_argument('--no_tf_subsetting', action='store_true', default=False, help='Whether to subset based on tf')
parser.add_argument('--max_n_links', type=str, help='Number of top links to retain')
parser.add_argument('--corr_t', type=str, help='Threshold cuttoff for correlation.')
parser.add_argument('--layer', type=str, help='Which layer of adata to use.')


args = parser.parse_args()

Expand All @@ -35,6 +39,12 @@
par['num_workers'] = args.num_workers
if args.no_tf_subsetting:
par['no_tf_subsetting'] = args.no_tf_subsetting
if args.max_n_links:
par['max_n_links'] = int(args.max_n_links)
if args.corr_t:
par['corr_t'] = float(args.corr_t)
if args.layer:
par['layer'] = args.layer

if args.resources_dir:
meta['resources_dir'] = args.resources_dir
Expand Down
34 changes: 20 additions & 14 deletions src/exp_analysis/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def calculate_feature_distance(sample: pd.DataFrame, control: pd.DataFrame, top_

distance_df = pd.DataFrame({'distance_raw':distance_raw, 'distance_rank':distance_rank}, index=entries_common)
return distance_df
def cosine_similarity(nets_dict, col_name='source', weight_col='weight', figsize=(4, 4)):
def cosine_similarity(nets_dict, col_name='source', weight_col='weight', figsize=(4, 4), title='Cosine Similarity', ax=None):
from itertools import combinations
from sklearn.metrics.pairwise import cosine_similarity
import seaborn as sns
Expand Down Expand Up @@ -91,20 +91,22 @@ def cosine_similarity(nets_dict, col_name='source', weight_col='weight', figsize
for j in range(cosine_sim_matrix.shape[1]):
if i==j:
cosine_sim_matrix[i,j]=np.NaN

# 5. Visualize the Cosine Similarity matrix as a heatmap
fig, ax = plt.subplots(1, 1, figsize=figsize)
if ax is None:
# 5. Visualize the Cosine Similarity matrix as a heatmap
fig, ax = plt.subplots(1, 1, figsize=figsize)
else:
fig = None

sns.heatmap(cosine_sim_matrix, annot=True, cmap="coolwarm", xticklabels=nets_names, yticklabels=nets_names, ax=ax)
ax.grid(True)
ax.set_title('Cosine Similarity')
ax.grid(False)
ax.set_title(title)

# Rotate x labels for readability
plt.xticks(rotation=45, ha='right')

return cosine_sim_matrix, fig

def jaccard_similarity(nets_dict, col_name='link', figsize=(4, 4)):
def jaccard_similarity(nets_dict, col_name='link', figsize=(4, 4), title='jaccard Similarity', ax=None):
from itertools import combinations
import seaborn as sns
import matplotlib.pyplot as plt
Expand Down Expand Up @@ -132,10 +134,13 @@ def jaccard_similarity(nets_dict, col_name='link', figsize=(4, 4)):
# Fill diagonal with 1s (as similarity of a network with itself is 1)
np.fill_diagonal(jaccard_matrix, np.NaN)
# 4. Visualize the Jaccard matrix as a heatmap
fig, ax = plt.subplots(1, 1, figsize=figsize)
if ax is None:
fig, ax = plt.subplots(1, 1, figsize=figsize)
else:
fig = None
sns.heatmap(jaccard_matrix, annot=True, cmap="coolwarm", xticklabels=nets_names, yticklabels=nets_names, ax=ax)
ax.grid(True)
ax.set_title('Jaccard Similarity')
ax.grid(False)
ax.set_title(title)
# Rotate x labels for readability
plt.xticks(rotation=45, ha='right')

Expand Down Expand Up @@ -225,7 +230,7 @@ class Exp_analysis:
'''
def __init__(self, net, peak_gene_net=None):
self.net = net
self.net.weight = minmax_scale(self.net.weight)
# self.net.weight = minmax_scale(self.net.weight)
self.net['link'] = self.net['source'].astype(str) + '_' + self.net['target'].astype(str)

self.peak_gene_net = peak_gene_net
Expand Down Expand Up @@ -354,7 +359,7 @@ def plot_interactions(interaction_df: pd.DataFrame, min_subset_size=None, min_de
out_dict = upsetplot.plot(upsetplot.from_indicators(indicators=lambda a: a==True, data=interaction_df), fig=fig,
show_counts=True,
show_percentages = '{:.0%}',
sort_by='cardinality',
# sort_by='cardinality',
# min_subset_size =".1%", # min interaction to show
min_subset_size = min_subset_size, # min interaction to show
min_degree=min_degree,
Expand All @@ -372,9 +377,10 @@ def plot_interactions(interaction_df: pd.DataFrame, min_subset_size=None, min_de
methods_order = [label.get_text() for label in matrix_ax.get_yticklabels()]
# methods_order.reverse()
print(methods_order)
colors = colors_blind+colors_blind
for i_bar, bar in enumerate(totals_ax.patches):
if color_map is None:
bar.set_facecolor(colors_blind[i_bar])
bar.set_facecolor(colors[i_bar])
else:
bar.set_facecolor(color_map[methods_order[i_bar]])
bar.set_edgecolor('white')
Expand All @@ -384,7 +390,7 @@ def plot_interactions(interaction_df: pd.DataFrame, min_subset_size=None, min_de
bar.set_edgecolor('black')
bar.set_linewidth(.4)

for bar, new_color in zip(shading_ax.patches, colors_blind):
for bar, new_color in zip(shading_ax.patches, colors):
bar.set_facecolor(new_color)
bar.set_alpha(.1)
bar.set_edgecolor('black')
Expand Down
2 changes: 1 addition & 1 deletion src/methods/multi_omics/figr/script.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ par <- list(
multiomics_rna_r = "resources_test/grn-benchmark/multiomics_rna.rds",
multiomics_atac_r = "resources_test/grn-benchmark/multiomics_atac.rds",
temp_dir = "output/figr/",
cell_topic = "resources_test/prior/cell_topic.csv",
cell_topic = "resources/prior/cell_topic_d0_hvg.csv",
num_workers = 2,
n_topics = 48,
peak_gene = "output/figr/peak_gene.csv",
Expand Down
1 change: 1 addition & 0 deletions src/methods/multi_omics/scenicplus/config.vsh.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ functionality:
resources:
- type: python_script
path: script.py
- path: main.py

platforms:
- type: docker
Expand Down
Loading

0 comments on commit 885a27d

Please sign in to comment.