Skip to content
Snippets Groups Projects
Commit 277c98ff authored by bay9355's avatar bay9355
Browse files
parents dca69284 18ad0877
No related branches found
No related tags found
No related merge requests found
...@@ -181,9 +181,9 @@ class cami(): ...@@ -181,9 +181,9 @@ class cami():
:rtype: set() :rtype: set()
""" """
tool.create_tmp_output_dir(self.tmp_dir) # creates the temporary input directory tool.create_tmp_output_dir(self.tmp_dir) # creates the temporary input directory
print(f"preparing {tool.name} input...") if self.debug: print(f"preparing {tool.name} input...")
inputparams = tool.prepare_input() inputparams = tool.prepare_input()
print(f'running {tool.name}...') if self.debug: print(f'running {tool.name}...')
preds = set(tool.run_algorithm(inputparams)) preds = set(tool.run_algorithm(inputparams))
if self.debug: if self.debug:
print(f'{tool.name} predicted {len(preds)} active vertices (seeds not excluded):') print(f'{tool.name} predicted {len(preds)} active vertices (seeds not excluded):')
...@@ -225,6 +225,7 @@ class cami(): ...@@ -225,6 +225,7 @@ class cami():
to the corresponding tool to the corresponding tool
:rtype: dict(AlgorithmWrapper():set(Graph.vertex())) :rtype: dict(AlgorithmWrapper():set(Graph.vertex()))
""" """
if self.debug:
print(f'Creating result sets of all {self.nof_tools} tools...') print(f'Creating result sets of all {self.nof_tools} tools...')
pred_sets = {tool:None for tool in self.tool_wrappers} pred_sets = {tool:None for tool in self.tool_wrappers}
...@@ -338,10 +339,16 @@ class cami(): ...@@ -338,10 +339,16 @@ class cami():
}}, }},
} }
# transform all vertex indices to their corresponding gene names in a result set
for tool in result_sets:
self.result_gene_sets[tool.name] = set([gene_name_map[vertex] for vertex in result_sets[tool]])
# create integer codes for cami_versions (needed for predicted_by vertex property) # create integer codes for cami_versions (needed for predicted_by vertex property)
recursion_limit = sys.getrecursionlimit() recursion_limit = sys.getrecursionlimit()
for cami_method_name, cami_params in camis.items(): for cami_method_name, cami_params in camis.items():
if self.debug:
print("Running " + cami_method_name) print("Running " + cami_method_name)
# create integer codes for cami_versions (needed for predicted_by vertex property)
tool_code = max(list(tool_name_map.keys())) + 1 tool_code = max(list(tool_name_map.keys())) + 1
tool_name_map[tool_code] = cami_method_name tool_name_map[tool_code] = cami_method_name
...@@ -349,7 +356,6 @@ class cami(): ...@@ -349,7 +356,6 @@ class cami():
predicted_by, cami_scores, predicted_by, cami_scores,
tool_name_map, tool_code, tool_name_map, tool_code,
cami_params['params']) cami_params['params'])
# sort the resulting vertices according to their cami_score # sort the resulting vertices according to their cami_score
cami_vlist = sorted(cami_vertices, key=lambda v: cami_scores[v], reverse=True) cami_vlist = sorted(cami_vertices, key=lambda v: cami_scores[v], reverse=True)
...@@ -363,30 +369,30 @@ class cami(): ...@@ -363,30 +369,30 @@ class cami():
for vertex in cami_vlist: for vertex in cami_vlist:
print(f'{gene_name_map[vertex]}\t{cami_scores[vertex]}\t{codes2tools[vertex]}') print(f'{gene_name_map[vertex]}\t{cami_scores[vertex]}\t{codes2tools[vertex]}')
else: else:
print(f'With the {len(seed_genes)} seed genes CAMI ({cami_method_name}) proposes {len(cami_vlist)} to add to the Active Module') print(f'With the {len(seed_genes)} seed genes CAMI ({cami_method_name}) proposes {len(cami_vlist)} genes to add to the Active Module')
# for visualization with nvenn # for visualization with nvenn
self.result_gene_sets[cami_method_name] = cami_genes self.result_gene_sets[cami_method_name] = set(cami_genes)
# transform all vertex indices to their corresponding gene names in a result set # transform all vertex indices to their corresponding gene names in a result set
for tool in result_sets: for tool in result_sets:
self.result_gene_sets[tool.name] = set([gene_name_map[vertex] for vertex in result_sets[tool]]) self.result_gene_sets[tool.name] = set([gene_name_map[vertex] for vertex in result_sets[tool]])
# add seeds to result sets for drugstone and digest # add seeds to result sets for drugstone and digest
for tool in result_sets: for toolname in self.result_gene_sets:
self.result_module_sets[tool.name] = set(gene_name_map[vertex] for vertex in set(result_sets[tool]).union(self.seed_lst)) self.result_module_sets[toolname] = self.result_gene_sets[toolname].union(set([gene_name_map[svertex] for svertex in self.seed_lst]))
print(f'With the {len(seed_genes)} seed genes CAMI ({cami_method_name}) proposes {len(cami_vlist)} to add to the Active Module')
assert(self.code2toolname == tool_name_map)
sys.setrecursionlimit(recursion_limit) sys.setrecursionlimit(recursion_limit)
# save the results in outputfiles # save the results in outputfiles
self.generate_output(cami_method_name, seed_genes, cami_vlist, cami_vertices, putative_vertices, cami_genes, self.generate_output(cami_method_name, seed_genes, cami_vlist, cami_vertices, putative_vertices, cami_genes,
gene_name_map, codes2tools, cami_scores) gene_name_map, codes2tools, cami_scores)
def generate_output(self, cami_method, seed_genes, cami_vlist, cami_vertices, putative_vertices, cami_genes, def generate_output(self, cami_method, seed_genes, cami_vlist, cami_vertices, putative_vertices, cami_genes,
gene_name_map, codes2tools, cami_scores): gene_name_map, codes2tools, cami_scores):
# save all predictions by all tools # save all predictions by all tools
if self.debug:
print('Saving the results...') print('Saving the results...')
with open(f'{self.output_dir}/all_predictions_{self.uid}.tsv', 'w') as outputfile: with open(f'{self.output_dir}/all_predictions_{self.uid}.tsv', 'w') as outputfile:
outputfile.write(f'CAMI predictions with {len(self.seed_lst)} of initially {len(self.initial_seed_lst)} seeds: {seed_genes},\n'+ outputfile.write(f'CAMI predictions with {len(self.seed_lst)} of initially {len(self.initial_seed_lst)} seeds: {seed_genes},\n'+
...@@ -401,7 +407,7 @@ class cami(): ...@@ -401,7 +407,7 @@ class cami():
ncbi_url = ('\tncbi_url' if self.ncbi else '') ncbi_url = ('\tncbi_url' if self.ncbi else '')
ncbi_summary = ('\tncbi_summary' if self.ncbi else '') ncbi_summary = ('\tncbi_summary' if self.ncbi else '')
with open(f'{self.output_dir}/CAMI_output_{self.uid}.tsv', 'w') as outputfile: with open(f'{self.output_dir}/{cami_method}_output_{self.uid}.tsv', 'w') as outputfile:
outputfile.write(f'gene\tindex_in_graph\tcami_score\tdegree_in_graph{ncbi_url}{ncbi_summary}\n') outputfile.write(f'gene\tindex_in_graph\tcami_score\tdegree_in_graph{ncbi_url}{ncbi_summary}\n')
for vertex in cami_vlist: for vertex in cami_vlist:
if self.ncbi: if self.ncbi:
...@@ -415,33 +421,29 @@ class cami(): ...@@ -415,33 +421,29 @@ class cami():
url, summary = '','' url, summary = '',''
outputfile.write(f'{gene_name_map[vertex]}\t{str(vertex)}\t{cami_scores[vertex]}\t{vertex.out_degree()}{url}{summary}\n') outputfile.write(f'{gene_name_map[vertex]}\t{str(vertex)}\t{cami_scores[vertex]}\t{vertex.out_degree()}{url}{summary}\n')
# save the whole module # # save the whole module
whole_module = [] # whole_module = []
with open(f'{self.output_dir}/CAMI_module_{cami_method}_{self.uid}.txt', 'w') as modfile: # with open(f'{self.output_dir}/{cami_method}_module_{self.uid}.txt', 'w') as modfile:
for vertex in seed_genes: # for vertex in seed_genes:
modfile.write(f'{vertex}\n') # modfile.write(f'{vertex}\n')
whole_module.append(vertex) # whole_module.append(vertex)
for vertex in cami_genes: # for vertex in cami_genes:
modfile.write(f'{vertex}\n') # modfile.write(f'{vertex}\n')
whole_module.append(vertex) # whole_module.append(vertex)
print(f'saved cami output in: {self.output_dir}/CAMI_output_{self.uid}.tsv') # print(f'saved {cami_method} output in: {cami_method}_output_{self.uid}.tsv')
print(f'saved the Consensus Active Module by CAMI in: {self.output_dir}/CAMI_nodes_{cami_method}_{self.uid}.txt') # print(f'saved the Consensus Active Module by CAMI in: {self.output_dir}/{cami_method}_module_{self.uid}.txt')
# save predictions by the other tools # save predicted modules by all other tools
for tool in self.result_gene_sets: for tool in self.result_module_sets:
with open(f'{self.output_dir}/{tool}_output_{self.uid}.tsv', 'w') as outputfile: with open(f'{self.output_dir}/{tool}_output_{self.uid}.tsv', 'w') as outputfile:
outputfile.write('gene\n') outputfile.write('gene\n')
for gene in self.result_gene_sets[tool]: for gene in self.result_gene_sets[tool]:
outputfile.write(f'{gene}\n') outputfile.write(f'{gene}\n')
if self.debug:
print(f'saved {tool} output in: {self.output_dir}/{tool}_output_{self.uid}.tsv') print(f'saved {tool} output in: {self.output_dir}/{tool}_output_{self.uid}.tsv')
# return values
consensus = {}
consensus['module'] = whole_module
consensus['seeds'] = self.seed_lst
def use_nvenn(self): def use_nvenn(self):
"""Create Venn Diagrams via a external tool named degradome. """Create Venn Diagrams via a external tool named degradome.
...@@ -489,7 +491,6 @@ class cami(): ...@@ -489,7 +491,6 @@ class cami():
#print(list(set(cami_symbol_edges))) #print(list(set(cami_symbol_edges)))
url = drugstone.send_request(cami_symbols, cami_symbol_edges) url = drugstone.send_request(cami_symbols, cami_symbol_edges)
print(f'You can find a network visualization of the CAMI module via: {url}') print(f'You can find a network visualization of the CAMI module via: {url}')
print('The link was also saved in the outputfolder for later.')
with open(f'{self.output_dir}/drugstone_link_{self.uid}.txt', 'w') as f: with open(f'{self.output_dir}/drugstone_link_{self.uid}.txt', 'w') as f:
f.write(url) f.write(url)
return url return url
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment