Skip to content

Commit 1563a5e

Browse files
committed
cleanup
1 parent a12cb8b commit 1563a5e

21 files changed

+82
-104
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ga4ghphetools"
3-
version = "0.5.21"
3+
version = "0.5.22"
44
edition = "2021"
55
keywords = ["GA4GH", "Phenopacket Schema", "Human Phenotype Ontology"]
66
description = "Generate GA4GH phenopackets from tabular data"

src/etl/etl_tools.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ impl EtlTools {
572572
pub fn get_cohort_data(&mut self) -> Result<CohortData, String> {
573573
self.check_is_completely_transformed()?;
574574
self.qc()?;
575-
let hpo_duplets = Self::all_hpo_duplets(&self);
575+
let hpo_duplets = Self::all_hpo_duplets(self);
576576
let ultra_terms: Vec<_> = hpo_duplets
577577
.iter()
578578
.filter(|d| d.hpo_label().contains("Ultra"))
@@ -584,7 +584,7 @@ impl EtlTools {
584584
.collect();
585585
let disease = match &self.dto.disease {
586586
Some(d) => d.clone(),
587-
None => { return Err(format!("Cannot create CohortData if ETL does not have disease data"))},
587+
None => { return Err("Cannot create CohortData if ETL does not have disease data".to_string())},
588588
};
589589
let mut row_list: Vec<RowData> = Vec::new();
590590
let n_rows = self.get_row_count()?;

src/export/cohort_renderer.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,12 @@ pub struct TopLevelHpoRenderer {
8787
impl TopLevelHpoRenderer {
8888
pub fn new(
8989
top_level_name: &str,
90-
hpo_header: &Vec<HpoTermDuplet>,
90+
hpo_header: &[HpoTermDuplet],
9191
rows: Vec<CohortRow>) -> Self {
9292
Self {
9393
top_level_name: top_level_name.to_string(),
9494
anchor: Self::make_anchor_id(top_level_name),
95-
hpo_header: hpo_header.clone(),
95+
hpo_header: hpo_header.to_vec(),
9696
n_hpo: hpo_header.len(),
9797
rows: rows
9898
}
@@ -139,13 +139,13 @@ impl CohortRenderer {
139139
let top_level_map = match crate::hpo::get_hpo_terms_by_toplevel(cohort.clone(), hpo.clone()){
140140
Ok(tlmap) => tlmap,
141141
Err(e) => {
142-
eprint!("{}", e.to_string());
142+
eprint!("{}", e);
143143
HashMap::<String, Vec<HpoTermDuplet>>::new()
144144
}
145145
};
146146
let mut top_level_list: Vec<TopLevelHpoRenderer> = Vec::new();
147147
for top in top_level_map {
148-
let top_level = Self::get_top_level_section(&top.0, top.1, &cohort)
148+
let top_level = Self::get_top_level_section(&top.0, top.1, cohort)
149149
.map_err(|e|e.to_string())?;
150150
top_level_list.push(top_level);
151151
}

src/export/html_renderer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ impl HtmlRenderer {
2727
e
2828
});
2929
match html {
30-
Ok(html) => { return html;},
30+
Ok(html) => { html },
3131
Err(e) => {
3232
panic!("{:?}",e);
3333
}

src/export/table_compare.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,10 @@ impl CategoryCounter {
189189
}
190190

191191
pub fn over_threshold(&self, threshold: usize) -> bool {
192-
return self
192+
self
193193
.row_counter_list
194194
.iter()
195-
.any(|c| c.over_threshold(threshold));
195+
.any(|c| c.over_threshold(threshold))
196196
}
197197

198198
pub fn get_subheader(&self) -> Vec<String> {
@@ -317,11 +317,11 @@ impl TableCompare {
317317
citation_set.insert(citation);
318318
};
319319
let citation_list: Vec<Citation> = citation_set.into_iter().collect();
320-
return citation_list;
320+
citation_list
321321
}
322322

323323
pub fn get_citations(&self) -> Vec<Citation> {
324-
return self.citation_list.clone();
324+
self.citation_list.clone()
325325
}
326326

327327

@@ -373,14 +373,14 @@ impl TableCompare {
373373
}
374374

375375
pub fn get_category_counters(&self) -> Vec<CategoryCounter> {
376-
return self.category_map.values().cloned().collect()
376+
self.category_map.values().cloned().collect()
377377
}
378378

379379
pub(crate) fn get_count(&self, duplet: &HpoTermDuplet) -> usize {
380-
return match self.total_term_count_map.get(duplet) {
380+
match self.total_term_count_map.get(duplet) {
381381
Some(c) => *c,
382382
None => 0,
383-
};
383+
}
384384
}
385385

386386

src/factory/cohort_qc.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ impl ConflictMap {
1717

1818

1919
fn conflict_count(&self) -> usize {
20-
self.na_terms.len()
20+
self.na_terms.len()
2121
}
2222

2323
pub fn no_conflict(&self) -> bool {
24-
return self.conflict_count() == 0;
24+
self.conflict_count() == 0
2525
}
2626

2727
pub fn report(&self) -> String {
@@ -100,9 +100,9 @@ impl CohortDataQc {
100100
pub fn qc_conflicting_pairs(&self, cohort: &CohortData) -> Result<(), String> {
101101
let conflicting_pairs = self.get_conflicting_termid_pairs(cohort)?;
102102
if conflicting_pairs.no_conflict() {
103-
return Ok(())
103+
Ok(())
104104
} else {
105-
return Err(conflicting_pairs.report());
105+
Err(conflicting_pairs.report())
106106
}
107107
}
108108

@@ -152,7 +152,7 @@ impl CohortDataQc {
152152
for tid in conflict_map.na_terms {
153153
let idx = term_id_to_index_map
154154
.get(&tid)
155-
.ok_or_else(|| format!("Could not get index for {}", tid.to_string()))?;
155+
.ok_or_else(|| format!("Could not get index for {}", tid))?;
156156
row.hpo_data[*idx] = crate::dto::hpo_term_dto::CellValue::Na;
157157
}
158158
}

src/factory/gene_variant_bundle.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl GeneVariantBundle {
4545

4646
// Start index is the index in the template matrix where this block of columns starts
4747
pub fn from_row(
48-
row: &Vec<String>,
48+
row: &[String],
4949
start_idx: usize
5050
) -> std::result::Result<Self, String> {
5151
let i = start_idx;

src/factory/mod.rs

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,9 @@ mod cohort_qc;
2828
/// * `cohort_dto` - A [`CohortData`] object representing the cohort.
2929
///
3030
/// # Returns
31-
/// * `Ok(String)` containing the template filename if the cohort is Mendelian,
32-
/// contains exactly one gene transcript, and has a cohort acronym.
31+
/// * `Ok(String)` containing the template filename (generated in the front end)
3332
/// * `Err(String)` if:
34-
/// - The cohort is not Mendelian,
35-
/// - No disease data is available,
36-
/// - More than one gene transcript is present (non-Mendelian case not implemented),
37-
/// - Or the cohort acronym is missing.
33+
/// - the cohort acronym is missing.
3834
///
3935
/// # Errors
4036
/// This function returns an error with a descriptive message when the filename
@@ -46,29 +42,12 @@ mod cohort_qc;
4642
/// // e.g., "ACVR1_FOP_individuals.json"
4743
/// ```
4844
pub fn extract_template_name(cohort_dto: &CohortData) -> Result<String, String> {
49-
if cohort_dto.is_melded() {
50-
let name = melded_cohort_name(cohort_dto)?;
51-
return Ok(format!("{}_individuals.json", name));
45+
let acronym = match &cohort_dto.cohort_acronym {
46+
Some(name) => name.to_string(),
47+
None => {return Err("No cohort acronym found".to_string());}
5248
};
53-
let disease_data = match cohort_dto.disease_list.first() {
54-
Some(data) => data.clone(),
55-
None => { return Err(format!("Could not extract disease data from Mendelian cohort"));},
56-
};
57-
if disease_data.gene_transcript_list.is_empty() {
58-
return Err(format!("No gene/transcript objects found for."));
59-
};
60-
// one or multiple gene symbols: YFG1 or YFG1-YFG2
61-
// this will work for Mendelian and digenic
62-
let symbol_str = disease_data
63-
.gene_transcript_list
64-
.iter()
65-
.map(|gtd| gtd.gene_symbol.to_string())
66-
.collect::<Vec<_>>()
67-
.join("-");
68-
match &cohort_dto.cohort_acronym {
69-
Some(acronym) => Ok(format!("{}_{}_individuals.json", symbol_str, acronym)),
70-
None => Err(format!("Cannot get template name if acronym is missing.")),
71-
}
49+
50+
Ok(format!("{}_individuals.json", acronym))
7251
}
7352

7453

src/hpoa/hpo_term_counter.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ impl HpoTermCounter {
2222
let pmid = row.individual_data.pmid.clone();
2323
let term_data_list = pmid_to_term_data_list_d
2424
.entry(pmid)
25-
.or_insert(Vec::new());
25+
.or_default();
2626
for (value, duplet) in row.hpo_data.iter().zip(cohort_dto.hpo_headers.clone()) {
2727
let hpo_data = HpoTermData{
2828
term_duplet: duplet.clone(),
@@ -39,7 +39,7 @@ impl HpoTermCounter {
3939
if term_data.is_not_ascertained() {
4040
continue; // Some of our upstream data has "na" values for a specific HPO term. There is no use adding these non-values to the HPOA (because they would yield 0/0)
4141
}
42-
let cterm = counted_term_map.entry(term_data.term_id().to_string()).or_insert(CountedHpoTerm::new(term_data.term_id(), term_data.label(), &pmid));
42+
let cterm = counted_term_map.entry(term_data.term_id().to_string()).or_insert(CountedHpoTerm::new(term_data.term_id(), term_data.label(), pmid));
4343
cterm.increment_value(&term_data.entry);
4444
}
4545
// we are now done with the counted terms for the current PMID

src/hpoa/hpoa_onset_calculator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl HpoaOnsetCalculator {
2828
return Err(format!("Invalid age string '{}' for '{}'", onset, row.individual_data.individual_id));
2929
}
3030
let onset_term = age::get_onset_term(&onset)?;
31-
let onset_list = pmid_to_onset_string_d.entry(pmid).or_insert(Vec::new());
31+
let onset_list = pmid_to_onset_string_d.entry(pmid).or_default();
3232
onset_list.push(onset_term);
3333
}
3434
}

0 commit comments

Comments
 (0)