Entering edit mode
2.9 years ago
rt2421
•
0
from Bio import AlignIO
from Bio import SeqIO
from Bio import Seq
import os
input_file = "/Users/richard/Desktop/texas1.fasta"
records = SeqIO.parse(input_file, 'fasta')
records = list(records)
maxlen = max(len(record.seq) for record in records)
# pad sequences so that they all have the same length
for record in records:
if len(record.seq) != maxlen:
sequence = str(record.seq).ljust(maxlen, '.')
record.seq = Seq.Seq(sequence)
assert all(len(record.seq) == maxlen for record in records)
output_file = '{}_padded.fasta'.format(os.path.splitext(input_file)[0])
with open(output_file, 'w') as f:
SeqIO.write(records, f, 'fasta')
alignment = AlignIO.read(output_file, "fasta")
print (alignment)
The Error that occurs in line 10 and is ValueError: max() arg is an empty sequence. Could it be that the fasta file is too big?
Check
records
first by printing it.Thank you, it looks like the file is empty. It actually looks like there are amino acid sequences and not nucleotide sequences in the fasta file.