-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbase_changer2.py
More file actions
35 lines (29 loc) · 940 Bytes
/
base_changer2.py
File metadata and controls
35 lines (29 loc) · 940 Bytes
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
import csv
from Bio.Seq import Seq
from Bio.SeqRecord import SeqRecord
from Bio import SeqIO
from sys import argv
script, ref, subs, outfile = argv
out = open(outfile, 'wb')
seq_string = []
user_descrip=raw_input("Give the file a description: ")
with open(ref, "r") as infile:
for k, line in enumerate(infile):
if ">" in line:
pass
else:
seq_string.append(line.strip("\n"))
seq_str = "".join(seq_string)
print len(seq_str)
new_indexed_seq=list(seq_str)
with open(subs) as subs_file:
subs_reader=csv.reader(subs_file, delimiter='\t')
for line in subs_reader:
pos = (int(line[0]) - 1)
base = line[1]
original_base=seq_str[pos]
new_indexed_seq[pos]=base
out_string="".join(new_indexed_seq)
with open(outfile, 'wb') as out:
out_seq = SeqRecord(Seq(out_string), id = 'anscestral_sequence', description=user_descrip)
SeqIO.write(out_seq, out, 'fasta')