From e9972eed006d43e29aa1451798663f23bac4fb7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20M=C3=A9nager?= <herve.menager@pasteur.fr> Date: Wed, 6 Nov 2019 23:12:27 +0100 Subject: [PATCH] fix the last commit about missing gene names (commit 7143e9d0 on #139) --- ippisite/ippidb/models.py | 7 +++++-- ippisite/ippidb/tests.py | 20 +++++++++++++++++--- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/ippisite/ippidb/models.py b/ippisite/ippidb/models.py index 872e3751..f2e01079 100644 --- a/ippisite/ippidb/models.py +++ b/ippisite/ippidb/models.py @@ -251,7 +251,10 @@ class Protein(AutoFillableModel): gene_names = info["gene_names"] # put whatever name it find - self.gene_name = gene_names[0]["name"] + try: + self.gene_name = gene_names[0]["name"] + except IndexError: + pass # then try to find the primary, if present for gene_name in gene_names: if gene_name["type"] == "primary": @@ -283,7 +286,7 @@ class Protein(AutoFillableModel): return len(self.entry_name) > 0 def __str__(self): - return "{} ({})".format(self.uniprot_id, self.recommended_name_long) + return "{} ({})".format(self.uniprot_id, self.recommended_name_long or self.short_name) class Domain(AutoFillableModel): diff --git a/ippisite/ippidb/tests.py b/ippisite/ippidb/tests.py index 832dd501..dec2ff7e 100644 --- a/ippisite/ippidb/tests.py +++ b/ippisite/ippidb/tests.py @@ -17,7 +17,7 @@ from .models import ( create_tanimoto, update_compound_cached_properties, ) -from .models import DrugBankCompound +from .models import DrugBankCompound, Protein from .utils import FingerPrinter, mol2smi, smi2mol, smi2inchi, smi2inchikey @@ -433,7 +433,7 @@ class TestGetDoiInfo(TestCase): class TestGetPfamInfo(TestCase): - def test_create_protein(self): + def test_get_pfam_info(self): target = {"id": "bZIP_1", "description": "bZIP transcription factor"} resp = ws.get_pfam_info("PF00170") self.assertEqual(resp, target) @@ -461,8 +461,22 @@ class TestGetGooglePatentInfo(TestCase): ) +class TestProtein(TestCase): + def test_create_protein_no_gene_name(self): + # this test ensures that we can save a protein with no gene name + # in the DB + p = Protein() + p.uniprot_id= 'P00784' + try: + p.save() + except Exception as exc: + self.fail("exception {exc} raised while saving protein P00784") + + + + class TestGetPubMEDIdInfo(TestCase): - def test_create_protein(self): + def test_get_pubmed_info(self): target = { "title": "Gene List significance at-a-glance with" " GeneValorization.", "journal_name": "Bioinformatics (Oxford, England)", -- GitLab