1pub mod annotations;
5pub mod audit;
6pub mod baselines;
7pub mod compare;
8pub mod fdr;
9pub mod graph;
10pub mod hodge;
11pub mod manifest;
12pub mod matrix;
13pub mod output;
14pub mod parser;
15pub mod permutation;
16pub mod ranking;
17pub mod report;
18pub mod shared;
19pub mod statistics;
20pub mod visualize;
21
22use std::collections::BTreeMap;
23
24use graph::SpliceGraph;
25use hodge::{Decomposition, decompose};
26use parser::Junction;
27
28#[derive(Debug)]
30pub struct GroupResult {
31 pub sample_id: String,
32 pub gene_id: String,
33 pub graph: SpliceGraph,
34 pub decomposition: Decomposition,
35}
36
37pub fn analyze_junctions(junctions: Vec<Junction>) -> Result<Vec<GroupResult>, String> {
41 let mut groups: BTreeMap<(String, String), Vec<Junction>> = BTreeMap::new();
42
43 for junction in junctions {
44 groups
45 .entry((junction.sample_id.clone(), junction.gene_id.clone()))
46 .or_default()
47 .push(junction);
48 }
49
50 let mut results = Vec::with_capacity(groups.len());
51 for ((sample_id, gene_id), rows) in groups {
52 let graph = SpliceGraph::from_junctions(&rows).map_err(|error| {
53 format!("could not build graph for sample '{sample_id}', gene '{gene_id}': {error}")
54 })?;
55 let decomposition = decompose(&graph).map_err(|error| {
56 format!(
57 "Hodge decomposition failed for sample '{sample_id}', gene '{gene_id}': {error}; inspect this sample/gene graph and its junction counts"
58 )
59 })?;
60 results.push(GroupResult {
61 sample_id,
62 gene_id,
63 graph,
64 decomposition,
65 });
66 }
67
68 Ok(results)
69}