Skip to content

Commit

Permalink
fix barcode with no onlist
Browse files Browse the repository at this point in the history
  • Loading branch information
kaizhang committed Dec 29, 2024
1 parent 796d6b7 commit cbccd3e
Show file tree
Hide file tree
Showing 3 changed files with 228 additions and 106 deletions.
52 changes: 25 additions & 27 deletions precellar/src/align/fastq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,22 +109,18 @@ impl FastqProcessor {
fq_reader.map(move |data| {
let align_qc = self.align_qc.get_mut(&modality).unwrap();
let results: Vec<_> = aligner.align_reads(num_threads, data);
results
.iter()
.for_each(|ali| {
match ali {
(Some(ali1), Some(ali2)) => {
align_qc.add_pair(&header, ali1, ali2).unwrap();
},
(Some(ali1), None) => {
align_qc.add_read1(&header, ali1).unwrap();
},
(None, Some(ali2)) => {
align_qc.add_read2(&header, ali2).unwrap();
},
_ => {}
}
});
results.iter().for_each(|ali| match ali {
(Some(ali1), Some(ali2)) => {
align_qc.add_pair(&header, ali1, ali2).unwrap();
}
(Some(ali1), None) => {
align_qc.add_read1(&header, ali1).unwrap();
}
(None, Some(ali2)) => {
align_qc.add_read2(&header, ali2).unwrap();
}
_ => {}
});
progress_bar.update(results.len()).unwrap();
results
})
Expand Down Expand Up @@ -170,7 +166,7 @@ impl FastqProcessor {

fn count_barcodes(&mut self) -> Result<IndexMap<RegionId, Whitelist>> {
let modality = self.modality();
let mut whitelists = self.get_whitelists()?;
let mut whitelists = self.get_whitelists();

fn count(
read: &Read,
Expand Down Expand Up @@ -215,28 +211,27 @@ impl FastqProcessor {
Ok(whitelists)
}

fn get_whitelists(&self) -> Result<IndexMap<RegionId, Whitelist>> {
fn get_whitelists(&self) -> IndexMap<RegionId, Whitelist> {
let regions = self
.assay
.library_spec
.get_modality(&self.modality())
.unwrap()
.read()
.map_err(|_| anyhow::anyhow!("Cannot obtain lock"))?;
.unwrap();
regions
.subregions
.iter()
.filter_map(|r| {
let r = r.read().unwrap();
if r.region_type.is_barcode() {
if let Some(onlist) = r.onlist.as_ref() {
let list = onlist
.read()
.map(|list| (r.region_id.to_string(), Whitelist::new(list)));
Some(list)
let id = r.region_id.to_string();
let list = if let Some(onlist) = r.onlist.as_ref() {
Whitelist::new(onlist.read().unwrap())
} else {
None
}
Whitelist::empty()
};
Some((id, list))
} else {
None
}
Expand Down Expand Up @@ -340,7 +335,10 @@ impl AnnotatedFastqReader {
} else if min_read == 0 {
panic!("Unequal number of reads in the chunk");
} else {
assert!(records.iter().map(|r| r.name()).all_equal(), "read names mismatch");
assert!(
records.iter().map(|r| r.name()).all_equal(),
"read names mismatch"
);
self.chunk.push(records);
}
}
Expand Down
1 change: 1 addition & 0 deletions python/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ serde_yaml = "0.9"
termtree = "0.5"
precellar = { workspace = true }
regex = "1.6"
rayon = "1.10"
log = "0.4"
env_logger = "0.11"
url = "2.5"
Expand Down
Loading

0 comments on commit cbccd3e

Please sign in to comment.