diff beta_diversity_through_plots_html_generation.py @ 0:78b8aba19876 draft

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/qiime/ commit c9bf747b23b4a9d6adc20c7740b9247c22654862
author iuc
date Thu, 18 May 2017 09:29:27 -0400
parents
children c6d84b3ad9db
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/beta_diversity_through_plots_html_generation.py	Thu May 18 09:29:27 2017 -0400
@@ -0,0 +1,63 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import argparse
+import os
+import re
+
+
+def generate_index_html(dir_list, args):
+    with open(args.html_file, 'w') as index_html_file:
+        s = ""
+        s += '<html>\n'
+        s += '\t<head><title>PCoA beta diversity results</title></head>\n'
+        s += '\t<body>\n'
+        s += '\t\t<a href="http://www.qiime.org" target="_blank">'
+        s += '<img src="http://qiime.org/_static/wordpressheader.png" '
+        s += 'alt="www.qiime.org""/></a>\n'
+        s += '\t\t<p>\n'
+        s += '\t\t\tBeta diversity metrics\n'
+        s += '\t\t\t<ul>\n'
+
+        for directory in dir_list:
+            regexp_result = re.search(
+                '([a-zA-Z\_]*)_emperor_pcoa_plot',
+                directory)
+            metric = regexp_result.group(1)
+            s += '\t\t\t\t<li>' + metric + ': '
+            s += '<a href="' + directory
+            s += '/index.html">PCoA results</a></td>\n'
+            s += '\t\t\t\t</li>\n'
+
+        s += '\t\t\t</ul>\n'
+        s += '\t\t</p>\n'
+        s += '\t</body>\n'
+        s += '</html>\n'
+
+        index_html_file.write(s)
+
+
+def build_html(args):
+    os.mkdir(args.html_dir)
+
+    dir_list = [name for name in os.listdir(args.data_directory)
+                if os.path.isdir(os.path.join(
+                    args.data_directory,
+                    name))]
+
+    generate_index_html(dir_list, args)
+
+    for directory in dir_list:
+        input_path = os.path.join(args.data_directory, directory)
+        cmd = 'cp -r ' + input_path + ' ' + args.html_dir
+        os.system(cmd)
+
+
+if __name__ == '__main__':
+    parser = argparse.ArgumentParser()
+    parser.add_argument('--data_directory', required=True)
+    parser.add_argument('--html_file', required=True)
+    parser.add_argument('--html_dir', required=True)
+    args = parser.parse_args()
+
+    build_html(args)