Skip to main content
Sign in
Snippets Groups Projects
Commit 97941f7c authored by Mia_Le's avatar Mia_Le
Browse files

Speichern des Links und der HTML von nVenn hinzugefügt

parent c5e66c17
No related branches found
No related tags found
No related merge requests found
......@@ -15,6 +15,9 @@ class AlgorithmWrapper(object):
self.ppi_network = Graph()
self.seeds = list()
self.home_path = ''
def set_weight(self, weight):
self.weight = weight
def set_ppi_network(self, graph):
self.ppi_network = graph
......
......
......@@ -4,6 +4,7 @@ import shutil
from DiamondWrapper import DiamondWrapper
from DominoWrapper import DominoWrapper
from RobustWrapper import RobustWrapper
from HHotNetWrapper import HHotNetWrapper
import preprocess
import uuid
import cami_suite
......@@ -13,14 +14,21 @@ import webbrowser
def main(ppi_network, seeds, tools, tool_weights, consensus, evaluate,
output_dir, identifier, save_temps, visualize, save_image, force):
print('CAMI started')
ppi_graph = preprocess.csv2graph(ppi_network)
nof_tools = len(tools)
ppi_graph = preprocess.csv2graph(ppi_network, nof_tools=nof_tools)
seed_lst = preprocess.txt2lst(seeds)
if tool_weights == None:
tool_weights = nof_tools * [1]
initial_seedlst = seed_lst.copy()
# rename seeds with their corresponding indices in the ppi_graph
name2index = preprocess.name2index_dict(ppi_graph)
checked_seed_lst = [name2index[v] for v in seed_lst if v in name2index]
print('Created the PPI-network Graph and seed list.')
if len(checked_seed_lst) != len(seed_lst) and not force:
n = len(checked_seed_lst)
m = len(seed_lst)
if n != m and not force:
name = ppi_graph.vertex_properties["name"]
print(f'There are {abs(m-n)} seeds missing in the PPI network: ({set([name[cseed] for cseed in checked_seed_lst]).symmetric_difference(set(initial_seedlst))})')
choice = input('Continue? [y/n]')
if choice == 'y':
pass
......@@ -71,16 +79,21 @@ def main(ppi_network, seeds, tools, tool_weights, consensus, evaluate,
wrappers = {'diamond': DiamondWrapper(),
'domino': DominoWrapper(),
'robust': RobustWrapper() #,
# 'hotnet': HotnetWrapper()
'robust': RobustWrapper(),
'hotnet': HHotNetWrapper()
}
tool_wrappers = [wrappers[tool] for tool in tools]
for idx, tool in enumerate(tool_wrappers):
tool.set_weight(tool_weights[idx])
cami = cami_suite.cami(ppi_graph, seed_lst, tool_wrappers, output_dir, identifier, tmp_dir, home_path)
for tool in tool_wrappers:
cami.initialize_tool(tool)
cami.set_initial_seed_lst(initial_seedlst)
if consensus or (not consensus and not evaluate):
result_sets = cami.make_predictions()
cami.create_consensus(result_sets)
......@@ -124,15 +137,15 @@ if __name__ == "__main__":
parser.add_argument('-t', '--tools', nargs='+', action='store', default=["diamond", "domino", "robust"],
help="List of tools that the user wants to use for prediction.\n Available tools are:\n" + \
"domino\ndiamond\nrobust\hotnet\nThe default tools are: diamond, domino and robust.")
parser.add_argument('-w', '--tool_weights', nargs='+', action='store', default=[1,1,1],
parser.add_argument('-w', '--tool_weights', nargs='+', action='store', default=None,
help="List of weights for the tools. If you have [domino, diamond, robust] as list of tools and diamonds weight should be twice as high as the other tools type: 1 2 1")
parser.add_argument('-c', '--consensus', action='store_true', help="run only the consensus prediction part of cami")
parser.add_argument('-e', '--evaluate', action='store_true', help="run only the evaluation part of cami")
parser.add_argument('-o', '--output_dir', action='store', help="path to output directory")
parser.add_argument('-id', '--identifier', action='store', help="ID for the current excecution of cami. Defaults to a randomly generated ID")
parser.add_argument('-tmp', '--save_temps', action='store_true', help="keep all temporary files")
parser.add_argument('-v', '--visualize', action='store_true', help="Visualize results using Degradome, an external webtool")
parser.add_argument('-img', '--save_image', action='store_true', help="Save the venn diagram from the visualization as png.")
parser.add_argument('-v', '--visualize', action='store_true', help="Visualize results using Degradome, an external webtool. Please note that degradome can only be used for visualization with up to 5 tools.")
parser.add_argument('-img', '--save_image', action='store_true', help="Save the venn diagram from the visualization as png. (Only possible for up to 5 tools)")
parser.add_argument('-f', '--force', action='store_true', help="Ignore warnings and overwrite everything when excecuting CAMI.")
#TODO List with additional arguments if needed by certain tools
......@@ -146,8 +159,8 @@ if __name__ == "__main__":
# add name for implemented tools here:
implemented_tools = ["domino",
"diamond",
"robust" #,
#"hotnet"
"robust",
"hotnet"
]
if args['tools']:
for tool in args['tools']:
......
......
......@@ -59,6 +59,7 @@ class cami():
self.ppi_graph = ppi_graph
self.ppi_vertex2gene = self.ppi_graph.vertex_properties["name"]
self.ppi_gene2vertex = {self.ppi_vertex2gene[vertex]:vertex for vertex in self.ppi_graph.vertices()}
self.initial_seed_lst = None
self.seed_lst = seed_lst
self.tool_wrappers = tool_wrappers
self.output_dir = output_dir
......@@ -70,6 +71,9 @@ class cami():
self.code2toolname[0] = 'CAMI'
self.home_path = home_path
def set_initial_seed_lst(self, seedlst):
self.initial_seed_lst = seedlst
def initialize_tool(self, tool):
tool.set_ppi_network(self.ppi_graph)
tool.set_seeds(self.seed_lst)
......@@ -191,7 +195,7 @@ class cami():
# translate tool code to string
codes2tools = {vertex:[self.code2toolname[idx] for idx,code in enumerate(predicted_by[vertex]) if code == 1] for vertex in self.ppi_graph.vertices()}
for vertex in cami_vertices:
for vertex in cami_vlist:
print(f'{name[vertex]}\t{cami_scores[vertex]}\t{codes2tools[vertex]}')
# save the results in outputfiles
......@@ -200,7 +204,8 @@ class cami():
# save all predictions by all tools
with open(f'{self.output_dir}/all_predictions_{self.uid}.tsv', 'w') as outputfile:
outputfile.write(f'CAMI predictions with {len(self.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,'+
f'initially: {self.initial_seed_lst}\n')
outputfile.write(f'gene\tpredicted_by\tcami_score\tindex_in_graph\tdegree_in_graph\n')
all_vertices = cami_vertices.union(putative_vertices)
for vertex in all_vertices:
......@@ -208,18 +213,18 @@ class cami():
print(f'saved all predictions by the used tools in: {self.output_dir}/all_predictions_{self.uid}.tsv')
# save the predictions made by cami
with open(f'{self.output_dir}/CAMI_{self.uid}_output.tsv', 'w') as outputfile:
with open(f'{self.output_dir}/CAMI_output_{self.uid}.tsv', 'w') as outputfile:
outputfile.write('gene\tindex_in_graph\tcami_score\n')
for vertex in cami_vlist:
outputfile.write(f'{name[vertex]}\t{str(vertex)}\t{cami_scores[vertex]}\n')
print(f'saved cami output in: {self.output_dir}/CAMI_{self.uid}_output.tsv')
outputfile.write(f'{name[vertex]}\t{str(vertex)}\t{cami_scores[vertex]}\t{vertex.out_degree()}\n')
print(f'saved cami output in: {self.output_dir}/CAMI_output_{self.uid}.tsv')
# for visualization
# transform all vertex indices to their corresponding gene names in a result set
self.result_gene_sets['CAMI'] = cami_genes
for tool in result_sets:
self.result_gene_sets[tool.name] = set([name[vertex] for vertex in result_sets[tool]])
self.result_gene_sets['CAMI'] = cami_genes
def visualize(self):
"""Create Venn Diagrams via a external tool named degradome.
Sends a request via requests to the degradome server.
......@@ -232,6 +237,8 @@ class cami():
for tool in self.result_gene_sets
if len(self.result_gene_sets[tool])>0}
url = degradome.send_request(degradome_sets)
with open(f'{self.output_dir}/venn_link_{self.uid}.txt', 'w') as f:
f.write(url)
return url
# TODO: save the venn diagram images in an outputfolder
# TODO: Include seeds?
......@@ -245,5 +252,7 @@ class cami():
print('Cannot use degradome to create venn diagrams of 6 or more tools')
def download_diagram(self, url):
imagefile = f'{self.output_dir}/{self.uid}_vdiagram.png'
degradome.download_image(url, imagefile)
\ No newline at end of file
venn_name = f'{self.output_dir}/vdiagram_{self.uid}'
response = degradome.download_image(url, venn_name + '.png')
with open(f'{venn_name}.html', 'w') as r:
r.write(response.html.html)
\ No newline at end of file
......@@ -18,7 +18,7 @@ def send_request(sets=dict()):
'header': 'rawData'
}
print(f'Sending result sets to {url} to create Venn diagrams...')
r = requests.post(url, data=values, timeout=30)
r = requests.post(url, data=values)
if r.ok:
match = re.search(r'(<a href=\\")(http:\/\/degradome.*)(\\">)', r.text)
if match:
......@@ -37,13 +37,12 @@ def download_image(degradome_url, file):
from requests_html import HTMLSession
session = HTMLSession()
response = session.get(degradome_url)
response.html.render(timeout=20, sleep=5)
response.html.render(timeout=20, sleep=3)
link_list = response.html.absolute_links
session.close()
for link in link_list:
if 'data:image/png;' in link:
urllib.request.urlretrieve(link, file)
print(f'Venn diagram image saved under: {file}')
return
return response
print(f'Something went wrong. Could not automatically download the venn diagram. Please try it manually under: {degradome_url}')
session.close()
import graph_tool
from idna import InvalidCodepointContext
def csv2graph(inputfile, delimiter="\t"):
def csv2graph(inputfile, delimiter="\t", nof_tools = 4):
"""transforms a csv-file to a Graph() object
:param inputfile: inputfile in csv-format
......@@ -14,7 +14,8 @@ def csv2graph(inputfile, delimiter="\t"):
g = graph_tool.load_graph_from_csv(inputfile, skip_first=True,
csv_options={'delimiter': '\t', 'quotechar': '"'})
g.vertex_properties["cami_score"] = g.new_vertex_property("float", val=0.0)
g.vertex_properties["predicted_by"] = g.new_vertex_property("vector<int16_t>", val=[-1,-1,-1,-1,-1])
values = (nof_tools + 6) * [-1]
g.vertex_properties["predicted_by"] = g.new_vertex_property("vector<int16_t>", val=values)
return g
def txt2lst(seed_file):
......
......
DIAMOnD @ 24379748
Subproject commit 24379748c5ee34f477a968ba3f1c0b325ff0614f
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment