@@ -8,10 +8,13 @@ pub fn calculate_lca(
88 taxa : Vec < u32 > ,
99 version : LineageVersion ,
1010 taxon_store : & TaxonStore ,
11- lineage_store : & LineageStore
11+ lineage_store : & LineageStore ,
12+ only_valid_taxa : bool
1213) -> i32 {
13- let cleaned_taxa = taxa. into_iter ( ) . filter ( |& taxon_id| taxon_store. is_valid ( taxon_id) ) ;
14-
14+ let cleaned_taxa = taxa
15+ . into_iter ( )
16+ . filter ( |& taxon_id| !only_valid_taxa || taxon_store. is_valid ( taxon_id) ) ;
17+
1518 let lineages: Vec < Vec < i32 > > = cleaned_taxa
1619 . into_iter ( )
1720 . map ( |taxon_id| get_lineage_array_numeric ( taxon_id, version, lineage_store) )
@@ -69,7 +72,7 @@ mod tests {
6972 let lineage_store: LineageStore = LineageStore :: try_from_file ( "../data/lineages_subset_10000.tsv" ) . expect ( "Reading the file failed" ) ;
7073
7174 assert_eq ! ( calculate_lca(
72- taxa, version, & taxon_store, & lineage_store) , 8287 ) ;
75+ taxa, version, & taxon_store, & lineage_store, true ) , 8287 ) ;
7376 }
7477
7578
@@ -81,6 +84,16 @@ mod tests {
8184 let lineage_store: LineageStore = LineageStore :: try_from_file ( "../data/lineages_subset_10000.tsv" ) . expect ( "Reading the file failed" ) ;
8285
8386 assert_eq ! ( calculate_lca(
84- taxa, version, & taxon_store, & lineage_store) , 1 ) ;
87+ taxa, version, & taxon_store, & lineage_store, true ) , 1 ) ;
88+ }
89+
90+ #[ test]
91+ fn test_calculate_lca_validate ( ) {
92+ let version: LineageVersion = LineageVersion :: V2 ;
93+ let taxon_store: TaxonStore = TaxonStore :: try_from_file ( "../data/taxons_subset_10000.tsv" ) . expect ( "Reading the file failed" ) ;
94+ let lineage_store: LineageStore = LineageStore :: try_from_file ( "../data/lineages_subset_10000.tsv" ) . expect ( "Reading the file failed" ) ;
95+
96+ assert_eq ! ( calculate_lca( vec![ 27 ] , version, & taxon_store, & lineage_store, true ) , 1 ) ;
97+ assert_eq ! ( calculate_lca( vec![ 27 ] , version, & taxon_store, & lineage_store, false ) , 27 ) ;
8598 }
8699}
0 commit comments