Mercurial > repos > immport-devteam > profile_cl
annotate profileCLs.py @ 1:62d8985a41e2 draft default tip
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
author | azomics |
---|---|
date | Thu, 23 Jul 2020 08:58:29 -0400 |
parents | |
children |
rev | line source |
---|---|
1
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
1 #!/usr/bin/env python |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
2 |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
3 ###################################################################### |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
4 # Copyright (c) 2016 Northrop Grumman. |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
5 # All rights reserved. |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
6 ###################################################################### |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
7 import sys |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
8 import os |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
9 from argparse import ArgumentParser |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
10 from jinja2 import Environment, FileSystemLoader |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
11 |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
12 profile_key = { |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
13 "1": "-", |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
14 "2": "lo", |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
15 "3": "+", |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
16 "4": "hi" |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
17 } |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
18 |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
19 |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
20 def run_flowCL(phenotype, output_txt, output_pdf, tool): |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
21 run_command = " ". join(["Rscript --slave --vanilla", tool, output_txt, phenotype]) |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
22 os.system(run_command) |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
23 get_graph = " ".join(["mv flowCL_results/*.pdf", output_pdf]) |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
24 os.system(get_graph) |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
25 return |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
26 |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
27 |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
28 def generate_flowCL_query(list_markers, list_types): |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
29 if (len(list_markers) != len(list_types)): |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
30 return("pb with headers") |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
31 query = [] |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
32 # go through both lists, remove fsc/ssc |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
33 for i in range(1, len(list_markers)): |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
34 if not list_markers[i].startswith("FSC") and not list_markers[i].startswith("SSC"): |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
35 query.append(list_markers[i].upper()) |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
36 query.append(profile_key[list_types[i]]) |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
37 # return concatenated string |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
38 return("".join(query)) |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
39 |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
40 |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
41 def translate_profiles(input_file, tool_dir, output, html_dir): |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
42 os.mkdir(html_dir) |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
43 |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
44 tool = "/".join([tool_dir, "getOntology.R"]) |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
45 html_table = "".join([html_dir, "/CLprofiles.txt"]) |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
46 score_table = "".join(["cp ", input_file, " ", html_dir, "/scores.txt"]) |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
47 os.system(score_table) |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
48 |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
49 # read profile |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
50 with open(input_file, "r") as flock_profiles, open(html_table, "w") as out: |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
51 headers = flock_profiles.readline() |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
52 headers = headers.strip() |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
53 # get all headers except for last 2 (count + percentage) |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
54 markers = headers.split("\t")[:-2] |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
55 counter = 0 |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
56 |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
57 out.write("Population\tFlowCL Query\tNb Results\tLink to PDF\t") |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
58 out.write("Top Result Label\tTop Result Score\tTop Result CL\n") |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
59 queries = {} |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
60 # create marker query for each population |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
61 for lines in flock_profiles: |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
62 lines = lines.strip("\n") |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
63 pop_profile = lines.split("\t")[:-2] |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
64 flowcl_query = generate_flowCL_query(markers, pop_profile) |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
65 counter += 1 |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
66 nb_results = "0" |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
67 top_label = "no_match" |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
68 top_score = "NA" |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
69 top_CL = "NA" |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
70 pdf_link = "NA" |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
71 # check if query was run before |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
72 if flowcl_query not in queries: |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
73 # create filenames for results & graphs |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
74 txt = "".join(["flowcl_pop", str(counter).zfill(2), ".txt"]) |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
75 text_result = "/".join([html_dir, txt]) |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
76 graph = "".join(["flowcl_pop", str(counter).zfill(2), ".pdf"]) |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
77 graph_output = "/".join([html_dir, graph]) |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
78 # run flowCL for each marker profile |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
79 run_flowCL(flowcl_query, text_result, graph_output, tool) |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
80 |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
81 # test that text file exists if not results are all NAs: |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
82 if os.path.isfile(text_result): |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
83 with open(text_result, "r") as res: |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
84 for line in res: |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
85 if line.startswith("Score"): |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
86 data = line.split(") ") |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
87 top_score = data[2][:-2] |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
88 tot_results = len(data) - 2 |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
89 nb_results = str(tot_results) |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
90 if tot_results == 5: |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
91 if len(data[6].split("+")) > 1: |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
92 nb_results = "5+" |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
93 elif line.startswith("Cell ID"): |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
94 prep_link = line.split(") ")[1][:-2] |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
95 cl = prep_link.replace("_", ":") |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
96 link = "".join(['<a href="http://www.immport-labs.org/immport-ontology/public/home/home/', cl, '" target="_blank">']) |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
97 top_CL = "".join([link, prep_link, "</a>"]) |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
98 elif line.startswith("Cell Label"): |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
99 top_label = line.split(") ")[1][:-2] |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
100 pdf_link = "".join(['<a href="', graph, '" target="_blank">PDF</a>']) |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
101 tmpflowcl_query = "".join(['<a href="', txt, '" target="_blank">', flowcl_query, '</a>']) |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
102 |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
103 queries[flowcl_query] = { |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
104 "query": tmpflowcl_query, |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
105 "results": nb_results, |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
106 "pdf": pdf_link, |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
107 "label": top_label, |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
108 "score": top_score, |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
109 "CL": top_CL |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
110 } |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
111 # write query results to CLprofiles.txt |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
112 out.write("\t".join([pop_profile[0], |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
113 queries[flowcl_query]["query"], |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
114 queries[flowcl_query]["results"], |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
115 queries[flowcl_query]["pdf"], |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
116 queries[flowcl_query]["label"], |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
117 queries[flowcl_query]["score"], |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
118 queries[flowcl_query]["CL"]]) + "\n") |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
119 |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
120 env = Environment(loader=FileSystemLoader(tool_dir + "/templates")) |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
121 template = env.get_template("profileCLs.template") |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
122 |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
123 real_directory = html_dir.replace("/job_working_directory", "") |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
124 context = {'outputDirectory': real_directory} |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
125 overview = template.render(**context) |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
126 with open(output, "w") as outf: |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
127 outf.write(overview) |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
128 |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
129 |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
130 if __name__ == "__main__": |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
131 parser = ArgumentParser( |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
132 prog="getCLs_from_profile", |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
133 description="runs flowCL on a each population defined by FLOCK.") |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
134 |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
135 parser.add_argument( |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
136 '-i', |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
137 dest="input_file", |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
138 required=True, |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
139 help="File location for the profile.txt from FLOCK.") |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
140 |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
141 parser.add_argument( |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
142 '-o', |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
143 dest="output", |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
144 required=True, |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
145 help="Name of the output html file.") |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
146 |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
147 parser.add_argument( |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
148 '-d', |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
149 dest="html_dir", |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
150 required=True, |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
151 help="Path to html supporting directory.") |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
152 |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
153 parser.add_argument( |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
154 '-t', |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
155 dest="tool_dir", |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
156 required=True, |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
157 help="Path to the tool directory") |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
158 |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
159 args = parser.parse_args() |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
160 |
62d8985a41e2
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/profile_cl commit 5cdc32e68f9ec685f9890902c5ecc75047248361"
azomics
parents:
diff
changeset
|
161 translate_profiles(args.input_file, args.tool_dir, args.output, args.html_dir) |