Skip to content

Commit 2e40067

Browse files
committed
clippy
1 parent 3dba71f commit 2e40067

File tree

12 files changed

+75
-75
lines changed

12 files changed

+75
-75
lines changed

.clippy.toml

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
avoid-breaking-exported-api = false
2+
enum-variant-name-threshold = 10

api/src/controllers/api/pept2prot.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ generate_json_handlers!(
7171

7272
let taxon_store = datastore.taxon_store();
7373

74-
result.into_iter().map(|item| {
74+
result.into_iter().flat_map(|item| {
7575
item.uniprot_accession_numbers.into_iter().map(|accession| {
7676
let uniprot_entry = accessions_map.get(&accession).unwrap();
7777

@@ -104,6 +104,6 @@ generate_json_handlers!(
104104
}
105105
}
106106
}).collect::<Vec<ProtInformation>>()
107-
}).flatten().collect()
107+
}).collect()
108108
}
109109
);

api/src/controllers/api/pept2taxa.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ generate_json_handlers!(
6969
let taxon_store = datastore.taxon_store();
7070
let lineage_store = datastore.lineage_store();
7171

72-
result.into_iter().map(|item| {
72+
result.into_iter().flat_map(|item| {
7373
item.taxa.into_iter().collect::<HashSet<usize>>().into_iter().filter_map(move |taxon| {
7474
let (name, rank) = taxon_store.get(taxon as u32)?;
7575
let lineage = match (extra, names) {
@@ -88,6 +88,6 @@ generate_json_handlers!(
8888
lineage
8989
})
9090
})
91-
}).flatten().collect()
91+
}).collect()
9292
}
9393
);

