comparison 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
comparison
equal deleted inserted replaced
0:47ec9c6f44b8 1:1c1902e12caf
118 p.add_argument("-P",dest="pipeline", 118 p.add_argument("-P",dest="pipeline",
119 choices=["vsearch","uparse","qiime"], 119 choices=["vsearch","uparse","qiime"],
120 type=str.lower, 120 type=str.lower,
121 default="vsearch") 121 default="vsearch")
122 p.add_argument("-S",dest="use_silva",action="store_true") 122 p.add_argument("-S",dest="use_silva",action="store_true")
123 p.add_argument("-H",dest="use_homd",action="store_true")
123 p.add_argument("-r",dest="reference_data_path") 124 p.add_argument("-r",dest="reference_data_path")
124 p.add_argument("-c",dest="categories_file") 125 p.add_argument("-c",dest="categories_file")
125 args = p.parse_args() 126 args = p.parse_args()
126 127
127 # Build the environment for running the pipeline 128 # Build the environment for running the pipeline
147 os.symlink(fqr1,r1) 148 os.symlink(fqr1,r1)
148 os.symlink(fqr2,r2) 149 os.symlink(fqr2,r2)
149 final_name.write("%s\n" % '\t'.join((r1,sample_name))) 150 final_name.write("%s\n" % '\t'.join((r1,sample_name)))
150 final_name.write("%s\n" % '\t'.join((r2,sample_name))) 151 final_name.write("%s\n" % '\t'.join((r2,sample_name)))
151 sample_names.append(sample_name) 152 sample_names.append(sample_name)
153
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"
152 161
153 # Construct the pipeline command 162 # Construct the pipeline command
154 print "Amplicon analysis: constructing pipeline command" 163 print "Amplicon analysis: constructing pipeline command"
155 pipeline = PipelineCmd("Amplicon_analysis_pipeline.sh") 164 pipeline = PipelineCmd("Amplicon_analysis_pipeline.sh")
156 if args.forward_pcr_primer: 165 if args.forward_pcr_primer:
166 if args.sliding_window_length: 175 if args.sliding_window_length:
167 pipeline.add_args("-l",args.sliding_window_length) 176 pipeline.add_args("-l",args.sliding_window_length)
168 if args.reference_data_path: 177 if args.reference_data_path:
169 pipeline.add_args("-r",args.reference_data_path) 178 pipeline.add_args("-r",args.reference_data_path)
170 pipeline.add_args("-P",args.pipeline) 179 pipeline.add_args("-P",args.pipeline)
171 if args.use_silva: 180 if ref_database == "silva":
172 pipeline.add_args("-S") 181 pipeline.add_args("-S")
182 elif ref_database == "homd":
183 pipeline.add_args("-H")
173 184
174 # Echo the pipeline command to stdout 185 # Echo the pipeline command to stdout
175 print "Running %s" % pipeline 186 print "Running %s" % pipeline
176 187
177 # Run the pipeline 188 # Run the pipeline
188 ex.returncode) 199 ex.returncode)
189 exit_code = ex.returncode 200 exit_code = ex.returncode
190 except Exception as ex: 201 except Exception as ex:
191 # Some other problem 202 # Some other problem
192 sys.stderr.write("Unexpected error: %s\n" % str(ex)) 203 sys.stderr.write("Unexpected error: %s\n" % str(ex))
204 exit_code = 1
193 205
194 # Write out the list of outputs 206 # Write out the list of outputs
195 outputs_file = "Pipeline_outputs.txt" 207 outputs_file = "Pipeline_outputs.txt"
196 list_outputs(outputs_file) 208 list_outputs(outputs_file)
197 209
296 # Alpha diversity boxplots 308 # Alpha diversity boxplots
297 print "Amplicon analysis: indexing alpha diversity boxplots" 309 print "Amplicon analysis: indexing alpha diversity boxplots"
298 boxplots_dir = os.path.abspath( 310 boxplots_dir = os.path.abspath(
299 os.path.join("RESULTS", 311 os.path.join("RESULTS",
300 "%s_%s" % (args.pipeline.title(), 312 "%s_%s" % (args.pipeline.title(),
301 ("gg" if not args.use_silva 313 ref_database),
302 else "silva")),
303 "Alpha_diversity", 314 "Alpha_diversity",
304 "Alpha_diversity_boxplot", 315 "Alpha_diversity_boxplot",
305 "Categories_shannon")) 316 "Categories_shannon"))
306 print "Amplicon analysis: gathering PDFs from %s" % boxplots_dir 317 print "Amplicon analysis: gathering PDFs from %s" % boxplots_dir
307 boxplot_pdfs = [os.path.basename(pdf) 318 boxplot_pdfs = [os.path.basename(pdf)