Last active
August 29, 2015 14:04
-
-
Save samuell/6f0ecbe4c5e88c04c387 to your computer and use it in GitHub Desktop.
To be included in: http://saml.rilspace.org/moar-languagez-gc-content-in-python-d-fpc-c-and-c
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
use std::io::BufferedReader; | |
use std::io::File; | |
use std::str::StrSlice; | |
fn main() { | |
let path = Path::new("Homo_sapiens.GRCh37.67.dna_rm.chromosome.Y.fa"); | |
let mut file = BufferedReader::new(File::open(&path)); | |
let mut gc = 0i; | |
let mut at = 0i; | |
for line in file.lines() { | |
for c in line.unwrap().as_slice().chars() { | |
match c { | |
'G' => gc += 1, | |
'C' => gc += 1, | |
'A' => at += 1, | |
'T' => at += 1, | |
_ => {} | |
} | |
} | |
} | |
let gc_frac: f64 = (gc as f64) / ((at as f64) + (gc as f64)); | |
println!("GC fraction: {}", gc_frac) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@huonw: I think you're right about some unfortunate differences in the code examples. I really should compile an updated benchmark soon.