BioJulia / FASTX.jl

Parse and process FASTA and FASTQ formatted files of biological sequences.
https://biojulia.dev
MIT License
61 stars 20 forks source link

Document `read!(::Reader, ::Record)` #94

Open jonathanBieler opened 1 year ago

jonathanBieler commented 1 year ago

Sorry, I'm a bit confused by the doc (or lack thereof), is that one correct way one has to read a fastq file, say if I want to read N reads (I could use while next !== nothing too) ? I think adding an example in the docs would be good.

reader = FASTQ.Reader(GzipDecompressorStream(open(file)) ; copy=false)

r = first(reader)

for k = 1:N

    # do something here

    next = iterate(reader)
    isnothing(next) && break
    r = next[1]
end

close(reader)

Also the old read!(reader, r) doesn't crash but does nothing, it should be an error now, no ?

jonathanBieler commented 1 year ago

Ha, I though I needed it to go trough paired files at once, but I can use for (r1,r2) in zip(reader1,reader2). Would still be good to document it though.

jakobnissen commented 1 year ago

Dear @jonathanBieler

Indeed, read! is a bug (see #95), which will be fixed in a few hours. Readers are like any other iterators. To get N elements from an iterator, you can use Iterators.take, or use zip(1:N, reader), or use a normal for loop.

jonathanBieler commented 1 year ago

Thanks, so the read! API is not deprecated ? might be worth mentioning it in the docs then. It was nice to have the same API for XAM, FASTX and VariantCallFormat, so one could write generic code for those.

jakobnissen commented 1 year ago

Hm... I've not deprecated it yet. I don't think it should be deprecated. You're right, it should be in the docs.