Mercurial > repos > bebatut > qiime
annotate beta_diversity_through_plots_html_generation.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 |
rev | line source |
---|---|
0
c1bd0c560018
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime commit bcbe76277f3e60303faf826f8ce7f018bc663a9a-dirty
bebatut
parents:
diff
changeset
|
1 #!/usr/bin/env python |
c1bd0c560018
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime commit bcbe76277f3e60303faf826f8ce7f018bc663a9a-dirty
bebatut
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
c1bd0c560018
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime commit bcbe76277f3e60303faf826f8ce7f018bc663a9a-dirty
bebatut
parents:
diff
changeset
|
3 |
c1bd0c560018
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime commit bcbe76277f3e60303faf826f8ce7f018bc663a9a-dirty
bebatut
parents:
diff
changeset
|
4 import sys |
c1bd0c560018
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime commit bcbe76277f3e60303faf826f8ce7f018bc663a9a-dirty
bebatut
parents:
diff
changeset
|
5 import os |
c1bd0c560018
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime commit bcbe76277f3e60303faf826f8ce7f018bc663a9a-dirty
bebatut
parents:
diff
changeset
|
6 import argparse |
c1bd0c560018
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime commit bcbe76277f3e60303faf826f8ce7f018bc663a9a-dirty
bebatut
parents:
diff
changeset
|
7 import re |
c1bd0c560018
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime commit bcbe76277f3e60303faf826f8ce7f018bc663a9a-dirty
bebatut
parents:
diff
changeset
|
8 |
c1bd0c560018
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime commit bcbe76277f3e60303faf826f8ce7f018bc663a9a-dirty
bebatut
parents:
diff
changeset
|
9 |
c1bd0c560018
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime commit bcbe76277f3e60303faf826f8ce7f018bc663a9a-dirty
bebatut
parents:
diff
changeset
|
10 def generate_index_html(dir_list, args): |
c1bd0c560018
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime commit bcbe76277f3e60303faf826f8ce7f018bc663a9a-dirty
bebatut
parents:
diff
changeset
|
11 with open('index.html','w') as index_html_file: |
c1bd0c560018
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime commit bcbe76277f3e60303faf826f8ce7f018bc663a9a-dirty
bebatut
parents:
diff
changeset
|
12 index_html_file.write('<html>\n') |
c1bd0c560018
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime commit bcbe76277f3e60303faf826f8ce7f018bc663a9a-dirty
bebatut
parents:
diff
changeset
|
13 index_html_file.write('\t<head><title>PCoA beta diversity results</title></head>\n') |
c1bd0c560018
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime commit bcbe76277f3e60303faf826f8ce7f018bc663a9a-dirty
bebatut
parents:
diff
changeset
|
14 index_html_file.write('\t<body>\n') |
c1bd0c560018
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime commit bcbe76277f3e60303faf826f8ce7f018bc663a9a-dirty
bebatut
parents:
diff
changeset
|
15 index_html_file.write('\t\t<a href="http://www.qiime.org" target="_blank"><img src="http://qiime.org/_static/wordpressheader.png" alt="www.qiime.org""/></a>\n') |
c1bd0c560018
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime commit bcbe76277f3e60303faf826f8ce7f018bc663a9a-dirty
bebatut
parents:
diff
changeset
|
16 index_html_file.write('\t\t<p>\n') |
c1bd0c560018
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime commit bcbe76277f3e60303faf826f8ce7f018bc663a9a-dirty
bebatut
parents:
diff
changeset
|
17 index_html_file.write('\t\t\tBeta diversity metrics\n') |
c1bd0c560018
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime commit bcbe76277f3e60303faf826f8ce7f018bc663a9a-dirty
bebatut
parents:
diff
changeset
|
18 index_html_file.write('\t\t\t<ul>\n') |
c1bd0c560018
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime commit bcbe76277f3e60303faf826f8ce7f018bc663a9a-dirty
bebatut
parents:
diff
changeset
|
19 |
c1bd0c560018
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime commit bcbe76277f3e60303faf826f8ce7f018bc663a9a-dirty
bebatut
parents:
diff
changeset
|
20 for directory in dir_list: |
c1bd0c560018
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime commit bcbe76277f3e60303faf826f8ce7f018bc663a9a-dirty
bebatut
parents:
diff
changeset
|
21 regexp_result = re.match('([a-zA-Z]*)_emperor_pcoa_plot',directory) |
c1bd0c560018
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime commit bcbe76277f3e60303faf826f8ce7f018bc663a9a-dirty
bebatut
parents:
diff
changeset
|
22 metric = regexp_result.group(1) |
c1bd0c560018
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime commit bcbe76277f3e60303faf826f8ce7f018bc663a9a-dirty
bebatut
parents:
diff
changeset
|
23 index_html_file.write('\t\t\t\t<li>' + metric + ': ') |
c1bd0c560018
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime commit bcbe76277f3e60303faf826f8ce7f018bc663a9a-dirty
bebatut
parents:
diff
changeset
|
24 index_html_file.write('<a href="' + directory + |
c1bd0c560018
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime commit bcbe76277f3e60303faf826f8ce7f018bc663a9a-dirty
bebatut
parents:
diff
changeset
|
25 '/index.html">PCoA results</a></td>\n') |
c1bd0c560018
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime commit bcbe76277f3e60303faf826f8ce7f018bc663a9a-dirty
bebatut
parents:
diff
changeset
|
26 index_html_file.write('\t\t\t\t</li>\n') |
c1bd0c560018
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime commit bcbe76277f3e60303faf826f8ce7f018bc663a9a-dirty
bebatut
parents:
diff
changeset
|
27 |
c1bd0c560018
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime commit bcbe76277f3e60303faf826f8ce7f018bc663a9a-dirty
bebatut
parents:
diff
changeset
|
28 index_html_file.write('\t\t\t</ul>\n') |
c1bd0c560018
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime commit bcbe76277f3e60303faf826f8ce7f018bc663a9a-dirty
bebatut
parents:
diff
changeset
|
29 index_html_file.write('\t\t</p>\n') |
c1bd0c560018
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime commit bcbe76277f3e60303faf826f8ce7f018bc663a9a-dirty
bebatut
parents:
diff
changeset
|
30 index_html_file.write('\t</body>\n') |
c1bd0c560018
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime commit bcbe76277f3e60303faf826f8ce7f018bc663a9a-dirty
bebatut
parents:
diff
changeset
|
31 index_html_file.write('</html>\n') |
c1bd0c560018
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime commit bcbe76277f3e60303faf826f8ce7f018bc663a9a-dirty
bebatut
parents:
diff
changeset
|
32 |
c1bd0c560018
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime commit bcbe76277f3e60303faf826f8ce7f018bc663a9a-dirty
bebatut
parents:
diff
changeset
|
33 def build_html(args): |
c1bd0c560018
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime commit bcbe76277f3e60303faf826f8ce7f018bc663a9a-dirty
bebatut
parents:
diff
changeset
|
34 os.mkdir(args.html_dir) |
c1bd0c560018
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime commit bcbe76277f3e60303faf826f8ce7f018bc663a9a-dirty
bebatut
parents:
diff
changeset
|
35 |
c1bd0c560018
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime commit bcbe76277f3e60303faf826f8ce7f018bc663a9a-dirty
bebatut
parents:
diff
changeset
|
36 dir_list = [ name for name in os.listdir(args.data_directory) if |
c1bd0c560018
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime commit bcbe76277f3e60303faf826f8ce7f018bc663a9a-dirty
bebatut
parents:
diff
changeset
|
37 os.path.isdir(os.path.join(args.data_directory, name)) ] |
c1bd0c560018
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime commit bcbe76277f3e60303faf826f8ce7f018bc663a9a-dirty
bebatut
parents:
diff
changeset
|
38 |
c1bd0c560018
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime commit bcbe76277f3e60303faf826f8ce7f018bc663a9a-dirty
bebatut
parents:
diff
changeset
|
39 generate_index_html(dir_list, args) |
c1bd0c560018
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime commit bcbe76277f3e60303faf826f8ce7f018bc663a9a-dirty
bebatut
parents:
diff
changeset
|
40 |
c1bd0c560018
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime commit bcbe76277f3e60303faf826f8ce7f018bc663a9a-dirty
bebatut
parents:
diff
changeset
|
41 os.system('cp -r index.html ' + args.html_dir) |
c1bd0c560018
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime commit bcbe76277f3e60303faf826f8ce7f018bc663a9a-dirty
bebatut
parents:
diff
changeset
|
42 |
c1bd0c560018
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime commit bcbe76277f3e60303faf826f8ce7f018bc663a9a-dirty
bebatut
parents:
diff
changeset
|
43 for directory in dir_list: |
c1bd0c560018
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime commit bcbe76277f3e60303faf826f8ce7f018bc663a9a-dirty
bebatut
parents:
diff
changeset
|
44 os.system('cp -r ' + args.data_directory + '/' + directory + ' ' + |
c1bd0c560018
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime commit bcbe76277f3e60303faf826f8ce7f018bc663a9a-dirty
bebatut
parents:
diff
changeset
|
45 args.html_dir) |
c1bd0c560018
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime commit bcbe76277f3e60303faf826f8ce7f018bc663a9a-dirty
bebatut
parents:
diff
changeset
|
46 |
c1bd0c560018
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime commit bcbe76277f3e60303faf826f8ce7f018bc663a9a-dirty
bebatut
parents:
diff
changeset
|
47 os.system('mv ' + args.html_dir + '/index.html ' + args.html_file) |
c1bd0c560018
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime commit bcbe76277f3e60303faf826f8ce7f018bc663a9a-dirty
bebatut
parents:
diff
changeset
|
48 |
c1bd0c560018
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime commit bcbe76277f3e60303faf826f8ce7f018bc663a9a-dirty
bebatut
parents:
diff
changeset
|
49 if __name__ == '__main__': |
c1bd0c560018
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime commit bcbe76277f3e60303faf826f8ce7f018bc663a9a-dirty
bebatut
parents:
diff
changeset
|
50 parser = argparse.ArgumentParser() |
c1bd0c560018
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime commit bcbe76277f3e60303faf826f8ce7f018bc663a9a-dirty
bebatut
parents:
diff
changeset
|
51 parser.add_argument('--data_directory', required=True) |
c1bd0c560018
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime commit bcbe76277f3e60303faf826f8ce7f018bc663a9a-dirty
bebatut
parents:
diff
changeset
|
52 parser.add_argument('--html_file', required=True) |
c1bd0c560018
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime commit bcbe76277f3e60303faf826f8ce7f018bc663a9a-dirty
bebatut
parents:
diff
changeset
|
53 parser.add_argument('--html_dir', required=True) |
c1bd0c560018
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime commit bcbe76277f3e60303faf826f8ce7f018bc663a9a-dirty
bebatut
parents:
diff
changeset
|
54 args = parser.parse_args() |
c1bd0c560018
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime commit bcbe76277f3e60303faf826f8ce7f018bc663a9a-dirty
bebatut
parents:
diff
changeset
|
55 |
c1bd0c560018
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime commit bcbe76277f3e60303faf826f8ce7f018bc663a9a-dirty
bebatut
parents:
diff
changeset
|
56 build_html(args) |