From 302ba055e79103b1bc4b740d8d79330c1f88f704 Mon Sep 17 00:00:00 2001
From: Martijn Vermaat <martijn@vermaat.name>
Date: Mon, 10 Oct 2011 10:27:42 +0000
Subject: [PATCH] Accept IVS locations in Variant_info LOVD interface

The fix is a hack, basically copying the same functionality from the
namechecker. I think this should eventually be merged somehow.

Fixes #63


git-svn-id: https://humgenprojects.lumc.nl/svn/mutalyzer/trunk@387 eb6bd6ab-9ccd-42b9-aceb-e2899b4a52f1
---
 mutalyzer/Crossmap.py |  3 +--
 mutalyzer/mapping.py  | 32 ++++++++++++++++++++++----------
 tests/test_website.py |  9 +++++++++
 3 files changed, 32 insertions(+), 12 deletions(-)

diff --git a/mutalyzer/Crossmap.py b/mutalyzer/Crossmap.py
index cd289e3e..20fb8edc 100644
--- a/mutalyzer/Crossmap.py
+++ b/mutalyzer/Crossmap.py
@@ -428,8 +428,7 @@ class Crossmap() :
         @return: The converted notation (may be unaltered)
         @rtype: integer
         """
-
-        if s[0] == '*' :
+        if s[0] == '*':
             return self.__STOP + int(s[1:])
 
         return int(s)
diff --git a/mutalyzer/mapping.py b/mutalyzer/mapping.py
index 0cb27e7e..afc5b837 100644
--- a/mutalyzer/mapping.py
+++ b/mutalyzer/mapping.py
@@ -254,15 +254,27 @@ class Converter(object) :
         @rtype: triple (integer, integer, integer)
         """
         if Type == 'c' :
-            main = C.main2int(Loc.MainSgn +  Loc.Main)
-            offset = C.offset2int(Loc.OffSgn +  Loc.Offset)
-            g = C.x2g(main, offset)
-            main, offset = C.g2x(g)
-        #if
-        else :
-            g = int(Loc.Main)
+            if Loc.IVSLoc:
+                ivs_number = int(Loc.IVSLoc.IVSNumber)
+                if ivs_number < 1 or ivs_number > C.numberOfIntrons():
+                    # Todo: Error handling in this entire module is 'suboptimal'
+                    raise Exception('Invalid intron')
+                if Loc.IVSLoc.OffSgn == '+':
+                    g = C.getSpliceSite(ivs_number * 2 - 1) + \
+                        C.orientation * int(Loc.IVSLoc.Offset)
+                else:
+                    g = C.getSpliceSite(ivs_number * 2) - \
+                        C.orientation * int(Loc.IVSLoc.Offset)
+                main, offset = C.g2x(g)
+            else:
+                main = C.main2int(Loc.PtLoc.MainSgn +  Loc.PtLoc.Main)
+                offset = C.offset2int(Loc.PtLoc.OffSgn +  Loc.PtLoc.Offset)
+                g = C.x2g(main, offset)
+                main, offset = C.g2x(g)
+        else:
+            g = int(Loc.PtLoc.Main)
             main, offset = C.g2x(g)
-        #else
+
         return (main, offset, g)
     #_getcoords
 
@@ -285,13 +297,13 @@ class Converter(object) :
 
         # Get the coordinates of the start position
         startmain, startoffset, start_g = \
-                self._getcoords(Cross, mutation.StartLoc.PtLoc,
+                self._getcoords(Cross, mutation.StartLoc,
                                 self.parseTree.RefType)
 
         # If there is an end position, calculate the coordinates.
         if mutation.EndLoc :
             endmain, endoffset, end_g = \
-                self._getcoords(Cross, mutation.EndLoc.PtLoc,
+                self._getcoords(Cross, mutation.EndLoc,
                                 self.parseTree.RefType)
         else :
             end_g, endmain, endoffset = start_g, startmain, startoffset
diff --git a/tests/test_website.py b/tests/test_website.py
index 61a7206b..29ba034f 100644
--- a/tests/test_website.py
+++ b/tests/test_website.py
@@ -589,6 +589,15 @@ facilisi."""
         expected = '\n'.join(['-612', '7720', '2016'])
         assert_equal(r.body, expected)
 
+    def test_variantinfo_ivs(self):
+        """
+        Test the /Variant_info interface used by LOVD2 (with IVS positioning).
+        """
+        r = self.app.get('/Variant_info?LOVD_ver=2.0-33&build=hg19&acc=NM_000249.3&var=c.IVS10%2B3A%3EG')
+        assert_equal(r.content_type, 'text/plain')
+        expected = '\n'.join(['884', '3', '884', '3', '37059093', '37059093', 'subst'])
+        assert_equal(r.body, expected)
+
     def test_upload_local_file(self):
         """
         Test the genbank uploader.
-- 
GitLab