Skip to content

Commit 60c06a1

Browse files
authored
Do not require comment to have 4 segments (#26)
* Attempt to fix 25
1 parent dec00ab commit 60c06a1

File tree

1 file changed

+27
-19
lines changed

1 file changed

+27
-19
lines changed

src/bin/commands/demux.rs

+27-19
Original file line numberDiff line numberDiff line change
@@ -190,25 +190,32 @@ impl ReadSet {
190190
// Else check it's a 4-part name... fix the read number at the front and
191191
// check to see if there's a real sample barcode on the back
192192
let sep_count = chars.iter().filter(|c| **c == Self::COLON).count();
193-
ensure!(
194-
sep_count == 3,
195-
"Comment in did not have 4 segments: {}",
196-
String::from_utf8(header.to_vec())?
197-
);
198-
let first_colon_idx = chars.iter().position(|ch| *ch == Self::COLON).unwrap();
199-
200-
// Illumina, in the unmatched FASTQs, can place a "0" in the index position, sigh
201-
let remainder = if chars.last().unwrap().is_ascii_digit() {
202-
&chars[first_colon_idx + 1..chars.len() - 1]
193+
if sep_count < 3 {
194+
writer.write_all(chars)?;
195+
if *chars.last().unwrap() != Self::COLON {
196+
writer.write_all(&[Self::COLON])?;
197+
}
203198
} else {
204-
&chars[first_colon_idx + 1..chars.len()]
205-
};
206-
207-
write!(writer, "{}:", read_num)?;
208-
writer.write_all(remainder)?;
209-
210-
if *remainder.last().unwrap() != Self::COLON {
211-
writer.write_all(&[Self::PLUS])?;
199+
ensure!(
200+
sep_count == 3,
201+
"Comment in did not have 4 segments: {}",
202+
String::from_utf8(header.to_vec())?
203+
);
204+
let first_colon_idx = chars.iter().position(|ch| *ch == Self::COLON).unwrap();
205+
206+
// Illumina, in the unmatched FASTQs, can place a "0" in the index position, sigh
207+
let remainder = if chars.last().unwrap().is_ascii_digit() {
208+
&chars[first_colon_idx + 1..chars.len() - 1]
209+
} else {
210+
&chars[first_colon_idx + 1..chars.len()]
211+
};
212+
213+
write!(writer, "{}:", read_num)?;
214+
writer.write_all(remainder)?;
215+
216+
if *remainder.last().unwrap() != Self::COLON {
217+
writer.write_all(&[Self::PLUS])?;
218+
}
212219
}
213220
}
214221
}
@@ -1648,13 +1655,13 @@ mod tests {
16481655
}
16491656

16501657
#[test]
1651-
#[should_panic(expected = "4 segments")]
16521658
fn test_write_header_comment_too_few_parts() {
16531659
let mut out = Vec::new();
16541660
let header = b"q1 0:0";
16551661
let barcode_segs =
16561662
[seg(b"ACGT", SegmentType::SampleBarcode), seg(b"GGTT", SegmentType::SampleBarcode)];
16571663
let umi_segs = [seg(b"AACCGGTT", SegmentType::MolecularBarcode)];
1664+
let expected = "@q1:AACCGGTT 0:0:ACGT+GGTT".to_string();
16581665
ReadSet::write_header_internal(
16591666
&mut out,
16601667
1,
@@ -1663,6 +1670,7 @@ mod tests {
16631670
umi_segs.iter().filter(|_| true),
16641671
)
16651672
.unwrap();
1673+
assert_eq!(String::from_utf8(out).unwrap(), expected);
16661674
}
16671675

16681676
// ############################################################################################

0 commit comments

Comments
 (0)