Skip to content

Commit

Permalink
Do not require comment to have 4 segments (#26)
Browse files Browse the repository at this point in the history
* Attempt to fix 25
  • Loading branch information
nh13 authored Jun 9, 2023
1 parent dec00ab commit 60c06a1
Showing 1 changed file with 27 additions and 19 deletions.
46 changes: 27 additions & 19 deletions src/bin/commands/demux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,25 +190,32 @@ impl ReadSet {
// Else check it's a 4-part name... fix the read number at the front and
// check to see if there's a real sample barcode on the back
let sep_count = chars.iter().filter(|c| **c == Self::COLON).count();
ensure!(
sep_count == 3,
"Comment in did not have 4 segments: {}",
String::from_utf8(header.to_vec())?
);
let first_colon_idx = chars.iter().position(|ch| *ch == Self::COLON).unwrap();

// Illumina, in the unmatched FASTQs, can place a "0" in the index position, sigh
let remainder = if chars.last().unwrap().is_ascii_digit() {
&chars[first_colon_idx + 1..chars.len() - 1]
if sep_count < 3 {
writer.write_all(chars)?;
if *chars.last().unwrap() != Self::COLON {
writer.write_all(&[Self::COLON])?;
}
} else {
&chars[first_colon_idx + 1..chars.len()]
};

write!(writer, "{}:", read_num)?;
writer.write_all(remainder)?;

if *remainder.last().unwrap() != Self::COLON {
writer.write_all(&[Self::PLUS])?;
ensure!(
sep_count == 3,
"Comment in did not have 4 segments: {}",
String::from_utf8(header.to_vec())?
);
let first_colon_idx = chars.iter().position(|ch| *ch == Self::COLON).unwrap();

// Illumina, in the unmatched FASTQs, can place a "0" in the index position, sigh
let remainder = if chars.last().unwrap().is_ascii_digit() {
&chars[first_colon_idx + 1..chars.len() - 1]
} else {
&chars[first_colon_idx + 1..chars.len()]
};

write!(writer, "{}:", read_num)?;
writer.write_all(remainder)?;

if *remainder.last().unwrap() != Self::COLON {
writer.write_all(&[Self::PLUS])?;
}
}
}
}
Expand Down Expand Up @@ -1648,13 +1655,13 @@ mod tests {
}

#[test]
#[should_panic(expected = "4 segments")]
fn test_write_header_comment_too_few_parts() {
let mut out = Vec::new();
let header = b"q1 0:0";
let barcode_segs =
[seg(b"ACGT", SegmentType::SampleBarcode), seg(b"GGTT", SegmentType::SampleBarcode)];
let umi_segs = [seg(b"AACCGGTT", SegmentType::MolecularBarcode)];
let expected = "@q1:AACCGGTT 0:0:ACGT+GGTT".to_string();
ReadSet::write_header_internal(
&mut out,
1,
Expand All @@ -1663,6 +1670,7 @@ mod tests {
umi_segs.iter().filter(|_| true),
)
.unwrap();
assert_eq!(String::from_utf8(out).unwrap(), expected);
}

// ############################################################################################
Expand Down

0 comments on commit 60c06a1

Please sign in to comment.