diff --git a/ippisite/ippidb/models.py b/ippisite/ippidb/models.py index 872e37518818704932a8d11419ef516d94dd3d6b..f2e01079291a32956bd6d3b393cf113c814f8d8f 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 832dd50163af0f2db37b017ece7ef32e5ae24bf3..dec2ff7ee625d6bd202bba436f569902016172f7 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)",