Skip to content

Commit 5bc9c40

Browse files
authored
Merge pull request #40 from bacpop/fastq_hotfix
Fastq input hotfix
2 parents 8515a65 + 4d6b25f commit 5bc9c40

16 files changed

+143
-18
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "sketchlib"
3-
version = "0.1.2"
3+
version = "0.1.3"
44
authors = [
55
"John Lees <[email protected]>",
66
"Nicholas Croucher <[email protected]>",

src/distances.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ impl<'a> Distances<'a> for DistanceMatrix<'a> {
137137
}
138138
}
139139

140-
impl<'a> fmt::Display for DistanceMatrix<'a> {
140+
impl fmt::Display for DistanceMatrix<'_> {
141141
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
142142
let mut dist_idx = 0;
143143
if let Some(queries) = &self.query_names {
@@ -267,7 +267,7 @@ impl<'a> Distances<'a> for SparseDistanceMatrix<'a> {
267267
}
268268
}
269269

270-
impl<'a> fmt::Display for SparseDistanceMatrix<'a> {
270+
impl fmt::Display for SparseDistanceMatrix<'_> {
271271
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
272272
let mut ref_name_iter = self.ref_names.iter();
273273
let mut ref_name = ref_name_iter.next().unwrap();

src/io.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ pub fn get_input_list(
8989
2 => ((fields[0].to_string()), fields[1].to_string(), None),
9090
3 => (
9191
(fields[0].to_string()),
92-
fields[0].to_string(),
92+
fields[1].to_string(),
9393
Some(fields[2].to_string()),
9494
),
9595
_ => {

src/multisketch.rs

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use serde::{Deserialize, Serialize};
1515
use crate::hashing::HashType;
1616
use crate::sketch::{Sketch, BBITS};
1717
use crate::sketch_datafile::SketchArrayFile;
18-
use crate::utils::get_progress_bar;
1918

2019
use std::collections::HashSet;
2120
#[derive(Serialize, Deserialize)]

src/structures.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
//! Support for .pdb files and the 3di alphabet
2+
#[cfg(feature = "3di")]
23
use crate::io::InputFastx;
4+
#[cfg(feature = "3di")]
35
use anyhow::Error;
46

7+
#[cfg(feature = "3di")]
58
use indicatif::{ProgressIterator, ProgressStyle};
69
#[cfg(feature = "3di")]
710
use pyo3::prelude::*;

tests/common/mod.rs

+15-11
Original file line numberDiff line numberDiff line change
@@ -115,27 +115,31 @@ impl TestSetup {
115115
writeln!(
116116
rfile,
117117
"{}",
118-
&format!(
119-
"{}\t{}",
120-
file,
121-
self.file_string(file, TestDir::Input),
122-
)
118+
&format!("{}\t{}", file, self.file_string(file, TestDir::Input),)
123119
)
124120
.unwrap();
125121
}
126122
RFILE_NAME
127123
}
128124

129-
pub fn create_par_rfile(&self) -> &str {
125+
/// Create an rfile wtih two fastqs in the tmp dir
126+
pub fn create_fastq_rfile(&self, prefix: &str) -> &str {
130127
let mut rfile = LineWriter::new(
131128
File::create(format!("{}/{}", self.get_wd(), RFILE_NAME))
132129
.expect("Could not write rfile"),
133130
);
134-
135-
let paths = read_dir(self.file_string("par_test", TestDir::Input)).unwrap();
136-
for path in paths {
137-
let path_str = path.unwrap().path().display().to_string();
138-
writeln!(rfile, "{path_str}\t{path_str}").unwrap();
131+
for file_idx in 1..=2 {
132+
let sample_name = format!("{prefix}_{file_idx}");
133+
writeln!(
134+
rfile,
135+
"{}",
136+
&format!(
137+
"{sample_name}\t{}\t{}",
138+
self.file_string(&format!("{sample_name}_fwd.fastq.gz"), TestDir::Input),
139+
self.file_string(&format!("{sample_name}_rev.fastq.gz"), TestDir::Input),
140+
)
141+
)
142+
.unwrap();
139143
}
140144
RFILE_NAME
141145
}

tests/delete.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ mod tests {
1616
fn test_delete_sketches() {
1717
let sandbox = TestSetup::setup();
1818

19-
let rfile1 = sandbox.create_rfile(&vec!["14412_3#82.contigs_velvet.fa.gz", "14412_3#84.contigs_velvet.fa.gz", "R6.fa.gz", "TIGR4.fa.gz"]);
19+
let rfile1 = sandbox.create_rfile(&vec![
20+
"14412_3#82.contigs_velvet.fa.gz",
21+
"14412_3#84.contigs_velvet.fa.gz",
22+
"R6.fa.gz",
23+
"TIGR4.fa.gz",
24+
]);
2025
Command::new(cargo_bin("sketchlib"))
2126
.current_dir(sandbox.get_wd())
2227
.arg("sketch")
@@ -27,7 +32,10 @@ mod tests {
2732
.assert()
2833
.success();
2934

30-
let rfile2 = sandbox.create_rfile(&vec!["14412_3#82.contigs_velvet.fa.gz", "14412_3#84.contigs_velvet.fa.gz"]);
35+
let rfile2 = sandbox.create_rfile(&vec![
36+
"14412_3#82.contigs_velvet.fa.gz",
37+
"14412_3#84.contigs_velvet.fa.gz",
38+
]);
3139
Command::new(cargo_bin("sketchlib"))
3240
.current_dir(sandbox.get_wd())
3341
.arg("sketch")

tests/sketch.rs

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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+
use sketchlib::multisketch::MultiSketch;
9+
10+
#[cfg(test)]
11+
12+
mod tests {
13+
use super::*;
14+
15+
#[test]
16+
fn sketch_fasta() {
17+
let sandbox = TestSetup::setup();
18+
19+
// Create a fasta rfile in the tmp dir
20+
Command::new(cargo_bin("sketchlib"))
21+
.current_dir(sandbox.get_wd())
22+
.arg("sketch")
23+
.arg("-o")
24+
.arg("assembly")
25+
.args(["-v", "-k", "31"])
26+
.arg(sandbox.file_string("14412_3#82.contigs_velvet.fa.gz", TestDir::Input))
27+
.arg(sandbox.file_string("14412_3#84.contigs_velvet.fa.gz", TestDir::Input))
28+
.assert()
29+
.success();
30+
31+
assert_eq!(true, sandbox.file_exists("assembly.skm"));
32+
assert_eq!(true, sandbox.file_exists("assembly.skd"));
33+
34+
Command::new(cargo_bin("sketchlib"))
35+
.current_dir(sandbox.get_wd())
36+
.arg("info")
37+
.arg("assembly")
38+
.assert()
39+
.stdout_matches_path(
40+
sandbox.file_string("assembly_sketch_info.stdout", TestDir::Correct),
41+
);
42+
43+
Command::new(cargo_bin("sketchlib"))
44+
.current_dir(sandbox.get_wd())
45+
.arg("info")
46+
.arg("--sample-info")
47+
.arg("assembly")
48+
.arg("-v")
49+
.assert()
50+
.stdout_matches_path(
51+
sandbox.file_string("assembly_sketch_full_info.stdout", TestDir::Correct),
52+
);
53+
}
54+
55+
#[test]
56+
fn sketch_fastq() {
57+
let sandbox = TestSetup::setup();
58+
59+
// Create a fastq rfile in the tmp dir
60+
let rfile_name = sandbox.create_fastq_rfile("test");
61+
Command::new(cargo_bin("sketchlib"))
62+
.current_dir(sandbox.get_wd())
63+
.arg("sketch")
64+
.arg("-f")
65+
.arg(rfile_name)
66+
.arg("-o")
67+
.arg("reads")
68+
.args(["--min-count", "2", "-v", "-k", "9", "--min-qual", "2"])
69+
.assert()
70+
.success();
71+
72+
assert_eq!(true, sandbox.file_exists("reads.skm"));
73+
assert_eq!(true, sandbox.file_exists("reads.skd"));
74+
75+
Command::new(cargo_bin("sketchlib"))
76+
.current_dir(sandbox.get_wd())
77+
.arg("info")
78+
.arg("reads")
79+
.assert()
80+
.stdout_matches_path(sandbox.file_string("read_sketch_info.stdout", TestDir::Correct));
81+
82+
Command::new(cargo_bin("sketchlib"))
83+
.current_dir(sandbox.get_wd())
84+
.arg("info")
85+
.arg("--sample-info")
86+
.arg("reads")
87+
.arg("-v")
88+
.assert()
89+
.stdout_matches_path(
90+
sandbox.file_string("read_sketch_full_info.stdout", TestDir::Correct),
91+
);
92+
}
93+
}
886 Bytes
Binary file not shown.
877 Bytes
Binary file not shown.
850 Bytes
Binary file not shown.
850 Bytes
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Name Sequence length Base frequencies Missing/ambig bases From reads Single strand Densified
2+
[..]14412_3#82.contigs_velvet.fa.gz 1832266 [571702, 352572, 343740, 564252] 579 false false false
3+
[..]14412_3#84.contigs_velvet.fa.gz 1823561 [571676, 350424, 342380, 559081] 1663 false false false
4+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
sketch_version=[..]
2+
sequence_type=DNA
3+
sketch_size=1024
4+
n_samples=2
5+
kmers=[31]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Name Sequence length Base frequencies Missing/ambig bases From reads Single strand Densified
2+
test_1 1 [603, 330, 334, 603] 0 true false true
3+
test_2 1 [617, 312, 314, 617] 0 true false true
4+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
sketch_version=[..]
2+
sequence_type=DNA
3+
sketch_size=1024
4+
n_samples=2
5+
kmers=[9]

0 commit comments

Comments
 (0)