Comments (3)
The function signature is:
pub fn write_to<W: io::Write>(
mut writer: W,
Shouldn't it be?
pub fn write_to<W: std::io::Write>(
writer: &mut W,
from seq_io.
I'm sorry if writing isn't documented well. I'm working on a next version with better docs, but it is progressing slowly.
The following should work, because io::Write
is also implemented for mutable references to Write
instances:
seq_io::fastq::write_to(&mut writer, &r.head, &r.seq, &r.qual)?;
Like this, the writer is not moved to the writing function. Also note the ?
, since it is necessary to handle write errors.
It is even simpler to use the write
method of records (it's a bit hidden because it's in the Record
trait:
r.write(&mut writer)?;
Did you use the records()
method on purpose for iterating over records? It will yield OwnedRecord
instances, which is comparable to the Rust-Bio reading methods. In case reading performance is important for you and you don't need to store the record objects for later use, I would advise to use the while let Some(r) = reader.next()
construct. It returns a RefRecord
borrowing its data from the underlying reader, and consequently no vector allocations and (mostly) no copying are required. See the bottom of the GitHub page for how the two compare (borrowed on top, owned below).
Your code would then be:
let mut reader = Reader::from_path("in.fastq")?;
let mut writer = BufWriter::new(File::create("out.fastq")?);
wile let Some(r) = reader.next() {
let r = r?;
r.write(&mut writer)?;
}
Also note that you need to use File::create
instead of File::open
to open a file in write mode, and that constructing a Path
instance is not necessary because File::create
accepts AsRef<Path>
which &str
implements.
from seq_io.
The following should work, because io::Write is also implemented for mutable references to Write instances:
Aah, it's the magic in the Write trait itself that I missed. Add the expected &mut
and the magic happens.
Thanks for the explanation :)
Also note that you need to use File::create instead of File::open to open a file in write mode
That one got picked up in my testing pretty quickly.
Did you use the records() method on purpose for iterating over records?
Mostly it was because the borrowed version didn't appear to implement Iter and I was switching from another fastq parsing library.
from seq_io.
Related Issues (11)
- parallel reading 10G fasta/fastq file HOT 5
- Open to a PR for impl Display (or Debug) etc.? HOT 1
- An error in record.rs in core HOT 2
- Issue when get the size of sequence length in reference genome file HOT 1
- Future incompatibility with buf_redux HOT 2
- curious error when reading fastq.gz files (maybe not an issue) HOT 2
- Depends on old crossbeam HOT 1
- Reading gz files? HOT 3
- Whole Genome Alignments HOT 1
- Release of 0.4.0 HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from seq_io.