annotate beta_diversity_through_plots_html_generation.py @ 0:20194da2549d draft

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