aseyboldt / fastq-rs

MIT License
47 stars 12 forks source link

Iterate through two fastqs together #3

Closed JakeHagen closed 7 years ago

JakeHagen commented 7 years ago

Hello

Thank you for this library. I am trying to learn rust by re-implementing some code. My code iterates through two fastqs and takes part of the sequence from one and appends it to the header of the other.

I can iterate through both at once using something like this:

    for (idx_records, read_records) in idx_parser.record_sets().zip(read_parser.record_sets()) {
        for (idx_record, read_record) in idx_records.iter().zip(read_records.iter()) {
            for (idx_read, read_read) in idx_record.iter().zip(read_record.iter()) {
                println!("Do something");
            }
        }
    }

But I was wondering if this was possible with parser.each()?

Sorry I know this is not an issue with your code, but any help would be appreciated Thanks

aseyboldt commented 7 years ago

I had the same problem recently, and using each doesn't seem easy at the moment. I'm working on a patch to make this possible though. I'm still fighting the borrow checker at one point, but hopefully I can work around that. I'll let you know when I push the branch.

JakeHagen commented 7 years ago

Great thank you.

aseyboldt commented 7 years ago

I finally got it working. Turns out I had to split the iterator into an advance() and a get method to make the borrow checker happy. If you want to try it out: #4 The function each_zipped should do what you want.

JakeHagen commented 7 years ago

This is great, thank you. Ill try it out as soon as I can.