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

feat: better error message when barcode length differs from expected #44

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

TimD1
Copy link

@TimD1 TimD1 commented Jul 9, 2024

@@ -74,7 +74,7 @@ impl BarcodeMatcher {
assert_eq!(
observed_bases.len(),
expected_bases.len(),
"observed_bases: {}, expected_bases: {}",
"Sample barcode length ({}) differs from expected ({}) during barcode matching",
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be helpful to additionally include the sequence of the barcode in question?

Copy link
Member

Choose a reason for hiding this comment

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

I think we want to know which sample this is caused by, as well as the barcode bases (actual and expected) along with the length.

Copy link
Author

Choose a reason for hiding this comment

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

Sounds good. I can add that info if I replace BarcodeMatcher.sample_barcodes with BarcodeMatcher.samples (vector of Sample structs storing sample_ids and barcodes). It looks like this was the eventual plan anyways:

/// Note - this is to be replaced by a sample struct in task 3. For now we're keeping things
/// very simple.
sample_barcodes: Vec<BString>,

 - barcode bases and lengths (actual and expected) and sample name are printed
 - fixes #31 by passing `Sample` to `count_mismatches()` instead of barcode string
 - all `count_mismatches()` tests updated to match new signature
 - minor miscellaneous comment typos fixed as well
@TimD1 TimD1 force-pushed the 31/td/barcode-length-mismatch-error-message branch from 3392552 to 745cdb8 Compare July 10, 2024 20:53
@TimD1
Copy link
Author

TimD1 commented Jul 10, 2024

This is my first time writing Rust, so please feel free to make suggestions for better style/design/etc.

A note on the new tests:
Since Samples do not allow empty barcodes:

fqtk/src/lib/samples.rs

Lines 48 to 50 in 6ed98a3

pub fn new(ordinal: usize, name: String, barcode: String) -> Self {
assert!(!name.is_empty(), "Sample name cannot be empty");
assert!(!barcode.is_empty(), "Sample barcode cannot be empty");

My understanding is that new() is the only way to get a new Sample outside of the samples.rs module, since Sample contains a private field (ordinal). Therefore, I dropped the test for BarcodeMatcher being initialized with a Sample with an empty barcode:

#[rstest]
#[case(true)]
#[case(false)]
#[should_panic(expected = "Sample barcode cannot be empty string")]
fn test_barcode_matcher_fails_if_empty_sample_barcode_provided(#[case] use_cache: bool) {
let sample_barcodes = vec!["AGCT", ""];
let _matcher = BarcodeMatcher::new(&sample_barcodes, 2, 1, use_cache);
}

And modified the test that allowed empty barcodes to be compared to check that it now fails.

#[test]
fn empty_string_can_run_in_count_mismatches() {
assert_eq!(BarcodeMatcher::count_mismatches("".as_bytes(), "".as_bytes()), 0);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants