Skip to content
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

Get nerd-sniped and do some micro-optimizations. #41

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ include = ["wrapper.h", "src/lib.rs", "LICENSE", "README.md"]
[dependencies]
anyhow = "1"
libc = "0.2"
rust-htslib = { version = "0.38.2", default-features = false, features = ["serde_feature"] }
rust-htslib = { version = "0.39.5", default-features = false, features = ["serde_feature"] }
star-sys = { version = "0.2", path = "star-sys" }

[profile.release]
Expand Down
14 changes: 13 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::os::raw::c_char;
use std::os::raw::c_int;
use std::path::Path;
use std::sync::Arc;
use std::time::Instant;

use anyhow::{format_err, Error};
use rust_htslib::bam;
Expand Down Expand Up @@ -253,6 +254,7 @@ impl StarAligner {

/// Aligns a given read and produces BAM records
pub fn align_read(&mut self, name: &[u8], read: &[u8], qual: &[u8]) -> Vec<bam::Record> {
let now = Instant::now();
// STAR will throw an error on empty reads - so just construct an empty record.
if read.len() == 0 {
// Make an unmapped record and return it
Expand All @@ -261,7 +263,17 @@ impl StarAligner {

Self::prepare_fastq(&mut self.fastq1, name, read, qual);
align_read_rust(self.aligner, self.fastq1.as_slice(), &mut self.aln_buf).unwrap();
self.parse_sam_to_records(name)
let record= self.parse_sam_to_records(name);
let new_now = Instant::now();
let (chr, pos, cigar, cigar_ops) = if record.len() > 0 {
let rec = &record[0];
(rec.tid().to_string(), rec.pos().to_string(), format!("{}", rec.cigar()), rec.cigar().len().to_string())
} else {
("NA".to_string(), "NA".to_string(), "NA".to_string(), "NA".to_string())
};
println!("{:?},{:?},{:?},{},{},{},{}", std::str::from_utf8(&read).unwrap(), new_now.duration_since(now), record.len(), chr, pos, cigar, cigar_ops);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lots of unnecessary memcpy going on here.

Suggested change
let (chr, pos, cigar, cigar_ops) = if record.len() > 0 {
let rec = &record[0];
(rec.tid().to_string(), rec.pos().to_string(), format!("{}", rec.cigar()), rec.cigar().len().to_string())
} else {
("NA".to_string(), "NA".to_string(), "NA".to_string(), "NA".to_string())
};
println!("{:?},{:?},{:?},{},{},{},{}", std::str::from_utf8(&read).unwrap(), new_now.duration_since(now), record.len(), chr, pos, cigar, cigar_ops);
if record.len() > 0 {
let rec = &record[0];
println!("{:?},{:?},{:?},{},{},{},{}", std::str::from_utf8(&read).unwrap(), new_now.duration_since(now), record.len(), rec.tid(), rec.pos(),rec.cigar(), rec.cigar().len())
} else {
println!("{:?},{:?},{:?},NA,NA,NA,NA", std::str::from_utf8(&read).unwrap(), new_now.duration_since(now), record.len())
};

Though I guess it doesn't really matter if this is just temporary benchmarking code.

But, maybe this should be an actual benchmark?

record

}

/// Aligns a given read and return the resulting SAM string
Expand Down