Skip to content

Commit

Permalink
Introduce a type alias for Stats. Return them from row_fill.
Browse files Browse the repository at this point in the history
  • Loading branch information
macklin-10x committed Mar 30, 2024
1 parent f8af31a commit 59da289
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 28 deletions.
3 changes: 2 additions & 1 deletion enclone_print/src/finish_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::build_table_stuff::build_table_stuff;
use crate::print_utils1::make_table;
use crate::print_utils3::{add_header_text, insert_reference_rows};
use crate::print_utils5::{build_diff_row, insert_consensus_row};
use crate::Stat;
use enclone_core::defs::{justification, ColInfo, EncloneControl, ExactClonotype};
use enclone_proto::types::DonorReferenceItem;
use std::collections::HashMap;
Expand Down Expand Up @@ -33,7 +34,7 @@ pub fn finish_table(
dref: &[DonorReferenceItem],
peer_groups: &[Vec<(usize, u8, u32)>],
mlog: &mut Vec<u8>,
stats: &[(String, Vec<String>)],
stats: &[Stat],
sr: Vec<Sr>,
extra_args: &[String],
pcols_sort: &[String],
Expand Down
6 changes: 4 additions & 2 deletions enclone_print/src/gene_scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

use enclone_core::{defs::GeneScanOpts, linear_condition::LinearCondition};

use crate::Stat;

pub struct InSet {
pub test: bool,
pub control: bool,
Expand All @@ -10,8 +12,8 @@ pub struct InSet {
pub fn gene_scan_test(
opts: &GeneScanOpts,
exact: bool,
stats: &[(String, Vec<String>)],
stats_orig: &[(String, Vec<String>)],
stats: &[Stat],
stats_orig: &[Stat],
nexacts: usize,
n: usize,
) -> Vec<InSet> {
Expand Down
2 changes: 2 additions & 0 deletions enclone_print/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ pub mod print_utils5;
pub mod proc_cvar_auto;
pub mod proc_lvar2;
pub mod proc_lvar_auto;

pub type Stat = (String, Vec<String>);
19 changes: 8 additions & 11 deletions enclone_print/src/print_clonotypes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use crate::print_utils3::{
};
use crate::print_utils4::{build_show_aa, compute_bu, compute_some_stats, SomeStats};
use crate::print_utils5::{delete_weaks, vars_and_shares};
use crate::Stat;
use enclone_args::proc_args_check::involves_gex_fb;
use enclone_core::allowed_vars::{CVARS_ALLOWED, CVARS_ALLOWED_PCELL, LVARS_ALLOWED};
use enclone_core::defs::{CloneInfo, ColInfo};
Expand Down Expand Up @@ -247,7 +248,7 @@ pub fn print_clonotypes(
// There are two passes. On the first pass we only identify the exact subclonotypes that
// are junk. On the second pass we remove those and then print the orbit.

let mut stats_pass1 = Vec::<Vec<(String, Vec<String>)>>::new();
let mut stats_pass1 = Vec::<Vec<Stat>>::new();
let mut bads = vec![false; exacts.len()];
for _ in [0] {
// pass 1
Expand Down Expand Up @@ -502,7 +503,7 @@ pub fn print_clonotypes(

// Set up to record stats that assign a value to each cell for a given variable.

let mut stats = Vec::<(String, Vec<String>)>::new();
let mut stats = Vec::<Stat>::new();

// Precompute for near and far.

Expand Down Expand Up @@ -533,13 +534,12 @@ pub fn print_clonotypes(
}
let clonotype_id = exacts[u];
let ex = &exact_clonotypes[clonotype_id];
let mut these_stats = Vec::<(String, Vec<String>)>::new();

if ctl.clono_filt_opt_def.whitef && !has_whitelist_contamination(ex) {
bads[u] = true;
}

row_fill(
let (_, mut these_stats) = row_fill(
1,
u,
ctl,
Expand Down Expand Up @@ -574,7 +574,6 @@ pub fn print_clonotypes(
&mut row,
&mut res.out_data,
&mut cx,
&mut these_stats,
)?;
stats.append(&mut these_stats.clone());

Expand Down Expand Up @@ -603,7 +602,7 @@ pub fn print_clonotypes(

stats.sort_by(|a, b| a.0.cmp(&b.0));
stats = {
let mut stats2 = Vec::<(String, Vec<String>)>::new();
let mut stats2 = Vec::<Stat>::new();
let mut i = 0;
while i < stats.len() {
let mut j = i + 1;
Expand Down Expand Up @@ -989,7 +988,7 @@ pub fn print_clonotypes(

// Set up to record stats that assign a value to each cell for a given variable.

let mut stats = Vec::<(String, Vec<String>)>::new();
let mut stats = Vec::<Stat>::new();

// Compute some stats;

Expand Down Expand Up @@ -1033,8 +1032,7 @@ pub fn print_clonotypes(
}
let clonotype_id = exacts[u];
let ex = &exact_clonotypes[clonotype_id];
let mut these_stats = Vec::<(String, Vec<String>)>::new();
let RowFillGexData { d_all, ind_all } = row_fill(
let (RowFillGexData { d_all, ind_all }, mut these_stats) = row_fill(
2,
u,
ctl,
Expand Down Expand Up @@ -1069,7 +1067,6 @@ pub fn print_clonotypes(
&mut row,
&mut res.out_data,
&mut cx,
&mut these_stats,
)?;
stats.append(&mut these_stats.clone());

Expand Down Expand Up @@ -1137,7 +1134,7 @@ pub fn print_clonotypes(

stats.sort_by(|a, b| a.0.cmp(&b.0));
let stats_orig = stats.clone();
let mut stats2 = Vec::<(String, Vec<String>)>::new();
let mut stats2 = Vec::<Stat>::new();
let mut i = 0;
while i < stats.len() {
let mut j = i + 1;
Expand Down
18 changes: 11 additions & 7 deletions enclone_print/src/print_utils2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crate::proc_lvar2::{proc_lvar2_outs, proc_lvar2_stats};
use crate::proc_lvar_auto::{
proc_lvar_auto_read_only, proc_lvar_auto_res_outs, proc_lvar_auto_res_stats,
};
use crate::Stat;
use amino::{codon_to_aa, nucleotide_to_aminoacid_sequence};
use enclone_core::allowed_vars::LVARS_ALLOWED;
use enclone_core::defs::{AlleleData, ColInfo, EncloneControl, ExactClonotype, GexInfo, POUT_SEP};
Expand Down Expand Up @@ -67,7 +68,7 @@ pub fn row_fill(
dref: &[DonorReferenceItem],
groups: &HashMap<usize, Vec<usize>>,
gex_readers: &[Option<GexReaders<'_>>],
stats_pass1: &[Vec<(String, Vec<String>)>],
stats_pass1: &[Vec<Stat>],
vdj_cells: &[Vec<String>],
n_vdj_gex: &[usize],
lvars: &[String],
Expand All @@ -83,8 +84,7 @@ pub fn row_fill(
row: &mut Vec<String>, // row of human-readable output; only written in pass #2
out_data: &mut [HashMap<String, String>], // row of parseable output
cx: &mut [Vec<String>],
stats: &mut Vec<(String, Vec<String>)>,
) -> Result<RowFillGexData, String> {
) -> Result<(RowFillGexData, Vec<Stat>), String> {
// Redefine some things to reduce dependencies.

let mat = &rsi.mat;
Expand Down Expand Up @@ -221,6 +221,8 @@ pub fn row_fill(
};
}

let mut stats = Vec::<Stat>::new();

'lvar_loop: for (i, &x) in all_lvars.iter().enumerate() {
// Process VAR_DEF variables.
if pass == 2 {
Expand Down Expand Up @@ -329,12 +331,14 @@ pub fn row_fill(
gex_readers,
&alt_bcs,
) {
proc_lvar_auto_res_stats(x, ex, &res, stats);
proc_lvar_auto_res_stats(x, ex, &res, &mut stats);
if pass == 2 {
proc_lvar_auto_res_outs(i, x, u, ctl, extra_args, lvars, &res, row, out_data);
}
} else {
proc_lvar2_stats(i, x, ctl, ex, gex_info, &gex_data, lvars, gex_mean, stats);
proc_lvar2_stats(
i, x, ctl, ex, gex_info, &gex_data, lvars, gex_mean, &mut stats,
);
if pass == 2 {
proc_lvar2_outs(
i,
Expand Down Expand Up @@ -567,7 +571,7 @@ pub fn row_fill(
varmat,
allele_data,
)? {
proc_cvar_auto_res_stats(pass, ex, col, ctl, extra_args, &res, stats);
proc_cvar_auto_res_stats(pass, ex, col, ctl, extra_args, &res, &mut stats);
if pass == 2 {
proc_cvar_auto_res_outs(
jj,
Expand Down Expand Up @@ -625,7 +629,7 @@ pub fn row_fill(
}
}
}
Ok(gex_data)
Ok((gex_data, stats))
}

struct RowFillGexInfo {
Expand Down
4 changes: 2 additions & 2 deletions enclone_print/src/print_utils4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use string_utils::TextUtils;
use vdj_ann::refx::RefData;
use vector_utils::{bin_member, bin_position, bin_position1_2, unique_sort};

use crate::finish_table::Sr;
use crate::{finish_table::Sr, Stat};

// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓

Expand Down Expand Up @@ -516,7 +516,7 @@ pub fn compute_bu(
d_all: &[Vec<u32>],
ind_all: &[Vec<u32>],
mat: &[Vec<Option<usize>>],
these_stats: &[(String, Vec<String>)],
these_stats: &[Stat],
refdata: &RefData,
) {
// Very bad computation because of embedded binary search.
Expand Down
3 changes: 2 additions & 1 deletion enclone_print/src/proc_cvar_auto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::print_utils1::{
};
use crate::print_utils3::comp_edit;
use crate::proc_lvar_auto::ProcVarAutoResult;
use crate::Stat;
use amino::{codon_to_aa, nucleotide_to_aminoacid_sequence};
use enclone_core::align_to_vdj_ref::{align_to_vdj_ref, cigar};
use enclone_core::defs::{AlleleData, ColInfo, EncloneControl, ExactClonotype, POUT_SEP};
Expand Down Expand Up @@ -1543,7 +1544,7 @@ pub fn proc_cvar_auto_res_stats(
ctl: &EncloneControl,
extra_args: &[String],
res: &ProcVarAutoResult,
stats: &mut Vec<(String, Vec<String>)>,
stats: &mut Vec<Stat>,
) {
let ProcVarAutoResult {
abbr,
Expand Down
3 changes: 2 additions & 1 deletion enclone_print/src/proc_lvar2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

use crate::print_utils2::RowFillGexData;
use crate::print_utils4::get_gex_matrix_entry;
use crate::Stat;
use enclone_core::defs::{EncloneControl, ExactClonotype, GexInfo, POUT_SEP};
use enclone_core::median::rounded_median;
use itertools::Itertools;
Expand Down Expand Up @@ -133,7 +134,7 @@ pub fn proc_lvar2_stats(
gex_data: &RowFillGexData,
lvars: &[String],
gex_mean: f64,
stats: &mut Vec<(String, Vec<String>)>,
stats: &mut Vec<Stat>,
) {
// Proceed.

Expand Down
4 changes: 3 additions & 1 deletion enclone_print/src/proc_lvar_auto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ use string_utils::{abbrev_list, strme, TextUtils};
use vdj_ann::refx::RefData;
use vector_utils::{bin_member, bin_position, unique_sort};

use crate::Stat;

pub struct ProcVarAutoResult {
pub abbr: String,
pub exact: String,
Expand Down Expand Up @@ -1433,7 +1435,7 @@ pub fn proc_lvar_auto_res_stats(
var: &str,
ex: &ExactClonotype,
res: &ProcVarAutoResult,
stats: &mut Vec<(String, Vec<String>)>,
stats: &mut Vec<Stat>,
) {
let ProcVarAutoResult {
abbr,
Expand Down
4 changes: 2 additions & 2 deletions enclone_vars/src/export_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ pub fn export_code(level: usize) -> Vec<(String, String)> {
cx: &mut Vec<Vec<String>>,
varmat: &Vec<Vec<Vec<u8>>>,
out_data: &mut Vec<HashMap<String, String>>,
stats: &mut Vec<(String, Vec<String>)>,
stats: &mut Vec<Stat>,
allele_data: &AlleleData,
) -> Result<bool, String> {
Expand Down Expand Up @@ -709,7 +709,7 @@ pub fn export_code(level: usize) -> Vec<(String, String)> {
ctl: &EncloneControl,
extra_args: &Vec<String>,
out_data: &mut Vec<HashMap<String, String>>,
stats: &mut Vec<(String, Vec<String>)>,
stats: &mut Vec<Stat>,
lvars: &Vec<String>,
row: &mut Vec<String>,
fate: &Vec<HashMap<String, String>>,
Expand Down

0 comments on commit 59da289

Please sign in to comment.