annotate amplicon_analysis_pipeline.py @ 0:47ec9c6f44b8 draft

planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
author pjbriggs
date Thu, 09 Nov 2017 10:13:29 -0500
parents
children 1c1902e12caf
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):
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
63 # Remove trailing "_L[0-9]+_001" from Fastq
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
64 # pair names
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
65 split_name = sample.split('_')
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
66 if split_name[-1] == "001":
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
67 split_name = split_name[:-1]
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
68 if split_name[-1].startswith('L'):
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
69 try:
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
70 int(split_name[-1][1:])
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
71 split_name = split_name[:-1]
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
72 except ValueError:
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
73 pass
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
74 return '_'.join(split_name)
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
75
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
76 def list_outputs(filen=None):
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
77 # List the output directory contents
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
78 # 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
79 # write to, otherwise write to stdout
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
80 if filen is not None:
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
81 fp = open(filen,'w')
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
82 else:
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
83 fp = sys.stdout
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
84 results_dir = os.path.abspath("RESULTS")
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
85 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
86 ix = 0
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
87 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
88 ix += 1
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
89 fp.write("-- %d: %s\n" % (ix,
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
90 os.path.relpath(d,results_dir)))
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
91 for f in files:
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
92 ix += 1
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
93 fp.write("---- %d: %s\n" % (ix,
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
94 os.path.relpath(f,results_dir)))
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
95 # Close output file
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
96 if filen is not None:
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
97 fp.close()
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
98
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
99 if __name__ == "__main__":
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
100 # Command line
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
101 print "Amplicon analysis: starting"
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
102 p = argparse.ArgumentParser()
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
103 p.add_argument("metatable",
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
104 metavar="METATABLE_FILE",
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
105 help="Metatable.txt file")
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
106 p.add_argument("fastq_pairs",
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
107 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
108 nargs="+",
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
109 default=list(),
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
110 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
111 "a R1/R2 FASTQ file pair")
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
112 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
113 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
114 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
115 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
116 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
117 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
118 p.add_argument("-P",dest="pipeline",
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
119 choices=["vsearch","uparse","qiime"],
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
120 type=str.lower,
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
121 default="vsearch")
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
122 p.add_argument("-S",dest="use_silva",action="store_true")
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
123 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
124 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
125 args = p.parse_args()
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
126
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
127 # 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
128 print "Amplicon analysis: building the environment"
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
129 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
130 os.symlink(metatable_file,"Metatable.txt")
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
131 print "-- made symlink to Metatable.txt"
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
132
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
133 # 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
134 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
135 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
136 os.symlink(categories_file,"Categories.txt")
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
137 print "-- made symlink to Categories.txt"
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
138
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
139 # 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
140 sample_names = []
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
141 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
142 fastqs = iter(args.fastq_pairs)
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
143 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
144 sample_name = clean_up_name(sample_name)
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
145 r1 = "%s_R1_.fastq" % sample_name
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
146 r2 = "%s_R2_.fastq" % sample_name
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
147 os.symlink(fqr1,r1)
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
148 os.symlink(fqr2,r2)
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
149 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
150 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
151 sample_names.append(sample_name)
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
152
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
153 # Construct the pipeline command
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
154 print "Amplicon analysis: constructing pipeline command"
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
155 pipeline = PipelineCmd("Amplicon_analysis_pipeline.sh")
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
156 if args.forward_pcr_primer:
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
157 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
158 if args.reverse_pcr_primer:
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
159 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
160 if args.trimming_threshold:
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
161 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
162 if args.minimum_overlap:
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
163 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
164 if args.minimum_length:
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
165 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
166 if args.sliding_window_length:
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
167 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
168 if args.reference_data_path:
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
169 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
170 pipeline.add_args("-P",args.pipeline)
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
171 if args.use_silva:
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
172 pipeline.add_args("-S")
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
173
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
174 # Echo the pipeline command to stdout
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
175 print "Running %s" % pipeline
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
176
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
177 # Run the pipeline
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
178 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
179 try:
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
180 subprocess.check_call(pipeline.cmd,
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
181 stdout=pipeline_out,
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
182 stderr=subprocess.STDOUT)
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
183 exit_code = 0
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
184 print "Pipeline completed ok"
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
185 except subprocess.CalledProcessError as ex:
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
186 # Non-zero exit status
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
187 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
188 ex.returncode)
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
189 exit_code = ex.returncode
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
190 except Exception as ex:
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
191 # Some other problem
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
192 sys.stderr.write("Unexpected error: %s\n" % str(ex))
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
193
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
194 # Write out the list of outputs
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
195 outputs_file = "Pipeline_outputs.txt"
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
196 list_outputs(outputs_file)
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
197
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
198 # Check for log file
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
199 log_file = "Amplicon_analysis_pipeline.log"
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
200 if os.path.exists(log_file):
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
201 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
202 if exit_code == 0:
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
203 # 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
204 # 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
205 # copied by Galaxy on job completion
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
206 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
207 html_out.write("""<html>
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
208 <head>
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
209 <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
210 <head>
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
211 <body>
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
212 <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
213 <ul>
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
214 """)
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
215 html_out.write(
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
216 "<li>%s</li>\n" %
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
217 ahref("Amplicon_analysis_pipeline.log",
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
218 type="text/plain"))
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
219 html_out.write(
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
220 "<li>%s</li>\n" %
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
221 ahref("pipeline.log",type="text/plain"))
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
222 html_out.write(
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
223 "<li>%s</li>\n" %
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
224 ahref("Pipeline_outputs.txt",
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
225 type="text/plain"))
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
226 html_out.write(
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
227 "<li>%s</li>\n" %
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
228 ahref("Metatable.html"))
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
229 html_out.write("""<ul>
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 </html>
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
232 """)
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
233 else:
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
234 # Check for known error messages
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
235 check_errors()
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
236 # Write pipeline stdout to tool stderr
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
237 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
238 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
239 sys.stderr.write("%s" % log.read())
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
240 # 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
241 print "\nAmplicon_analysis_pipeline.log:"
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
242 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
243 print "%s" % log.read()
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
244 else:
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
245 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
246 log_file)
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 # Handle FastQC boxplots
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
249 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
250 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
251 # PHRED value for trimming
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
252 phred_score = 20
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
253 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
254 phred_score = args.trimming_threshold
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
255 # Write header for HTML output file
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
256 quality_boxplots.write("""<html>
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
257 <head>
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
258 <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
259 <head>
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
260 <body>
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
261 <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
262 """)
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
263 # 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
264 for sample_name in sample_names:
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
265 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
266 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
267 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
268 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
269 fastqc_html_files = glob.glob(
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
270 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
271 if not fastqc_html_files:
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
272 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
273 continue
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
274 # 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
275 for f in fastqc_html_files:
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
276 boxplot = None
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
277 with open(f) as fp:
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
278 for line in fp.read().split(">"):
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
279 try:
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
280 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
281 boxplot = line + ">"
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
282 break
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
283 except ValueError:
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
284 pass
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
285 if boxplot is None:
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
286 boxplot = "Missing plot"
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
287 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
288 (os.path.basename(f),
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
289 boxplot))
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
290 quality_boxplots.write("""</body>
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
291 </html>
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
292 """)
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
293
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
294 # 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
295 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
296 # Alpha diversity boxplots
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
297 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
298 boxplots_dir = os.path.abspath(
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
299 os.path.join("RESULTS",
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
300 "%s_%s" % (args.pipeline.title(),
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
301 ("gg" if not args.use_silva
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
302 else "silva")),
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
303 "Alpha_diversity",
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
304 "Alpha_diversity_boxplot",
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
305 "Categories_shannon"))
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
306 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
307 boxplot_pdfs = [os.path.basename(pdf)
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
308 for pdf in
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
309 sorted(glob.glob(
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
310 os.path.join(boxplots_dir,"*.pdf")))]
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
311 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
312 boxplots_out.write("""<html>
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
313 <head>
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
314 <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
315 <head>
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
316 <body>
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
317 <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
318 """)
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
319 boxplots_out.write("<ul>\n")
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
320 for pdf in boxplot_pdfs:
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
321 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
322 boxplots_out.write("<ul>\n")
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
323 boxplots_out.write("""</body>
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
324 </html>
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
325 """)
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
326
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
327 # Finish
47ec9c6f44b8 planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff changeset
328 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
329 sys.exit(exit_code)