@@ -6,11 +6,22 @@ use bio_types::sequence::SequenceReadPairOrientation;
66use derive_new:: new;
77use itertools:: Itertools ;
88use rust_htslib:: bam;
9+ use rust_htslib:: bam:: record:: Aux ;
910use std:: collections:: { HashMap , HashSet } ;
1011use std:: ops:: BitOrAssign ;
1112
1213const ALLELES : & [ u8 ] = b"ACGT" ;
1314
15+ pub fn get_umi_string ( rec : & bam:: record:: Record ) -> String {
16+ let umi = match rec. aux ( b"RX" ) {
17+ Ok ( Aux :: String ( value) ) => {
18+ format ! ( " RX:Z:{}" , value)
19+ }
20+ _ => String :: from ( "" ) ,
21+ } ;
22+ umi
23+ }
24+
1425#[ derive( Eq , PartialEq ) ]
1526enum StrandObservation {
1627 None ,
@@ -94,12 +105,10 @@ impl<'a> CalcOverlappingConsensus<'a> {
94105 if let Some ( mut read_orientations) = read_orientations_opt {
95106 consensus_strand. append ( & mut read_orientations)
96107 }
97- let consensus_rec = fastq:: Record :: with_attrs (
98- & name,
99- Some ( & String :: from_utf8 ( consensus_strand) . unwrap ( ) ) ,
100- & consensus_seq,
101- & consensus_qual,
102- ) ;
108+ let umi = get_umi_string ( & self . recs1 ( ) [ 0 ] ) ;
109+ let description = format ! ( "{}{}" , String :: from_utf8( consensus_strand) . unwrap( ) , umi) ;
110+ let consensus_rec =
111+ fastq:: Record :: with_attrs ( & name, Some ( & description) , & consensus_seq, & consensus_qual) ;
103112 ( consensus_rec, consensus_lh)
104113 }
105114
@@ -141,9 +150,7 @@ impl<'a> CalcOverlappingConsensus<'a> {
141150 StrandObservation :: Forward => consensus_strand. push ( b'+' ) ,
142151 StrandObservation :: Reverse => consensus_strand. push ( b'-' ) ,
143152 StrandObservation :: Both => consensus_strand. push ( b'*' ) ,
144- StrandObservation :: None => {
145- unreachable ! ( )
146- }
153+ StrandObservation :: None => consensus_strand. push ( b'.' ) ,
147154 }
148155 }
149156 fn build_read_orientation_string ( & self ) -> Option < Vec < u8 > > {
@@ -282,12 +289,10 @@ impl<'a> CalcNonOverlappingConsensus<'a> {
282289 self . seqids( ) . len( ) ,
283290 )
284291 } ;
285- let consensus_rec = fastq:: Record :: with_attrs (
286- & name,
287- Some ( & String :: from_utf8 ( consensus_strand) . unwrap ( ) ) ,
288- & consensus_seq,
289- & consensus_qual,
290- ) ;
292+ let umi = get_umi_string ( & self . recs ( ) [ 0 ] ) ;
293+ let description = format ! ( "{}{}" , String :: from_utf8( consensus_strand) . unwrap( ) , umi) ;
294+ let consensus_rec =
295+ fastq:: Record :: with_attrs ( & name, Some ( & description) , & consensus_seq, & consensus_qual) ;
291296 ( consensus_rec, consensus_lh)
292297 }
293298 pub fn recs ( & self ) -> & [ bam:: Record ] {
0 commit comments