From 0edcf9875a66a881803c0f9d842fae1e95af05f2 Mon Sep 17 00:00:00 2001 From: Manuel Holtgrewe Date: Fri, 25 Oct 2024 14:49:56 +0200 Subject: [PATCH] refactor: consolidating protobuf definitions (#508) (#509) Release-As: 0.16.0 --- protos/varfish/v1/seqvars/output.proto | 20 +--- protos/varfish/v1/seqvars/query.proto | 23 +--- src/seqvars/query/interpreter/frequency.rs | 8 +- .../query/interpreter/regions_allowlist.rs | 14 +-- src/seqvars/query/mod.rs | 4 +- src/seqvars/query/schema/query.rs | 101 +++++++----------- 6 files changed, 59 insertions(+), 111 deletions(-) diff --git a/protos/varfish/v1/seqvars/output.proto b/protos/varfish/v1/seqvars/output.proto index 61743b9c..4db7b3ff 100644 --- a/protos/varfish/v1/seqvars/output.proto +++ b/protos/varfish/v1/seqvars/output.proto @@ -335,9 +335,9 @@ message FrequencyAnnotation { // gnomAD-genomes filter optional NuclearFrequency gnomad_genomes = 2; // gnomAD-MT filter - optional GnomadMitochondrialFrequency gnomad_mtdna = 3; + optional MitochondrialFrequency gnomad_mtdna = 3; // HelixMtDb filter - optional HelixMtDbFrequency helixmtdb = 4; + optional MitochondrialFrequency helixmtdb = 4; // In-house filter optional NuclearFrequency inhouse = 5; } @@ -356,8 +356,8 @@ message NuclearFrequency { float af = 5; } -// gnomAD mitochondrial frequency information. -message GnomadMitochondrialFrequency { +// Mitochondrial frequency information. +message MitochondrialFrequency { // Number of covered alleles. int32 an = 1; // Number of heteroplasmic carriers. @@ -368,18 +368,6 @@ message GnomadMitochondrialFrequency { float af = 4; } -// HelixMtDb frequency information. -message HelixMtDbFrequency { - // Number of covered alleles. - int32 an = 1; - // Number of heterozygous carriers in HelixMtDb - int32 het = 2; - // Number of homozygous carriers in HelixMtDb - int32 homalt = 3; - // Frequency in HelixMtDb - float af = 4; -} - // Database identifiers. message DbIds { // dbSNP ID. diff --git a/protos/varfish/v1/seqvars/query.proto b/protos/varfish/v1/seqvars/query.proto index 634d101f..d1715f31 100644 --- a/protos/varfish/v1/seqvars/query.proto +++ b/protos/varfish/v1/seqvars/query.proto @@ -102,8 +102,8 @@ message NuclearFrequencySettings { optional float frequency = 5; } -// gnomAD mitochondrial filter options. -message GnomadMitochondrialFrequencySettings { +// Mitochondrial filter options. +message MitochondrialFrequencySettings { // Whether to enable filtration by 1000 Genomes. bool enabled = 1; // Maximal number of heteroplasmic carriers. @@ -114,19 +114,6 @@ message GnomadMitochondrialFrequencySettings { optional float frequency = 4; } -// HelixMtDb filter options. -message HelixMtDbFrequencySettings { - // Whether to enable filtration by mtDB - bool enabled = 1; - // Maximal number of heterozygous carriers in HelixMtDb - optional int32 heteroplasmic = 2; - // Maximal number of homozygous carriers in HelixMtDb - optional int32 homoplasmic = 3; - // Maximal frequency in HelixMtDb - optional float frequency = 4; -} - - // Population frequency filter options. message QuerySettingsFrequency { // gnomAD-exomes filter @@ -134,9 +121,9 @@ message QuerySettingsFrequency { // gnomAD-genomes filter NuclearFrequencySettings gnomad_genomes = 2; // gnomAD-MT filter - GnomadMitochondrialFrequencySettings gnomad_mtdna = 3; + MitochondrialFrequencySettings gnomad_mtdna = 3; // HelixMtDb filter - HelixMtDbFrequencySettings helixmtdb = 4; + MitochondrialFrequencySettings helixmtdb = 4; // In-house filter NuclearFrequencySettings inhouse = 5; } @@ -284,7 +271,7 @@ message Range { // 1-based start position. int32 start = 1; // 1-based end position. - int32 end = 2; + int32 stop = 2; } // Genomic region. diff --git a/src/seqvars/query/interpreter/frequency.rs b/src/seqvars/query/interpreter/frequency.rs index 03ecc6d2..12680896 100644 --- a/src/seqvars/query/interpreter/frequency.rs +++ b/src/seqvars/query/interpreter/frequency.rs @@ -108,8 +108,8 @@ mod test { VcfVariant, }, query::{ - CaseQuery, GnomadMitochondrialFrequencySettings, HelixMtDbFrequencySettings, - NuclearFrequencySettings, QuerySettingsFrequency, + CaseQuery, MitochondrialFrequencySettings, NuclearFrequencySettings, + QuerySettingsFrequency, }, }; @@ -423,7 +423,7 @@ mod test { ) -> Result<(), anyhow::Error> { let query = CaseQuery { frequency: QuerySettingsFrequency { - helixmtdb: HelixMtDbFrequencySettings { + helixmtdb: MitochondrialFrequencySettings { enabled: query_helixmtdb_enabled, frequency: query_helixmtdb_frequency, heteroplasmic: query_helixmtdb_heteroplasmic, @@ -534,7 +534,7 @@ mod test { ) -> Result<(), anyhow::Error> { let query = CaseQuery { frequency: QuerySettingsFrequency { - gnomad_mtdna: GnomadMitochondrialFrequencySettings { + gnomad_mtdna: MitochondrialFrequencySettings { enabled: query_gnomad_mtdna_enabled, frequency: query_gnomad_mtdna_frequency, heteroplasmic: query_gnomad_mtdna_heteroplasmic, diff --git a/src/seqvars/query/interpreter/regions_allowlist.rs b/src/seqvars/query/interpreter/regions_allowlist.rs index e6ecdb15..3d59d6d7 100644 --- a/src/seqvars/query/interpreter/regions_allowlist.rs +++ b/src/seqvars/query/interpreter/regions_allowlist.rs @@ -25,7 +25,7 @@ pub fn passes(query: &CaseQuery, seqvar: &VariantRecord) -> bool { } } -fn overlaps(region: &GenomicRegion, seqvar_chrom: &str, seqvar_pos: i32, seqvar_end: i32) -> bool { +fn overlaps(region: &GenomicRegion, seqvar_chrom: &str, seqvar_pos: i32, seqvar_stop: i32) -> bool { let GenomicRegion { chrom: region_chrom, range: region_range, @@ -39,10 +39,10 @@ fn overlaps(region: &GenomicRegion, seqvar_chrom: &str, seqvar_pos: i32, seqvar_ if let Some(Range { start: region_start, - end: region_end, + stop: region_stop, }) = region_range { - *region_start <= seqvar_end && *region_end >= seqvar_pos + *region_start <= seqvar_stop && *region_stop >= seqvar_pos } else { true } @@ -64,18 +64,18 @@ mod test { #[case] region_range: Option<(i32, i32)>, #[case] seqvar_chrom: &str, #[case] seqvar_start: i32, - #[case] seqvar_end: i32, + #[case] seqvar_stop: i32, #[case] expected: bool, ) { let region = super::GenomicRegion { chrom: String::from(region_chrom), - range: region_range.map(|(region_start, region_end)| super::Range { + range: region_range.map(|(region_start, region_stop)| super::Range { start: region_start, - end: region_end, + stop: region_stop, }), }; assert_eq!( - super::overlaps(®ion, seqvar_chrom, seqvar_start, seqvar_end), + super::overlaps(®ion, seqvar_chrom, seqvar_start, seqvar_stop), expected ); } diff --git a/src/seqvars/query/mod.rs b/src/seqvars/query/mod.rs index 1b7aa20a..af0045d4 100644 --- a/src/seqvars/query/mod.rs +++ b/src/seqvars/query/mod.rs @@ -1123,13 +1123,13 @@ mod variant_related_annotation { hemialt: seqvar.population_frequencies.gnomad_genomes.hemi, af: seqvar.population_frequencies.gnomad_genomes.af(), }), - gnomad_mtdna: Some(pbs_output::GnomadMitochondrialFrequency { + gnomad_mtdna: Some(pbs_output::MitochondrialFrequency { an: seqvar.population_frequencies.gnomad_mtdna.an, het: seqvar.population_frequencies.gnomad_mtdna.het, homalt: seqvar.population_frequencies.gnomad_mtdna.hom, af: seqvar.population_frequencies.gnomad_mtdna.af(), }), - helixmtdb: Some(pbs_output::HelixMtDbFrequency { + helixmtdb: Some(pbs_output::MitochondrialFrequency { an: seqvar.population_frequencies.helixmtdb.an, het: seqvar.population_frequencies.helixmtdb.het, homalt: seqvar.population_frequencies.helixmtdb.hom, diff --git a/src/seqvars/query/schema/query.rs b/src/seqvars/query/schema/query.rs index 38701a79..bef4d309 100644 --- a/src/seqvars/query/schema/query.rs +++ b/src/seqvars/query/schema/query.rs @@ -521,35 +521,9 @@ impl From for NuclearFrequencySettings { } } -/// gnomAD mitochondrial filter options. -#[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize)] -pub struct GnomadMitochondrialFrequencySettings { - /// Whether to enable filtration by 1000 Genomes. - pub enabled: bool, - /// Maximal number of heteroplasmic carriers. - pub heteroplasmic: Option, - /// Maximal number of homoplasmic carriers. - pub homoplasmic: Option, - /// Maximal allele frequency. - pub frequency: Option, -} - -impl Eq for GnomadMitochondrialFrequencySettings {} - -impl From for GnomadMitochondrialFrequencySettings { - fn from(value: pb_query::GnomadMitochondrialFrequencySettings) -> Self { - Self { - enabled: value.enabled, - heteroplasmic: value.heteroplasmic, - homoplasmic: value.homoplasmic, - frequency: value.frequency, - } - } -} - /// HelixMtDb filter options. #[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize)] -pub struct HelixMtDbFrequencySettings { +pub struct MitochondrialFrequencySettings { /// Whether to enable filtration by mtDB. pub enabled: bool, /// Maximal number of heterozygous carriers in HelixMtDb. @@ -560,10 +534,10 @@ pub struct HelixMtDbFrequencySettings { pub frequency: Option, } -impl Eq for HelixMtDbFrequencySettings {} +impl Eq for MitochondrialFrequencySettings {} -impl From for HelixMtDbFrequencySettings { - fn from(value: pb_query::HelixMtDbFrequencySettings) -> Self { +impl From for MitochondrialFrequencySettings { + fn from(value: pb_query::MitochondrialFrequencySettings) -> Self { Self { enabled: value.enabled, heteroplasmic: value.heteroplasmic, @@ -581,9 +555,9 @@ pub struct QuerySettingsFrequency { /// gnomAD-genomes filter. pub gnomad_genomes: NuclearFrequencySettings, /// gnomAD-mtDNA filter. - pub gnomad_mtdna: GnomadMitochondrialFrequencySettings, + pub gnomad_mtdna: MitochondrialFrequencySettings, /// HelixMtDb filter. - pub helixmtdb: HelixMtDbFrequencySettings, + pub helixmtdb: MitochondrialFrequencySettings, /// In-house filter. pub inhouse: NuclearFrequencySettings, } @@ -595,10 +569,10 @@ impl From for QuerySettingsFrequency { gnomad_genomes: NuclearFrequencySettings::from( value.gnomad_genomes.unwrap_or_default(), ), - gnomad_mtdna: GnomadMitochondrialFrequencySettings::from( + gnomad_mtdna: MitochondrialFrequencySettings::from( value.gnomad_mtdna.unwrap_or_default(), ), - helixmtdb: HelixMtDbFrequencySettings::from(value.helixmtdb.unwrap_or_default()), + helixmtdb: MitochondrialFrequencySettings::from(value.helixmtdb.unwrap_or_default()), inhouse: NuclearFrequencySettings::from(value.inhouse.unwrap_or_default()), } } @@ -1124,14 +1098,14 @@ pub struct Range { /// 1-based start position. pub start: i32, /// 1-based end position. - pub end: i32, + pub stop: i32, } impl From for Range { fn from(value: pb_query::Range) -> Self { Self { start: value.start, - end: value.end, + stop: value.stop, } } } @@ -1679,41 +1653,40 @@ mod tests { #[test] fn test_gnomad_mitochondrial_frequency_settings_from() { - let pb_gnomad_mitochondrial_frequency_settings = - pb_query::GnomadMitochondrialFrequencySettings { - enabled: true, - heteroplasmic: Some(10), - homoplasmic: Some(20), - frequency: Some(0.1), - }; - let gnomad_mitochondrial_frequency_settings = GnomadMitochondrialFrequencySettings { + let pb_gnomad_mitochondrial_frequency_settings = pb_query::MitochondrialFrequencySettings { + enabled: true, + heteroplasmic: Some(10), + homoplasmic: Some(20), + frequency: Some(0.1), + }; + let gnomad_mitochondrial_frequency_settings = MitochondrialFrequencySettings { enabled: true, heteroplasmic: Some(10), homoplasmic: Some(20), frequency: Some(0.1), }; assert_eq!( - GnomadMitochondrialFrequencySettings::from(pb_gnomad_mitochondrial_frequency_settings), + MitochondrialFrequencySettings::from(pb_gnomad_mitochondrial_frequency_settings), gnomad_mitochondrial_frequency_settings ); } #[test] fn test_helix_mtdb_frequency_settings_from() { - let pb_helix_mtdb_frequency_settings = pb_query::HelixMtDbFrequencySettings { + let pb_helix_mtdb_frequency_settings = pb_query::MitochondrialFrequencySettings { enabled: true, heteroplasmic: Some(10), homoplasmic: Some(20), frequency: Some(0.1), }; - let helix_mtdb_frequency_settings = HelixMtDbFrequencySettings { + let helix_mtdb_frequency_settings = MitochondrialFrequencySettings { enabled: true, heteroplasmic: Some(10), homoplasmic: Some(20), frequency: Some(0.1), }; assert_eq!( - HelixMtDbFrequencySettings::from(pb_helix_mtdb_frequency_settings), + MitochondrialFrequencySettings::from(pb_helix_mtdb_frequency_settings), helix_mtdb_frequency_settings ); } @@ -1757,13 +1730,13 @@ mod tests { hemizygous: Some(30), frequency: Some(0.1), }), - gnomad_mtdna: Some(pb_query::GnomadMitochondrialFrequencySettings { + gnomad_mtdna: Some(pb_query::MitochondrialFrequencySettings { enabled: true, heteroplasmic: Some(10), homoplasmic: Some(20), frequency: Some(0.1), }), - helixmtdb: Some(pb_query::HelixMtDbFrequencySettings { + helixmtdb: Some(pb_query::MitochondrialFrequencySettings { enabled: true, heteroplasmic: Some(10), homoplasmic: Some(20), @@ -1792,13 +1765,13 @@ mod tests { hemizygous: Some(30), frequency: Some(0.1), }, - gnomad_mtdna: GnomadMitochondrialFrequencySettings { + gnomad_mtdna: MitochondrialFrequencySettings { enabled: true, heteroplasmic: Some(10), homoplasmic: Some(20), frequency: Some(0.1), }, - helixmtdb: HelixMtDbFrequencySettings { + helixmtdb: MitochondrialFrequencySettings { enabled: true, heteroplasmic: Some(10), homoplasmic: Some(20), @@ -2038,8 +2011,8 @@ mod tests { #[test] fn test_range_from() { - let pb_range = pb_query::Range { start: 1, end: 2 }; - let range = Range { start: 1, end: 2 }; + let pb_range = pb_query::Range { start: 1, stop: 2 }; + let range = Range { start: 1, stop: 2 }; assert_eq!(Range::from(pb_range), range); } @@ -2047,11 +2020,11 @@ mod tests { fn test_genomic_region_from() { let pb_genomic_region = pb_query::GenomicRegion { chrom: "chrom".to_string(), - range: Some(pb_query::Range { start: 1, end: 2 }), + range: Some(pb_query::Range { start: 1, stop: 2 }), }; let genomic_region = GenomicRegion { chrom: "chrom".to_string(), - range: Some(Range { start: 1, end: 2 }), + range: Some(Range { start: 1, stop: 2 }), }; assert_eq!(GenomicRegion::from(pb_genomic_region), genomic_region); } @@ -2062,14 +2035,14 @@ mod tests { genes: vec!["gene".to_string()], genome_regions: vec![pb_query::GenomicRegion { chrom: "chrom".to_string(), - range: Some(pb_query::Range { start: 1, end: 2 }), + range: Some(pb_query::Range { start: 1, stop: 2 }), }], }; let query_settings_locus = QuerySettingsLocus { genes: vec!["gene".to_string()], genome_regions: vec![GenomicRegion { chrom: "chrom".to_string(), - range: Some(Range { start: 1, end: 2 }), + range: Some(Range { start: 1, stop: 2 }), }], }; assert_eq!( @@ -2184,13 +2157,13 @@ mod tests { hemizygous: Some(30), frequency: Some(0.1), }), - gnomad_mtdna: Some(pb_query::GnomadMitochondrialFrequencySettings { + gnomad_mtdna: Some(pb_query::MitochondrialFrequencySettings { enabled: true, heteroplasmic: Some(10), homoplasmic: Some(20), frequency: Some(0.1), }), - helixmtdb: Some(pb_query::HelixMtDbFrequencySettings { + helixmtdb: Some(pb_query::MitochondrialFrequencySettings { enabled: true, heteroplasmic: Some(10), homoplasmic: Some(20), @@ -2231,7 +2204,7 @@ mod tests { genes: vec!["gene".to_string()], genome_regions: vec![pb_query::GenomicRegion { chrom: "chrom".to_string(), - range: Some(pb_query::Range { start: 1, end: 2 }), + range: Some(pb_query::Range { start: 1, stop: 2 }), }], }), clinvar: Some(pb_query::QuerySettingsClinVar { @@ -2294,13 +2267,13 @@ mod tests { hemizygous: Some(30), frequency: Some(0.1), }, - gnomad_mtdna: GnomadMitochondrialFrequencySettings { + gnomad_mtdna: MitochondrialFrequencySettings { enabled: true, heteroplasmic: Some(10), homoplasmic: Some(20), frequency: Some(0.1), }, - helixmtdb: HelixMtDbFrequencySettings { + helixmtdb: MitochondrialFrequencySettings { enabled: true, heteroplasmic: Some(10), homoplasmic: Some(20), @@ -2338,7 +2311,7 @@ mod tests { genes: vec!["gene".to_string()], genome_regions: vec![GenomicRegion { chrom: "chrom".to_string(), - range: Some(Range { start: 1, end: 2 }), + range: Some(Range { start: 1, stop: 2 }), }], }, clinvar: QuerySettingsClinVar {