api/src/controllers/api/taxonomy.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ generate_json_handlers!(
7777

7878
Some(TaxaInformation {
7979
taxon: Taxon {
80-
taxon_id: taxon_id,
80+
taxon_id,
8181
taxon_name: name.to_string(),
8282
taxon_rank: rank.clone().into()
8383
},

api/src/controllers/private_api/proteins.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ generate_json_handlers!(
8686

8787
let common_lineage = get_lineage_array(lca as u32, LineageVersion::V2, lineage_store)
8888
.iter()
89-
.filter(|&taxon_id| taxon_id.is_some())
90-
.map(|taxon_id| taxon_id.unwrap())
89+
.filter_map(|taxon_id| *taxon_id)
9190
.collect::<Vec<i32>>();
9291

9392
ProteinInformation {

api/src/errors.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use thiserror::Error;
22

33
#[derive(Error, Debug)]
4+
#[allow(clippy::enum_variant_names)]
45
pub enum AppError {
56
#[error("{0}")]
67
IoError(#[from] std::io::Error),

api/src/helpers/ec_helper.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub fn ec_numbers_from_map(
3333
.collect()
3434
}
3535

36-
pub fn ec_numbers_from_list(fa_data: &Vec<&str>, ec_store: &EcStore, extra: bool) -> Vec<EcNumber> {
36+
pub fn ec_numbers_from_list(fa_data: &[&str], ec_store: &EcStore, extra: bool) -> Vec<EcNumber> {
3737
fa_data
3838
.iter()
3939
.filter(|key| key.starts_with("EC:"))

api/src/helpers/go_helper.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub fn go_terms_from_map(
3535
domains: bool
3636
) -> GoTerms {
3737
let go_terms = fa_data
38-
.into_iter()
38+
.iter()
3939
.filter(|(key, _)| key.starts_with("GO:"));
4040

4141
if domains {
@@ -50,7 +50,7 @@ pub fn go_terms_from_map(
5050
}
5151

5252
pub fn go_terms_from_list(
53-
fa_data: &Vec<&str>,
53+
fa_data: &[&str],
5454
go_store: &GoStore,
5555
extra: bool,
5656
domains: bool

api/src/helpers/interpro_helper.rs

+12-14
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub fn interpro_entries_from_map(
7171
}
7272

7373
pub fn interpro_entries_from_list(
74-
fa_data: &Vec<&str>,
74+
fa_data: &[&str],
7575
interpro_store: &InterproStore,
7676
extra: bool,
7777
domains: bool
@@ -150,19 +150,17 @@ fn interpro_entry(
150150
domain: domain.to_string()
151151
})
152152
}
153+
} else if extra {
154+
Some(InterproEntry::Extra {
155+
code: trimmed_key.to_string(),
156+
protein_count: count,
157+
name: name.to_string(),
158+
domain: domain.to_string()
159+
})
153160
} else {
154-
if extra {
155-
Some(InterproEntry::Extra {
156-
code: trimmed_key.to_string(),
157-
protein_count: count,
158-
name: name.to_string(),
159-
domain: domain.to_string()
160-
})
161-
} else {
162-
Some(InterproEntry::Default {
163-
code: trimmed_key.to_string(),
164-
protein_count: count
165-
})
166-
}
161+
Some(InterproEntry::Default {
162+
code: trimmed_key.to_string(),
163+
protein_count: count
164+
})
167165
}
168166
}

api/src/helpers/tree_helper/mod.rs

+15-20
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use frequency::FrequencyTable;
66
use node::Node;
77

88
use super::lineage_helper::{
9-
get_amount_of_ranks,
109
get_lineage_array,
1110
LineageVersion
1211
};
@@ -20,32 +19,28 @@ pub fn build_tree(
2019
lineage_store: &LineageStore,
2120
taxon_store: &TaxonStore
2221
) -> Node {
23-
let amount_of_ranks = get_amount_of_ranks(version) as usize;
24-
2522
let mut root: Node = Node::new(1, "Organism".to_string(), "no rank".to_string());
2623
for taxon_id in frequencies.keys() {
2724
let mut current_node = &mut root;
2825

2926
let lineage = get_lineage_array(*taxon_id, version, lineage_store);
3027

31-
for rank in 0 .. amount_of_ranks {
32-
if let Some(lineage_id) = lineage[rank] {
33-
if lineage_id < 0 {
34-
continue;
35-
}
36-
37-
let child = current_node.get_child(lineage_id as usize);
38-
if child.is_none() {
39-
let (name, rank) = taxon_store.get(lineage_id as u32).unwrap();
40-
current_node.add_child(Node::new(
41-
lineage_id as usize,
42-
name.clone(),
43-
rank.clone().into()
44-
));
45-
}
46-
47-
current_node = current_node.get_child(lineage_id as usize).unwrap();
28+
for lineage_id in lineage.into_iter().flatten() {
29+
if lineage_id < 0 {
30+
continue;
31+
}
32+
33+
let child = current_node.get_child(lineage_id as usize);
34+
if child.is_none() {
35+
let (name, rank) = taxon_store.get(lineage_id as u32).unwrap();
36+
current_node.add_child(Node::new(
37+
lineage_id as usize,
38+
name.clone(),
39+
rank.clone().into()
40+
));
4841
}
42+
43+
current_node = current_node.get_child(lineage_id as usize).unwrap();
4944
}
5045

5146
current_node.data.self_count += frequencies.get(taxon_id).unwrap_or(&0);

api/src/helpers/tree_helper/node.rs

+6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ pub struct Node {
1515
pub children: Vec<Node>
1616
}
1717

18+
impl Default for NodeData {
19+
fn default() -> Self {
20+
Self::new()
21+
}
22+
}
23+
1824
impl NodeData {
1925
pub fn new() -> NodeData {
2026
NodeData {

datastore/src/taxon_store.rs

+31-31
Original file line numberDiff line numberDiff line change
@@ -112,37 +112,37 @@ impl FromStr for LineageRank {
112112
}
113113
}
114114

115-
impl Into<String> for LineageRank {
116-
fn into(self) -> String {
117-
match self {
118-
Self::NoRank => "no rank".to_string(),
119-
Self::Superkindom => "superkingdom".to_string(),
120-
Self::Kingdom => "kingdom".to_string(),
121-
Self::Subkingdom => "subkingdom".to_string(),
122-
Self::Superphylum => "superphylum".to_string(),
123-
Self::Phylum => "phylum".to_string(),
124-
Self::Subphylum => "subphylum".to_string(),
125-
Self::Superclass => "superclass".to_string(),
126-
Self::Class => "class".to_string(),
127-
Self::Subclass => "subclass".to_string(),
128-
Self::Superorder => "superorder".to_string(),
129-
Self::Order => "order".to_string(),
130-
Self::Suborder => "suborder".to_string(),
131-
Self::Infraorder => "infraorder".to_string(),
132-
Self::Superfamily => "superfamily".to_string(),
133-
Self::Family => "family".to_string(),
134-
Self::Subfamily => "subfamily".to_string(),
135-
Self::Tribe => "tribe".to_string(),
136-
Self::Subtribe => "subtribe".to_string(),
137-
Self::Genus => "genus".to_string(),
138-
Self::Subgenus => "subgenus".to_string(),
139-
Self::SpeciesGroup => "species group".to_string(),
140-
Self::SpeciesSubgroup => "species subgroup".to_string(),
141-
Self::Species => "species".to_string(),
142-
Self::Subspecies => "subspecies".to_string(),
143-
Self::Strain => "strain".to_string(),
144-
Self::Varietas => "varietas".to_string(),
145-
Self::Forma => "forma".to_string()
115+
impl From<LineageRank> for String {
116+
fn from(val: LineageRank) -> Self {
117+
match val {
118+
LineageRank::NoRank => "no rank".to_string(),
119+
LineageRank::Superkindom => "superkingdom".to_string(),
120+
LineageRank::Kingdom => "kingdom".to_string(),
121+
LineageRank::Subkingdom => "subkingdom".to_string(),
122+
LineageRank::Superphylum => "superphylum".to_string(),
123+
LineageRank::Phylum => "phylum".to_string(),
124+
LineageRank::Subphylum => "subphylum".to_string(),
125+
LineageRank::Superclass => "superclass".to_string(),
126+
LineageRank::Class => "class".to_string(),
127+
LineageRank::Subclass => "subclass".to_string(),
128+
LineageRank::Superorder => "superorder".to_string(),
129+
LineageRank::Order => "order".to_string(),
130+
LineageRank::Suborder => "suborder".to_string(),
131+
LineageRank::Infraorder => "infraorder".to_string(),
132+
LineageRank::Superfamily => "superfamily".to_string(),
133+
LineageRank::Family => "family".to_string(),
134+
LineageRank::Subfamily => "subfamily".to_string(),
135+
LineageRank::Tribe => "tribe".to_string(),
136+
LineageRank::Subtribe => "subtribe".to_string(),
137+
LineageRank::Genus => "genus".to_string(),
138+
LineageRank::Subgenus => "subgenus".to_string(),
139+
LineageRank::SpeciesGroup => "species group".to_string(),
140+
LineageRank::SpeciesSubgroup => "species subgroup".to_string(),
141+
LineageRank::Species => "species".to_string(),
142+
LineageRank::Subspecies => "subspecies".to_string(),
143+
LineageRank::Strain => "strain".to_string(),
144+
LineageRank::Varietas => "varietas".to_string(),
145+
LineageRank::Forma => "forma".to_string()
146146
}
147147
}
148148
}

0 commit comments

Comments
 (0)