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

refactor: Extract repeated H5 loading code into a couple of small types #548

Merged
merged 4 commits into from
Apr 2, 2024
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
59 changes: 30 additions & 29 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 3 additions & 30 deletions enclone_main/src/stop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,32 +35,7 @@ pub fn main_enclone_stop(
let ctl = &setup.ctl;
let tall = &setup.tall.unwrap();

// Load the GEX and FB data. This is quite horrible: the code and computation are duplicated
// verbatim in fcell.rs.

let mut d_readers = Vec::<Option<Reader>>::new();
let mut ind_readers = Vec::<Option<Reader>>::new();
for li in 0..ctl.origin_info.n() {
if !ctl.origin_info.gex_path[li].is_empty() {
let x = gex_info.h5_data[li].as_ref();
d_readers.push(Some(x.unwrap().as_reader()));
ind_readers.push(Some(gex_info.h5_indices[li].as_ref().unwrap().as_reader()));
} else {
d_readers.push(None);
ind_readers.push(None);
}
}
let mut h5_data = Vec::<(usize, Vec<u32>, Vec<u32>)>::new();
for li in 0..ctl.origin_info.n() {
h5_data.push((li, Vec::new(), Vec::new()));
}
h5_data.par_iter_mut().for_each(|res| {
let li = res.0;
if !ctl.origin_info.gex_path[li].is_empty() && ctl.gen_opt.h5_pre {
res.1 = d_readers[li].as_ref().unwrap().read_raw().unwrap();
res.2 = ind_readers[li].as_ref().unwrap().read_raw().unwrap();
}
});
let gex_readers = setup.create_gex_readers();

// Find and print clonotypes. (But we don't actually print them here.)
if !ctl.gen_opt.trace_barcode.is_empty() {
Expand All @@ -85,7 +60,7 @@ pub fn main_enclone_stop(
mut rsi,
mut out_datas,
gene_scan_result,
} = print_clonotypes(setup, exacts, &d_readers, &ind_readers, &h5_data, &fate)?;
} = print_clonotypes(setup, exacts, &gex_readers, &fate)?;

// Gather some data for gene scan.
let (mut tests, mut controls) = (vec![], vec![]);
Expand Down Expand Up @@ -197,9 +172,7 @@ pub fn main_enclone_stop(
&fate,
&tests,
&controls,
&h5_data,
&d_readers,
&ind_readers,
&gex_readers,
drefs,
&groups,
&opt_d_val,
Expand Down
47 changes: 9 additions & 38 deletions enclone_tail/src/tail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::group::group_and_print_clonotypes;

use enclone_core::defs::{ColInfo, EncloneControl, ExactClonotype, GexInfo};

use enclone_core::enclone_structs::{BarcodeFates, JoinInfo};
use enclone_core::enclone_structs::{BarcodeFates, GexReaders, JoinInfo};
use enclone_proto::types::DonorReferenceItem;
use io_utils::fwrite;
use ndarray::s;
Expand Down Expand Up @@ -39,9 +39,7 @@ pub fn tail_code(
fate: &[BarcodeFates],
tests: &Vec<usize>,
controls: &Vec<usize>,
h5_data: &Vec<(usize, Vec<u32>, Vec<u32>)>,
d_readers: &Vec<Option<Reader>>,
ind_readers: &Vec<Option<Reader>>,
gex_readers: &[Option<GexReaders<'_>>],
dref: &Vec<DonorReferenceItem>,
groups: &Vec<Vec<(i32, String)>>,
opt_d_val: &Vec<(usize, Vec<Vec<Vec<usize>>>)>,
Expand Down Expand Up @@ -175,23 +173,11 @@ pub fn tail_code(
let z2 = gex_info.h5_indptr[li][p as usize + 1] as usize;
let d: Vec<u32>;
let ind: Vec<u32>;
if ctl.gen_opt.h5_pre {
d = h5_data[li].1[z1..z2].to_vec();
ind = h5_data[li].2[z1..z2].to_vec();
} else {
d = d_readers[li]
.as_ref()
.unwrap()
.read_slice(s![z1..z2])
.unwrap()
.to_vec();
ind = ind_readers[li]
.as_ref()
.unwrap()
.read_slice(s![z1..z2])
.unwrap()
.to_vec();
}
let (d, ind) = gex_readers[li]
.as_ref()
.unwrap()
.get_range(z1..z2)
.unwrap();
for j in 0..d.len() {
if ind[j] == fid as u32 {
raw_count = d[j] as f64;
Expand Down Expand Up @@ -228,23 +214,8 @@ pub fn tail_code(
let z2 = gex_info.h5_indptr[li][p as usize + 1] as usize;
let d: Vec<u32>;
let ind: Vec<u32>;
if ctl.gen_opt.h5_pre {
d = h5_data[li].1[z1..z2].to_vec();
ind = h5_data[li].2[z1..z2].to_vec();
} else {
d = d_readers[li]
.as_ref()
.unwrap()
.read_slice(s![z1..z2])
.unwrap()
.to_vec();
ind = ind_readers[li]
.as_ref()
.unwrap()
.read_slice(s![z1..z2])
.unwrap()
.to_vec();
}
let (d, ind) =
gex_readers[li].as_ref().unwrap().get_range(z1..z2).unwrap();
for j in 0..d.len() {
if ind[j] == fid as u32 {
raw_count = d[j] as f64;
Expand Down