annotate amplicon_analysis_pipeline.py @ 11:570228bb2fb7 draft

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