annotate amplicon_analysis_pipeline.py @ 38:7b2c40450792 draft

planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit 601f7d1e21b25c583cc6e1a563029bab3f226921-dirty
author pjbriggs
date Wed, 17 Oct 2018 05:01:57 -0400
parents e832be1635b4
children d19fca1c009c
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):
38
7b2c40450792 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit 601f7d1e21b25c583cc6e1a563029bab3f226921-dirty
pjbriggs
parents: 37
diff changeset
63 # Remove extensions and trailing "_L[0-9]+_001" from
7b2c40450792 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit 601f7d1e21b25c583cc6e1a563029bab3f226921-dirty
pjbriggs
parents: 37
diff changeset
64 # Fastq pair names
7b2c40450792 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit 601f7d1e21b25c583cc6e1a563029bab3f226921-dirty
pjbriggs
parents: 37
diff changeset
65 sample_name = '.'.join(sample.split('.')[:1])
7b2c40450792 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit 601f7d1e21b25c583cc6e1a563029bab3f226921-dirty
pjbriggs
parents: 37
diff changeset
66 split_name = sample_name.split('_')
0
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
67 if split_name[-1] == "001":
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
68 split_name = split_name[:-1]
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
69 if split_name[-1].startswith('L'):
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
70 try:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
71 int(split_name[-1][1:])
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
72 split_name = split_name[:-1]
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
73 except ValueError:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
74 pass
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
75 return '_'.join(split_name)
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
76
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
77 def list_outputs(filen=None):
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
78 # List the output directory contents
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
79 # 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
80 # write to, otherwise write to stdout
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
81 if filen is not None:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
82 fp = open(filen,'w')
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
83 else:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
84 fp = sys.stdout
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
85 results_dir = os.path.abspath("RESULTS")
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
86 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
87 ix = 0
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
88 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
89 ix += 1
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
90 fp.write("-- %d: %s\n" % (ix,
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
91 os.path.relpath(d,results_dir)))
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
92 for f in files:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
93 ix += 1
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
94 fp.write("---- %d: %s\n" % (ix,
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
95 os.path.relpath(f,results_dir)))
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
96 # Close output file
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
97 if filen is not None:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
98 fp.close()
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
99
8
8292f8262a9d planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit f72ff88ee11d09703bf38524dbb8026ee14bc3ef-dirty
pjbriggs
parents: 2
diff changeset
100 def find_executable(name):
8292f8262a9d planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit f72ff88ee11d09703bf38524dbb8026ee14bc3ef-dirty
pjbriggs
parents: 2
diff changeset
101 # Locate executable on PATH
8292f8262a9d planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit f72ff88ee11d09703bf38524dbb8026ee14bc3ef-dirty
pjbriggs
parents: 2
diff changeset
102 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
103 exe = os.path.normpath(
31b7950136ed planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit afee03cb577aa68e650a2b7d65b31c000440d9ee
pjbriggs
parents: 27
diff changeset
104 os.path.abspath(os.path.join(p,name)))
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)
38
7b2c40450792 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit 601f7d1e21b25c583cc6e1a563029bab3f226921-dirty
pjbriggs
parents: 37
diff changeset
156 print "Cleaned up sample name: %s" % sample_name
0
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
157 r1 = "%s_R1_.fastq" % sample_name
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
158 r2 = "%s_R2_.fastq" % sample_name
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
159 os.symlink(fqr1,r1)
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
160 os.symlink(fqr2,r2)
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((r1,sample_name)))
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
162 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
163 sample_names.append(sample_name)
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
164
2
a898ee628343 Updated to version 1.2.1.0
pjbriggs
parents: 0
diff changeset
165 # Reference database
a898ee628343 Updated to version 1.2.1.0
pjbriggs
parents: 0
diff changeset
166 if args.use_silva:
a898ee628343 Updated to version 1.2.1.0
pjbriggs
parents: 0
diff changeset
167 ref_database = "silva"
a898ee628343 Updated to version 1.2.1.0
pjbriggs
parents: 0
diff changeset
168 elif args.use_homd:
a898ee628343 Updated to version 1.2.1.0
pjbriggs
parents: 0
diff changeset
169 ref_database = "homd"
a898ee628343 Updated to version 1.2.1.0
pjbriggs
parents: 0
diff changeset
170 else:
a898ee628343 Updated to version 1.2.1.0
pjbriggs
parents: 0
diff changeset
171 ref_database = "gg"
a898ee628343 Updated to version 1.2.1.0
pjbriggs
parents: 0
diff changeset
172
0
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
173 # Construct the pipeline command
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
174 print "Amplicon analysis: constructing pipeline command"
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
175 pipeline = PipelineCmd("Amplicon_analysis_pipeline.sh")
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
176 if args.forward_pcr_primer:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
177 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
178 if args.reverse_pcr_primer:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
179 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
180 if args.trimming_threshold:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
181 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
182 if args.minimum_overlap:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
183 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
184 if args.minimum_length:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
185 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
186 if args.sliding_window_length:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
187 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
188 if args.reference_data_path:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
189 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
190 pipeline.add_args("-P",args.pipeline)
2
a898ee628343 Updated to version 1.2.1.0
pjbriggs
parents: 0
diff changeset
191 if ref_database == "silva":
0
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
192 pipeline.add_args("-S")
2
a898ee628343 Updated to version 1.2.1.0
pjbriggs
parents: 0
diff changeset
193 elif ref_database == "homd":
a898ee628343 Updated to version 1.2.1.0
pjbriggs
parents: 0
diff changeset
194 pipeline.add_args("-H")
0
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
195
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
196 # Echo the pipeline command to stdout
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
197 print "Running %s" % pipeline
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
198
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
199 # Run the pipeline
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
200 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
201 try:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
202 subprocess.check_call(pipeline.cmd,
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
203 stdout=pipeline_out,
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
204 stderr=subprocess.STDOUT)
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
205 exit_code = 0
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
206 print "Pipeline completed ok"
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
207 except subprocess.CalledProcessError as ex:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
208 # Non-zero exit status
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
209 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
210 ex.returncode)
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
211 exit_code = ex.returncode
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
212 except Exception as ex:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
213 # Some other problem
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
214 sys.stderr.write("Unexpected error: %s\n" % str(ex))
2
a898ee628343 Updated to version 1.2.1.0
pjbriggs
parents: 0
diff changeset
215 exit_code = 1
0
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
216
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
217 # Write out the list of outputs
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
218 outputs_file = "Pipeline_outputs.txt"
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
219 list_outputs(outputs_file)
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
220
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
221 # Check for log file
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
222 log_file = "Amplicon_analysis_pipeline.log"
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
223 if os.path.exists(log_file):
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
224 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
225 if exit_code == 0:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
226 # 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
227 # 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
228 # copied by Galaxy on job completion
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
229 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
230 html_out.write("""<html>
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
231 <head>
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
232 <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
233 <head>
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
234 <body>
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
235 <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
236 <ul>
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
237 """)
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
238 html_out.write(
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
239 "<li>%s</li>\n" %
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
240 ahref("Amplicon_analysis_pipeline.log",
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
241 type="text/plain"))
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
242 html_out.write(
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
243 "<li>%s</li>\n" %
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
244 ahref("pipeline.log",type="text/plain"))
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
245 html_out.write(
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
246 "<li>%s</li>\n" %
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
247 ahref("Pipeline_outputs.txt",
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
248 type="text/plain"))
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
249 html_out.write(
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
250 "<li>%s</li>\n" %
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
251 ahref("Metatable.html"))
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
252 html_out.write("""<ul>
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
253 </body>
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
254 </html>
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
255 """)
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
256 else:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
257 # Check for known error messages
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
258 check_errors()
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
259 # Write pipeline stdout to tool stderr
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
260 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
261 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
262 sys.stderr.write("%s" % log.read())
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
263 # 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
264 print "\nAmplicon_analysis_pipeline.log:"
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
265 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
266 print "%s" % log.read()
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
267 else:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
268 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
269 log_file)
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
270
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
271 # Handle FastQC boxplots
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
272 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
273 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
274 # PHRED value for trimming
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
275 phred_score = 20
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
276 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
277 phred_score = args.trimming_threshold
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
278 # Write header for HTML output file
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
279 quality_boxplots.write("""<html>
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
280 <head>
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
281 <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
282 <head>
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
283 <body>
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
284 <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
285 """)
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
286 # 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
287 for sample_name in sample_names:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
288 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
289 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
290 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
291 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
292 fastqc_html_files = glob.glob(
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
293 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
294 if not fastqc_html_files:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
295 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
296 continue
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
297 # 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
298 for f in fastqc_html_files:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
299 boxplot = None
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
300 with open(f) as fp:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
301 for line in fp.read().split(">"):
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
302 try:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
303 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
304 boxplot = line + ">"
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
305 break
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
306 except ValueError:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
307 pass
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
308 if boxplot is None:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
309 boxplot = "Missing plot"
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
310 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
311 (os.path.basename(f),
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
312 boxplot))
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
313 quality_boxplots.write("""</body>
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
314 </html>
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
315 """)
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
316
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
317 # 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
318 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
319 # Alpha diversity boxplots
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
320 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
321 boxplots_dir = os.path.abspath(
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
322 os.path.join("RESULTS",
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
323 "%s_%s" % (args.pipeline.title(),
2
a898ee628343 Updated to version 1.2.1.0
pjbriggs
parents: 0
diff changeset
324 ref_database),
0
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
325 "Alpha_diversity",
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
326 "Alpha_diversity_boxplot",
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
327 "Categories_shannon"))
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
328 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
329 boxplot_pdfs = [os.path.basename(pdf)
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
330 for pdf in
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
331 sorted(glob.glob(
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
332 os.path.join(boxplots_dir,"*.pdf")))]
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
333 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
334 boxplots_out.write("""<html>
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
335 <head>
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
336 <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
337 <head>
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
338 <body>
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
339 <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
340 """)
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
341 boxplots_out.write("<ul>\n")
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
342 for pdf in boxplot_pdfs:
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
343 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
344 boxplots_out.write("<ul>\n")
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
345 boxplots_out.write("""</body>
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
346 </html>
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
347 """)
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
348
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
349 # Finish
b433086738d6 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit ba3e5b591407db52a586361efb21927c8171ec0e
pjbriggs
parents:
diff changeset
350 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
351 sys.exit(exit_code)