quickstart/quickstart.rs
1//! Minimal MCP-counter quick-start (mirrors the README).
2//!
3//! Builds a tiny in-memory expression matrix of real HUGO marker symbols and
4//! runs the human MCP-counter estimator. Run with:
5//!
6//! cargo run --example quickstart
7
8use mcpcounter_rust::{mcp_counter, ExprMatrix, FeaturesType};
9
10fn main() {
11 // 6 genes (rows) x 3 samples (cols), log2-scale expression, stored row-major.
12 // Five are MCP-counter markers; GAPDH is a non-marker housekeeping gene and
13 // is ignored, exactly as in R (markers are matched by name against the
14 // bundled signature).
15 let genes = vec![
16 "CD3D".to_string(), // T cells
17 "CD28".to_string(), // T cells
18 "CD8B".to_string(), // CD8 T cells
19 "CD19".to_string(), // B lineage
20 "CD79A".to_string(), // B lineage
21 "GAPDH".to_string(), // not a marker -> ignored
22 ];
23 let samples = vec![
24 "tumor_A".to_string(),
25 "tumor_B".to_string(),
26 "normal".to_string(),
27 ];
28 #[rustfmt::skip]
29 let data = vec![
30 // tumor_A tumor_B normal
31 8.1, 7.4, 2.0, // CD3D
32 7.6, 7.1, 1.8, // CD28
33 6.9, 6.2, 1.5, // CD8B
34 4.2, 8.3, 2.1, // CD19
35 4.0, 8.0, 1.9, // CD79A
36 11.0, 11.1, 11.0, // GAPDH (flat housekeeping)
37 ];
38
39 let expr = ExprMatrix::new(genes, samples, data);
40 let result = mcp_counter(&expr, FeaturesType::HugoSymbols);
41
42 // Each score is the mean of a population's present markers. Populations with
43 // no present markers are dropped (as in R); the rest appear in MCP-counter's
44 // signature order: T cells, CD8 T cells, B lineage.
45 print!("{:<14}", "population");
46 for s in &result.samples {
47 print!("{s:>10}");
48 }
49 println!();
50 for (p, pop) in result.populations.iter().enumerate() {
51 print!("{pop:<14}");
52 for s in 0..result.samples.len() {
53 print!("{:>10.3}", result.score(p, s));
54 }
55 println!();
56 }
57}