@@ -2,22 +2,24 @@ use std::collections::HashSet;
22
33use phenopackets:: schema:: v2:: { Phenopacket , core:: genomic_interpretation:: Call } ;
44
5- use crate :: dto:: cohort_dto:: { DiseaseData } ;
5+ use crate :: { dto:: cohort_dto:: { CohortData , DiseaseData } , repo :: qc_report :: QcReport } ;
66
77
88
99#[ derive( Clone , Debug ) ]
1010pub struct DiseaseQc {
1111 disease_data : DiseaseData ,
12- ppkt_list : Vec < Phenopacket >
12+ ppkt_list : Vec < Phenopacket > ,
13+ cohort : CohortData ,
1314}
1415
1516
1617impl DiseaseQc {
17- pub fn new ( disease_data : & DiseaseData ) -> Self {
18+ pub fn new ( disease_data : & DiseaseData , cohort : & CohortData ) -> Self {
1819 Self {
1920 disease_data : disease_data. clone ( ) ,
20- ppkt_list : Vec :: new ( )
21+ ppkt_list : Vec :: new ( ) ,
22+ cohort : cohort. clone ( )
2123 }
2224 }
2325
@@ -30,7 +32,8 @@ impl DiseaseQc {
3032 return self . ppkt_list . len ( ) ;
3133 }
3234
33- pub fn check_moi ( & self ) -> Option < String > {
35+ pub fn check_moi ( & self ) -> Vec < QcReport > {
36+ let mut errs: Vec < QcReport > = Vec :: new ( ) ;
3437 let mut allowable_allele_counts: HashSet < usize > = HashSet :: new ( ) ;
3538 for moi in & self . disease_data . mode_of_inheritance_list {
3639 if moi. is_autosomal_dominant ( ) {
@@ -40,16 +43,17 @@ impl DiseaseQc {
4043 } else if moi. is_x_chromosomal ( ) {
4144 allowable_allele_counts. insert ( 1 ) ;
4245 } else {
43- return Some ( format ! ( "Did not recognize MOI: {:?}" , moi) ) ;
46+ eprintln ! ( "Did not recognize MOI: {:?}" , moi) ;
4447 }
4548 }
4649 for ppkt in & self . ppkt_list {
4750 let ac = Self :: get_allele_count ( ppkt) ;
4851 if ! allowable_allele_counts. contains ( & ac) {
49- return Some ( format ! ( "{}: Expected counts of {:?} but got {} for {}." , ppkt. id, allowable_allele_counts, ac, self . disease_data_display( ) ) )
52+ let qc = QcReport :: moi_mismatch ( & self . disease_data_display ( ) , & ppkt. id , & allowable_allele_counts, ac) ;
53+ errs. push ( qc) ;
5054 }
5155 }
52- None
56+ errs
5357 }
5458
5559 fn disease_data_display ( & self ) -> String {
@@ -87,4 +91,15 @@ impl DiseaseQc {
8791
8892 ac
8993 }
94+
95+ pub fn check_all_rows_output_as_ppkt ( & self ) -> Option < QcReport > {
96+ let n_nrows = self . cohort . rows . len ( ) ;
97+ let n_phenopackets = self . phenopacket_count ( ) ;
98+ if n_nrows == n_phenopackets {
99+ return None ;
100+ } else {
101+ return Some ( QcReport :: count_mismatch ( & self . disease_data_display ( ) , n_nrows, n_phenopackets) )
102+ }
103+ }
104+
90105}
0 commit comments