diff --git a/ippisite/ippidb/tests.py b/ippisite/ippidb/tests.py index f9720708e183042e27b29b246c635c8bd5fd4585..ed1a17904e24745f18af1a925a7b71991ffd8fa4 100644 --- a/ippisite/ippidb/tests.py +++ b/ippisite/ippidb/tests.py @@ -13,7 +13,8 @@ from openbabel import vectorUnsignedInt, OBFingerprint from ippidb import ws, models from ippidb.ws import get_uniprot_info -from .models import Compound, CompoundTanimoto, create_tanimoto, update_compound_cached_properties, Symmetry +from .models import Compound, CompoundTanimoto, create_tanimoto, \ + update_compound_cached_properties, Symmetry from .models import DrugBankCompound from .utils import FingerPrinter, mol2smi, smi2mol, smi2inchi, smi2inchikey @@ -24,15 +25,18 @@ class MolSmiTestCase(TestCase): """ def setUp(self): - self.smiles_str = "C" - # the MOL version is also a valid regexp to validate arbitrary name in the openbabel-generated version - self.mol_str = "\n OpenBabel[0-9]{11}D\n\n 1 0 0 0 0 0 0 0 0 0999 V2000\n 1.0000 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\nM END\n" + self.smiles = "C" + # the MOL version is also a valid regexp to validate arbitrary name in + # the openbabel-generated version + self.mol = "\n OpenBabel[0-9]{11}D\n\n 1 0 0 0 0 0 0 0 " \ + " 0 0999 V2000\n 1.0000 0.0000 0.0000 C 0 0 0 0 " \ + " 0 0 0 0 0 0 0 0\nM END\n" def test_mol2smi(self): - self.assertEqual(mol2smi(self.mol_str), self.smiles_str) + self.assertEqual(mol2smi(self.mol), self.smiles) def test_smi2mol2smi(self): - self.assertTrue(re.compile(self.mol_str).match(smi2mol(self.smiles_str))) + self.assertTrue(re.compile(self.mol).match(smi2mol(self.smiles))) class SmiInchi(TestCase): @@ -41,8 +45,11 @@ class SmiInchi(TestCase): """ def setUp(self): - self.smiles_str = "CC(C)C(=O)C1=C(C(=C(C(=C1)C(=O)C2=CC=C(C=C2)OC3=CC=CC=C3)O)O)O" - self.inchi_str = "InChI=1S/C23H20O6/c1-13(2)19(24)17-12-18(22(27)23(28)21(17)26)20(25)14-8-10-16(11-9-14)29-15-6-4-3-5-7-15/h3-13,26-28H,1-2H3" + self.smiles_str = "CC(C)C(=O)C1=C(C(=C(C(=C1)C(=O)C2=CC=C(C=C2)" \ + "OC3=CC=CC=C3)O)O)O" + self.inchi_str = "InChI=1S/C23H20O6/c1-13(2)19(24)17-12-18(22" \ + "(27)23(28)21(17)26)20(25)14-8-10-16(11-9-14)29-15-6-4-3-" \ + "5-7-15/h3-13,26-28H,1-2H3" self.inchikey_str = "CVVQMBDTMYUWTR-UHFFFAOYSA-N" def test_smi2inchi(self): @@ -60,10 +67,14 @@ class FingerPrinterTestCase(TestCase): def setUp(self): self.fingerprinter = FingerPrinter("FP4") self.smiles = "CC" - self.fp = vectorUnsignedInt([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) + self.fp = vectorUnsignedInt([ + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) self.smiles_dict = {1: "CC", 2: "CCC"} - self.fp_dict = {1: vectorUnsignedInt([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]), - 2: vectorUnsignedInt([3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])} + self.fp_dict = { + 1: vectorUnsignedInt([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0]), + 2: vectorUnsignedInt([3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0])} self.tanimoto_dict = {1: 1.0, 2: 0.5} def test_fingerprints_available(self): @@ -84,13 +95,18 @@ class FingerPrinterTestCase(TestCase): self.assertEqualVUI(self.fingerprinter.fp(self.smiles), self.fp) def test_fp_dict(self): - self.assertEqualVUIdict(self.fingerprinter.fp_dict(self.smiles_dict), self.fp_dict) + self.assertEqualVUIdict(self.fingerprinter.fp_dict(self.smiles_dict), + self.fp_dict) def test_tanimoto_fps(self): - self.assertEqual(self.fingerprinter.tanimoto_fps(self.smiles, self.fp_dict), self.tanimoto_dict) + self.assertEqual(self.fingerprinter.tanimoto_fps(self.smiles, + self.fp_dict), + self.tanimoto_dict) def test_tanimoto_smiles(self): - self.assertEqual(self.fingerprinter.tanimoto_smiles(self.smiles, self.smiles_dict), self.tanimoto_dict) + self.assertEqual(self.fingerprinter.tanimoto_smiles(self.smiles, + self.smiles_dict), + self.tanimoto_dict) class FingerPrinterTestCaseCompound1ECFP4(TestCase): @@ -98,11 +114,14 @@ class FingerPrinterTestCaseCompound1ECFP4(TestCase): def setUp(self): self.fingerprinter = FingerPrinter("ECFP4") self.smiles = "CC(C)C(=O)c1cc(C(=O)c2ccc(Oc3ccccc3)cc2)c(O)c(O)c1O" - self.smiles_dict = {1: "CC(C)C(=O)c1cc(C(=O)c2ccc(Oc3ccccc3)cc2)c(O)c(O)c1O"} + self.smiles_dict = {1: "CC(C)C(=O)c1cc(C(=O)c2ccc(Oc3ccccc3)cc2)c(O)" + "c(O)c1O"} self.tanimoto_dict = {1: 1.0} def test_tanimoto_smiles(self): - self.assertEqual(self.fingerprinter.tanimoto_smiles(self.smiles, self.smiles_dict), self.tanimoto_dict) + self.assertEqual(self.fingerprinter.tanimoto_smiles(self.smiles, + self.smiles_dict), + self.tanimoto_dict) def create_dummy_compound(id_, smiles): @@ -169,31 +188,33 @@ class CompoundTanimotoTestCase(TestCase): def setUp(self): self.smiles_dict = {1: "CC", 2: "CCC"} - self.smiles_query = "CC" + self.query = "CC" for id_, smiles in self.smiles_dict.items(): create_dummy_compound(id_, smiles) def test_create(self): - create_tanimoto(self.smiles_query, "FP4") - ct = CompoundTanimoto.objects.get(id=1, canonical_smiles=self.smiles_query) + create_tanimoto(self.query, "FP4") + ct = CompoundTanimoto.objects.get(id=1, canonical_smiles=self.query) self.assertEqual(ct.tanimoto, 1.0) - ct = CompoundTanimoto.objects.get(id=2, canonical_smiles=self.smiles_query) + ct = CompoundTanimoto.objects.get(id=2, canonical_smiles=self.query) self.assertEqual(ct.tanimoto, 0.5) class CompoundTanimotoTestCaseCompound1ECFP4(TestCase): def setUp(self): - self.smiles_dict = {1: "CC(C)C(=O)c1cc(C(=O)c2ccc(Oc3ccccc3)cc2)c(O)c(O)c1O", - 2: "NC(=N)N[C@H](C1CCCCC1)C(=O)NCC(=O)N1CCC(CC1)c1cc(n[nH]1)-c1ccc(Cl)cc1Cl"} - self.smiles_query = "CC(C)C(=O)c1cc(C(=O)c2ccc(Oc3ccccc3)cc2)c(O)c(O)c1O" + self.smiles_dict = { + 1: "CC(C)C(=O)c1cc(C(=O)c2ccc(Oc3ccccc3)cc2)c(O)c(O)c1O", + 2: "NC(=N)N[C@H](C1CCCCC1)C(=O)NCC(=O)N1CCC(CC1)c1cc(n[nH]1)" + "-c1ccc(Cl)cc1Cl"} + self.query = "CC(C)C(=O)c1cc(C(=O)c2ccc(Oc3ccccc3)cc2)c(O)c(O)c1O" for id_, smiles in self.smiles_dict.items(): create_dummy_compound(id_, smiles) def test_create(self): - create_tanimoto(self.smiles_query, "ECFP4") - ct = CompoundTanimoto.objects.get(id=1, canonical_smiles=self.smiles_query) - ct2 = CompoundTanimoto.objects.get(id=2, canonical_smiles=self.smiles_query) + create_tanimoto(self.query, "ECFP4") + ct = CompoundTanimoto.objects.get(id=1, canonical_smiles=self.query) + ct2 = CompoundTanimoto.objects.get(id=2, canonical_smiles=self.query) self.assertEqual(ct.tanimoto, 1.0) self.assertEqual(float(ct2.tanimoto), 0.0971) @@ -341,6 +362,7 @@ class QueryCompoundViewsTestCase(TestCase): response = self.client.get(url) self.assertEqual(response.status_code, 200) + class TestGetDoiInfo(TestCase): """ Test retrieving information for a DOI entry @@ -348,8 +370,10 @@ class TestGetDoiInfo(TestCase): def test_get_doi_info(self): resp = ws.get_doi_info('10.1073/pnas.0805139105') - self.assertEqual(resp['title'], 'A quantitative atlas of mitotic phosphorylation') - self.assertEqual(resp['journal_name'], 'Proceedings of the National Academy of Sciences') + self.assertEqual(resp['title'], 'A quantitative atlas of mitotic' + ' phosphorylation') + self.assertEqual(resp['journal_name'], 'Proceedings of the National' + ' Academy of Sciences') self.assertEqual(resp['biblio_year'], 2008) self.assertEqual(resp['authors_list'], 'Dephoure N., Zhou C., Villen J., Beausoleil S. A., ' @@ -365,24 +389,29 @@ class TestGetPfamInfo(TestCase): class TestGetGooglePatentInfo(TestCase): def test_it(self): - target = {'title': 'Secure virtual machine bootstrap in untrusted cloud infrastructures', + target = {'title': 'Secure virtual machine bootstrap in untrusted' + ' cloud infrastructures', 'journal_name': None, 'biblio_year': '2010', - 'authors_list': 'Fabio R. Maino, Pere Monclus, David A. McGrew, Robert T. Bell, ' + 'authors_list': 'Fabio R. Maino, Pere Monclus, David A.' + ' McGrew, Robert T. Bell, ' 'Steven Joseph Rich, Cisco Technology Inc'} resp = ws.get_google_patent_info('US8856504') self.assertEqual(resp, target) def test_entry_not_found(self): - self.assertRaises(ws.PatentNotFound, ws.get_google_patent_info, 'US8856504US8856504US885US8856504US8856504') + self.assertRaises(ws.PatentNotFound, ws.get_google_patent_info, + 'US8856504US8856504US885US8856504US8856504') class TestGetPubMEDIdInfo(TestCase): def test_create_protein(self): - target = {'title': 'Gene List significance at-a-glance with GeneValorization.', + target = {'title': 'Gene List significance at-a-glance with' + ' GeneValorization.', 'journal_name': 'Bioinformatics (Oxford, England)', 'biblio_year': '2011', - 'authors_list': 'Brancotte B, Biton A, Bernard-Pierrot I, Radvanyi F, Reyal F, Cohen-Boulakia S'} + 'authors_list': 'Brancotte B, Biton A, Bernard-Pierrot I, ' + 'Radvanyi F, Reyal F, Cohen-Boulakia S'} resp = ws.get_pubmed_info('21349868') self.assertEqual(resp, target) @@ -394,27 +423,37 @@ class TestGetUniprotInfo(TestCase): def test_get_uniprot_info(self): resp = get_uniprot_info('Q15286') - self.assertEqual(resp['recommended_name'], 'Ras-related protein Rab-35') + self.assertEqual(resp['recommended_name'], + 'Ras-related protein Rab-35') self.assertEqual(resp['organism'], 9606) self.assertEqual(resp['gene_id'], 11021) - exp_gene_names = [{'name': 'RAB35', 'type': 'primary'}, {'name': 'RAB1C', 'type': 'synonym'}, + exp_gene_names = [{'name': 'RAB35', 'type': 'primary'}, + {'name': 'RAB1C', 'type': 'synonym'}, {'name': 'RAY', 'type': 'synonym'}] self.assertEqual(sorted(resp['gene_names'], key=lambda k: k['name']), sorted(exp_gene_names, key=lambda k: k['name'])) self.assertEqual(resp['entry_name'], 'RAB35_HUMAN') self.assertEqual(resp['short_name'], 'RAB35') - exp_molecular_functions = ['GO_0003924', 'GO_0005525', 'GO_0005546', 'GO_0019003'] - self.assertEqual(sorted(resp['molecular_functions']), sorted(exp_molecular_functions)) - exp_cellular_localisations = ['GO_0000139', 'GO_0005829', 'GO_0005886', 'GO_0005905', 'GO_0010008', - 'GO_0030665', 'GO_0031253', 'GO_0042470', 'GO_0045171', 'GO_0045334', - 'GO_0055038', 'GO_0070062', 'GO_0098993'] - self.assertEqual(sorted(resp['cellular_localisations']), sorted(exp_cellular_localisations)) - exp_biological_processes = ['GO_0000281', 'GO_0006886', 'GO_0008104', 'GO_0016197', - 'GO_0019882', 'GO_0031175', 'GO_0032456', 'GO_0032482', - 'GO_0036010', 'GO_0048227', 'GO_1990090'] - self.assertEqual(sorted(resp['biological_processes']), sorted(exp_biological_processes)) + exp_molecular_functions = ['GO_0003924', 'GO_0005525', 'GO_0005546', + 'GO_0019003'] + self.assertEqual(sorted(resp['molecular_functions']), + sorted(exp_molecular_functions)) + exp_cellular_localisations = ['GO_0000139', 'GO_0005829', 'GO_0005886', + 'GO_0005905', 'GO_0010008', 'GO_0030665', + 'GO_0031253', 'GO_0042470', 'GO_0045171', + 'GO_0045334', 'GO_0055038', 'GO_0070062', + 'GO_0098993'] + self.assertEqual(sorted(resp['cellular_localisations']), + sorted(exp_cellular_localisations)) + exp_biological_processes = ['GO_0000281', 'GO_0006886', 'GO_0008104', + 'GO_0016197', 'GO_0019882', 'GO_0031175', + 'GO_0032456', 'GO_0032482', 'GO_0036010', + 'GO_0048227', 'GO_1990090'] + self.assertEqual(sorted(resp['biological_processes']), + sorted(exp_biological_processes)) exp_accessions = ['Q15286', 'B2R6E0', 'B4E390'] - self.assertEqual(sorted(resp['accessions']), sorted(exp_accessions)) + self.assertEqual(sorted(resp['accessions']), + sorted(exp_accessions)) exp_citations = [ {'doi': '10.1006/bbrc.1994.2889', 'pmid': '7811277'}, {'doi': '10.1038/ng1285', 'pmid': '14702039'}, @@ -433,9 +472,11 @@ class TestGetUniprotInfo(TestCase): ] self.assertEqual(sorted(exp_citations, key=lambda k: k['pmid']), sorted(resp['citations'], key=lambda k: k['pmid'])) - exp_alternative_names = [{'full': 'GTP-binding protein RAY'}, {'full': 'Ras-related protein Rab-1C'}] - self.assertEqual(sorted(exp_alternative_names, key=lambda k: k['full']), - sorted(resp['alternative_names'], key=lambda k: k['full'])) + exp_alternative_names = [{'full': 'GTP-binding protein RAY'}, + {'full': 'Ras-related protein Rab-1C'}] + self.assertEqual( + sorted(exp_alternative_names, key=lambda k: k['full']), + sorted(resp['alternative_names'], key=lambda k: k['full'])) def test_get_uniprot_info_domains(self): resp = get_uniprot_info('O00255') @@ -456,7 +497,8 @@ class TestGetPDBUniProtMapping(TestCase): self.assertEqual(len(resp), len(set(resp))) def test_entry_not_found(self): - self.assertRaises(ws.EntryNotFoundError, ws.get_pdb_uniprot_mapping, 'Xu85') + self.assertRaises(ws.EntryNotFoundError, ws.get_pdb_uniprot_mapping, + 'Xu85') class TestConvertIUPACToSMILESAndMore(TestCase): @@ -469,17 +511,27 @@ class TestConvertIUPACToSMILESAndMore(TestCase): ( '2,4,6-trinitrotoluene', { - "inchi": "InChI=1/C7H5N3O6/c1-4-6(9(13)14)2-5(8(11)12)3-7(4)10(15)16/h2-3H,1H3", - "stdinchi": "InChI=1S/C7H5N3O6/c1-4-6(9(13)14)2-5(8(11)12)3-7(4)10(15)16/h2-3H,1H3", + "inchi": "InChI=1/C7H5N3O6/c1-4-6(9(13)14)2-5(8(11)12)" + "3-7(4)10(15)16/h2-3H,1H3", + "stdinchi": "InChI=1S/C7H5N3O6/c1-4-6(9(13)14)2-5(8(11)" + "12)3-7(4)10(15)16/h2-3H,1H3", "stdinchikey": "SPSSULHKWOKEEL-UHFFFAOYSA-N", - "smiles": "[N+](=O)([O-])C1=C(C)C(=CC(=C1)[N+](=O)[O-])[N+](=O)[O-]", + "smiles": "[N+](=O)([O-])C1=C(C)C(=CC(=C1)[N+](=O)[O-])" + "[N+](=O)[O-]", } ), ( - '3-{1-oxo-6-[4-(piperidin-4-yl)butanamido]-2,3-dihydro-1H-isoindol-2-yl}propanoic acid', + '3-{1-oxo-6-[4-(piperidin-4-yl)butanamido]-2,3-dihydro-1H-' + 'isoindol-2-yl}propanoic acid', { - "inchi": "InChI=1/C20H27N3O4/c24-18(3-1-2-14-6-9-21-10-7-14)22-16-5-4-15-13-23(11-8-19(25)26)20(27)17(15)12-16/h4-5,12,14,21H,1-3,6-11,13H2,(H,22,24)(H,25,26)/f/h22,25H", - "stdinchi": "InChI=1S/C20H27N3O4/c24-18(3-1-2-14-6-9-21-10-7-14)22-16-5-4-15-13-23(11-8-19(25)26)20(27)17(15)12-16/h4-5,12,14,21H,1-3,6-11,13H2,(H,22,24)(H,25,26)", + "inchi": "InChI=1/C20H27N3O4/c24-18(3-1-2-14-6-9-21-10-" + "7-14)22-16-5-4-15-13-23(11-8-19(25)26)20(27)17" + "(15)12-16/h4-5,12,14,21H,1-3,6-11,13H2,(H,22," + "24)(H,25,26)/f/h22,25H", + "stdinchi": "InChI=1S/C20H27N3O4/c24-18(3-1-2-14-6-9-21" + "-10-7-14)22-16-5-4-15-13-23(11-8-19(25)26)" + "20(27)17(15)12-16/h4-5,12,14,21H,1-3,6-11," + "13H2,(H,22,24)(H,25,26)", "stdinchikey": "HWRXVANHVCXVHA-UHFFFAOYSA-N", "smiles": "O=C1N(CC2=CC=C(C=C12)NC(CCCC1CCNCC1)=O)CCC(=O)O" } @@ -490,16 +542,21 @@ class TestConvertIUPACToSMILESAndMore(TestCase): dict_returned = ws.convert_iupac_to_smiles_and_inchi(iupac) self.assertEqual(dict_expected["smiles"], dict_returned["smiles"]) self.assertEqual(dict_expected["inchi"], dict_returned["inchi"]) - self.assertEqual(dict_expected["stdinchi"], dict_returned["stdinchi"]) - self.assertEqual(dict_expected["stdinchikey"], dict_returned["stdinchikey"]) + self.assertEqual(dict_expected["stdinchi"], + dict_returned["stdinchi"]) + self.assertEqual(dict_expected["stdinchikey"], + dict_returned["stdinchikey"]) def test_invalid_entry(self): - self.assertRaises(ws.EntryNotFoundError, ws.convert_iupac_to_smiles_and_inchi, '3-{1-oxo-6-[4-(piperid') - self.assertRaises(ws.EntryNotFoundError, ws.convert_iupac_to_smiles_and_inchi, None) + self.assertRaises(ws.EntryNotFoundError, + ws.convert_iupac_to_smiles_and_inchi, + '3-{1-oxo-6-[4-(piperid') + self.assertRaises(ws.EntryNotFoundError, + ws.convert_iupac_to_smiles_and_inchi, None) class DuplicateGeneNameTestCase(TestCase): def test_works(self): models.Protein.objects.get_or_create(uniprot_id='P12497') - models.Protein.objects.get_or_create(uniprot_id='P0C6F2') \ No newline at end of file + models.Protein.objects.get_or_create(uniprot_id='P0C6F2')