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

fix: problem with variants in multi-stop codon txs (#95) #96

Merged
merged 6 commits into from
Apr 6, 2023
Merged
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
14 changes: 10 additions & 4 deletions src/mapper/altseq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ pub struct AltSeqBuilder {
pub reference_data: RefTranscriptData,
/// Whether the transcript reference amino acid sequence has multiple stop codons.
pub ref_has_multiple_stops: bool,
/// Position of the first stop codon in the reference amino acid. It is difficult
/// to handle transcripts with multiple stop codons, but we can make a reasonable
/// prediction up to the first stop codon. This rescues changes to the `p.Met1`.
pub first_stop_pos: Option<usize>,
}

impl AltSeqBuilder {
Expand All @@ -214,11 +218,13 @@ impl AltSeqBuilder {
panic!("Must initialize with HgvsVariant::CdsVariant");
}
let ref_has_multiple_stops = reference_data.aa_sequence.matches('*').count() > 1;
let first_stop_pos = reference_data.aa_sequence.find('*');

Self {
var_c,
reference_data,
ref_has_multiple_stops,
first_stop_pos,
}
}

Expand Down Expand Up @@ -433,7 +439,7 @@ impl AltSeqBuilder {
&self.reference_data.protein_accession,
&self.reference_data.aa_sequence,
is_substitution,
self.ref_has_multiple_stops,
self.ref_has_multiple_stops && self.first_stop_pos.map(|p| p <= start).unwrap_or(false),
)
}

Expand Down Expand Up @@ -465,7 +471,7 @@ impl AltSeqBuilder {
&self.reference_data.protein_accession,
&self.reference_data.aa_sequence,
false,
self.ref_has_multiple_stops,
self.ref_has_multiple_stops && self.first_stop_pos.map(|p| p <= start).unwrap_or(false),
)
}

Expand Down Expand Up @@ -496,7 +502,7 @@ impl AltSeqBuilder {
&self.reference_data.protein_accession,
&self.reference_data.aa_sequence,
false,
self.ref_has_multiple_stops,
self.ref_has_multiple_stops && self.first_stop_pos.map(|p| p <= start).unwrap_or(false),
)
}

Expand Down Expand Up @@ -975,7 +981,7 @@ impl AltSeqToHgvsp {
} else {
// is non-dup insertion
let start = *start as usize - 1;
let end = start as usize + 1;
let end = start + 1;

aa_start = Some(ProtPos {
aa: self.ref_seq()[(start - 1)..start].to_owned(),
Expand Down
10 changes: 8 additions & 2 deletions src/mapper/assembly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,12 +437,18 @@ mod test {
}

#[test]
fn test_fail_c_to_p_brca2() -> Result<(), anyhow::Error> {
fn test_c_to_p_brca2() -> Result<(), anyhow::Error> {
let mapper = build_mapper_38(true)?;
let hgvs_c = "NM_000059.3:c.7790delAAG";
let var_c = HgvsVariant::from_str(hgvs_c)?;

assert!(mapper.c_to_p(&var_c).is_err());
// NB: this used to fail in Python hgvs but works here now as we do not
// perform comprehensive validation yet (1 bp interval/position, but 3bp
// deleted).
assert_eq!(
"NP_000050.2:p.Glu2598LysfsTer50",
format!("{}", mapper.c_to_p(&var_c)?)
);

Ok(())
}
Expand Down
9 changes: 9 additions & 0 deletions src/mapper/variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1626,6 +1626,9 @@ mod test {
Ok(())
}

/// Check the case with multiple stop codons. We introduced a change in hgvs-rs
/// that does not handle multiple stop codons in the transcript sequence as
/// conservatively as the Python version.
#[test]
fn hgvs_c_to_p_multiple_stop_codons() -> Result<(), anyhow::Error> {
let hgvsc = "NM_999992.1:c.4G>A";
Expand Down Expand Up @@ -1904,6 +1907,12 @@ mod test {
run_gxp_test("tests/data/mapper/gcp/real.tsv", false)
}

/// Check for issues with variants affecting `Met1` leading to `p.Met1?`.
#[test]
fn real_met1() -> Result<(), anyhow::Error> {
run_gxp_test("tests/data/mapper/gcp/real-met1.tsv", false)
}

#[test]
fn noncoding() -> Result<(), anyhow::Error> {
run_gxp_test("tests/data/mapper/gcp/noncoding.tsv", false)
Expand Down
10 changes: 8 additions & 2 deletions src/normalizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1384,9 +1384,15 @@ mod test {

{
// gene BRCA2
//
// NB: this used to fail in Python hgvs but works here now as we do not
// perform comprehensive validation yet (1 bp interval/position, but 3bp
// deleted).
let raw = HgvsVariant::from_str("NM_000059.3:c.7790delAAG")?;
// with self.assertRaises(HGVSInvalidVariantError):
assert!(norm.normalize(&raw).is_err());
assert_eq!(
"NM_000059.3:c.7791delA",
format!("{}", norm.normalize(&raw)?)
);
}

Ok(())
Expand Down
3 changes: 3 additions & 0 deletions tests/data/mapper/gcp/real-met1.tsv
Git LFS file not shown
4 changes: 2 additions & 2 deletions tests/data/seqrepo_cache.fasta
Git LFS file not shown