INNER CODE UNIT · Python
does_each_sequence_have_the_same_length
nickjcroucher/gubbins · python/gubbins/ValidateFastaAlignment.py:51
def does_each_sequence_have_the_same_length(self):
try:
with open(self.input_filename) as input_handle:
alignments = AlignIO.parse(input_handle, "fasta")
sequence_length = -1
for alignment in alignments:
for record in alignment:
if sequence_length == -1:
sequence_length = len(record.seq)
elif sequence_length != len(record.seq):
print("Error with the input FASTA file: The sequences are not of the same length, this is not an alignment: "+record.name)
return False
except:
print("Unexpected error:", sys.exc_info()[0])
print("Error with the input FASTA file: It is in the wrong format, check it is an alignment")
return False
return True