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

fix memory leaks, add rerun-if #10

Merged
merged 1 commit into from
Jan 15, 2020
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ failure = "*"
[build-dependencies]
cc = "^1.0"
fs-utils = "*"

glob = "^0.3"
2 changes: 1 addition & 1 deletion STAR
Submodule STAR updated 1 files
+1 −1 source/Genome.cpp
40 changes: 24 additions & 16 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
// Copyright (c) 2019 10x Genomics, Inc. All rights reserved.

use fs_utils::copy::copy_directory;
use glob::glob;
use std::env;
use std::path::Path;
use std::process::Command;

fn libcxx() -> &'static str {
match env::var("CXX") {
Ok(cxx) => {
match Path::new(&cxx).file_name().unwrap().to_str().unwrap() {
s if s.contains("clang++") => "c++",
s if s.contains("g++") => "stdc++",
s => panic!("unknown compiler: {}", s),
}
}
Err(_) => {
match env::var("TARGET") {
Ok(ref s) if s.contains("darwin") => "c++",
Ok(ref s) if s.contains("linux") => "stdc++",
Ok(ref s) => panic!("unknown target: {}", s),
Err(_) => panic!("TARGET is undefined"),
}
}
Ok(cxx) => match Path::new(&cxx).file_name().unwrap().to_str().unwrap() {
s if s.contains("clang++") => "c++",
s if s.contains("g++") => "stdc++",
s => panic!("unknown compiler: {}", s),
},
Err(_) => match env::var("TARGET") {
Ok(ref s) if s.contains("darwin") => "c++",
Ok(ref s) if s.contains("linux") => "stdc++",
Ok(ref s) => panic!("unknown target: {}", s),
Err(_) => panic!("TARGET is undefined"),
},
}
}

Expand All @@ -48,7 +45,8 @@ fn main() {
.arg("liborbit.a")
.status()
.unwrap()
.success() != true
.success()
!= true
{
panic!("failed to build STAR");
}
Expand All @@ -62,4 +60,14 @@ fn main() {
println!("cargo:rustc-link-search=native={}", &out);
println!("cargo:rustc-link-lib=static=orbit");
println!("cargo:rustc-link-lib=dylib={}", libcxx());

// so we don't rebuild every time
for star_source in glob("STAR/source/**/*").expect("error in glob(STAR/source)") {
let star_source = star_source
.as_ref()
.expect("error in glob(STAR/source)")
.to_str()
.expect("STAR source could not be made into valid unicode");
println!("cargo:rerun-if-changed={}", star_source);
}
}
16 changes: 10 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ impl StarReference {

let reference = unsafe { bindings::init_star_ref(length, c_args) };

// recover stray CStrings to prevent leaked memory
nvec.into_iter().for_each(|ptr| unsafe {
CString::from_raw(ptr);
});

let inner = InnerStarReference {
reference,
header,
Expand Down Expand Up @@ -423,17 +428,15 @@ mod test {
println!("{:?}", recs);
}


#[test]
fn test_multithreaded_alignment() {

let settings = StarSettings::new(ERCC_REF);
let reference = StarReference::load(settings).unwrap();
let mut aligner1 = reference.get_aligner();
let mut aligner2 = reference.get_aligner();

let t1 = std::thread::spawn(move || {
for _ in 0 .. 100000 {
for _ in 0..100000 {
let recs = aligner1.align_read(NAME, ERCC_READ_1, ERCC_QUAL_1);
assert_eq!(recs.len(), 1);
assert_eq!(recs[0].pos(), 50);
Expand All @@ -442,7 +445,7 @@ mod test {
});

let t2 = std::thread::spawn(move || {
for _ in 0 .. 100000 {
for _ in 0..100000 {
let recs = aligner2.align_read(NAME, ERCC_READ_2, ERCC_QUAL_2);
assert_eq!(recs.len(), 1);
assert_eq!(recs[0].pos(), 500);
Expand All @@ -454,7 +457,6 @@ mod test {
assert!(t2.join().is_ok());
}


#[test]
#[ignore]
fn test_align_read() {
Expand Down Expand Up @@ -520,7 +522,9 @@ mod test {
let reference = StarReference::load(settings).unwrap();
let mut aligner = reference.get_aligner();

let mut out = bam::Writer::from_path(&"test/test.bam", &reference.header(), bam::Format::BAM).unwrap();
let mut out =
bam::Writer::from_path(&"test/test.bam", &reference.header(), bam::Format::BAM)
.unwrap();
let read = b"GTGCGGGGAGAAGTTTCAAGAAGGTTCTTATGGAAAAAAGGCTGTGAGCATAGAAAGCAGTCATAGGAGGTTGGGGAACTAGCTTGTCCCTCCCCACC";
let qual = b"GGGAGIGIIIGIIGGGGIIGGIGGAGGAGGAAG.GGIIIG<AGGAGGGIGGGGIIIIIGGIGGGGGIGIIGGAGGGGGIGGGIGIIGGGGIIGGGIIG";
let name = b"gatactaga";
Expand Down