From 18e228a6f732904b4762c010da6f757fccbe99d4 Mon Sep 17 00:00:00 2001
From: Martijn Vermaat <martijn@vermaat.name>
Date: Mon, 10 Oct 2011 14:43:31 +0000
Subject: [PATCH] Give an error on protein reference sequences

Until protein reference sequences are supported, give an error with a message
instead of crashing. Fixes #62.


git-svn-id: https://humgenprojects.lumc.nl/svn/mutalyzer/trunk@388 eb6bd6ab-9ccd-42b9-aceb-e2899b4a52f1
---
 mutalyzer/Retriever.py       | 11 ++++++++++-
 mutalyzer/parsers/genbank.py |  5 +++++
 tests/test_website.py        | 13 +++++++++++++
 3 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/mutalyzer/Retriever.py b/mutalyzer/Retriever.py
index d77f7fa6..ded70bcc 100644
--- a/mutalyzer/Retriever.py
+++ b/mutalyzer/Retriever.py
@@ -19,6 +19,7 @@ import StringIO        # StringIO()
 from Bio import SeqIO  # read()
 from Bio import Entrez # efetch(), read(), esearch(), esummary()
 from Bio.Seq import UnknownSeq
+from Bio.Alphabet import ProteinAlphabet
 from xml.dom import DOMException, minidom
 from xml.parsers import expat
 
@@ -734,7 +735,15 @@ class GenBankRetriever(Retriever):
 
         # Now we have the file, so we can parse it.
         GenBankParser = genbank.GBparser()
-        return GenBankParser.create_record(filename)
+        record = GenBankParser.create_record(filename)
+
+        # Todo: This will change once we support protein references
+        if isinstance(record.seq.alphabet, ProteinAlphabet):
+            self._output.addMessage(__file__, 4, 'EPROTEINREF',
+                                    'Protein reference sequences are not supported.')
+            return None
+
+        return record
     #loadrecord
 #GenBankRetriever
 
diff --git a/mutalyzer/parsers/genbank.py b/mutalyzer/parsers/genbank.py
index 0e5bf2ee..060e9a52 100644
--- a/mutalyzer/parsers/genbank.py
+++ b/mutalyzer/parsers/genbank.py
@@ -6,6 +6,7 @@ mutalyzer GenRecord. Record populated with data from a GenBank file.
 
 import bz2
 from Bio import SeqIO, Entrez
+from Bio.Alphabet import ProteinAlphabet
 
 from mutalyzer.config import Config
 from mutalyzer import Db
@@ -455,6 +456,10 @@ class GBparser():
 
         record.version = biorecord.id.split('.')[1]
 
+        # Todo: This will change once we support protein references
+        if isinstance(biorecord.seq.alphabet, ProteinAlphabet):
+            return record
+
         exonList = []
         geneDict = {}
 
diff --git a/tests/test_website.py b/tests/test_website.py
index 29ba034f..97a67cd5 100644
--- a/tests/test_website.py
+++ b/tests/test_website.py
@@ -175,6 +175,19 @@ class TestWSGI():
                       '0 Warnings',
                       'Details of the parse error')
 
+    def test_check_protein_reference(self):
+        """
+        Submit the name checker form with a protein reference sequence (not
+        supported).
+        """
+        r = self.app.get('/check')
+        form = r.forms[0]
+        form['mutationName'] = 'BAA81889.1:c.274G>T'
+        r = form.submit()
+        r.mustcontain('1 Error',
+                      '0 Warnings',
+                      'Protein reference sequences are not supported')
+
     def test_check_noninteractive(self):
         """
         Submit the name checker form non-interactively.
-- 
GitLab