annotate amplicon_analysis_pipeline.py @ 3:3ab198df8f3f draft

planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit 15390f18b91d838880d952eb2714f689bbd8a042
author pjbriggs
date Thu, 18 Oct 2018 09:18:04 -0400
parents 1c1902e12caf
children 86a12d75ebe4
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",
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
120 choices=["vsearch","uparse","qiime"],
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
121 type=str.lower,
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
122 default="vsearch")
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
1c1902e12caf Updated to version 1.2.1.0
pjbriggs
parents: 0
diff changeset
158 if args.use_silva:
1c1902e12caf Updated to version 1.2.1.0
pjbriggs
parents: 0
diff changeset
159 ref_database = "silva"
1c1902e12caf Updated to version 1.2.1.0
pjbriggs
parents: 0
diff changeset
160 elif args.use_homd:
1c1902e12caf Updated to version 1.2.1.0
pjbriggs
parents: 0
diff changeset
161 ref_database = "homd"
1c1902e12caf Updated to version 1.2.1.0
pjbriggs
parents: 0
diff changeset
162 else:
1c1902e12caf Updated to version 1.2.1.0
pjbriggs
parents: 0
diff changeset
163 ref_database = "gg"
1c1902e12caf Updated to version 1.2.1.0
pjbriggs
parents: 0
diff changeset
164
0
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
165 # Construct the pipeline command
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
166 print "Amplicon analysis: constructing pipeline command"
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
167 pipeline = PipelineCmd("Amplicon_analysis_pipeline.sh")
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
168 if args.forward_pcr_primer:
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
169 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
170 if args.reverse_pcr_primer:
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
171 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
172 if args.trimming_threshold:
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
173 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
174 if args.minimum_overlap:
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
175 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
176 if args.minimum_length:
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
177 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
178 if args.sliding_window_length:
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
179 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
180 if args.reference_data_path:
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
181 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
182 pipeline.add_args("-P",args.pipeline)
1
1c1902e12caf Updated to version 1.2.1.0
pjbriggs
parents: 0
diff changeset
183 if ref_database == "silva":
0
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
184 pipeline.add_args("-S")
1
1c1902e12caf Updated to version 1.2.1.0
pjbriggs
parents: 0
diff changeset
185 elif ref_database == "homd":
1c1902e12caf Updated to version 1.2.1.0
pjbriggs
parents: 0
diff changeset
186 pipeline.add_args("-H")
0
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
187
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
188 # Echo the pipeline command to stdout
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
189 print "Running %s" % pipeline
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
190
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
191 # Run the pipeline
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
192 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
193 try:
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
194 subprocess.check_call(pipeline.cmd,
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
195 stdout=pipeline_out,
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
196 stderr=subprocess.STDOUT)
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
197 exit_code = 0
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
198 print "Pipeline completed ok"
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
199 except subprocess.CalledProcessError as ex:
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
200 # Non-zero exit status
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
201 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
202 ex.returncode)
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
203 exit_code = ex.returncode
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
204 except Exception as ex:
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
205 # Some other problem
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
206 sys.stderr.write("Unexpected error: %s\n" % str(ex))
1
1c1902e12caf Updated to version 1.2.1.0
pjbriggs
parents: 0
diff changeset
207 exit_code = 1
0
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
208
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
209 # Write out the list of outputs
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
210 outputs_file = "Pipeline_outputs.txt"
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
211 list_outputs(outputs_file)
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 # Check for log file
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
214 log_file = "Amplicon_analysis_pipeline.log"
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
215 if os.path.exists(log_file):
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
216 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
217 if exit_code == 0:
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
218 # 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
219 # 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
220 # copied by Galaxy on job completion
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
221 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
222 html_out.write("""<html>
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
223 <head>
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
224 <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
225 <head>
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
226 <body>
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
227 <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
228 <ul>
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
229 """)
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
230 html_out.write(
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
231 "<li>%s</li>\n" %
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
232 ahref("Amplicon_analysis_pipeline.log",
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
233 type="text/plain"))
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("pipeline.log",type="text/plain"))
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
237 html_out.write(
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
238 "<li>%s</li>\n" %
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
239 ahref("Pipeline_outputs.txt",
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
240 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("Metatable.html"))
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
244 html_out.write("""<ul>
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
245 </body>
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
246 </html>
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
247 """)
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
248 else:
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
249 # Check for known error messages
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
250 check_errors()
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
251 # Write pipeline stdout to tool stderr
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
252 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
253 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
254 sys.stderr.write("%s" % log.read())
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
255 # 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
256 print "\nAmplicon_analysis_pipeline.log:"
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
257 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
258 print "%s" % log.read()
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
259 else:
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
260 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
261 log_file)
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
262
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
263 # Handle FastQC boxplots
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
264 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
265 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
266 # PHRED value for trimming
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
267 phred_score = 20
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
268 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
269 phred_score = args.trimming_threshold
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
270 # Write header for HTML output file
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
271 quality_boxplots.write("""<html>
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
272 <head>
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
273 <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
274 <head>
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
275 <body>
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
276 <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
277 """)
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
278 # 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
279 for sample_name in sample_names:
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
280 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
281 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
282 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
283 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
284 fastqc_html_files = glob.glob(
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
285 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
286 if not fastqc_html_files:
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
287 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
288 continue
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
289 # 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
290 for f in fastqc_html_files:
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
291 boxplot = None
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
292 with open(f) as fp:
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
293 for line in fp.read().split(">"):
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
294 try:
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
295 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
296 boxplot = line + ">"
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
297 break
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
298 except ValueError:
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
299 pass
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
300 if boxplot is None:
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
301 boxplot = "Missing plot"
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
302 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
303 (os.path.basename(f),
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
304 boxplot))
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
305 quality_boxplots.write("""</body>
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
306 </html>
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
307 """)
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
308
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
309 # 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
310 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
311 # Alpha diversity boxplots
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
312 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
313 boxplots_dir = os.path.abspath(
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
314 os.path.join("RESULTS",
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
315 "%s_%s" % (args.pipeline.title(),
1
1c1902e12caf Updated to version 1.2.1.0
pjbriggs
parents: 0
diff changeset
316 ref_database),
0
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
317 "Alpha_diversity",
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
318 "Alpha_diversity_boxplot",
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
319 "Categories_shannon"))
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
320 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
321 boxplot_pdfs = [os.path.basename(pdf)
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
322 for pdf in
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
323 sorted(glob.glob(
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
324 os.path.join(boxplots_dir,"*.pdf")))]
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
325 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
326 boxplots_out.write("""<html>
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
327 <head>
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
328 <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
329 <head>
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
330 <body>
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
331 <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
332 """)
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
333 boxplots_out.write("<ul>\n")
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
334 for pdf in boxplot_pdfs:
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
335 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
336 boxplots_out.write("<ul>\n")
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
337 boxplots_out.write("""</body>
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
338 </html>
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
339 """)
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
340
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
341 # Finish
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
342 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
343 sys.exit(exit_code)