annotate amplicon_analysis_pipeline.py @ 47:1bc0077b2c91 draft

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