When running this code on a fasta file and a max() arg error occurs
0
0
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?

python • 809 views
ADD COMMENT
1
Entering edit mode

Check records first by printing it.

ADD REPLY
0
Entering edit mode

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.

ADD REPLY

Login before adding your answer.

Traffic: 986 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6