annotate beta_diversity_through_plots_html_generation.py @ 6:a3b69e0b9246 draft

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit a4b0969b33a68a0ea9ba12291f6694aec24f13ed
author iuc
date Tue, 30 Oct 2018 19:54:15 -0400
parents a3d1104d090c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a3d1104d090c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
1 #!/usr/bin/env python
a3d1104d090c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
2 # -*- coding: utf-8 -*-
a3d1104d090c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
3
a3d1104d090c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
4 import argparse
a3d1104d090c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
5 import os
a3d1104d090c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
6 import re
a3d1104d090c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
7
a3d1104d090c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
8
a3d1104d090c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
9 def generate_index_html(dir_list, args):
a3d1104d090c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
10 with open(args.html_file, 'w') as index_html_file:
a3d1104d090c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
11 s = ""
a3d1104d090c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
12 s += '<html>\n'
a3d1104d090c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
13 s += '\t<head><title>PCoA beta diversity results</title></head>\n'
a3d1104d090c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
14 s += '\t<body>\n'
a3d1104d090c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
15 s += '\t\t<a href="http://www.qiime.org" target="_blank">'
a3d1104d090c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
16 s += '<img src="http://qiime.org/_static/wordpressheader.png" '
a3d1104d090c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
17 s += 'alt="www.qiime.org""/></a>\n'
a3d1104d090c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
18 s += '\t\t<p>\n'
a3d1104d090c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
19 s += '\t\t\tBeta diversity metrics\n'
a3d1104d090c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
20 s += '\t\t\t<ul>\n'
a3d1104d090c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
21
a3d1104d090c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
22 for directory in dir_list:
a3d1104d090c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
23 regexp_result = re.search(
6
a3b69e0b9246 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit a4b0969b33a68a0ea9ba12291f6694aec24f13ed
iuc
parents: 0
diff changeset
24 r'([a-zA-Z\_]*)_emperor_pcoa_plot',
0
a3d1104d090c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
25 directory)
a3d1104d090c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
26 metric = regexp_result.group(1)
a3d1104d090c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
27 s += '\t\t\t\t<li>' + metric + ': '
a3d1104d090c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
28 s += '<a href="' + directory
a3d1104d090c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
29 s += '/index.html">PCoA results</a></td>\n'
a3d1104d090c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
30 s += '\t\t\t\t</li>\n'
a3d1104d090c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
31
a3d1104d090c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
32 s += '\t\t\t</ul>\n'
a3d1104d090c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
33 s += '\t\t</p>\n'
a3d1104d090c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
34 s += '\t</body>\n'
a3d1104d090c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
35 s += '</html>\n'
a3d1104d090c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
36
a3d1104d090c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
37 index_html_file.write(s)
a3d1104d090c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
38
a3d1104d090c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
39
a3d1104d090c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
40 def build_html(args):
a3d1104d090c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
41 os.mkdir(args.html_dir)
a3d1104d090c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
42
a3d1104d090c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
43 dir_list = [name for name in os.listdir(args.data_directory)
a3d1104d090c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
44 if os.path.isdir(os.path.join(
a3d1104d090c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
45 args.data_directory,
a3d1104d090c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
46 name))]
a3d1104d090c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
47
a3d1104d090c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
48 generate_index_html(dir_list, args)
a3d1104d090c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
49
a3d1104d090c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
50 for directory in dir_list:
a3d1104d090c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
51 input_path = os.path.join(args.data_directory, directory)
a3d1104d090c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
52 cmd = 'cp -r ' + input_path + ' ' + args.html_dir
a3d1104d090c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
53 os.system(cmd)
a3d1104d090c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
54
a3d1104d090c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
55
a3d1104d090c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
56 if __name__ == '__main__':
a3d1104d090c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
57 parser = argparse.ArgumentParser()
a3d1104d090c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
58 parser.add_argument('--data_directory', required=True)
a3d1104d090c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
59 parser.add_argument('--html_file', required=True)
a3d1104d090c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
60 parser.add_argument('--html_dir', required=True)
a3d1104d090c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
61 args = parser.parse_args()
a3d1104d090c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
62
a3d1104d090c planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
63 build_html(args)