Skip to content

Use BufWriter in fasta_redux #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 22, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/fasta_redux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use std::cmp::min;
use std::env;
use std::io;
use std::io::BufWriter;
use std::io::prelude::*;

const LINE_LEN: usize = 60;
Expand Down Expand Up @@ -57,7 +58,7 @@ static HOMO_SAPIENS: [AminoAcid;4] = [
fn sum_and_scale(a: &'static [AminoAcid]) -> Vec<AminoAcid> {
let mut p = 0f32;
let mut result: Vec<AminoAcid> = a.iter().map(|a_i| {
p += a_i.p;
p += a_i.p;
AminoAcid { c: a_i.c, p: p * LOOKUP_SCALE }
}).collect();
let result_len = result.len();
Expand Down Expand Up @@ -146,7 +147,7 @@ impl<'a, W: Write> RandomFasta<'a, W> {
fn nextc(&mut self) -> u8 {
let r = self.rng(LOOKUP_SCALE);
for i in (r as usize..LOOKUP_SIZE) {
if self.lookup[i].p >= r {
if self.lookup[i].p >= r {
return self.lookup[i].c;
}
}
Expand Down Expand Up @@ -179,9 +180,9 @@ fn main() {
} else {
1000
};

let stdout = io::stdout();
let mut out = stdout.lock();
let mut out = BufWriter::new(stdout.lock());

out.write_all(b">ONE Homo sapiens alu\n").unwrap();
{
Expand Down