-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathbowtie2_recursive.py
executable file
·51 lines (42 loc) · 1.5 KB
/
bowtie2_recursive.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/python
import sys
from subprocess import call
print "Usage: bowtie2_recursive.py ListOfFastqFiles FastaReference NumberOfThreads"
try:
files = sys.argv[1]
except:
files = raw_input("Introduce list of pairs of FASTQ files: ")
try:
ref = sys.argv[2]
except:
ref = raw_input("Introduce FASTA reference: ")
try:
threads = sys.argv[3]
tt = int(threads)
except:
threads = raw_input("Introduce number of threads (integer): ")
ref_name = ref.split(".")
ref_name = ".".join(ref_name[:-1])
try:
for n in range(1,5):
file = "%s.%s.bt2" % (ref_name,n)
f_op = open(file)
for n in range(1,3):
file = "%s.rev.%s.bt2" % (ref_name,n)
f_op = open(file)
except:
call("bowtie2-build %s %s" % (ref, ref_name), shell=True)
data = open(files).readlines()
for n in range(0,len(data)/2):
file1 = data[n*2][:-1]
file2 = data[(n*2)+1][:-1]
file_name = file1.split(".")
if file_name[-1] == "gz":
file_name = ".".join(file_name[:-2])
elif file_name[-1] == "fq" or file_name[-1] == "fastq":
file_name = ".".join(file_name[:-1])
print "Running Bowtie2 with %s and %s against %s" % (file1,file2,ref_name)
call("bowtie2 -p 12 --very-sensitive -x %s -1 %s -2 %s | samtools view -bS - > %s.bam" % (ref_name,file1,file2,file_name), shell=True )
call("samtools sort %s.bam %s_sort" % (file_name,file_name), shell=True)
call("rm %s.bam" % (file_name), shell=True)
call("samtools index %s_sort.bam" % (file_name), shell=True)