Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

draft: Refactor internal data structures of seqvar query schema #397

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/seqvars/query/interpreter/clinvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,19 @@ pub fn passes(
.unwrap_or_default();

let result = match description.to_lowercase().as_str() {
"benign" => query.clinvar_include_benign,
"benign" => query.clinvar.include_benign,
"benign/likely benign" => {
query.clinvar_include_benign || query.clinvar_include_likely_benign
query.clinvar.include_benign || query.clinvar.include_likely_benign
}
"likely benign" => query.clinvar_include_likely_benign,
"pathogenic" => query.clinvar_include_pathogenic,
"likely benign" => query.clinvar.include_likely_benign,
"pathogenic" => query.clinvar.include_pathogenic,
"pathogenic/likely pathogenic" => {
query.clinvar_include_pathogenic || query.clinvar_include_likely_pathogenic
query.clinvar.include_pathogenic || query.clinvar.include_likely_pathogenic
}
"likely pathogenic" => query.clinvar_include_likely_pathogenic,
"uncertain significance" => query.clinvar_include_uncertain_significance,
"likely pathogenic" => query.clinvar.include_likely_pathogenic,
"uncertain significance" => query.clinvar.include_uncertain_significance,
"conflicting classifications of pathogenicity" => {
query.clinvar_include_uncertain_significance
query.clinvar.include_uncertain_significance
}
_ => {
// We could also downtone this to debug.
Expand Down
198 changes: 136 additions & 62 deletions src/seqvars/query/interpreter/frequency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,54 +2,66 @@ use crate::seqvars::query::schema::{CaseQuery, SequenceVariant};

/// Determine whether the `SequenceVariant` passes the frequency filter.
pub fn passes(query: &CaseQuery, s: &SequenceVariant) -> Result<bool, anyhow::Error> {
let q = &query;
let pop = &query.population_frequency;
let is_mtdna = annonars::common::cli::canonicalize(&s.chrom) == "MT";

if is_mtdna {
if q.helixmtdb_enabled
&& (q.helixmtdb_frequency.is_some()
&& s.helixmtdb_af() > q.helixmtdb_frequency.expect("tested before")
|| q.helixmtdb_heteroplasmic.is_some()
&& s.helix_het > q.helixmtdb_heteroplasmic.expect("tested before")
|| q.helixmtdb_homoplasmic.is_some()
&& s.helix_hom > q.helixmtdb_homoplasmic.expect("tested before"))
if pop.helixmtdb.enabled
&& (pop.helixmtdb.frequency.is_some()
&& s.helixmtdb_af() > pop.helixmtdb.frequency.expect("tested before")
|| pop.helixmtdb.heteroplasmic.is_some()
&& s.population_frequencies.helixmtdb.het
> pop.helixmtdb.heteroplasmic.expect("tested before")
|| pop.helixmtdb.homoplasmic.is_some()
&& s.population_frequencies.helixmtdb.hom
> pop.helixmtdb.homoplasmic.expect("tested before"))
{
tracing::trace!("variant {:?} fails HelixMtDb frequency filter {:?}", s, &q);
tracing::trace!(
"variant {:?} fails HelixMtDb frequency filter {:?}",
s,
&pop
);
return Ok(false);
}
} else if q.gnomad_exomes_enabled
&& (q.gnomad_exomes_frequency.is_some()
&& s.gnomad_exomes_af() > q.gnomad_exomes_frequency.expect("tested before")
|| q.gnomad_exomes_heterozygous.is_some()
&& s.gnomad_exomes_het > q.gnomad_exomes_heterozygous.expect("tested before")
|| q.gnomad_exomes_homozygous.is_some()
&& s.gnomad_exomes_hom > q.gnomad_exomes_homozygous.expect("tested before")
|| q.gnomad_exomes_hemizygous.is_some()
&& s.gnomad_exomes_hemi > q.gnomad_exomes_hemizygous.expect("tested before"))
} else if pop.gnomad.exomes_enabled
&& (pop.gnomad.exomes_frequency.is_some()
&& s.gnomad_exomes_af() > pop.gnomad.exomes_frequency.expect("tested before")
|| pop.gnomad.exomes_heterozygous.is_some()
&& s.population_frequencies.gnomad.exomes_het
> pop.gnomad.exomes_heterozygous.expect("tested before")
|| pop.gnomad.exomes_homozygous.is_some()
&& s.population_frequencies.gnomad.exomes_hom
> pop.gnomad.exomes_homozygous.expect("tested before")
|| pop.gnomad.exomes_hemizygous.is_some()
&& s.population_frequencies.gnomad.exomes_hemi
> pop.gnomad.exomes_hemizygous.expect("tested before"))
{
tracing::trace!(
"variant {:?} fails gnomAD exomes frequency filter {:?}",
s,
&q.gnomad_exomes_frequency
&pop.gnomad.exomes_frequency
);
return Ok(false);
}

if q.gnomad_genomes_enabled
&& (q.gnomad_genomes_frequency.is_some()
&& s.gnomad_genomes_af() > q.gnomad_genomes_frequency.expect("tested before")
|| q.gnomad_genomes_heterozygous.is_some()
&& s.gnomad_genomes_het > q.gnomad_genomes_heterozygous.expect("tested before")
|| q.gnomad_genomes_homozygous.is_some()
&& s.gnomad_genomes_hom > q.gnomad_genomes_homozygous.expect("tested before")
if pop.gnomad.genomes_enabled
&& (pop.gnomad.genomes_frequency.is_some()
&& s.gnomad_genomes_af() > pop.gnomad.genomes_frequency.expect("tested before")
|| pop.gnomad.genomes_heterozygous.is_some()
&& s.population_frequencies.gnomad.genomes_het
> pop.gnomad.genomes_heterozygous.expect("tested before")
|| pop.gnomad.genomes_homozygous.is_some()
&& s.population_frequencies.gnomad.genomes_hom
> pop.gnomad.genomes_homozygous.expect("tested before")
|| !is_mtdna
&& q.gnomad_genomes_hemizygous.is_some()
&& s.gnomad_genomes_hemi > q.gnomad_genomes_hemizygous.expect("tested before"))
&& pop.gnomad.genomes_hemizygous.is_some()
&& s.population_frequencies.gnomad.genomes_hemi
> pop.gnomad.genomes_hemizygous.expect("tested before"))
{
tracing::trace!(
"variant {:?} fails gnomAD genomes frequency filter {:?}",
s,
&q.gnomad_genomes_frequency
&pop.gnomad.genomes_frequency
);
return Ok(false);
}
Expand All @@ -63,7 +75,9 @@ mod test {
use mehari::annotate::seqvars::ann::{AnnField, Consequence};
use rstest::rstest;

use crate::seqvars::query::schema::{CaseQuery, SequenceVariant};
use crate::seqvars::query::schema::{
CaseQuery, HelixMtDBs, PopulationFrequencies, SequenceVariant,
};

#[rstest]
// -- frequency ---------------------------------------------------------
Expand Down Expand Up @@ -130,19 +144,35 @@ mod test {
#[case] query_gnomad_exomes_hemizygous: Option<i32>,
#[case] expected_pass_all: bool,
) -> Result<(), anyhow::Error> {
use crate::seqvars::query::schema::{
GnomadOptions, Gnomads, PopulationFrequencies, PopulationFrequencyOptions,
};

let query = CaseQuery {
gnomad_exomes_enabled: query_gnomad_exomes_enabled,
gnomad_exomes_frequency: query_gnomad_exomes_frequency,
gnomad_exomes_heterozygous: query_gnomad_exomes_heterozygous,
gnomad_exomes_homozygous: query_gnomad_exomes_homozygous,
gnomad_exomes_hemizygous: query_gnomad_exomes_hemizygous,
population_frequency: PopulationFrequencyOptions {
gnomad: GnomadOptions {
exomes_enabled: query_gnomad_exomes_enabled,
exomes_frequency: query_gnomad_exomes_frequency,
exomes_heterozygous: query_gnomad_exomes_heterozygous,
exomes_homozygous: query_gnomad_exomes_homozygous,
exomes_hemizygous: query_gnomad_exomes_hemizygous,
..Default::default()
},
..Default::default()
},
..Default::default()
};
let seq_var = SequenceVariant {
gnomad_exomes_an: seqvar_gnomad_exomes_an,
gnomad_exomes_het: seqvar_gnomad_exomes_het,
gnomad_exomes_hom: seqvar_gnomad_exomes_hom,
gnomad_exomes_hemi: seqvar_gnomad_exomes_hemi,
population_frequencies: PopulationFrequencies {
gnomad: Gnomads {
exomes_an: seqvar_gnomad_exomes_an,
exomes_het: seqvar_gnomad_exomes_het,
exomes_hom: seqvar_gnomad_exomes_hom,
exomes_hemi: seqvar_gnomad_exomes_hemi,
..Default::default()
},
..Default::default()
},
chrom: "X".to_string(),
reference: "G".into(),
alternative: "A".into(),
Expand Down Expand Up @@ -241,19 +271,35 @@ mod test {
#[case] query_gnomad_genomes_hemizygous: Option<i32>,
#[case] expected_pass_all: bool,
) -> Result<(), anyhow::Error> {
use crate::seqvars::query::schema::{
GnomadOptions, Gnomads, PopulationFrequencies, PopulationFrequencyOptions,
};

let query = CaseQuery {
gnomad_genomes_enabled: query_gnomad_genomes_enabled,
gnomad_genomes_frequency: query_gnomad_genomes_frequency,
gnomad_genomes_heterozygous: query_gnomad_genomes_heterozygous,
gnomad_genomes_homozygous: query_gnomad_genomes_homozygous,
gnomad_genomes_hemizygous: query_gnomad_genomes_hemizygous,
population_frequency: PopulationFrequencyOptions {
gnomad: GnomadOptions {
genomes_enabled: query_gnomad_genomes_enabled,
genomes_frequency: query_gnomad_genomes_frequency,
genomes_heterozygous: query_gnomad_genomes_heterozygous,
genomes_homozygous: query_gnomad_genomes_homozygous,
genomes_hemizygous: query_gnomad_genomes_hemizygous,
..Default::default()
},
..Default::default()
},
..Default::default()
};
let seq_var = SequenceVariant {
gnomad_genomes_an: seqvar_gnomad_genomes_an,
gnomad_genomes_het: seqvar_gnomad_genomes_het,
gnomad_genomes_hom: seqvar_gnomad_genomes_hom,
gnomad_genomes_hemi: seqvar_gnomad_genomes_hemi,
population_frequencies: PopulationFrequencies {
gnomad: Gnomads {
genomes_an: seqvar_gnomad_genomes_an,
genomes_het: seqvar_gnomad_genomes_het,
genomes_hom: seqvar_gnomad_genomes_hom,
genomes_hemi: seqvar_gnomad_genomes_hemi,
..Default::default()
},
..Default::default()
},
chrom: "X".to_string(),
reference: "G".into(),
alternative: "A".into(),
Expand Down Expand Up @@ -333,17 +379,29 @@ mod test {
#[case] query_helix_homoplasmic: Option<i32>,
#[case] expected_pass_all: bool,
) -> Result<(), anyhow::Error> {
use crate::seqvars::query::schema::{HelixMtDbOptions, PopulationFrequencyOptions};

let query = CaseQuery {
helixmtdb_enabled: query_helix_enabled,
helixmtdb_frequency: query_helix_frequency,
helixmtdb_heteroplasmic: query_helix_heteroplasmic,
helixmtdb_homoplasmic: query_helix_homoplasmic,
population_frequency: PopulationFrequencyOptions {
helixmtdb: HelixMtDbOptions {
enabled: query_helix_enabled,
frequency: query_helix_frequency,
heteroplasmic: query_helix_heteroplasmic,
homoplasmic: query_helix_homoplasmic,
},
..Default::default()
},
..Default::default()
};
let seq_var = SequenceVariant {
helix_an: seqvar_helix_an,
helix_het: seqvar_helix_het,
helix_hom: seqvar_helix_hom,
population_frequencies: PopulationFrequencies {
helixmtdb: HelixMtDBs {
an: seqvar_helix_an,
het: seqvar_helix_het,
hom: seqvar_helix_hom,
},
..Default::default()
},
chrom: "MT".to_string(),
reference: "G".into(),
alternative: "A".into(),
Expand Down Expand Up @@ -424,17 +482,33 @@ mod test {
#[case] query_gnomad_genomes_homoplasmic: Option<i32>,
#[case] expected_pass_all: bool,
) -> Result<(), anyhow::Error> {
use crate::seqvars::query::schema::{
GnomadOptions, Gnomads, PopulationFrequencies, PopulationFrequencyOptions,
};

let query = CaseQuery {
gnomad_genomes_enabled: query_gnomad_genomes_enabled,
gnomad_genomes_frequency: query_gnomad_genomes_frequency,
gnomad_genomes_heterozygous: query_gnomad_genomes_heteroplasmic,
gnomad_genomes_homozygous: query_gnomad_genomes_homoplasmic,
population_frequency: PopulationFrequencyOptions {
gnomad: GnomadOptions {
genomes_enabled: query_gnomad_genomes_enabled,
genomes_frequency: query_gnomad_genomes_frequency,
genomes_heterozygous: query_gnomad_genomes_heteroplasmic,
genomes_homozygous: query_gnomad_genomes_homoplasmic,
..Default::default()
},
..Default::default()
},
..Default::default()
};
let seq_var = SequenceVariant {
gnomad_genomes_an: seqvar_gnomad_genomes_an,
gnomad_genomes_het: seqvar_gnomad_genomes_het,
gnomad_genomes_hom: seqvar_gnomad_genomes_hom,
population_frequencies: PopulationFrequencies {
gnomad: Gnomads {
genomes_an: seqvar_gnomad_genomes_an,
genomes_het: seqvar_gnomad_genomes_het,
genomes_hom: seqvar_gnomad_genomes_hom,
..Default::default()
},
..Default::default()
},
chrom: "MT".to_string(),
reference: "G".into(),
alternative: "A".into(),
Expand Down
2 changes: 1 addition & 1 deletion src/seqvars/query/interpreter/regions_allowlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::seqvars::query::schema::{CaseQuery, GenomicRegion, Range, SequenceVar

/// Determine whether the `SequenceVariant` passes the regions allowlist filter.
pub fn passes(query: &CaseQuery, seqvar: &SequenceVariant) -> bool {
if let Some(region_allowlist) = &query.genomic_regions {
if let Some(region_allowlist) = &query.locus.genomic_regions {
if region_allowlist.is_empty() {
true
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/seqvars/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@

sorted_iter
.map(|res| res.expect("problem reading line after sorting by HGNC ID"))
.group_by(|by_hgnc_id| by_hgnc_id.hgnc_id.clone())

Check warning on line 297 in src/seqvars/query/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

use of deprecated method `itertools::Itertools::group_by`: Use .chunk_by() instead

warning: use of deprecated method `itertools::Itertools::group_by`: Use .chunk_by() instead --> src/seqvars/query/mod.rs:297:14 | 297 | .group_by(|by_hgnc_id| by_hgnc_id.hgnc_id.clone()) | ^^^^^^^^ | = note: `#[warn(deprecated)]` on by default
.into_iter()
.map(|(_, group)| {
group
Expand Down Expand Up @@ -520,7 +520,7 @@
trace_rss_now();

tracing::info!("Translating gene allow list...");
let hgnc_allowlist = if let Some(gene_allowlist) = &query.gene_allowlist {
let hgnc_allowlist = if let Some(gene_allowlist) = &query.locus.gene_allowlist {
if gene_allowlist.is_empty() {
None
} else {
Expand Down
28 changes: 14 additions & 14 deletions src/seqvars/query/output/variant_related.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,20 +398,20 @@ impl Frequency {
.gnomad_genomes(
NuclearFrequency::new(
seqvar.gnomad_genomes_af(),
seqvar.gnomad_genomes_an,
seqvar.gnomad_genomes_het,
seqvar.gnomad_genomes_hom,
seqvar.gnomad_genomes_hemi,
seqvar.population_frequencies.gnomad.genomes_an,
seqvar.population_frequencies.gnomad.genomes_het,
seqvar.population_frequencies.gnomad.genomes_hom,
seqvar.population_frequencies.gnomad.genomes_hemi,
)
.some_unless_empty(),
)
.gnomad_exomes(
NuclearFrequency::new(
seqvar.gnomad_exomes_af(),
seqvar.gnomad_exomes_an,
seqvar.gnomad_exomes_het,
seqvar.gnomad_exomes_hom,
seqvar.gnomad_exomes_hemi,
seqvar.population_frequencies.gnomad.exomes_an,
seqvar.population_frequencies.gnomad.exomes_het,
seqvar.population_frequencies.gnomad.exomes_hom,
seqvar.population_frequencies.gnomad.exomes_hemi,
)
.some_unless_empty(),
)
Expand All @@ -421,18 +421,18 @@ impl Frequency {
.gnomad_mtdna(
MtdnaFrequency::new(
seqvar.gnomad_genomes_af(),
seqvar.gnomad_genomes_an,
seqvar.gnomad_genomes_het,
seqvar.gnomad_genomes_hom,
seqvar.population_frequencies.gnomad.genomes_an,
seqvar.population_frequencies.gnomad.genomes_het,
seqvar.population_frequencies.gnomad.genomes_hom,
)
.some_unless_empty(),
)
.helixmtdb(
MtdnaFrequency::new(
seqvar.helixmtdb_af(),
seqvar.helix_an,
seqvar.helix_het,
seqvar.helix_hom,
seqvar.population_frequencies.helixmtdb.an,
seqvar.population_frequencies.helixmtdb.het,
seqvar.population_frequencies.helixmtdb.hom,
)
.some_unless_empty(),
)
Expand Down
Loading
Loading