Skip to content

Commit 4c66f08

Browse files
authored
Merge pull request #67 from unipept/fix/ncbi-rank-updates
Prepare the Unipept API for the newest NCBI taxonomy
2 parents 5dcb3fb + ac10a1b commit 4c66f08

File tree

14 files changed

+109
-187
lines changed

14 files changed

+109
-187
lines changed

api/src/controllers/api/pept2lca.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ async fn handler(
8787
}
8888

8989
generate_handlers! (
90-
[ V1, V2 ]
90+
[ V2 ]
9191
async fn json_handler(
9292
state => State<AppState>,
9393
params => Parameters,

api/src/controllers/api/pept2taxa.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ async fn handler(
120120
}
121121

122122
generate_handlers! (
123-
[ V1, V2 ]
123+
[ V2 ]
124124
async fn json_handler(
125125
state => State<AppState>,
126126
params => Parameters,

api/src/controllers/api/peptinfo.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ async fn handler(
110110
}
111111

112112
generate_handlers! (
113-
[ V1, V2 ]
113+
[ V2 ]
114114
async fn json_handler(
115115
state => State<AppState>,
116116
params => Parameters,

api/src/controllers/api/protinfo.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ async fn handler(
105105
}
106106

107107
generate_handlers! (
108-
[ V1, V2 ]
108+
[ V2 ]
109109
async fn json_handler(
110110
state => State<AppState>,
111111
params => Parameters,

api/src/controllers/api/taxa2lca.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ async fn handler(
8080
}
8181

8282
generate_handlers! (
83-
[ V1, V2 ]
83+
[ V2 ]
8484
async fn json_handler(
8585
state => State<AppState>,
8686
params => Parameters,

api/src/controllers/api/taxa2tree.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ fn handler(
8383
}
8484

8585
generate_handlers!(
86-
[ V1, V2 ]
86+
[ V2 ]
8787
async fn json_handler(
8888
state => State<AppState>,
8989
GetContent(params) => GetContent<GetParameters>,
@@ -94,7 +94,7 @@ generate_handlers!(
9494
);
9595

9696
generate_handlers!(
97-
[ V1, V2 ]
97+
[ V2 ]
9898
async fn json_handler(
9999
state => State<AppState>,
100100
PostContent(params) => PostContent<PostParameters>,
@@ -105,7 +105,7 @@ generate_handlers!(
105105
);
106106

107107
generate_handlers!(
108-
[ V1, V2 ]
108+
[ V2 ]
109109
async fn html_handler(
110110
state => State<AppState>,
111111
GetContent(params) => GetContent<GetParameters>,
@@ -123,7 +123,7 @@ generate_handlers!(
123123
);
124124

125125
generate_handlers!(
126-
[ V1, V2 ]
126+
[ V2 ]
127127
async fn html_handler(
128128
state => State<AppState>,
129129
PostContent(params) => PostContent<PostParameters>,

api/src/controllers/api/taxonomy.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,13 @@ async fn handler(
119119
// If descendants is true, we need to get all the taxa at the requested level and
120120
// report those as children of the root.
121121
if descendants {
122-
children = Some(lineage_store.get_all_taxon_ids_at_rank("superkingdom")?
122+
children = Some(lineage_store.get_all_taxon_ids_at_rank("domain")?
123123
.iter()
124124
.flat_map(|sk_taxon| {
125125
descendants_ranks
126126
.iter()
127127
.cloned()
128-
.filter_map(|desc_rank| get_children_at_rank(*sk_taxon, LineageRank::Superkingdom, desc_rank, lineage_store))
128+
.filter_map(|desc_rank| get_children_at_rank(*sk_taxon, LineageRank::Domain, desc_rank, lineage_store))
129129
.flat_map(|set| set.into_iter())
130130
.collect::<Vec<u32>>()
131131
})
@@ -197,7 +197,7 @@ async fn handler(
197197
}
198198

199199
generate_handlers!(
200-
[ V1, V2 ]
200+
[ V2 ]
201201
async fn json_handler(
202202
state => State<AppState>,
203203
params => Parameters,

api/src/helpers/lca_helper.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ pub fn calculate_lca(
1111
lineage_store: &LineageStore
1212
) -> i32 {
1313
let cleaned_taxa = taxa.into_iter().filter(|&taxon_id| taxon_store.is_valid(taxon_id));
14-
14+
1515
let lineages: Vec<Vec<i32>> = cleaned_taxa
1616
.into_iter()
1717
.map(|taxon_id| get_lineage_array_numeric(taxon_id, version, lineage_store))
1818
.collect();
19-
19+
2020
let amount_of_ranks = get_amount_of_ranks(version);
2121
let genus_index = get_genus_index(version);
2222
let species_index = get_species_index(version);

api/src/helpers/lineage_helper/mod.rs

+8-22
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
pub mod v1;
21
pub mod v2;
32

43
use datastore::{LineageStore, TaxonStore};
@@ -60,7 +59,7 @@ macro_rules! create_lineages {
6059

6160
pub fn get_lineage_array_numeric(taxon_id: u32, lineage_store: &LineageStore) -> Vec<i32> {
6261
let lineage = lineage_store.get(taxon_id).cloned().unwrap_or_default();
63-
62+
6463
vec![
6564
$(
6665
get_id(lineage.$field).unwrap_or(0),
@@ -70,7 +69,7 @@ macro_rules! create_lineages {
7069

7170
pub fn get_lineage_with_names(taxon_id: u32, lineage_store: &LineageStore, taxon_store: &TaxonStore) -> Option<LineageWithNames> {
7271
let lineage = lineage_store.get(taxon_id)?;
73-
72+
7473
Some(LineageWithNames {
7574
$(
7675
[<$field _id>]: get_id(lineage.$field),
@@ -96,83 +95,70 @@ pub(crate) use create_lineages;
9695

9796
#[derive(Clone, Copy)]
9897
pub enum LineageVersion {
99-
V1,
10098
V2
10199
}
102100

103101
#[derive(Serialize, Debug)]
104102
#[serde(untagged)]
103+
#[allow(clippy::large_enum_variant)]
105104
pub enum Lineage {
106-
DefaultV1(v1::Lineage),
107-
NamesV1(v1::LineageWithNames),
108105
DefaultV2(v2::Lineage),
109106
NamesV2(v2::LineageWithNames)
110107
}
111108

112109
pub fn get_lineage(taxon_id: u32, version: LineageVersion, lineage_store: &LineageStore) -> Option<Lineage> {
113110
match version {
114-
LineageVersion::V1 => v1::get_lineage(taxon_id, lineage_store).map(Lineage::DefaultV1),
115111
LineageVersion::V2 => v2::get_lineage(taxon_id, lineage_store).map(Lineage::DefaultV2)
116112
}
117113
}
118114

119115
pub fn get_empty_lineage(version: LineageVersion) -> Option<Lineage> {
120116
match version {
121-
LineageVersion::V1 => v1::get_empty_lineage().map(Lineage::DefaultV1),
122117
LineageVersion::V2 => v2::get_empty_lineage().map(Lineage::DefaultV2)
123118
}
124119
}
125120

126121
pub fn get_lineage_array(taxon_id: u32, version: LineageVersion, lineage_store: &LineageStore) -> Vec<Option<i32>> {
127122
match version {
128-
LineageVersion::V1 => v1::get_lineage_array(taxon_id, lineage_store),
129123
LineageVersion::V2 => v2::get_lineage_array(taxon_id, lineage_store)
130124
}
131125
}
132126

133127
pub fn get_lineage_array_numeric(taxon_id: u32, version: LineageVersion, lineage_store: &LineageStore) -> Vec<i32> {
134128
match version {
135-
LineageVersion::V1 => v1::get_lineage_array_numeric(taxon_id, lineage_store),
136129
LineageVersion::V2 => v2::get_lineage_array_numeric(taxon_id, lineage_store)
137130
}
138131
}
139132

140133
pub fn get_lineage_with_names(
141134
taxon_id: u32,
142-
version: LineageVersion,
135+
_version: LineageVersion,
143136
lineage_store: &LineageStore,
144137
taxon_store: &TaxonStore
145138
) -> Option<Lineage> {
146-
match version {
147-
LineageVersion::V1 => v1::get_lineage_with_names(taxon_id, lineage_store, taxon_store).map(Lineage::NamesV1),
148-
LineageVersion::V2 => v2::get_lineage_with_names(taxon_id, lineage_store, taxon_store).map(Lineage::NamesV2)
149-
}
139+
v2::get_lineage_with_names(taxon_id, lineage_store, taxon_store).map(Lineage::NamesV2)
150140
}
151141

152142
pub fn get_empty_lineage_with_names(version: LineageVersion) -> Option<Lineage> {
153143
match version {
154-
LineageVersion::V1 => v1::get_empty_lineage_with_names().map(Lineage::NamesV1),
155144
LineageVersion::V2 => v2::get_empty_lineage_with_names().map(Lineage::NamesV2)
156145
}
157146
}
158147

159148
pub fn get_amount_of_ranks(version: LineageVersion) -> u8 {
160149
match version {
161-
LineageVersion::V1 => 28,
162-
LineageVersion::V2 => 27
150+
LineageVersion::V2 => 28
163151
}
164152
}
165153

166154
pub fn get_genus_index(version: LineageVersion) -> u8 {
167155
match version {
168-
LineageVersion::V1 => 20,
169-
LineageVersion::V2 => 18
156+
LineageVersion::V2 => 19
170157
}
171158
}
172159

173160
pub fn get_species_index(version: LineageVersion) -> u8 {
174161
match version {
175-
LineageVersion::V1 => 24,
176-
LineageVersion::V2 => 22
162+
LineageVersion::V2 => 23
177163
}
178164
}

api/src/helpers/lineage_helper/v1.rs

-36
This file was deleted.

api/src/helpers/lineage_helper/v2.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ use serde::Serialize;
55
use super::create_lineages;
66

77
create_lineages!(
8-
superkingdom,
8+
domain,
9+
realm,
910
kingdom,
1011
subkingdom,
1112
superphylum,

api/src/routes.rs

+1-31
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub fn create_router(state: AppState) -> Router {
4444
}
4545

4646
fn create_api_routes() -> Router<AppState> {
47-
Router::new().nest("/v1", create_api_v1_routes()).nest("/v2", create_api_v2_routes())
47+
Router::new().nest("/v1", create_api_v2_routes()).nest("/v2", create_api_v2_routes())
4848
}
4949

5050
macro_rules! define_routes {
@@ -65,36 +65,6 @@ macro_rules! define_routes {
6565

6666
pub(crate) use define_routes;
6767

68-
fn create_api_v1_routes() -> Router<AppState> {
69-
define_routes!(
70-
"/pept2ec",
71-
get(pept2ec::get_json_handler).post(pept2ec::post_json_handler),
72-
"/pept2funct",
73-
get(pept2funct::get_json_handler).post(pept2funct::post_json_handler),
74-
"/pept2go",
75-
get(pept2go::get_json_handler).post(pept2go::post_json_handler),
76-
"/pept2interpro",
77-
get(pept2interpro::get_json_handler).post(pept2interpro::post_json_handler),
78-
"/pept2lca",
79-
get(pept2lca::get_json_handler_v1).post(pept2lca::post_json_handler_v1),
80-
"/pept2prot",
81-
get(pept2prot::get_json_handler).post(pept2prot::post_json_handler),
82-
"/pept2taxa",
83-
get(pept2taxa::get_json_handler_v1).post(pept2taxa::post_json_handler_v1),
84-
"/peptinfo",
85-
get(peptinfo::get_json_handler_v1).post(peptinfo::post_json_handler_v1),
86-
"/protinfo",
87-
get(protinfo::get_json_handler_v1).post(protinfo::post_json_handler_v1),
88-
"/taxa2lca",
89-
get(taxa2lca::get_json_handler_v1).post(taxa2lca::post_json_handler_v1),
90-
"/taxa2tree",
91-
get(taxa2tree::get_json_handler_v1).post(taxa2tree::post_json_handler_v1),
92-
"/taxonomy",
93-
get(taxonomy::get_json_handler_v1).post(taxonomy::post_json_handler_v1)
94-
)
95-
.route("/taxa2tree.html", get(taxa2tree::get_html_handler_v1).post(taxa2tree::post_html_handler_v1))
96-
}
97-
9868
fn create_api_v2_routes() -> Router<AppState> {
9969
define_routes!(
10070
"/pept2ec",

0 commit comments

Comments
 (0)