annotate beta_diversity_through_plots_html_generation.py @ 2:45b4946c4458 draft

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