From bcef1633716c3661678d9b5b864da9f98625e3c9 Mon Sep 17 00:00:00 2001
From: Martijn Vermaat <martijn@vermaat.name>
Date: Wed, 15 Oct 2014 10:53:33 +0200
Subject: [PATCH] Fix several error cases in LOVD2 getGS call

The `getGS` website view for LOVD2 would report "transcript not found" if
the genomic reference has multiple transcripts annotated or if the variant
description raises an error in the variant checker.
---
 mutalyzer/variantchecker.py | 32 ++++++++++++++++----------------
 tests/test_website.py       | 28 ++++++++++++++++++++++++++++
 2 files changed, 44 insertions(+), 16 deletions(-)

diff --git a/mutalyzer/variantchecker.py b/mutalyzer/variantchecker.py
index aabac6e0..65dd7056 100644
--- a/mutalyzer/variantchecker.py
+++ b/mutalyzer/variantchecker.py
@@ -1702,22 +1702,6 @@ def check_variant(description, output):
     record = GenRecord.GenRecord(output)
     record.record = retrieved_record
 
-    # Note: The GenRecord instance is carrying the sequence in .record.seq.
-    #       So is the Mutator instance in .mutator.orig.
-
-    mutator = Mutator(record.record.seq, output)
-
-    # Todo: If processing of the variant fails, we might still want to show
-    # information about the record, gene, transcript.
-
-    try:
-        process_variant(mutator, parsed_description, record, output)
-    except _VariantError:
-        return
-
-    output.addOutput('original', str(mutator.orig))
-    output.addOutput('mutated', str(mutator.mutated))
-
     # Create the legend.
     for gene in record.record.geneList:
         for transcript in sorted(gene.transcriptList, key=attrgetter('name')):
@@ -1735,6 +1719,22 @@ def check_variant(description, output):
                                   transcript.proteinProduct,
                                   transcript.linkMethod])
 
+    # Note: The GenRecord instance is carrying the sequence in .record.seq.
+    #       So is the Mutator instance in .mutator.orig.
+
+    mutator = Mutator(record.record.seq, output)
+
+    # Todo: If processing of the variant fails, we might still want to show
+    # information about the record, gene, transcript.
+
+    try:
+        process_variant(mutator, parsed_description, record, output)
+    except _VariantError:
+        return
+
+    output.addOutput('original', str(mutator.orig))
+    output.addOutput('mutated', str(mutator.mutated))
+
     # Chromosomal region (only for GenBank human transcript references).
     # This is still quite ugly code, and should be cleaned up once we have
     # a refactored mapping module.
diff --git a/tests/test_website.py b/tests/test_website.py
index 44d9e996..e579433a 100644
--- a/tests/test_website.py
+++ b/tests/test_website.py
@@ -553,6 +553,34 @@ class TestWebsite(MutalyzerTest):
         assert 'go to bottom' not in r.data
         assert '<input' not in r.data
 
+    @fix(database, cache('NG_012337.1'))
+    def test_getgs_coding_multiple_transcripts(self):
+        """
+        Test the /getGS interface on a coding description and genomic
+        reference with multiple transcripts.
+        """
+        r = self.app.get('/getGS',
+                         query_string={'variantRecord': 'NM_003002.2',
+                                       'forward': '1',
+                                       'mutationName': 'NG_012337.1:c.45A>T'},
+                         follow_redirects=False)
+        assert '/name-checker?' in r.location
+        assert 'description=NG_012337.1' in r.location
+
+    @fix(database, cache('NG_008939.1'))
+    def test_getgs_variant_error(self):
+        """
+        Test the /getGS interface on a variant description with an error.
+        """
+        # The error is that position c.45 is a C, not an A.
+        r = self.app.get('/getGS',
+                         query_string={'variantRecord': 'NM_000532.4',
+                                       'forward': '1',
+                                       'mutationName': 'NG_008939.1:c.45A>T'},
+                         follow_redirects=False)
+        assert '/name-checker?' in r.location
+        assert 'description=NG_008939.1' in r.location
+
     @fix(database, hg19, hg19_transcript_mappings)
     def test_variantinfo_g2c(self):
         """
-- 
GitLab