MCPcopy Index your code
hub / github.com/SingleRust/SingleRust / run_differential_expression

Function run_differential_expression

src/memory/processing/diffexp/mod.rs:445–509  ·  view source on GitHub ↗
(
    adata: &IMAnnData,
    csr_matrix: &CsrMatrix<T>,
    groups_to_test: &[String],
    reference_group: &Option<String>,
    groupby: &str,
    method: TestMethod,
    correction_method: Correctio

Source from the content-addressed store, hash-verified

443
444#[allow(clippy::too_many_arguments)]
445fn run_differential_expression<T>(
446 adata: &IMAnnData,
447 csr_matrix: &CsrMatrix<T>,
448 groups_to_test: &[String],
449 reference_group: &Option<String>,
450 groupby: &str,
451 method: TestMethod,
452 correction_method: CorrectionMethod,
453 compute_lfc: bool,
454 pseudocount: f64,
455 n_genes: usize,
456 var_names: &[String],
457) -> anyhow::Result<DifferentialExpressionResults>
458where
459 T: FloatOpsTS,
460 CsrMatrix<T>: MatrixStatTests<T>,
461{
462 let mut scores_map: HashMap<String, Vec<f64>> = HashMap::new();
463 let mut pvals_map: HashMap<String, Vec<f64>> = HashMap::new();
464 let mut pvals_adj_map: HashMap<String, Vec<f64>> = HashMap::new();
465 let mut logfoldchanges_map: HashMap<String, Vec<f64>> = HashMap::new();
466 let mut gene_names_map: HashMap<String, Vec<String>> = HashMap::new();
467
468 for group in groups_to_test {
469 let group_indices = get_group_indices(adata, groupby, group)?;
470 let reference_indices = match reference_group {
471 None => {
472 let mut all_indices: Vec<usize> = (0..adata.n_obs()).collect();
473 all_indices.retain(|&idx| !group_indices.contains(&idx));
474
475 if all_indices.is_empty() {
476 return Err(anyhow::anyhow!("No cells found in reference group: rest"));
477 }
478 all_indices
479 }
480 Some(reference_group) => get_group_indices(adata, groupby, reference_group)?,
481 };
482
483 let group_results = run_tests_for_group(
484 csr_matrix,
485 &group_indices,
486 &reference_indices,
487 method,
488 correction_method.clone(),
489 compute_lfc,
490 pseudocount,
491 n_genes,
492 var_names,
493 )?;
494
495 scores_map.insert(group.clone(), group_results.scores);
496 pvals_map.insert(group.clone(), group_results.pvals);
497 pvals_adj_map.insert(group.clone(), group_results.pvals_adj);
498 logfoldchanges_map.insert(group.clone(), group_results.logfoldchanges);
499 gene_names_map.insert(group.clone(), group_results.gene_names);
500 }
501
502 Ok(DifferentialExpressionResults {

Callers 1

compute_rank_gene_groupsFunction · 0.85

Calls 3

get_group_indicesFunction · 0.85
run_tests_for_groupFunction · 0.85
cloneMethod · 0.80

Tested by

no test coverage detected