import sys
from Bio import SeqIO
f = sys.argv[1]
seq_records = SeqIO.parse(f, 'fasta')
refseq_record = next(seq_records)
for seq_record in seq_records:
for i in range(0, len(refseq_record)):
nt1 = refseq_record[i]
nt2 = seq_record[i]
if nt1 != nt2:
print (seq_record.id, i+1, nt2, nt1)
Hello,
I get IndexError: string index out of range error at line 12:
nt2 = seq_record[i]
Could you please help me with this?
>Solution :
Force the min value length between the reference sequence and the current sequence
import sys
from Bio import SeqIO
f = sys.argv[1]
seq_records = SeqIO.parse(f, 'fasta')
refseq_record = next(seq_records)
for seq_record in seq_records:
min_length = min(len(refseq_record), len(seq_record))
for i in range(0, min_length):
nt1 = refseq_record[i]
nt2 = seq_record[i]
if nt1 != nt2:
print(seq_record.id, i + 1, nt2, nt1)