User Tools

Site Tools


script:bowtiewrapper

Bowtie Wrapper Script

bowtie_wrapper.py
 
import argparse
import subprocess
 
'''
Functions for trimming and mapping reads
Author: Tai Montgomery, Oct. 22, 2018
Command line usage:
python3 bowtie_wrapper.py -i 'input_file' -o 'output_'file - p 'path_to_bowtie_index'
'''
 
def arg_parse():
    '''
    Parse command line arguments
    '''
    parser = argparse.ArgumentParser()
    parser.add_argument('-i', '--input_file', required=True, help="input file in fastq format") 
    parser.add_argument('-o', '--output_file', required=True, help="output file name")
    parser.add_argument('-p', '--bowtie_path', required=True, help="path to bowtie index")
    args = parser.parse_args()
    return args.input_file, args.output_file, args.bowtie_path
 
def trim(input_file, output_file):
	'''
	Trim and filter reads using trimmomatic
	'''
	print('starting trimmomatic to trim reads....')
	subprocess.run(['trimmomatic', 'SE', input_file, output_file, 'ILLUMINACLIP:/home/student/TruSeq-smallRNA.fa:2:30:10', 'MINLEN:16', 'AVGQUAL:30'], stderr=open('bowtie_stderr.txt', 'w'))
	print('done.')
 
def map(bowtie_path, trimmed_file):
	'''
	Map reads using bowtie2
	'''
	print('starting bowtie to map reads....')
	subprocess.run(['bowtie2', '-x', bowtie_path, '-U', trimmed_file, '-S', 'output.sam'], stderr=open('bowtie_stderr.txt', 'a'))
	print('done.')
 
if __name__ == '__main__':
	infile, outfile, path = arg_parse()
	trim(infile, outfile)
	trimmed_file = outfile
	map(path, trimmed_file)
	print('See bowtie_stderr.txt')
script/bowtiewrapper.txt · Last modified: 2018/10/30 12:05 by dokuroot