annotate beta_diversity_through_plots_html_generation.py @ 8:2aca5aae5d10 draft default tip

"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c845cb240f57663cf1e2240c5c506ea0b294872c"
author iuc
date Thu, 05 Dec 2019 07:48:48 -0500
parents 2a39329e51c5
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
c11972e98d44 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
c11972e98d44 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
2 # -*- coding: utf-8 -*-
c11972e98d44 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
3
c11972e98d44 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
4 import argparse
c11972e98d44 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
5 import os
c11972e98d44 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
6 import re
c11972e98d44 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
7
c11972e98d44 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
8
c11972e98d44 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):
c11972e98d44 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:
c11972e98d44 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
11 s = ""
c11972e98d44 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
12 s += '<html>\n'
c11972e98d44 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'
c11972e98d44 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'
c11972e98d44 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">'
c11972e98d44 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" '
c11972e98d44 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'
c11972e98d44 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'
c11972e98d44 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'
c11972e98d44 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'
c11972e98d44 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
21
c11972e98d44 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:
c11972e98d44 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
2a39329e51c5 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
c11972e98d44 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
25 directory)
c11972e98d44 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)
c11972e98d44 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 + ': '
c11972e98d44 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
c11972e98d44 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'
c11972e98d44 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'
c11972e98d44 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
31
c11972e98d44 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'
c11972e98d44 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'
c11972e98d44 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'
c11972e98d44 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
35 s += '</html>\n'
c11972e98d44 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
36
c11972e98d44 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)
c11972e98d44 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
38
c11972e98d44 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
39
c11972e98d44 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):
c11972e98d44 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)
c11972e98d44 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
42
c11972e98d44 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)
c11972e98d44 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(
c11972e98d44 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
45 args.data_directory,
c11972e98d44 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
46 name))]
c11972e98d44 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
47
c11972e98d44 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)
c11972e98d44 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
49
c11972e98d44 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:
c11972e98d44 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)
c11972e98d44 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
c11972e98d44 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
53 os.system(cmd)
c11972e98d44 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
54
c11972e98d44 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
55
c11972e98d44 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
56 if __name__ == '__main__':
c11972e98d44 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
57 parser = argparse.ArgumentParser()
c11972e98d44 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)
c11972e98d44 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)
c11972e98d44 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)
c11972e98d44 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()
c11972e98d44 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
62
c11972e98d44 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
iuc
parents:
diff changeset
63 build_html(args)