-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1ddda78
commit ef34f0f
Showing
9 changed files
with
198 additions
and
28 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,4 +27,5 @@ | |
pub mod config; | ||
pub(crate) mod kmer; | ||
pub(crate) mod reader; | ||
pub mod startup; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use std::{error::Error, fmt::Debug, path::Path, vec::IntoIter}; | ||
|
||
use bio::io::fasta::Reader; | ||
use bytes::Bytes; | ||
use needletail::parse_fastx_file; | ||
use rayon::prelude::{ParallelBridge, ParallelIterator}; | ||
|
||
pub(crate) trait SequenceReader { | ||
fn sequence_reader<P: AsRef<Path> + Debug>(path: P) -> Result<IntoIter<Bytes>, Box<dyn Error>>; | ||
} | ||
|
||
pub(crate) struct RustBio; | ||
|
||
impl SequenceReader for RustBio { | ||
fn sequence_reader<P: AsRef<Path> + Debug>(path: P) -> Result<IntoIter<Bytes>, Box<dyn Error>> { | ||
Ok(Reader::from_file(path)? | ||
.records() | ||
.into_iter() | ||
.par_bridge() | ||
.map(|read| read.expect("Error reading fasta record.")) | ||
.map(|record| Bytes::copy_from_slice(record.seq())) | ||
.collect::<Vec<Bytes>>() | ||
.into_iter()) | ||
} | ||
} | ||
|
||
pub(crate) struct Needletail; | ||
|
||
impl SequenceReader for Needletail { | ||
fn sequence_reader<P: AsRef<Path> + Debug>(path: P) -> Result<IntoIter<Bytes>, Box<dyn Error>> { | ||
let mut reader = parse_fastx_file(path)?; | ||
let mut v = Vec::new(); | ||
while let Some(record) = reader.next() { | ||
let record = record.expect("invalid record"); | ||
let seq = record.seq(); | ||
let seq = Bytes::copy_from_slice(&seq); | ||
v.push(seq); | ||
} | ||
Ok(v.into_iter()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters