Mercurial > repos > bebatut > qiime
comparison beta_diversity_through_plots_wrapper.py @ 0:c1bd0c560018 draft default tip
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime commit bcbe76277f3e60303faf826f8ce7f018bc663a9a-dirty
author | bebatut |
---|---|
date | Tue, 02 Feb 2016 05:50:37 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c1bd0c560018 |
---|---|
1 #!/usr/bin/env python | |
2 | |
3 # create a html output for beta_diverity_through_plots.py | |
4 # to replace beta_diversity_through_plot_html.py in qiime 1.8 | |
5 # Leroi Laura laura.leroi@ifremer.fr | |
6 | |
7 import optparse | |
8 import os | |
9 import sys | |
10 import subprocess | |
11 | |
12 # Create html template | |
13 def html_maker(metrics): | |
14 | |
15 tag="" | |
16 plots = metrics.split(',') | |
17 for i in range(0, len(plots)): | |
18 tag = tag+"""\t\t<option value='%s_emperor_pcoa_plot/index.html'>%s</option>\n""" % (plots[i], plots[i]) | |
19 template_html= """ | |
20 <!doctype html> | |
21 <html lang="en"> | |
22 <head> | |
23 <meta charset="utf-8"> | |
24 <script type="text/javascript" src="/galaxy/static/scripts/libs/jquery/jquery.js"></script> | |
25 </head> | |
26 <body> | |
27 <label for="outputs">Select a beta-diversity metric :</label> | |
28 <select id="outputs" name="outputs"> | |
29 %s | |
30 </select> | |
31 <br/> | |
32 <br/> | |
33 <iframe id="plot" name="plot" style="position:absolute; width: 90%%; height: 90%%;" src="" frameborder="0"></iframe> | |
34 <script> | |
35 $(document).ready(function(){ | |
36 var str = ""; | |
37 $( "#outputs option:selected" ).each(function() { | |
38 str += $( this ).val() + " "; | |
39 $("#plot").attr("src", str); | |
40 }); | |
41 | |
42 }); | |
43 $( "#outputs" ).change(function () { | |
44 var str = ""; | |
45 $( "#outputs option:selected" ).each(function() { | |
46 str += $( this ).val() + " "; | |
47 $("#plot").attr("src", str); | |
48 }); | |
49 }).change(); | |
50 </script> | |
51 </body> | |
52 </html> """ % (tag) | |
53 return template_html | |
54 | |
55 | |
56 def html_matrix_maker(metrics): | |
57 | |
58 tag="" | |
59 plots = metrics.split(',') | |
60 for i in range(0, len(plots)): | |
61 tag = tag+"""\t\t<a href='%s_dm.txt'>%s_dm</a><br/>\n""" % (plots[i], plots[i]) | |
62 | |
63 template_html= """ | |
64 <!doctype html> | |
65 <html lang="en"> | |
66 <body> | |
67 <label>Metrics matrix : </label><br/> | |
68 %s | |
69 </body> | |
70 </html> """ % (tag) | |
71 return template_html | |
72 | |
73 | |
74 def main(): | |
75 | |
76 #On importe l environnemnent envqiime | |
77 pipe = subprocess.Popen(". /home12/caparmor/bioinfo/GALAXY_DEV/ourenv/envqiime; python -c 'import os; print \"newenv = %r\" % os.environ'", stdout=subprocess.PIPE, shell=True) | |
78 exec(pipe.communicate()[0]) | |
79 os.environ.update(newenv) | |
80 | |
81 #New parser | |
82 parser = optparse.OptionParser() | |
83 #beta diversity options | |
84 parser.add_option('--metrics',dest='metrics') | |
85 parser.add_option('--biom',dest='biom') | |
86 parser.add_option('--mapping',dest='mapping') | |
87 parser.add_option('--tree',dest='tree') | |
88 parser.add_option('--depth',dest='depth') | |
89 parser.add_option('--masterhtml',dest='masterhtml') | |
90 parser.add_option('--outputfolder',dest='outputfolder') | |
91 parser.add_option('--matrixhtml',dest='matrixhtml') | |
92 | |
93 (options,args) = parser.parse_args() | |
94 | |
95 #New hmtl template | |
96 master = open('./master.html', 'w') | |
97 master.write(html_maker(options.metrics)) | |
98 master.close() | |
99 #On lance le fichier avec les options precisees pour l'affichage html | |
100 os.system("mv master.html %s" % options.masterhtml) | |
101 | |
102 #parameter file, which specifies changes to the default behavior | |
103 parameters = open('./parameters.txt','w') | |
104 parameters.write("beta_diversity:metrics %s" % options.metrics) | |
105 parameters.close() | |
106 | |
107 if options.depth: | |
108 if options.tree : | |
109 os.system("beta_diversity_through_plots.py -i %s -m %s -t %s -e %s -o %s -p ./parameters.txt >& file_log.txt" % (options.biom, options.mapping, options.tree, options.depth, options.outputfolder)) | |
110 else : | |
111 os.system("beta_diversity_through_plots.py -i %s -m %s -e %s -o %s -p ./parameters.txt >& file_log.txt" % (options.biom, options.mapping, options.depth, options.outputfolder)) | |
112 else: | |
113 if options.tree : | |
114 os.system("beta_diversity_through_plots.py -i %s -m %s -t %s -o %s -p ./parameters.txt >& file_log.txt" % (options.biom, options.mapping, options.tree, options.outputfolder)) | |
115 else : | |
116 os.system("beta_diversity_through_plots.py -i %s -m %s -o %s -p ./parameters.txt >& file_log.txt" % (options.biom, options.mapping, options.outputfolder)) | |
117 | |
118 os.system("mkdir %s/txt" % (options.outputfolder)) | |
119 os.system("mv %s/*_dm.txt %s/txt" %(options.outputfolder,options.outputfolder)) | |
120 os.system("compress_path.py -i %s/txt -o %s" % (options.outputfolder,options.matrixhtml)) | |
121 | |
122 if __name__=="__main__": | |
123 main() | |
124 |