https://github.com/fjruizruano/ngs-protocols
Tip revision: 39a091d1fa569a7fc717ac73c4b3de07f0a1204d authored by fjruizruano on 03 August 2023, 11:48:27 UTC
adding gfa2fas.py and extract_gfa.py
adding gfa2fas.py and extract_gfa.py
Tip revision: 39a091d
bowtie2_recursive.py
#!/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)