Skip to content

Commit

Permalink
implement sequence-read trait
Browse files Browse the repository at this point in the history
  • Loading branch information
johanneskoester committed Apr 25, 2019
1 parent 86549ad commit 9d0ec33
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Expand Up @@ -39,7 +39,7 @@ regex = "1.0"
multimap = "0.4"
fxhash = "0.2"
statrs = "0.9.0"
bio-types = ">=0.4"
bio-types = ">=0.5.1"
fnv = "1.0"
strum = "0.13"
strum_macros = "0.13"
Expand Down
20 changes: 20 additions & 0 deletions src/io/fastq.rs
Expand Up @@ -20,6 +20,8 @@ use std::io;
use std::io::prelude::*;
use std::path::Path;

use bio_types::sequence::SequenceRead;

use crate::utils::TextSlice;

/// Trait for FASTQ readers.
Expand Down Expand Up @@ -234,6 +236,24 @@ impl fmt::Display for Record {
}
}

impl SequenceRead for Record {
fn name(&self) -> &[u8] {
self.id.as_bytes()
}

fn base(&self, i: usize) -> u8 {
self.seq.as_bytes()[i]
}

fn base_qual(&self, i: usize) -> u8 {
self.qual.as_bytes()[i]
}

fn len(&self) -> usize {
self.seq().len()
}
}

/// An iterator over the records of a FastQ file.
#[derive(Debug)]
pub struct Records<R: io::Read> {
Expand Down

0 comments on commit 9d0ec33

Please sign in to comment.