Mercurial > repos > bebatut > qiime
comparison 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 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:c1bd0c560018 |
|---|---|
| 1 #!/usr/bin/env python | |
| 2 # -*- coding: utf-8 -*- | |
| 3 | |
| 4 import sys | |
| 5 import os | |
| 6 import argparse | |
| 7 import re | |
| 8 | |
| 9 | |
| 10 def generate_index_html(dir_list, args): | |
| 11 with open('index.html','w') as index_html_file: | |
| 12 index_html_file.write('<html>\n') | |
| 13 index_html_file.write('\t<head><title>PCoA beta diversity results</title></head>\n') | |
| 14 index_html_file.write('\t<body>\n') | |
| 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') | |
| 16 index_html_file.write('\t\t<p>\n') | |
| 17 index_html_file.write('\t\t\tBeta diversity metrics\n') | |
| 18 index_html_file.write('\t\t\t<ul>\n') | |
| 19 | |
| 20 for directory in dir_list: | |
| 21 regexp_result = re.match('([a-zA-Z]*)_emperor_pcoa_plot',directory) | |
| 22 metric = regexp_result.group(1) | |
| 23 index_html_file.write('\t\t\t\t<li>' + metric + ': ') | |
| 24 index_html_file.write('<a href="' + directory + | |
| 25 '/index.html">PCoA results</a></td>\n') | |
| 26 index_html_file.write('\t\t\t\t</li>\n') | |
| 27 | |
| 28 index_html_file.write('\t\t\t</ul>\n') | |
| 29 index_html_file.write('\t\t</p>\n') | |
| 30 index_html_file.write('\t</body>\n') | |
| 31 index_html_file.write('</html>\n') | |
| 32 | |
| 33 def build_html(args): | |
| 34 os.mkdir(args.html_dir) | |
| 35 | |
| 36 dir_list = [ name for name in os.listdir(args.data_directory) if | |
| 37 os.path.isdir(os.path.join(args.data_directory, name)) ] | |
| 38 | |
| 39 generate_index_html(dir_list, args) | |
| 40 | |
| 41 os.system('cp -r index.html ' + args.html_dir) | |
| 42 | |
| 43 for directory in dir_list: | |
| 44 os.system('cp -r ' + args.data_directory + '/' + directory + ' ' + | |
| 45 args.html_dir) | |
| 46 | |
| 47 os.system('mv ' + args.html_dir + '/index.html ' + args.html_file) | |
| 48 | |
| 49 if __name__ == '__main__': | |
| 50 parser = argparse.ArgumentParser() | |
| 51 parser.add_argument('--data_directory', required=True) | |
| 52 parser.add_argument('--html_file', required=True) | |
| 53 parser.add_argument('--html_dir', required=True) | |
| 54 args = parser.parse_args() | |
| 55 | |
| 56 build_html(args) |
