Skip to content

Commit

Permalink
Reader outputting BAM records
Browse files Browse the repository at this point in the history
  • Loading branch information
hextraza committed Mar 15, 2023
1 parent 7c91640 commit c843aba
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
11 changes: 5 additions & 6 deletions src/parse/bam.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use super::sorted_bam_reader::SortedBamReader;
use debruijn::dna_string::DnaString;
use rust_htslib::bam::record::Aux;

use rust_htslib::bam::record::{Aux, Record};
use std::time::{Duration, Instant};

const READ_BLOCK_REPORT_SIZE: usize = 1000000;
Expand All @@ -11,11 +10,11 @@ pub struct UMIReader {
reader: SortedBamReader,
read_counter: usize,
pub current_umi_group: Vec<DnaString>,
pub current_metadata_group: Vec<(u8, String, String, bool, String)>,
pub current_metadata_group: Vec<(u8, String, String, bool, String, Record)>,
pub current_umi: String,
pub current_cell_barcode: String,
pub next_umi_group: Vec<DnaString>,
pub next_metadata_group: Vec<(u8, String, String, bool, String)>,
pub next_metadata_group: Vec<(u8, String, String, bool, String, Record)>,
next_umi: String,
next_cell_barcode: String,
terminate_on_error: bool,
Expand Down Expand Up @@ -162,7 +161,7 @@ impl UMIReader {
if self.current_iteration_key == current_iteration_key {
self.current_umi_group.push(seq);
self.current_metadata_group
.push((mapq, orientation, pair, rev_comp, hit));
.push((mapq, orientation, pair, rev_comp, hit, record));
self.current_cell_barcode = current_cell_barcode.clone();

self.current_iteration_key = current_iteration_key;
Expand All @@ -172,7 +171,7 @@ impl UMIReader {
} else {
self.next_umi_group.push(seq);
self.next_metadata_group
.push((mapq, orientation, pair, rev_comp, hit));
.push((mapq, orientation, pair, rev_comp, hit, record));
self.next_umi = read_umi.clone();
self.next_cell_barcode = current_cell_barcode;
self.next_iteration_key = current_iteration_key;
Expand Down
19 changes: 10 additions & 9 deletions src/process/bam.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use array_tool::vec::Intersect;
use debruijn::dna_string::DnaString;
use rust_htslib::bam::record::Record;
use std::collections::HashMap;
use std::io::Error;

Expand Down Expand Up @@ -132,7 +133,7 @@ pub fn process(
.current_metadata_group
.clone()
.into_iter()
.map(|(_, _, _, r, _)| r)
.map(|(_, _, _, r, _, _)| r)
.collect::<Vec<bool>>(),
)
} else {
Expand All @@ -146,7 +147,7 @@ pub fn process(
.current_metadata_group
.clone()
.into_iter()
.map(|(_, _, _, r, _)| r)
.map(|(_, _, _, r, _, _)| r)
.collect::<Vec<bool>>(),
)
};
Expand Down Expand Up @@ -315,10 +316,10 @@ pub fn process(
}

fn metadata_to_sequence_hashmap(
metadata: Vec<(u8, String, String, bool, String)>,
metadata: Vec<(u8, String, String, bool, String, Record)>,
sequences: Vec<DnaString>,
) -> HashMap<String, (u8, String, String, bool, String)> {
let mut ret: HashMap<String, (u8, String, String, bool, String)> = HashMap::new();
) -> HashMap<String, (u8, String, String, bool, String, Record)> {
let mut ret: HashMap<String, (u8, String, String, bool, String, Record)> = HashMap::new();

for (i, seq) in sequences.iter().enumerate() {
ret.insert(seq.to_string(), metadata[i].clone());
Expand All @@ -329,7 +330,7 @@ fn metadata_to_sequence_hashmap(

fn get_mapq_scores(
sequences: Vec<String>,
metadata_table: &HashMap<String, (u8, String, String, bool, String)>,
metadata_table: &HashMap<String, (u8, String, String, bool, String, Record)>,
) -> Vec<u8> {
let mut ret: Vec<u8> = Vec::new();

Expand All @@ -354,7 +355,7 @@ fn get_mapq_scores(

fn get_hits(
sequences: Vec<String>,
metadata_table: &HashMap<String, (u8, String, String, bool, String)>,
metadata_table: &HashMap<String, (u8, String, String, bool, String, Record)>,
) -> Vec<String> {
let mut ret: Vec<String> = Vec::new();

Expand All @@ -379,7 +380,7 @@ fn get_hits(

fn get_orientation(
sequences: Vec<String>,
metadata_table: &HashMap<String, (u8, String, String, bool, String)>,
metadata_table: &HashMap<String, (u8, String, String, bool, String, Record)>,
) -> Vec<String> {
let mut ret: Vec<String> = Vec::new();

Expand All @@ -404,7 +405,7 @@ fn get_orientation(

fn get_pair(
sequences: Vec<String>,
metadata_table: &HashMap<String, (u8, String, String, bool, String)>,
metadata_table: &HashMap<String, (u8, String, String, bool, String, Record)>,
) -> Vec<String> {
let mut ret: Vec<String> = Vec::new();

Expand Down

0 comments on commit c843aba

Please sign in to comment.