Skip to content

Commit

Permalink
allow translation of empty and multiline sequences
Browse files Browse the repository at this point in the history
  • Loading branch information
Felix Van der Jeugt committed Jul 8, 2019
1 parent a8e8bb7 commit 99c45b7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
15 changes: 14 additions & 1 deletion src/dna/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,23 @@ impl<'a> From<&'a [u8]> for Strand {
}
}

impl<'a> From<&'a Vec<String>> for Strand {
fn from(lines: &Vec<String>) -> Self {
Strand(lines.iter()
.flat_map(|s| s.as_bytes())
.map(Nucleotide::from)
.collect())
}
}

impl Strand {
/// A reading frame of this strand, 1-indexed.
pub fn frame<'a>(&'a self, start: usize) -> Frame<'a> {
Frame(&self.0[start - 1..])
Frame(if self.0.len() > start - 1 {
&self.0[start - 1..]
} else {
&[]
})
}

/// The reverse strand of this one.
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ fn translate(args: args::Translate) -> Result<()> {
for record in fasta::Reader::new(io::stdin(), true).records() {
let fasta::Record { header, sequence } = record?;

let forward = Strand::from(sequence[0].as_bytes());
let forward = Strand::from(&sequence);
let reverse = forward.reversed();
for &(name, frame, reversed) in &frames {
let strand = if reversed { &reverse } else { &forward };
Expand Down

0 comments on commit 99c45b7

Please sign in to comment.