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

fix: Fix read processing when building consensus reads #199

Merged
merged 6 commits into from
Dec 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 20 additions & 15 deletions src/bam/collapse_reads_to_fragments/calc_consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,22 @@ use bio_types::sequence::SequenceReadPairOrientation;
use derive_new::new;
use itertools::Itertools;
use rust_htslib::bam;
use rust_htslib::bam::record::Aux;
use std::collections::{HashMap, HashSet};
use std::ops::BitOrAssign;

const ALLELES: &[u8] = b"ACGT";

pub fn get_umi_string(rec: &bam::record::Record) -> String {
let umi = match rec.aux(b"RX") {
Ok(Aux::String(value)) => {
format!(" RX:Z:{}", value)
}
_ => String::from(""),
};
umi
}

#[derive(Eq, PartialEq)]
enum StrandObservation {
None,
Expand Down Expand Up @@ -94,12 +105,10 @@ impl<'a> CalcOverlappingConsensus<'a> {
if let Some(mut read_orientations) = read_orientations_opt {
consensus_strand.append(&mut read_orientations)
}
let consensus_rec = fastq::Record::with_attrs(
&name,
Some(&String::from_utf8(consensus_strand).unwrap()),
&consensus_seq,
&consensus_qual,
);
let umi = get_umi_string(&self.recs1()[0]);
let description = format!("{}{}", String::from_utf8(consensus_strand).unwrap(), umi);
let consensus_rec =
fastq::Record::with_attrs(&name, Some(&description), &consensus_seq, &consensus_qual);
(consensus_rec, consensus_lh)
}

Expand Down Expand Up @@ -141,9 +150,7 @@ impl<'a> CalcOverlappingConsensus<'a> {
StrandObservation::Forward => consensus_strand.push(b'+'),
StrandObservation::Reverse => consensus_strand.push(b'-'),
StrandObservation::Both => consensus_strand.push(b'*'),
StrandObservation::None => {
unreachable!()
}
StrandObservation::None => consensus_strand.push(b'.'),
}
}
fn build_read_orientation_string(&self) -> Option<Vec<u8>> {
Expand Down Expand Up @@ -282,12 +289,10 @@ impl<'a> CalcNonOverlappingConsensus<'a> {
self.seqids().len(),
)
};
let consensus_rec = fastq::Record::with_attrs(
&name,
Some(&String::from_utf8(consensus_strand).unwrap()),
&consensus_seq,
&consensus_qual,
);
let umi = get_umi_string(&self.recs()[0]);
let description = format!("{}{}", String::from_utf8(consensus_strand).unwrap(), umi);
let consensus_rec =
fastq::Record::with_attrs(&name, Some(&description), &consensus_seq, &consensus_qual);
(consensus_rec, consensus_lh)
}
pub fn recs(&self) -> &[bam::Record] {
Expand Down
Loading