Skip to content

Commit 4b88dc0

Browse files
committed
refactoring QcReport
1 parent a463b6b commit 4b88dc0

File tree

7 files changed

+44
-41
lines changed

7 files changed

+44
-41
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.4"
3+
version = "0.5.5"
44
edition = "2021"
55
keywords = ["GA4GH", "Phenopacket Schema", "Human Phenotype Ontology"]
66
description = "Generate GA4GH phenopackets from tabular data"

src/repo/cohort_qc.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ impl CohortQc {
7272
.filter_map(|dqc| dqc.check_all_rows_output_as_ppkt()),
7373
);
7474

75+
errs.extend(
76+
self.disease_qc_list
77+
.iter()
78+
.flat_map(|dqc|dqc.check_no_hpo())
79+
);
80+
7581
errs
7682
}
7783

src/repo/dashboard_data.rs

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/repo/disease_qc.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,16 @@ impl DiseaseQc {
102102
}
103103
}
104104

105+
pub fn check_no_hpo(&self) -> Vec<QcReport> {
106+
let mut errs: Vec<QcReport> = Vec::new();
107+
for ppkt in &self.ppkt_list {
108+
let n_hpo = ppkt.phenotypic_features.iter().filter(|p| ! p.excluded )
109+
.count();
110+
if n_hpo == 0 {
111+
errs.push(QcReport::no_hpo(&self.disease_data_display(), &ppkt.id));
112+
}
113+
}
114+
errs
115+
}
116+
105117
}

src/repo/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use crate::repo::{gpt_repository::GptRepository, repo_qc::RepoQc};
1010

1111
mod cohort_dir;
1212
mod cohort_qc;
13-
pub mod dashboard_data;
1413
mod disease_qc;
1514
mod gpt_repository;
1615
pub mod qc_report;

src/repo/qc_report.rs

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
11
use std::collections::HashSet;
22

3+
use serde::de::Unexpected;
4+
5+
6+
7+
#[derive(Debug, Clone, serde::Serialize)]
8+
#[serde(rename_all = "camelCase")]
9+
enum RepoErrorType {
10+
UnexpectedFile,
11+
MoiMismatch,
12+
PpktExportError,
13+
NoHpoTermError
14+
}
315

416

517
#[derive(Debug, Clone, serde::Serialize)]
618
#[serde(rename_all = "camelCase")]
719
pub struct QcReport {
820
pub cohort_name: String,
921
pub message: String,
10-
pub is_ok: bool,
22+
pub error_type: RepoErrorType,
1123
}
1224

1325

@@ -20,7 +32,7 @@ impl QcReport {
2032
let msg = format!("Unexpected file: {}", unexpected);
2133
Self { cohort_name: cohort_name.to_string(),
2234
message: msg,
23-
is_ok: false
35+
error_type: RepoErrorType::UnexpectedFile
2436
}
2537
}
2638

@@ -36,7 +48,7 @@ impl QcReport {
3648
let message= format!("Expected counts of {} but got {} for {}.", set,ac, ppkt_id);
3749
Self { cohort_name: cohort_name.to_string(),
3850
message,
39-
is_ok: false
51+
error_type: RepoErrorType::MoiMismatch
4052
}
4153
}
4254

@@ -45,7 +57,16 @@ impl QcReport {
4557
Self {
4658
cohort_name: cohort_name.to_string(),
4759
message,
48-
is_ok: false,
60+
error_type: RepoErrorType::PpktExportError,
61+
}
62+
}
63+
64+
pub fn no_hpo(cohort_name: &str, ppkt_id: &str) -> Self {
65+
let message = format!("Phenopacket {} had no observed HPO terms", ppkt_id);
66+
Self {
67+
cohort_name: cohort_name.to_string(),
68+
message,
69+
error_type: RepoErrorType::NoHpoTermError
4970
}
5071
}
5172

tests/integration_cohort.rs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -105,25 +105,6 @@ pub fn acvr1_cohort_with_repeated_term(
105105
}
106106

107107

108-
#[rstest]
109-
fn export_with_het(
110-
hpo: Arc<FullCsrOntology>
111-
) {
112-
let cohort = "/Users/robin/GIT/phenopacket-store/notebooks/KLF1/KLF1_CDAN4B_individuals.json";
113-
let file_data = std::fs::read_to_string(cohort)
114-
.map_err(|e|
115-
format!("Could not extract string data from {}: {}", cohort, e.to_string())).unwrap();
116-
let cohort: CohortData = serde_json::from_str(&file_data)
117-
.map_err(|e| format!("Could not transform string {} to CohortDto: {}",
118-
file_data, e.to_string())).unwrap();
119-
let orcid = "0000-0000-0000-0001".to_string();
120-
let ppkt_list = ga4ghphetools::ppkt::get_phenopackets(cohort, orcid, hpo).unwrap();
121-
let interp = ppkt_list[2].interpretations[0].clone();
122-
if let Some(dx) = interp.diagnosis {
123-
println!("# genomic interpretations = {}", dx.genomic_interpretations.len());
124-
}
125-
126-
}
127108

128109

129110

0 commit comments

Comments
 (0)