I have an input_file.fa file similar to this ( FASTA ):
> header1 description
data data
data
>header2 description
more data
data
data
I want to read one piece at a time in a file, so each piece contains one header and corresponding data, for example. block 1:
> header1 description
data data
data
Of course, I could just read in the file how to split it up:
with open("1.fa") as f:
for block in f.read().split(">"):
pass
But I want to avoid reading the entire file into memory, because the files are often large.
I can read in the file line at the rate:
with open("input_file.fa") as f:
for line in f:
pass
But ideally, I want something like this:
with open("input_file.fa", newline=">") as f:
for block in f:
pass
But I get an error message:
ValueError: illegal newline value:>
I also tried using the csv module , but without success.
3 , , , , , / ? , , , - :
with open("input_file.fa") as f:
blocks = magic_generator_split_by_>
for block in blocks:
pass
, , , , , , . .