-
Dear developers, When streaming chunks using noodles-htsget, is there a way to lazily parse CRAM records in memory? In the noodles-htsget example, I've tried to replace: noodles/noodles-htsget/examples/htsget_download_reads.rs Lines 32 to 34 in 779500a with things like: let first_chunk = &chunks
.try_next()
.await
.expect("can't load chunk")
.unwrap()[..];
let mut reader = Reader::new(first_chunk);
let header = reader
.read_header()
.unwrap();
while let Some(chunk) = chunks.try_next().await.expect("can't load chunk") {
let mut reader = Reader::new(&chunk[..]);
for result in reader.records(&header) {
let record = result.expect(&format!("{:?}", chunk));
println!("{:?}", record);
}
} But when trying to instantiate records, I keep getting:
Would you have any advice to parsing these records without saving the actual file? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I would recommend converting the chunks stream to an async reader using Since you're working with CRAM, note that it commonly requires a reference sequence. Also note that htsget responses may include records outside the requested region(s), which you must filter yourself. Here's a full example showing all of this:
|
Beta Was this translation helpful? Give feedback.
I would recommend converting the chunks stream to an async reader using
tokio_util::io::StreamReader
. This way, you can usecram::r#async::io::Reader
as you normally would.Since you're working with CRAM, note that it commonly requires a reference sequence. Also note that htsget responses may include records outside the requested region(s), which you must filter yourself.
Here's a full example showing all of this:
main.rs