annotate amplicon_analysis_pipeline.py @ 4:86a12d75ebe4 draft default tip

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