Mercurial > repos > jackcurragh > ribogalaxy_bowtie_rrna
comparison bowtie_rRNA_removal_wrapper/bowtie_rRNA_tRNA_removal_wrapper.py @ 21:b49ad9f12dfa draft
Uploaded
author | jackcurragh |
---|---|
date | Wed, 11 May 2022 13:37:35 +0000 |
parents | dbb3e98144fd |
children | ca7c965f7cc9 |
comparison
equal
deleted
inserted
replaced
20:87b1fa00d6ab | 21:b49ad9f12dfa |
---|---|
409 stop_err( 'Something is wrong with the alignment parameters and the alignment could not be run\n' + str( e ) ) | 409 stop_err( 'Something is wrong with the alignment parameters and the alignment could not be run\n' + str( e ) ) |
410 try: | 410 try: |
411 # have to nest try-except in try-finally to handle 2.4 | 411 # have to nest try-except in try-finally to handle 2.4 |
412 try: | 412 try: |
413 # prepare actual mapping commands | 413 # prepare actual mapping commands |
414 if options.paired == 'paired': | 414 if options.output != 'XXXX': |
415 cmd2 = 'bowtie %s %s -1 %s -2 %s > %s' % ( aligning_cmds, ref_file_name, options.input1, options.input2, options.output ) | 415 print('incorrect option') |
416 else: | 416 if options.paired == 'paired': |
417 cmd2 = 'bowtie %s %s %s > %s' % ( aligning_cmds, ref_file_name, options.input1, options.output ) | 417 cmd2 = 'bowtie %s %s -1 %s -2 %s > %s | samtools view -b -S > %s' % ( aligning_cmds, ref_file_name, options.input1, options.input2, options.output, options.output ) |
418 else: | |
419 cmd2 = 'bowtie %s %s %s > %s | samtools view -b -S > %s' % ( aligning_cmds, ref_file_name, options.input1, options.output, options.output ) | |
420 else: | |
421 if options.paired == 'paired': | |
422 cmd2 = 'bowtie %s %s -1 %s -2 %s' % ( aligning_cmds, ref_file_name, options.input1, options.input2 ) | |
423 else: | |
424 print('correct option') | |
425 cmd2 = 'bowtie %s %s %s' % ( aligning_cmds, ref_file_name, options.input1 ) | |
426 print(cmd2) | |
418 # align | 427 # align |
419 tmp = tempfile.NamedTemporaryFile( dir=tmp_index_dir ).name | 428 tmp = tempfile.NamedTemporaryFile( dir=tmp_index_dir ).name |
420 with open(tmp, 'w') as tmp_stderr: | 429 with open(tmp, 'w') as tmp_stderr: |
421 returncode = subprocess.call(args=cmd2, shell=True, cwd=tmp_index_dir, stderr=tmp_stderr.fileno()) | 430 returncode = subprocess.call(args=cmd2, shell=True, cwd=tmp_index_dir, stderr=tmp_stderr.fileno()) |
422 # get stderr, allowing for case where it's very large | 431 # get stderr, allowing for case where it's very large |
454 shutil.move( left, options.output_unmapped_reads_l ) | 463 shutil.move( left, options.output_unmapped_reads_l ) |
455 shutil.move( right, options.output_unmapped_reads_r ) | 464 shutil.move( right, options.output_unmapped_reads_r ) |
456 except Exception as e: | 465 except Exception as e: |
457 sys.stdout.write( 'Error producing the unmapped output file.\n' ) | 466 sys.stdout.write( 'Error producing the unmapped output file.\n' ) |
458 # check that there are results in the output file | 467 # check that there are results in the output file |
459 if os.path.getsize( options.output ) == 0: | 468 if options.output != "XXXX" and os.path.getsize( options.output ) == 0: |
460 raise Exception('The output file is empty, there may be an error with your input file or settings.') | 469 raise Exception('The output file is empty, there may be an error with your input file or settings.') |
461 except Exception as e: | 470 except Exception as e: |
462 stop_err( 'Error aligning sequence. ' + str( e ) ) | 471 stop_err( 'Error aligning sequence. ' + str( e ) ) |
463 finally: | 472 finally: |
464 # clean up temp dir | 473 # clean up temp dir |