Mercurial > repos > pjbriggs > amplicon_analysis_pipeline
annotate amplicon_analysis_pipeline.py @ 1:1c1902e12caf draft
Updated to version 1.2.1.0
author | pjbriggs |
---|---|
date | Wed, 25 Apr 2018 03:54:00 -0400 |
parents | 47ec9c6f44b8 |
children | 3ab198df8f3f |
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") |
1 | 123 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
|
124 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
|
125 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
|
126 args = p.parse_args() |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
127 |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
128 # 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
|
129 print "Amplicon analysis: building the environment" |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
130 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
|
131 os.symlink(metatable_file,"Metatable.txt") |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
132 print "-- made symlink to Metatable.txt" |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
133 |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
134 # 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
|
135 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
|
136 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
|
137 os.symlink(categories_file,"Categories.txt") |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
138 print "-- made symlink to Categories.txt" |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
139 |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
140 # 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
|
141 sample_names = [] |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
142 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
|
143 fastqs = iter(args.fastq_pairs) |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
144 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
|
145 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
|
146 r1 = "%s_R1_.fastq" % sample_name |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
147 r2 = "%s_R2_.fastq" % sample_name |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
148 os.symlink(fqr1,r1) |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
149 os.symlink(fqr2,r2) |
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((r1,sample_name))) |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
151 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
|
152 sample_names.append(sample_name) |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
153 |
1 | 154 # Reference database |
155 if args.use_silva: | |
156 ref_database = "silva" | |
157 elif args.use_homd: | |
158 ref_database = "homd" | |
159 else: | |
160 ref_database = "gg" | |
161 | |
0
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
162 # Construct the pipeline command |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
163 print "Amplicon analysis: constructing pipeline command" |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
164 pipeline = PipelineCmd("Amplicon_analysis_pipeline.sh") |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
165 if args.forward_pcr_primer: |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
166 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
|
167 if args.reverse_pcr_primer: |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
168 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
|
169 if args.trimming_threshold: |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
170 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
|
171 if args.minimum_overlap: |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
172 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
|
173 if args.minimum_length: |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
174 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
|
175 if args.sliding_window_length: |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
176 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
|
177 if args.reference_data_path: |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
178 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
|
179 pipeline.add_args("-P",args.pipeline) |
1 | 180 if ref_database == "silva": |
0
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
181 pipeline.add_args("-S") |
1 | 182 elif ref_database == "homd": |
183 pipeline.add_args("-H") | |
0
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
184 |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
185 # Echo the pipeline command to stdout |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
186 print "Running %s" % pipeline |
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 # Run the pipeline |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
189 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
|
190 try: |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
191 subprocess.check_call(pipeline.cmd, |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
192 stdout=pipeline_out, |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
193 stderr=subprocess.STDOUT) |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
194 exit_code = 0 |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
195 print "Pipeline completed ok" |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
196 except subprocess.CalledProcessError as ex: |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
197 # Non-zero exit status |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
198 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
|
199 ex.returncode) |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
200 exit_code = ex.returncode |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
201 except Exception as ex: |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
202 # Some other problem |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
203 sys.stderr.write("Unexpected error: %s\n" % str(ex)) |
1 | 204 exit_code = 1 |
0
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
205 |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
206 # Write out the list of outputs |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
207 outputs_file = "Pipeline_outputs.txt" |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
208 list_outputs(outputs_file) |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
209 |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
210 # Check for log file |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
211 log_file = "Amplicon_analysis_pipeline.log" |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
212 if os.path.exists(log_file): |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
213 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
|
214 if exit_code == 0: |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
215 # 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
|
216 # 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
|
217 # copied by Galaxy on job completion |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
218 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
|
219 html_out.write("""<html> |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
220 <head> |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
221 <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
|
222 <head> |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
223 <body> |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
224 <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
|
225 <ul> |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
226 """) |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
227 html_out.write( |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
228 "<li>%s</li>\n" % |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
229 ahref("Amplicon_analysis_pipeline.log", |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
230 type="text/plain")) |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
231 html_out.write( |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
232 "<li>%s</li>\n" % |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
233 ahref("pipeline.log",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_outputs.txt", |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
237 type="text/plain")) |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
238 html_out.write( |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
239 "<li>%s</li>\n" % |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
240 ahref("Metatable.html")) |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
241 html_out.write("""<ul> |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
242 </body> |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
243 </html> |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
244 """) |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
245 else: |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
246 # Check for known error messages |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
247 check_errors() |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
248 # Write pipeline stdout to tool stderr |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
249 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
|
250 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
|
251 sys.stderr.write("%s" % log.read()) |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
252 # 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
|
253 print "\nAmplicon_analysis_pipeline.log:" |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
254 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
|
255 print "%s" % log.read() |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
256 else: |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
257 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
|
258 log_file) |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
259 |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
260 # Handle FastQC boxplots |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
261 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
|
262 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
|
263 # PHRED value for trimming |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
264 phred_score = 20 |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
265 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
|
266 phred_score = args.trimming_threshold |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
267 # Write header for HTML output file |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
268 quality_boxplots.write("""<html> |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
269 <head> |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
270 <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
|
271 <head> |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
272 <body> |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
273 <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
|
274 """) |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
275 # 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
|
276 for sample_name in sample_names: |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
277 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
|
278 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
|
279 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
|
280 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
|
281 fastqc_html_files = glob.glob( |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
282 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
|
283 if not fastqc_html_files: |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
284 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
|
285 continue |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
286 # 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
|
287 for f in fastqc_html_files: |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
288 boxplot = None |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
289 with open(f) as fp: |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
290 for line in fp.read().split(">"): |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
291 try: |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
292 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
|
293 boxplot = line + ">" |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
294 break |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
295 except ValueError: |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
296 pass |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
297 if boxplot is None: |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
298 boxplot = "Missing plot" |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
299 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
|
300 (os.path.basename(f), |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
301 boxplot)) |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
302 quality_boxplots.write("""</body> |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
303 </html> |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
304 """) |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
305 |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
306 # 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
|
307 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
|
308 # Alpha diversity boxplots |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
309 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
|
310 boxplots_dir = os.path.abspath( |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
311 os.path.join("RESULTS", |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
312 "%s_%s" % (args.pipeline.title(), |
1 | 313 ref_database), |
0
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
314 "Alpha_diversity", |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
315 "Alpha_diversity_boxplot", |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
316 "Categories_shannon")) |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
317 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
|
318 boxplot_pdfs = [os.path.basename(pdf) |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
319 for pdf in |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
320 sorted(glob.glob( |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
321 os.path.join(boxplots_dir,"*.pdf")))] |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
322 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
|
323 boxplots_out.write("""<html> |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
324 <head> |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
325 <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
|
326 <head> |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
327 <body> |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
328 <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
|
329 """) |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
330 boxplots_out.write("<ul>\n") |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
331 for pdf in boxplot_pdfs: |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
332 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
|
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 boxplots_out.write("""</body> |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
335 </html> |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
336 """) |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
337 |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
338 # Finish |
47ec9c6f44b8
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit b63924933a03255872077beb4d0fde49d77afa92
pjbriggs
parents:
diff
changeset
|
339 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
|
340 sys.exit(exit_code) |