I am trying to design a parser for FASTA files (without using biopython) and am having problems in the following area: I have a list of DNA sequences such as ['AAACCCGAU', 'AUUCCCCCCGGA', 'AACCCGGUU', 'AAACCCCUU'] etc.. named sequence_lines2. My target program is: If the element in the list has any multiple of 60 characters, join it to the next element. This way I can remove the line breaks in FASTA files. The code I have written looks like this:
for el in sequence_lines2:
if len(el) == 60:
sequence_lines3 = "".join(el)
How can I make this work? And how to achieve the multip开发者_开发百科les of 60? Thanks in advance!
----Edit---- If anyone's interesting in joining elements, have a look here!.
Try with this one liner :
result = "".join([el for el in sequence_lines2 if not len(el) % 60])
The len(el) % 60
computes the modulo of length with 60 and if the result is 0, this is a multiple of 60.
精彩评论