Skip to content
Snippets Groups Projects
Commit 0ca1b12c authored by mlmial's avatar mlmial
Browse files

edited seed variation plots

parent c86cfaf6
No related branches found
No related tags found
No related merge requests found
...@@ -52,15 +52,13 @@ def make_seedvariation(cami, n_iterations, removal_frac=0.2, vis=False, plot=Tru ...@@ -52,15 +52,13 @@ def make_seedvariation(cami, n_iterations, removal_frac=0.2, vis=False, plot=Tru
for tool in prediction_tools: for tool in prediction_tools:
res_table.write(f'\t{tool}_msr_ks_pvalue') res_table.write(f'\t{tool}_msr_ks_pvalue')
# if relevance scores file exsits: # with open(os.path.join(cami.tmp_dir, f'{used_tools[0]}_{cami.uid}_relevance_scores.tsv'), 'r') as f:
if os.path.exists(os.path.join(cami.tmp_dir, f'{used_tools[0]}_{identifier}_relevance_scores.tsv)')): # for line in f:
with open(os.path.join(cami.tmp_dir, f'{used_tools[0]}_{identifier}_relevance_scores.tsv)'), 'r') as f: # val_name = line.split('\t')[0]
for line in f: # res_table.write(f'\t{val_name}')
val_name = line.split('\t')[0]
redisc_table.write(f'\t{val_name}')
res_table.write('\n') res_table.write('\n')
# result dictionaries of the form {tool:list(value for each iteration)}
#result dictionaries of the form {tool:list(value for each iteration)}
tp_rate_dict = {k:list() for k in used_tools} tp_rate_dict = {k:list() for k in used_tools}
redisc_rate_dict = {k:list() for k in used_tools} redisc_rate_dict = {k:list() for k in used_tools}
module_size_dict = {k:list() for k in used_tools} module_size_dict = {k:list() for k in used_tools}
...@@ -89,10 +87,6 @@ def make_seedvariation(cami, n_iterations, removal_frac=0.2, vis=False, plot=Tru ...@@ -89,10 +87,6 @@ def make_seedvariation(cami, n_iterations, removal_frac=0.2, vis=False, plot=Tru
# reinitialize tools # reinitialize tools
cami.initialize_all_tools() cami.initialize_all_tools()
# repeat consensus
if ident%20==0:
predict_and_make_consensus(cami)
else:
predict_and_make_consensus(cami) predict_and_make_consensus(cami)
used_seeds = [cami.ppi_vertex2gene[seed] for seed in cami.seed_lst] used_seeds = [cami.ppi_vertex2gene[seed] for seed in cami.seed_lst]
...@@ -143,11 +137,11 @@ def make_seedvariation(cami, n_iterations, removal_frac=0.2, vis=False, plot=Tru ...@@ -143,11 +137,11 @@ def make_seedvariation(cami, n_iterations, removal_frac=0.2, vis=False, plot=Tru
p_val = kolmogorov_smirnoff.calculate_ks_p_value(list(module_size_dict[tool]), p_val = kolmogorov_smirnoff.calculate_ks_p_value(list(module_size_dict[tool]),
list(module_size_dict[pred_tool])) list(module_size_dict[pred_tool]))
res_table.write(f'\t{p_val}') res_table.write(f'\t{p_val}')
if os.path.exists(os.path.join(cami.tmp_dir, f'{used_tools[0]}_{identifier}_relevance_scores.tsv)')):
with open(os.path.join(cami.tmp_dir, f'{tool}_{identifier}_relevance_scores.tsv'), 'r') as f: #with open(os.path.join(cami.tmp_dir, f'{tool}_{identifier}_relevance_scores.tsv'), 'r') as f:
for line in f: # for line in f:
rel_score = line.split('\t')[1].strip() # rel_score = line.split('\t')[1].strip()
res_table.write(f'\t{rel_score}') # res_table.write(f'\t{rel_score}')
res_table.write('\n') res_table.write('\n')
print(f'Result tables are saved in the following locations:') print(f'Result tables are saved in the following locations:')
...@@ -168,12 +162,13 @@ def make_seedvariation(cami, n_iterations, removal_frac=0.2, vis=False, plot=Tru ...@@ -168,12 +162,13 @@ def make_seedvariation(cami, n_iterations, removal_frac=0.2, vis=False, plot=Tru
if second_occurrence_index > -1: if second_occurrence_index > -1:
# replace the character at that index with the replacement character # replace the character at that index with the replacement character
tool_name = tool[:second_occurrence_index] + '\n' + tool[second_occurrence_index + 1:] tool_name = tool[:second_occurrence_index] + '\n' + tool[second_occurrence_index + 1:]
tool_name = tool_name.replace('_hub_penalty', '').replace('damping_factor', 'df').replace('confidence_level', 'cl').replace('ranking_trustrank', 'tr')
tool_labels[idx] = tool_name tool_labels[idx] = tool_name
if plot: if plot:
#PLOT #PLOT
# Create a figure instance # Create a figure instance
#print(sys.getrecursionlimit()) #print(sys.getrecursionlimit())
fig1, (ax1, ax5, ax4) = plt.subplots(3, 1, figsize=(20,20)) fig1, (ax1, ax5) = plt.subplots(2, 1, figsize=(12,12))
fig1.subplots_adjust(left=0.2) fig1.subplots_adjust(left=0.2)
# Extract Figure and Axes instance # Extract Figure and Axes instance
...@@ -186,7 +181,7 @@ def make_seedvariation(cami, n_iterations, removal_frac=0.2, vis=False, plot=Tru ...@@ -186,7 +181,7 @@ def make_seedvariation(cami, n_iterations, removal_frac=0.2, vis=False, plot=Tru
for violin, tool in zip(violins1['bodies'], tools): for violin, tool in zip(violins1['bodies'], tools):
if tool in [tw.name for tw in cami.tool_wrappers]: if tool in [tw.name for tw in cami.tool_wrappers]:
violin.set_facecolor('saddlebrown') violin.set_facecolor('saddlebrown')
elif tool == 'first_neighbors': elif tool == 'first_neighbours':
violin.set_facecolor('orange') violin.set_facecolor('orange')
elif tool in ['union', 'intersection']: elif tool in ['union', 'intersection']:
violin.set_facecolor('peachpuff') violin.set_facecolor('peachpuff')
...@@ -194,7 +189,7 @@ def make_seedvariation(cami, n_iterations, removal_frac=0.2, vis=False, plot=Tru ...@@ -194,7 +189,7 @@ def make_seedvariation(cami, n_iterations, removal_frac=0.2, vis=False, plot=Tru
violin.set_facecolor('red') violin.set_facecolor('red')
# Add title # Add title
ax1.set_title(f'Rediscovery rate after randomly removing {nof_removals} seeds {nof_iterations} times from {identifier} seeds.', wrap=True, fontsize=14) ax1.set_title(f'Rediscovery rate after randomly removing {nof_removals} seeds {nof_iterations} times\nfrom {identifier} seeds.', wrap=True, fontsize=14)
ax1.set_xticks(list(range(1,len(tools)+1))) ax1.set_xticks(list(range(1,len(tools)+1)))
ax1.set_xticklabels(tool_labels) ax1.set_xticklabels(tool_labels)
...@@ -202,26 +197,26 @@ def make_seedvariation(cami, n_iterations, removal_frac=0.2, vis=False, plot=Tru ...@@ -202,26 +197,26 @@ def make_seedvariation(cami, n_iterations, removal_frac=0.2, vis=False, plot=Tru
ax1.set_ylabel('Rediscovery rate (<rediscovered seeds>/<removed seeds>)', wrap=True, fontsize=14) ax1.set_ylabel('Rediscovery rate (<rediscovered seeds>/<removed seeds>)', wrap=True, fontsize=14)
violins2 = ax4.violinplot([tp_rate_dict[tool] for tool in tools], showmeans=True, showextrema=True) # violins2 = ax4.violinplot([tp_rate_dict[tool] for tool in tools], showmeans=True, showextrema=True)
for violinpart in list(violins2.keys())[2:]: # for violinpart in list(violins2.keys())[2:]:
violins2[violinpart].set_color('k') # violins2[violinpart].set_color('k')
for violin, tool in zip(violins2['bodies'], tools): # for violin, tool in zip(violins2['bodies'], tools):
if tool in [tw.name for tw in cami.tool_wrappers]: # if tool in [tw.name for tw in cami.tool_wrappers]:
violin.set_facecolor('tan') # violin.set_facecolor('tan')
elif tool == 'first_neighbors': # elif tool == 'first_neighbors':
violin.set_facecolor('peachpuff') # violin.set_facecolor('peachpuff')
elif tool in ['union', 'intersection']: # elif tool in ['union', 'intersection']:
violin.set_facecolor('orange') # violin.set_facecolor('orange')
else: # else:
violin.set_facecolor('darkorange') # violin.set_facecolor('darkorange')
# Add title # # Add title
ax4.set_title(f'True positive rates after randomly removing {nof_removals} seeds {nof_iterations} times from {identifier} seeds.', wrap=True, fontsize=14) # ax4.set_title(f'True positive rates after randomly removing {nof_removals} seeds {nof_iterations} times from {identifier} seeds.', wrap=True, fontsize=14)
ax4.set_xticks(list(range(1,len(tools)+1))) # ax4.set_xticks(list(range(1,len(tools)+1)))
ax4.set_xticklabels(tool_labels) # ax4.set_xticklabels(tool_labels)
ax4.tick_params(axis='x', labelsize=11) # ax4.tick_params(axis='x', labelsize=11)
ax4.set_ylabel('Sensitivity (TP/TP + FN)', wrap=True, fontsize=14) # ax4.set_ylabel('Sensitivity (TP/TP + FN)', wrap=True, fontsize=14)
violins3 = ax5.violinplot([module_size_dict[tool] for tool in tools], showmeans=True, showextrema=True) violins3 = ax5.violinplot([module_size_dict[tool] for tool in tools], showmeans=True, showextrema=True)
# Add title # Add title
...@@ -231,14 +226,14 @@ def make_seedvariation(cami, n_iterations, removal_frac=0.2, vis=False, plot=Tru ...@@ -231,14 +226,14 @@ def make_seedvariation(cami, n_iterations, removal_frac=0.2, vis=False, plot=Tru
for violin, tool in zip(violins3['bodies'], tools): for violin, tool in zip(violins3['bodies'], tools):
if tool in [tw.name for tw in cami.tool_wrappers]: if tool in [tw.name for tw in cami.tool_wrappers]:
violin.set_facecolor('midnightblue') violin.set_facecolor('midnightblue')
elif tool == 'first_neighbors': elif tool == 'first_neighbours':
violin.set_facecolor('mediumblue') violin.set_facecolor('mediumblue')
elif tool in ['union', 'intersection']: elif tool in ['union', 'intersection']:
violin.set_facecolor('lightsteelblue') violin.set_facecolor('lightsteelblue')
else: else:
violin.set_facecolor('royalblue') violin.set_facecolor('royalblue')
ax5.set_title(f'Ratio of number of rediscovered seeds and predicted module size after removing {nof_removals} seeds {nof_iterations} times from {identifier} seeds.', wrap=True, fontsize=14) ax5.set_title(f'Rediscovery module size ratio after removing {nof_removals} seeds {nof_iterations} times\nfrom {identifier} seeds.', wrap=True, fontsize=14)
ax5.set_xticks(list(range(1,len(tools)+1))) ax5.set_xticks(list(range(1,len(tools)+1)))
ax5.set_xticklabels(tool_labels) ax5.set_xticklabels(tool_labels)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment