|
| 1 | +use predicates::prelude::*; |
| 2 | +use snapbox::cmd::{cargo_bin, Command}; |
| 3 | +use std::path::Path; |
| 4 | + |
| 5 | +pub mod common; |
| 6 | +use crate::common::*; |
| 7 | + |
| 8 | +#[path = "../src/io.rs"] |
| 9 | +pub mod io; |
| 10 | + |
| 11 | +use sketchlib::multisketch::MultiSketch; |
| 12 | + |
| 13 | +#[cfg(test)] |
| 14 | + |
| 15 | +mod tests { |
| 16 | + use super::*; |
| 17 | + |
| 18 | + #[test] |
| 19 | + fn concat_competibility_test() { |
| 20 | + let sandbox = TestSetup::setup(); |
| 21 | + let ref_db1 = sandbox.file_string("sketches1", TestDir::Input); |
| 22 | + let ref_db2 = sandbox.file_string("sketches2", TestDir::Input); |
| 23 | + let file_list_name = sandbox.file_string("fasta.txt", TestDir::Input); |
| 24 | + let non_seq_files: Option<Vec<String>> = None; |
| 25 | + |
| 26 | + |
| 27 | + let file_list: Option<String> = Some(file_list_name); |
| 28 | + //get input files with file_list |
| 29 | + log::info!("Getting input files for test"); |
| 30 | + let input_file_list = io::get_input_list(&file_list, &non_seq_files); |
| 31 | + log::info!("Parsed {} samples in input list", input_file_list.len()); |
| 32 | + |
| 33 | + //check if any of the new files are already existant in the db |
| 34 | + let db1_metadata: MultiSketch = MultiSketch::load(&ref_db1) |
| 35 | + .unwrap_or_else(|_| panic!("Could not read sketch metadata from {}.skm", ref_db1)); |
| 36 | + println!("{:?}", db1_metadata); |
| 37 | + |
| 38 | + //check if any of the new files are already existant in the db |
| 39 | + let db2_metadata: MultiSketch = MultiSketch::load(&ref_db2) |
| 40 | + .unwrap_or_else(|_| panic!("Could not read sketch metadata from {}.skm", ref_db2)); |
| 41 | + println!("{:?}", db2_metadata); |
| 42 | + |
| 43 | + // Test case 1: |
| 44 | + assert!( |
| 45 | + !db1_metadata.concat_competibility(&input_file_list), |
| 46 | + "Sketches should not be compatible" |
| 47 | + ); |
| 48 | + } |
| 49 | + |
| 50 | + #[test] |
| 51 | + fn test_concat_sketches() { |
| 52 | + let sandbox = TestSetup::setup(); |
| 53 | + |
| 54 | + Command::new(cargo_bin("sketchlib")) |
| 55 | + .current_dir(sandbox.get_wd()) |
| 56 | + .arg("sketch") |
| 57 | + .args(&["--k-vals", "17"]) |
| 58 | + .arg("--seq-files") |
| 59 | + .arg(sandbox.file_string("14412_3#82.contigs_velvet.fa.gz", TestDir::Input)) |
| 60 | + .arg(sandbox.file_string("14412_3#84.contigs_velvet.fa.gz", TestDir::Input)) |
| 61 | + .arg("-v") |
| 62 | + .args(&["-o", "part1"]) |
| 63 | + .assert() |
| 64 | + .success(); |
| 65 | + log::info!("Part 1 Sketched"); |
| 66 | + |
| 67 | + Command::new(cargo_bin("sketchlib")) |
| 68 | + .current_dir(sandbox.get_wd()) |
| 69 | + .arg("sketch") |
| 70 | + .args(&["--k-vals", "17"]) |
| 71 | + .arg("--seq-files") |
| 72 | + .arg(sandbox.file_string("R6.fa.gz", TestDir::Input)) |
| 73 | + .arg(sandbox.file_string("TIGR4.fa.gz", TestDir::Input)) |
| 74 | + .arg("-v") |
| 75 | + .args(&["-o", "part2"]) |
| 76 | + .assert() |
| 77 | + .success(); |
| 78 | + log::info!("Part 2 Sketched"); |
| 79 | + |
| 80 | + Command::new(cargo_bin("sketchlib")) |
| 81 | + .current_dir(sandbox.get_wd()) |
| 82 | + .arg("sketch") |
| 83 | + .args(&["--k-vals", "17"]) |
| 84 | + .arg("--seq-files") |
| 85 | + .arg(sandbox.file_string("R6.fa.gz", TestDir::Input)) |
| 86 | + .arg(sandbox.file_string("TIGR4.fa.gz", TestDir::Input)) |
| 87 | + .arg(sandbox.file_string("14412_3#82.contigs_velvet.fa.gz", TestDir::Input)) |
| 88 | + .arg(sandbox.file_string("14412_3#84.contigs_velvet.fa.gz", TestDir::Input)) |
| 89 | + .arg("-v") |
| 90 | + .args(&["-o", "concat_ref"]) |
| 91 | + .assert() |
| 92 | + .success(); |
| 93 | + log::info!("concat_ref Sketched"); |
| 94 | + |
| 95 | + // Overlapping labels fails |
| 96 | + Command::new(cargo_bin("sketchlib")) |
| 97 | + .current_dir(sandbox.get_wd()) |
| 98 | + .arg("concat") |
| 99 | + .arg("part1") |
| 100 | + .arg("--seq-files") |
| 101 | + .arg(sandbox.file_string("14412_3#82.contigs_velvet.fa.gz", TestDir::Input)) |
| 102 | + .arg(sandbox.file_string("14412_3#84.contigs_velvet.fa.gz", TestDir::Input)) |
| 103 | + .arg("-v") |
| 104 | + .args(&["-o", "concat_test"]) |
| 105 | + .assert() |
| 106 | + .failure(); |
| 107 | + |
| 108 | + Command::new(cargo_bin("sketchlib")) |
| 109 | + .current_dir(sandbox.get_wd()) |
| 110 | + .arg("concat") |
| 111 | + .arg("part1") |
| 112 | + .arg("--seq-files") |
| 113 | + // .arg(sandbox.file_string("fasta_part2.txt", TestDir::Input)) |
| 114 | + .arg(sandbox.file_string("R6.fa.gz", TestDir::Input)) |
| 115 | + .arg(sandbox.file_string("TIGR4.fa.gz", TestDir::Input)) |
| 116 | + .arg("-v") |
| 117 | + .args(&["-o", "concat_test"]) |
| 118 | + .assert() |
| 119 | + .success(); |
| 120 | + log::info!("concat_test Sketched"); |
| 121 | + |
| 122 | + // Check .skm the same |
| 123 | + let concat_sketch: MultiSketch = |
| 124 | + MultiSketch::load(&sandbox.file_string("concat_test", TestDir::Output)) |
| 125 | + .expect("Failed to load output merged sketch"); |
| 126 | + let expected_sketch = |
| 127 | + MultiSketch::load(&sandbox.file_string("concat_ref", TestDir::Output)) |
| 128 | + .expect("Failed to load expected merged sketch"); |
| 129 | + println!("{}", concat_sketch); |
| 130 | + println!("{}", expected_sketch); |
| 131 | + assert_eq!( |
| 132 | + concat_sketch, expected_sketch, |
| 133 | + "Concat sketch metadata does not match" |
| 134 | + ); |
| 135 | + |
| 136 | + // Check .skd the same |
| 137 | + let predicate_file = predicate::path::eq_file(Path::new( |
| 138 | + &sandbox.file_string("concat_test.skd", TestDir::Output), |
| 139 | + )); |
| 140 | + assert_eq!( |
| 141 | + true, |
| 142 | + predicate_file.eval(Path::new( |
| 143 | + &sandbox.file_string("concat_ref.skd", TestDir::Output) |
| 144 | + )), |
| 145 | + "Concat sketch data does not match" |
| 146 | + ); |
| 147 | + } |
| 148 | +} |
0 commit comments