@@ -190,25 +190,32 @@ impl ReadSet {
190
190
// Else check it's a 4-part name... fix the read number at the front and
191
191
// check to see if there's a real sample barcode on the back
192
192
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
+ }
203
198
} 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
+ }
212
219
}
213
220
}
214
221
}
@@ -1648,13 +1655,13 @@ mod tests {
1648
1655
}
1649
1656
1650
1657
#[ test]
1651
- #[ should_panic( expected = "4 segments" ) ]
1652
1658
fn test_write_header_comment_too_few_parts ( ) {
1653
1659
let mut out = Vec :: new ( ) ;
1654
1660
let header = b"q1 0:0" ;
1655
1661
let barcode_segs =
1656
1662
[ seg ( b"ACGT" , SegmentType :: SampleBarcode ) , seg ( b"GGTT" , SegmentType :: SampleBarcode ) ] ;
1657
1663
let umi_segs = [ seg ( b"AACCGGTT" , SegmentType :: MolecularBarcode ) ] ;
1664
+ let expected = "@q1:AACCGGTT 0:0:ACGT+GGTT" . to_string ( ) ;
1658
1665
ReadSet :: write_header_internal (
1659
1666
& mut out,
1660
1667
1 ,
@@ -1663,6 +1670,7 @@ mod tests {
1663
1670
umi_segs. iter ( ) . filter ( |_| true ) ,
1664
1671
)
1665
1672
. unwrap ( ) ;
1673
+ assert_eq ! ( String :: from_utf8( out) . unwrap( ) , expected) ;
1666
1674
}
1667
1675
1668
1676
// ############################################################################################
0 commit comments