annotate amplicon_analysis_pipeline.py @ 29:31b7950136ed draft

planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit afee03cb577aa68e650a2b7d65b31c000440d9ee
author pjbriggs
date Mon, 01 Oct 2018 07:31:44 -0400
parents b5e43dfe07ac
children 18e6427c5e4a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
1 #!/usr/bin/env python
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
2 #
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
3 # Wrapper script to run Amplicon_analysis_pipeline.sh
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
4 # from Galaxy tool
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
5
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
6 import sys
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
7 import os
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
8 import argparse
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
9 import subprocess
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
10 import glob
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
11
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
12 class PipelineCmd(object):
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
13 def __init__(self,cmd):
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
14 self.cmd = [str(cmd)]
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
15 def add_args(self,*args):
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
16 for arg in args:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
17 self.cmd.append(str(arg))
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
18 def __repr__(self):
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
19 return ' '.join([str(arg) for arg in self.cmd])
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
20
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
21 def ahref(target,name=None,type=None):
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
22 if name is None:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
23 name = os.path.basename(target)
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
24 ahref = "<a href='%s'" % target
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
25 if type is not None:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
26 ahref += " type='%s'" % type
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
27 ahref += ">%s</a>" % name
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
28 return ahref
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
29
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
30 def check_errors():
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
31 # Errors in Amplicon_analysis_pipeline.log
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
32 with open('Amplicon_analysis_pipeline.log','r') as pipeline_log:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
33 log = pipeline_log.read()
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
34 if "Names in the first column of Metatable.txt and in the second column of Final_name.txt do not match" in log:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
35 print_error("""*** Sample IDs don't match dataset names ***
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
36
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
37 The sample IDs (first column of the Metatable file) don't match the
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
38 supplied sample names for the input Fastq pairs.
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
39 """)
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
40 # Errors in pipeline output
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
41 with open('pipeline.log','r') as pipeline_log:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
42 log = pipeline_log.read()
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
43 if "Errors and/or warnings detected in mapping file" in log:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
44 with open("Metatable_log/Metatable.log","r") as metatable_log:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
45 # Echo the Metatable log file to the tool log
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
46 print_error("""*** Error in Metatable mapping file ***
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
47
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
48 %s""" % metatable_log.read())
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
49 elif "No header line was found in mapping file" in log:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
50 # Report error to the tool log
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
51 print_error("""*** No header in Metatable mapping file ***
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
52
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
53 Check you've specified the correct file as the input Metatable""")
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
54
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
55 def print_error(message):
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
56 width = max([len(line) for line in message.split('\n')]) + 4
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
57 sys.stderr.write("\n%s\n" % ('*'*width))
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
58 for line in message.split('\n'):
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
59 sys.stderr.write("* %s%s *\n" % (line,' '*(width-len(line)-4)))
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
60 sys.stderr.write("%s\n\n" % ('*'*width))
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
61
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
62 def clean_up_name(sample):
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
63 # Remove trailing "_L[0-9]+_001" from Fastq
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
64 # pair names
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
65 split_name = sample.split('_')
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
66 if split_name[-1] == "001":
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
67 split_name = split_name[:-1]
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
68 if split_name[-1].startswith('L'):
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
69 try:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
70 int(split_name[-1][1:])
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
71 split_name = split_name[:-1]
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
72 except ValueError:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
73 pass
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
74 return '_'.join(split_name)
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
75
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
76 def list_outputs(filen=None):
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
77 # List the output directory contents
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
78 # If filen is specified then will be the filename to
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
79 # write to, otherwise write to stdout
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
80 if filen is not None:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
81 fp = open(filen,'w')
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
82 else:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
83 fp = sys.stdout
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
84 results_dir = os.path.abspath("RESULTS")
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
85 fp.write("Listing contents of output dir %s:\n" % results_dir)
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
86 ix = 0
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
87 for d,dirs,files in os.walk(results_dir):
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
88 ix += 1
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
89 fp.write("-- %d: %s\n" % (ix,
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
90 os.path.relpath(d,results_dir)))
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
91 for f in files:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
92 ix += 1
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
93 fp.write("---- %d: %s\n" % (ix,
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
94 os.path.relpath(f,results_dir)))
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
95 # Close output file
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
96 if filen is not None:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
97 fp.close()
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
98
8
8292f8262a9d planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit f72ff88ee11d09703bf38524dbb8026ee14bc3ef-dirty
pjbriggs
parents: 2
diff changeset
99 def find_executable(name):
8292f8262a9d planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit f72ff88ee11d09703bf38524dbb8026ee14bc3ef-dirty
pjbriggs
parents: 2
diff changeset
100 # Locate executable on PATH
8292f8262a9d planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit f72ff88ee11d09703bf38524dbb8026ee14bc3ef-dirty
pjbriggs
parents: 2
diff changeset
101 for p in os.environ['PATH'].split(os.pathsep):
29
31b7950136ed planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit afee03cb577aa68e650a2b7d65b31c000440d9ee
pjbriggs
parents: 27
diff changeset
102 exe = os.path.normpath(
31b7950136ed planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit afee03cb577aa68e650a2b7d65b31c000440d9ee
pjbriggs
parents: 27
diff changeset
103 os.path.abspath(os.path.join(p,name)))
31b7950136ed planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit afee03cb577aa68e650a2b7d65b31c000440d9ee
pjbriggs
parents: 27
diff changeset
104 print "Checking %s" % exe
9
32a43bc3dd58 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit f72ff88ee11d09703bf38524dbb8026ee14bc3ef-dirty
pjbriggs
parents: 8
diff changeset
105 if os.path.isfile(exe) and os.access(exe,os.X_OK):
8
8292f8262a9d planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit f72ff88ee11d09703bf38524dbb8026ee14bc3ef-dirty
pjbriggs
parents: 2
diff changeset
106 return exe
8292f8262a9d planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit f72ff88ee11d09703bf38524dbb8026ee14bc3ef-dirty
pjbriggs
parents: 2
diff changeset
107 return None
8292f8262a9d planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit f72ff88ee11d09703bf38524dbb8026ee14bc3ef-dirty
pjbriggs
parents: 2
diff changeset
108
0
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
109 if __name__ == "__main__":
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
110 # Command line
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
111 print "Amplicon analysis: starting"
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
112 p = argparse.ArgumentParser()
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
113 p.add_argument("metatable",
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
114 metavar="METATABLE_FILE",
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
115 help="Metatable.txt file")
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
116 p.add_argument("fastq_pairs",
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
117 metavar="SAMPLE_NAME FQ_R1 FQ_R2",
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
118 nargs="+",
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
119 default=list(),
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
120 help="Triplets of SAMPLE_NAME followed by "
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
121 "a R1/R2 FASTQ file pair")
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
122 p.add_argument("-g",dest="forward_pcr_primer")
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
123 p.add_argument("-G",dest="reverse_pcr_primer")
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
124 p.add_argument("-q",dest="trimming_threshold")
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
125 p.add_argument("-O",dest="minimum_overlap")
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
126 p.add_argument("-L",dest="minimum_length")
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
127 p.add_argument("-l",dest="sliding_window_length")
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
128 p.add_argument("-P",dest="pipeline",
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
129 choices=["vsearch","uparse","qiime"],
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
130 type=str.lower,
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
131 default="vsearch")
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
132 p.add_argument("-S",dest="use_silva",action="store_true")
2
a898ee628343 Updated to version 1.2.1.0
pjbriggs
parents: 0
diff changeset
133 p.add_argument("-H",dest="use_homd",action="store_true")
0
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
134 p.add_argument("-r",dest="reference_data_path")
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
135 p.add_argument("-c",dest="categories_file")
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
136 args = p.parse_args()
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
137
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
138 # Build the environment for running the pipeline
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
139 print "Amplicon analysis: building the environment"
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
140 metatable_file = os.path.abspath(args.metatable)
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
141 os.symlink(metatable_file,"Metatable.txt")
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
142 print "-- made symlink to Metatable.txt"
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
143
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
144 # Link to Categories.txt file (if provided)
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
145 if args.categories_file is not None:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
146 categories_file = os.path.abspath(args.categories_file)
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
147 os.symlink(categories_file,"Categories.txt")
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
148 print "-- made symlink to Categories.txt"
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
149
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
150 # Link to FASTQs and construct Final_name.txt file
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
151 sample_names = []
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
152 with open("Final_name.txt",'w') as final_name:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
153 fastqs = iter(args.fastq_pairs)
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
154 for sample_name,fqr1,fqr2 in zip(fastqs,fastqs,fastqs):
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
155 sample_name = clean_up_name(sample_name)
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
156 r1 = "%s_R1_.fastq" % sample_name
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
157 r2 = "%s_R2_.fastq" % sample_name
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
158 os.symlink(fqr1,r1)
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
159 os.symlink(fqr2,r2)
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
160 final_name.write("%s\n" % '\t'.join((r1,sample_name)))
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
161 final_name.write("%s\n" % '\t'.join((r2,sample_name)))
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
162 sample_names.append(sample_name)
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
163
2
a898ee628343 Updated to version 1.2.1.0
pjbriggs
parents: 0
diff changeset
164 # Reference database
a898ee628343 Updated to version 1.2.1.0
pjbriggs
parents: 0
diff changeset
165 if args.use_silva:
a898ee628343 Updated to version 1.2.1.0
pjbriggs
parents: 0
diff changeset
166 ref_database = "silva"
a898ee628343 Updated to version 1.2.1.0
pjbriggs
parents: 0
diff changeset
167 elif args.use_homd:
a898ee628343 Updated to version 1.2.1.0
pjbriggs
parents: 0
diff changeset
168 ref_database = "homd"
a898ee628343 Updated to version 1.2.1.0
pjbriggs
parents: 0
diff changeset
169 else:
a898ee628343 Updated to version 1.2.1.0
pjbriggs
parents: 0
diff changeset
170 ref_database = "gg"
a898ee628343 Updated to version 1.2.1.0
pjbriggs
parents: 0
diff changeset
171
8
8292f8262a9d planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit f72ff88ee11d09703bf38524dbb8026ee14bc3ef-dirty
pjbriggs
parents: 2
diff changeset
172 # Executables
8292f8262a9d planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit f72ff88ee11d09703bf38524dbb8026ee14bc3ef-dirty
pjbriggs
parents: 2
diff changeset
173 os.mkdir("bin")
8292f8262a9d planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit f72ff88ee11d09703bf38524dbb8026ee14bc3ef-dirty
pjbriggs
parents: 2
diff changeset
174 os.environ["PATH"] = os.path.abspath("bin") + \
8292f8262a9d planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit f72ff88ee11d09703bf38524dbb8026ee14bc3ef-dirty
pjbriggs
parents: 2
diff changeset
175 os.pathsep + \
10
b47cf1d6fb47 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit f72ff88ee11d09703bf38524dbb8026ee14bc3ef-dirty
pjbriggs
parents: 9
diff changeset
176 os.environ["PATH"]
8
8292f8262a9d planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit f72ff88ee11d09703bf38524dbb8026ee14bc3ef-dirty
pjbriggs
parents: 2
diff changeset
177 print "-- updated PATH: %s" % os.environ["PATH"]
8292f8262a9d planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit f72ff88ee11d09703bf38524dbb8026ee14bc3ef-dirty
pjbriggs
parents: 2
diff changeset
178 # Pipeline wants 'vsearch113' but bioconda version is just
8292f8262a9d planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit f72ff88ee11d09703bf38524dbb8026ee14bc3ef-dirty
pjbriggs
parents: 2
diff changeset
179 # 'vsearch'
8292f8262a9d planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit f72ff88ee11d09703bf38524dbb8026ee14bc3ef-dirty
pjbriggs
parents: 2
diff changeset
180 vsearch = find_executable("vsearch113")
8292f8262a9d planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit f72ff88ee11d09703bf38524dbb8026ee14bc3ef-dirty
pjbriggs
parents: 2
diff changeset
181 if vsearch is None:
8292f8262a9d planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit f72ff88ee11d09703bf38524dbb8026ee14bc3ef-dirty
pjbriggs
parents: 2
diff changeset
182 vsearch = find_executable("vsearch")
8292f8262a9d planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit f72ff88ee11d09703bf38524dbb8026ee14bc3ef-dirty
pjbriggs
parents: 2
diff changeset
183 if vsearch:
8292f8262a9d planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit f72ff88ee11d09703bf38524dbb8026ee14bc3ef-dirty
pjbriggs
parents: 2
diff changeset
184 os.symlink(vsearch,os.path.join("bin","vsearch113"))
8292f8262a9d planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit f72ff88ee11d09703bf38524dbb8026ee14bc3ef-dirty
pjbriggs
parents: 2
diff changeset
185 print "-- made symlink to %s" % vsearch
8292f8262a9d planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit f72ff88ee11d09703bf38524dbb8026ee14bc3ef-dirty
pjbriggs
parents: 2
diff changeset
186 else:
8292f8262a9d planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit f72ff88ee11d09703bf38524dbb8026ee14bc3ef-dirty
pjbriggs
parents: 2
diff changeset
187 sys.stderr.write("Missing 'vsearch[113]'\n")
8292f8262a9d planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit f72ff88ee11d09703bf38524dbb8026ee14bc3ef-dirty
pjbriggs
parents: 2
diff changeset
188 # Pipeline wants 'fasta-splitter.pl' but bioconda provides
8292f8262a9d planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit f72ff88ee11d09703bf38524dbb8026ee14bc3ef-dirty
pjbriggs
parents: 2
diff changeset
189 # 'fasta-splitter'
8292f8262a9d planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit f72ff88ee11d09703bf38524dbb8026ee14bc3ef-dirty
pjbriggs
parents: 2
diff changeset
190 fasta_splitter = find_executable("fasta-splitter.pl")
8292f8262a9d planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit f72ff88ee11d09703bf38524dbb8026ee14bc3ef-dirty
pjbriggs
parents: 2
diff changeset
191 if fasta_splitter is None:
29
31b7950136ed planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit afee03cb577aa68e650a2b7d65b31c000440d9ee
pjbriggs
parents: 27
diff changeset
192 fasta_splitter = find_executable("fasta-splitter")
31b7950136ed planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit afee03cb577aa68e650a2b7d65b31c000440d9ee
pjbriggs
parents: 27
diff changeset
193 if os.path.islink(fasta_splitter):
31b7950136ed planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit afee03cb577aa68e650a2b7d65b31c000440d9ee
pjbriggs
parents: 27
diff changeset
194 fasta_splitter = os.path.join(
31b7950136ed planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit afee03cb577aa68e650a2b7d65b31c000440d9ee
pjbriggs
parents: 27
diff changeset
195 os.path.dirname(fasta_splitter),
31b7950136ed planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit afee03cb577aa68e650a2b7d65b31c000440d9ee
pjbriggs
parents: 27
diff changeset
196 os.readlink(fasta_splitter))
8
8292f8262a9d planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit f72ff88ee11d09703bf38524dbb8026ee14bc3ef-dirty
pjbriggs
parents: 2
diff changeset
197 if fasta_splitter:
27
b5e43dfe07ac planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit e4cd2df591ac5b9da5a1731e81f921313ed9e979
pjbriggs
parents: 26
diff changeset
198 os.symlink(fasta_splitter,os.path.join("bin","fasta-splitter.pl"))
13
c87b166cbfe1 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit 777167fc30406b792d0cf924753069526f8b3e5e-dirty
pjbriggs
parents: 12
diff changeset
199 print "-- made symlink to %s" % fasta_splitter
8
8292f8262a9d planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit f72ff88ee11d09703bf38524dbb8026ee14bc3ef-dirty
pjbriggs
parents: 2
diff changeset
200 else:
8292f8262a9d planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit f72ff88ee11d09703bf38524dbb8026ee14bc3ef-dirty
pjbriggs
parents: 2
diff changeset
201 sys.stderr.write("Missing 'fasta-splitter[.pl]'\n")
15
07b04a63abf1 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit af3afa7bd2c2441074879938cd93d9965908bbc7-dirty
pjbriggs
parents: 13
diff changeset
202 # Qiime 1.8.0 wants 'RDP_JAR_PATH' env var to point to
07b04a63abf1 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit af3afa7bd2c2441074879938cd93d9965908bbc7-dirty
pjbriggs
parents: 13
diff changeset
203 # the rdp_classifier.jar file
07b04a63abf1 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit af3afa7bd2c2441074879938cd93d9965908bbc7-dirty
pjbriggs
parents: 13
diff changeset
204 # biconda provides this in the 'share/rdp_classifier/' dir
18
877d53e2d963 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit af3afa7bd2c2441074879938cd93d9965908bbc7-dirty
pjbriggs
parents: 17
diff changeset
205 # which is a link to the 'share/rdp_classifier-<VERSION>/' dir
15
07b04a63abf1 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit af3afa7bd2c2441074879938cd93d9965908bbc7-dirty
pjbriggs
parents: 13
diff changeset
206 rdp_classifier = find_executable("rdp_classifier")
07b04a63abf1 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit af3afa7bd2c2441074879938cd93d9965908bbc7-dirty
pjbriggs
parents: 13
diff changeset
207 if rdp_classifier:
18
877d53e2d963 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit af3afa7bd2c2441074879938cd93d9965908bbc7-dirty
pjbriggs
parents: 17
diff changeset
208 # Generate expected path to JAR file
16
4bd582d23d4e planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit af3afa7bd2c2441074879938cd93d9965908bbc7-dirty
pjbriggs
parents: 15
diff changeset
209 rdp_classifier = os.path.normpath(
4bd582d23d4e planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit af3afa7bd2c2441074879938cd93d9965908bbc7-dirty
pjbriggs
parents: 15
diff changeset
210 os.path.join(os.path.dirname(rdp_classifier),
15
07b04a63abf1 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit af3afa7bd2c2441074879938cd93d9965908bbc7-dirty
pjbriggs
parents: 13
diff changeset
211 "..",
07b04a63abf1 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit af3afa7bd2c2441074879938cd93d9965908bbc7-dirty
pjbriggs
parents: 13
diff changeset
212 "share",
07b04a63abf1 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit af3afa7bd2c2441074879938cd93d9965908bbc7-dirty
pjbriggs
parents: 13
diff changeset
213 "rdp_classifier",
07b04a63abf1 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit af3afa7bd2c2441074879938cd93d9965908bbc7-dirty
pjbriggs
parents: 13
diff changeset
214 "rdp_classifier.jar"))
17
e1ba19551395 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit af3afa7bd2c2441074879938cd93d9965908bbc7-dirty
pjbriggs
parents: 16
diff changeset
215 if rdp_classifier and os.path.exists(rdp_classifier):
18
877d53e2d963 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit af3afa7bd2c2441074879938cd93d9965908bbc7-dirty
pjbriggs
parents: 17
diff changeset
216 # Get real directory (which contains version)
877d53e2d963 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit af3afa7bd2c2441074879938cd93d9965908bbc7-dirty
pjbriggs
parents: 17
diff changeset
217 rdp_classifier_dir = os.readlink(
877d53e2d963 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit af3afa7bd2c2441074879938cd93d9965908bbc7-dirty
pjbriggs
parents: 17
diff changeset
218 os.path.dirname(rdp_classifier))
877d53e2d963 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit af3afa7bd2c2441074879938cd93d9965908bbc7-dirty
pjbriggs
parents: 17
diff changeset
219 # Extract the version
877d53e2d963 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit af3afa7bd2c2441074879938cd93d9965908bbc7-dirty
pjbriggs
parents: 17
diff changeset
220 rdp_version = '-'.join(os.path.basename(
877d53e2d963 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit af3afa7bd2c2441074879938cd93d9965908bbc7-dirty
pjbriggs
parents: 17
diff changeset
221 rdp_classifier_dir).split('-')[1:])
877d53e2d963 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit af3afa7bd2c2441074879938cd93d9965908bbc7-dirty
pjbriggs
parents: 17
diff changeset
222 # Make a symlink to JAR file with version in the name
877d53e2d963 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit af3afa7bd2c2441074879938cd93d9965908bbc7-dirty
pjbriggs
parents: 17
diff changeset
223 rdp_jar_path = os.path.join(os.path.abspath("bin"),
877d53e2d963 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit af3afa7bd2c2441074879938cd93d9965908bbc7-dirty
pjbriggs
parents: 17
diff changeset
224 "rdp_classifier-%s.jar" %
877d53e2d963 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit af3afa7bd2c2441074879938cd93d9965908bbc7-dirty
pjbriggs
parents: 17
diff changeset
225 rdp_version)
877d53e2d963 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit af3afa7bd2c2441074879938cd93d9965908bbc7-dirty
pjbriggs
parents: 17
diff changeset
226 os.symlink(rdp_classifier,rdp_jar_path)
877d53e2d963 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit af3afa7bd2c2441074879938cd93d9965908bbc7-dirty
pjbriggs
parents: 17
diff changeset
227 print "-- made symlink to %s" % rdp_classifier
877d53e2d963 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit af3afa7bd2c2441074879938cd93d9965908bbc7-dirty
pjbriggs
parents: 17
diff changeset
228 # Set the RDP_JAR_PATH env var
877d53e2d963 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit af3afa7bd2c2441074879938cd93d9965908bbc7-dirty
pjbriggs
parents: 17
diff changeset
229 os.environ["RDP_JAR_PATH"] = rdp_jar_path
15
07b04a63abf1 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit af3afa7bd2c2441074879938cd93d9965908bbc7-dirty
pjbriggs
parents: 13
diff changeset
230 print "-- set RDP_JAR_PATH: %s" % os.environ["RDP_JAR_PATH"]
07b04a63abf1 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit af3afa7bd2c2441074879938cd93d9965908bbc7-dirty
pjbriggs
parents: 13
diff changeset
231 else:
07b04a63abf1 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit af3afa7bd2c2441074879938cd93d9965908bbc7-dirty
pjbriggs
parents: 13
diff changeset
232 sys.stderr.write("Missing 'rdp_classifier.jar'\n")
21
092e39db5f59 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit bae32168fbfd40305a4768b889a8e7689e5987e3-dirty
pjbriggs
parents: 18
diff changeset
233 # Set up qiime_config file
092e39db5f59 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit bae32168fbfd40305a4768b889a8e7689e5987e3-dirty
pjbriggs
parents: 18
diff changeset
234 qiime_config_file = os.path.abspath("qiime_config")
092e39db5f59 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit bae32168fbfd40305a4768b889a8e7689e5987e3-dirty
pjbriggs
parents: 18
diff changeset
235 with open(qiime_config_file,'w') as qiime_config:
092e39db5f59 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit bae32168fbfd40305a4768b889a8e7689e5987e3-dirty
pjbriggs
parents: 18
diff changeset
236 # Set qiime_scripts_dir
22
eb7d118dd322 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit bae32168fbfd40305a4768b889a8e7689e5987e3-dirty
pjbriggs
parents: 21
diff changeset
237 qiime_config.write("qiime_scripts_dir\t%s" %
21
092e39db5f59 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit bae32168fbfd40305a4768b889a8e7689e5987e3-dirty
pjbriggs
parents: 18
diff changeset
238 os.path.dirname(
092e39db5f59 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit bae32168fbfd40305a4768b889a8e7689e5987e3-dirty
pjbriggs
parents: 18
diff changeset
239 find_executable("single_rarefaction.py")))
092e39db5f59 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit bae32168fbfd40305a4768b889a8e7689e5987e3-dirty
pjbriggs
parents: 18
diff changeset
240 os.environ["QIIME_CONFIG_FP"] = qiime_config_file
092e39db5f59 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit bae32168fbfd40305a4768b889a8e7689e5987e3-dirty
pjbriggs
parents: 18
diff changeset
241 print "-- set QIIME_CONFIG_FP: %s" % os.environ["QIIME_CONFIG_FP"]
8
8292f8262a9d planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit f72ff88ee11d09703bf38524dbb8026ee14bc3ef-dirty
pjbriggs
parents: 2
diff changeset
242
0
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
243 # Construct the pipeline command
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
244 print "Amplicon analysis: constructing pipeline command"
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
245 pipeline = PipelineCmd("Amplicon_analysis_pipeline.sh")
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
246 if args.forward_pcr_primer:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
247 pipeline.add_args("-g",args.forward_pcr_primer)
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
248 if args.reverse_pcr_primer:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
249 pipeline.add_args("-G",args.reverse_pcr_primer)
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
250 if args.trimming_threshold:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
251 pipeline.add_args("-q",args.trimming_threshold)
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
252 if args.minimum_overlap:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
253 pipeline.add_args("-O",args.minimum_overlap)
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
254 if args.minimum_length:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
255 pipeline.add_args("-L",args.minimum_length)
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
256 if args.sliding_window_length:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
257 pipeline.add_args("-l",args.sliding_window_length)
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
258 if args.reference_data_path:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
259 pipeline.add_args("-r",args.reference_data_path)
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
260 pipeline.add_args("-P",args.pipeline)
2
a898ee628343 Updated to version 1.2.1.0
pjbriggs
parents: 0
diff changeset
261 if ref_database == "silva":
0
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
262 pipeline.add_args("-S")
2
a898ee628343 Updated to version 1.2.1.0
pjbriggs
parents: 0
diff changeset
263 elif ref_database == "homd":
a898ee628343 Updated to version 1.2.1.0
pjbriggs
parents: 0
diff changeset
264 pipeline.add_args("-H")
0
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
265
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
266 # Echo the pipeline command to stdout
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
267 print "Running %s" % pipeline
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
268
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
269 # Run the pipeline
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
270 with open("pipeline.log","w") as pipeline_out:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
271 try:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
272 subprocess.check_call(pipeline.cmd,
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
273 stdout=pipeline_out,
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
274 stderr=subprocess.STDOUT)
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
275 exit_code = 0
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
276 print "Pipeline completed ok"
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
277 except subprocess.CalledProcessError as ex:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
278 # Non-zero exit status
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
279 sys.stderr.write("Pipeline failed: exit code %s\n" %
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
280 ex.returncode)
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
281 exit_code = ex.returncode
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
282 except Exception as ex:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
283 # Some other problem
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
284 sys.stderr.write("Unexpected error: %s\n" % str(ex))
2
a898ee628343 Updated to version 1.2.1.0
pjbriggs
parents: 0
diff changeset
285 exit_code = 1
0
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
286
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
287 # Write out the list of outputs
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
288 outputs_file = "Pipeline_outputs.txt"
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
289 list_outputs(outputs_file)
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
290
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
291 # Check for log file
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
292 log_file = "Amplicon_analysis_pipeline.log"
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
293 if os.path.exists(log_file):
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
294 print "Found log file: %s" % log_file
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
295 if exit_code == 0:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
296 # Create an HTML file to link to log files etc
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
297 # NB the paths to the files should be correct once
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
298 # copied by Galaxy on job completion
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
299 with open("pipeline_outputs.html","w") as html_out:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
300 html_out.write("""<html>
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
301 <head>
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
302 <title>Amplicon analysis pipeline: log files</title>
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
303 <head>
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
304 <body>
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
305 <h1>Amplicon analysis pipeline: log files</h1>
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
306 <ul>
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
307 """)
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
308 html_out.write(
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
309 "<li>%s</li>\n" %
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
310 ahref("Amplicon_analysis_pipeline.log",
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
311 type="text/plain"))
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
312 html_out.write(
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
313 "<li>%s</li>\n" %
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
314 ahref("pipeline.log",type="text/plain"))
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
315 html_out.write(
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
316 "<li>%s</li>\n" %
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
317 ahref("Pipeline_outputs.txt",
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
318 type="text/plain"))
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
319 html_out.write(
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
320 "<li>%s</li>\n" %
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
321 ahref("Metatable.html"))
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
322 html_out.write("""<ul>
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
323 </body>
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
324 </html>
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
325 """)
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
326 else:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
327 # Check for known error messages
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
328 check_errors()
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
329 # Write pipeline stdout to tool stderr
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
330 sys.stderr.write("\nOutput from pipeline:\n")
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
331 with open("pipeline.log",'r') as log:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
332 sys.stderr.write("%s" % log.read())
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
333 # Write log file contents to tool log
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
334 print "\nAmplicon_analysis_pipeline.log:"
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
335 with open(log_file,'r') as log:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
336 print "%s" % log.read()
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
337 else:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
338 sys.stderr.write("ERROR missing log file \"%s\"\n" %
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
339 log_file)
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
340
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
341 # Handle FastQC boxplots
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
342 print "Amplicon analysis: collating per base quality boxplots"
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
343 with open("fastqc_quality_boxplots.html","w") as quality_boxplots:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
344 # PHRED value for trimming
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
345 phred_score = 20
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
346 if args.trimming_threshold is not None:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
347 phred_score = args.trimming_threshold
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
348 # Write header for HTML output file
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
349 quality_boxplots.write("""<html>
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
350 <head>
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
351 <title>Amplicon analysis pipeline: Per-base Quality Boxplots (FastQC)</title>
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
352 <head>
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
353 <body>
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
354 <h1>Amplicon analysis pipeline: Per-base Quality Boxplots (FastQC)</h1>
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
355 """)
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
356 # Look for raw and trimmed FastQC output for each sample
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
357 for sample_name in sample_names:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
358 fastqc_dir = os.path.join(sample_name,"FastQC")
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
359 quality_boxplots.write("<h2>%s</h2>" % sample_name)
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
360 for d in ("Raw","cutdapt_sickle/Q%s" % phred_score):
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
361 quality_boxplots.write("<h3>%s</h3>" % d)
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
362 fastqc_html_files = glob.glob(
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
363 os.path.join(fastqc_dir,d,"*_fastqc.html"))
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
364 if not fastqc_html_files:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
365 quality_boxplots.write("<p>No FastQC outputs found</p>")
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
366 continue
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
367 # Pull out the per-base quality boxplots
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
368 for f in fastqc_html_files:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
369 boxplot = None
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
370 with open(f) as fp:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
371 for line in fp.read().split(">"):
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
372 try:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
373 line.index("alt=\"Per base quality graph\"")
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
374 boxplot = line + ">"
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
375 break
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
376 except ValueError:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
377 pass
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
378 if boxplot is None:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
379 boxplot = "Missing plot"
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
380 quality_boxplots.write("<h4>%s</h4><p>%s</p>" %
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
381 (os.path.basename(f),
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
382 boxplot))
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
383 quality_boxplots.write("""</body>
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
384 </html>
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
385 """)
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
386
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
387 # Handle additional output when categories file was supplied
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
388 if args.categories_file is not None:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
389 # Alpha diversity boxplots
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
390 print "Amplicon analysis: indexing alpha diversity boxplots"
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
391 boxplots_dir = os.path.abspath(
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
392 os.path.join("RESULTS",
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
393 "%s_%s" % (args.pipeline.title(),
2
a898ee628343 Updated to version 1.2.1.0
pjbriggs
parents: 0
diff changeset
394 ref_database),
0
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
395 "Alpha_diversity",
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
396 "Alpha_diversity_boxplot",
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
397 "Categories_shannon"))
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
398 print "Amplicon analysis: gathering PDFs from %s" % boxplots_dir
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
399 boxplot_pdfs = [os.path.basename(pdf)
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
400 for pdf in
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
401 sorted(glob.glob(
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
402 os.path.join(boxplots_dir,"*.pdf")))]
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
403 with open("alpha_diversity_boxplots.html","w") as boxplots_out:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
404 boxplots_out.write("""<html>
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
405 <head>
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
406 <title>Amplicon analysis pipeline: Alpha Diversity Boxplots (Shannon)</title>
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
407 <head>
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
408 <body>
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
409 <h1>Amplicon analysis pipeline: Alpha Diversity Boxplots (Shannon)</h1>
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
410 """)
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
411 boxplots_out.write("<ul>\n")
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
412 for pdf in boxplot_pdfs:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
413 boxplots_out.write("<li>%s</li>\n" % ahref(pdf))
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
414 boxplots_out.write("<ul>\n")
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
415 boxplots_out.write("""</body>
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
416 </html>
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
417 """)
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
418
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
419 # Finish
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
420 print "Amplicon analysis: finishing, exit code: %s" % exit_code
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
421 sys.exit(exit_code)