-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpileup-fix.py
executable file
·51 lines (38 loc) · 1.31 KB
/
pileup-fix.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
#!/scratch/user/rkumar/softwares/qiime-1.5/python-2.7.1-release/bin/python
#-------------------------------------------------------------------------
# Name - pileup-fix.py
# Desc - The program takes a pileup file and insert the missing coordinates and only works for 1 reference file (haven't considered for more than 1 fasta seq)
# Author - Ranjit Kumar ([email protected])
# Source code - https://github.com/ranjit58/NGS/blob/master/pileup-fix.py
# Usage - pileup-fix.py fatsa_file pileup pileup_fixed
#-------------------------------------------------------------------------
import sys
import re
import Bio
from Bio import SeqIO
seq = {}
count = 1
seqid = ""
fasta_file = open(sys.argv[1],"rU")
print "Completed reading the fasta file..."
for record in SeqIO.parse(fasta_file,"fasta"):
seqid = record.id
for chr in record.seq:
seq[count] = chr
count += 1
fasta_file.close()
#for i in seq.keys():
# print i, "\t", seq[i]
print "Processing file, please wait..."
input = open(sys.argv[2],"r")
output = open(sys.argv[3],"w")
count = 1
for line in input:
line=line.rstrip('\n')
tabs = re.split('\t',line)
while int(tabs[1]) > count:
output.write( seqid + "\t" + str(count) + "\t" + str(seq[count]) + "\t0\t\t\n" )
count += 1
output.write (line + "\n")
count += 1
print "Completed..."