diff --git a/.github/workflows/comparison.yml b/.github/workflows/comparison.yml new file mode 100644 index 0000000..c5a1bf5 --- /dev/null +++ b/.github/workflows/comparison.yml @@ -0,0 +1,23 @@ +name: Compare + +on: + push: + branches: + - main + pull_request: + +jobs: + crossmap: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Update Rust + run: rustup update stable && rustup default stable + - name: Install CrossMap + run: pip install CrossMap + - uses: Swatinem/rust-cache@v2 + with: + workspaces: . + - run: | + mkdir -p chainfiles + cargo run --release --features=binaries -- -d chainfiles hg19ToHg38 \ No newline at end of file diff --git a/src/bin/kitchen_sink.rs b/src/bin/kitchen_sink.rs index bf46063..2dc7a49 100644 --- a/src/bin/kitchen_sink.rs +++ b/src/bin/kitchen_sink.rs @@ -142,23 +142,26 @@ impl std::fmt::Display for LiftoverResult { // CrossMap execution //////////////////////////////////////////////////////////////////////////////////////// -/// A struct for working with `crossmap`. +/// A struct for working with `CrossMap`. struct CrossMap; impl CrossMap { - /// Ensures the `crossmap` is installed. + /// Ensures the `CrossMap` is installed. fn ensure_installed() -> Result<()> { - Command::new("crossmap") + Command::new("CrossMap") .arg("--version") .stdout(Stdio::piped()) .stderr(Stdio::piped()) .status() - .context("retrieving `crossmap`'s version") + .context("retrieving `CrossMap`'s version") .map(|_| ()) } /// Runs `crossmap bed` on a chain file and bed file. fn run_bed(chain_file: &Path, bed_file: &Path) -> Result> { + println!("Chainfile: {:?}", chain_file); + println!("Bed file: {:?}", bed_file); + let process = Command::new("crossmap") .arg("bed") .arg(chain_file) @@ -167,12 +170,16 @@ impl CrossMap { .stderr(Stdio::piped()) .spawn()?; + println!("there"); + let mut results = HashMap::new(); let output = process .wait_with_output() .context("running `crossmap bed`")?; + println!("there"); + if !output.status.success() { bail!("the `crossmap bed` command returned a non-zero exit code"); } @@ -181,11 +188,13 @@ impl CrossMap { let stderr = String::from_utf8_lossy(&output.stderr); for line in stderr.lines() { if !line.contains("[INFO]") { - panic!("`crossmap` returned something on stderr: {stderr}"); + panic!("`CrossMap` returned something on stderr: {stderr}"); } } } + println!("world!"); + let stdout = String::from_utf8(output.stdout).context("decoding stdout from byte stream")?; @@ -193,7 +202,7 @@ impl CrossMap { let parts = line.split("\t").collect::>(); assert!( parts.len() > 3, - "should always have at least four parts of a `crossmap` result line; found \ + "should always have at least four parts of a `CrossMap` result line; found \ `{line}`" ); @@ -221,7 +230,7 @@ impl CrossMap { LiftoverResult::Mapped(to) } - _ => unreachable!("cannot parse `crossmap` result: `{line}`"), + _ => unreachable!("cannot parse `CrossMap` result: `{line}`"), }; results.insert(from, to); @@ -333,7 +342,7 @@ impl WorkDirectory { self.0.join("reference") } - /// The input positions bed file to `crossmap`. + /// The input positions bed file to `CrossMap`. fn input_bed_file(&self) -> PathBuf { self.0.join("input.bed") } @@ -389,10 +398,10 @@ impl Deref for WorkDirectory { } //////////////////////////////////////////////////////////////////////////////////////// -// Comparsion between `chainfile` and `crossmap` +// Comparsion between `chainfile` and`CrossMap` //////////////////////////////////////////////////////////////////////////////////////// -/// A comparison of liftover results between `chainfile` and `crossmap`. +/// A comparison of liftover results between `chainfile` and `CrossMap`. #[derive(Clone, Debug)] struct Comparison { /// The original position. @@ -401,7 +410,7 @@ struct Comparison { /// The lifted position from `chainfile`. chainfile: LiftoverResult, - /// The lifted position from `crossmap`. + /// The lifted position from `CrossMap`. crossmap: LiftoverResult, } @@ -475,8 +484,8 @@ fn throw(args: &Args) -> Result<()> { info!("working directory: {}", work_dir.display()); - info!("crossmap: ensuring `crossmap` is installed"); - CrossMap::ensure_installed().context("ensuring `crossmap` is installed")?; + info!("crossmap: ensuring `CrossMap` is installed"); + CrossMap::ensure_installed().context("ensuring `CrossMap` is installed")?; let chain_file_path = work_dir .download_chain_file(&args.chain) @@ -510,7 +519,7 @@ fn throw(args: &Args) -> Result<()> { info!("crossmap: running liftover"); for (from, crossmap_result) in CrossMap::run_bed(&chain_file_path, &work_dir.input_bed_file()) - .context("getting the `crossmap` mappings")? + .context("getting the `CrossMap` mappings")? { let start = Coordinate::::new(from.contig.as_str(), Strand::Positive, from.start); @@ -570,7 +579,7 @@ fn throw(args: &Args) -> Result<()> { let matched_percent = (n_matches as f64 * 100.0) / total_comparisons as f64; println!( - "`chainfile` and `crossmap` matched in {matched_percent:.2}% of cases (n = {})", + "`chainfile` and `CrossMap` matched in {matched_percent:.2}% of cases (n = {})", total_comparisons );