def test_get_sas(self): """Test get_sas() function""" with utils.temporary_working_directory(): shutil.copy(os.path.join(TOPDIR, 'test', 'input', 'test.pdb'), '1abc.pdb') out = cryptosite.am_bmi.get_sas('1abc', 1.4) self.assertEqual(len(out), 60)
def test_read_ligand_data(self): """Test read_ligand_data() function""" with utils.temporary_working_directory() as tmpdir: cryptosite.patch_mapper.make_ligand_file('ligands.ids') xyz, ligands = cryptosite.patch_mapper.read_ligand_data() self.assertEqual(len(xyz), 16) self.assertEqual(len(ligands), 16)
def test_build_model_gaps(self): """Test build_model() with gaps""" import modeller.automodel def mocked_loopmodel_make(self): self.loop.outputs.append({ 'failure': None, 'name': 'input.pdb', 'Normalized DOPE score': -1. }) with utils.temporary_working_directory() as tmpdir: with open('alignment.pir', 'w') as fh: fh.write(">P1;XXX\n") fh.write("structureX:input.pdb:1:A:2:A::::\n") fh.write("A--A*\n") fh.write(">P1;xxx_X\n") fh.write("sequence:input::::::::\n") fh.write("AAAA*\n") with open('input.pdb', 'w') as fh: fh.write(pdb_line + '\n') fh.write(pdb_line[:25] + '2' + pdb_line[26:] + '\n') with utils.mocked_object(modeller.automodel.loopmodel, 'make', mocked_loopmodel_make): cleaning.build_model('XXX', ['A']) os.unlink('XXX_mdl.pdb')
def test_gather_features(self): """Test gather_features() function""" def mocked_get_cnc(apo): residues = {} for i, res in enumerate( ('ALA', 'MET', 'GLU', 'ASN', 'PHE', 'GLN', 'LYS', 'VAL', 'GLU', 'LYS', 'ILE', 'GLY')): residues[(res, i + 1, 'A')] = 42. return residues, ('1', '1') with utils.temporary_working_directory() as tmpdir: shutil.copy(os.path.join(TOPDIR, 'test', 'input', 'pm_XXX.pdb'), 'XXX_mdl.pdb') shutil.copy(os.path.join(TOPDIR, 'test', 'input', 'XXX_mdlA.sqc'), '.') shutil.copy(os.path.join(TOPDIR, 'test', 'input', 'XXX_mdlA.hcs'), '.') with utils.mocked_object(bmi_feature_parser, 'get_cnc', mocked_get_cnc): bmi_feature_parser.gather_features('XXX_mdl', ['A']) with open('XXX_mdlA.feat') as fh: data = fh.readlines() self.assertEqual(len(data), 96) self.assertEqual( data[0][:116], 'ATOM 1 N ALA A 1 -17.647 -2.542 37.435 ' '1.00 25.00 N' '\t12.16\t11.0\t42.0\t18.98\t-\t0.17\t0.0\t2.00')
def test_gather_features(self): """Test gather_features() function""" def mocked_get_cnc(apo): residues = {} for i, res in enumerate(('ALA', 'MET', 'GLU', 'ASN', 'PHE', 'GLN', 'LYS', 'VAL', 'GLU', 'LYS', 'ILE', 'GLY')): residues[(res, i + 1, 'A')] = 42. return residues, ('1', '1') with utils.temporary_working_directory() as tmpdir: shutil.copy(os.path.join(TOPDIR, 'test', 'input', 'pm_XXX.pdb'), 'XXX_mdl.pdb') shutil.copy(os.path.join(TOPDIR, 'test', 'input', 'XXX_mdlA.sqc'), '.') shutil.copy(os.path.join(TOPDIR, 'test', 'input', 'XXX_mdlA.hcs'), '.') with utils.mocked_object(bmi_feature_parser, 'get_cnc', mocked_get_cnc): bmi_feature_parser.gather_features('XXX_mdl', ['A']) with open('XXX_mdlA.feat') as fh: data = fh.readlines() self.assertEqual(len(data), 96) self.assertEqual(data[0][:116], 'ATOM 1 N ALA A 1 -17.647 -2.542 37.435 ' '1.00 25.00 N' '\t12.16\t11.0\t42.0\t18.98\t-\t0.17\t0.0\t2.00')
def test_read_ligand_data(self): """Test read_ligand_data() function""" with utils.temporary_working_directory(): cryptosite.patch_mapper.make_ligand_file('ligands.ids') xyz, ligands = cryptosite.patch_mapper.read_ligand_data() self.assertEqual(len(xyz), 16) self.assertEqual(len(ligands), 16)
def test_get_sas(self): """Test get_sas() function""" with utils.temporary_working_directory() as tmpdir: shutil.copy(os.path.join(TOPDIR, 'test', 'input', 'test.pdb'), '1abc.pdb') out = cryptosite.am_bmi.get_sas('1abc', 1.4) self.assertEqual(len(out), 60)
def test_get_cnc(self): """Test get_cnc() function""" with utils.temporary_working_directory() as tmpdir: shutil.copy(os.path.join(TOPDIR, 'test', 'input', 'test.pdb'), '1abc.pdb') res, num = bmi_feature_parser.get_cnc('1abc') self.assertEqual(len(res), 8) self.assertEqual(num, ('1', '1'))
def test_extract_chains(self): """Test extract_chains()""" fname = os.path.join(TOPDIR, 'test', 'input', 'test.pdb') with utils.temporary_working_directory() as tmpdir: tmp_pdb = os.path.join(tmpdir, 'test.pdb') shutil.copy(fname, tmp_pdb) chains = cryptosite.setup.extract_chains(tmp_pdb, ['B', 'A']) self.assertEqual(chains, ['A', 'B'])
def test_patchmap_feature(self): """Test patchmap_feature() function""" with utils.temporary_working_directory() as tmpdir: shutil.copy(os.path.join(TOPDIR, 'test', 'input', 'test.pdb'), '.') with mock_patch_dock_lig_score(): cryptosite.patch_mapper.patchmap_feature('test') with open('test.pdb.ptm') as fh: contents = fh.readlines() self.assertEqual(len(contents), 8)
def test_patchmap_feature(self): """Test patchmap_feature() function""" with utils.temporary_working_directory(): shutil.copy(os.path.join(TOPDIR, 'test', 'input', 'test.pdb'), '.') with mock_patch_dock_lig_score(): cryptosite.patch_mapper.patchmap_feature('test') with open('test.pdb.ptm') as fh: contents = fh.readlines() self.assertEqual(len(contents), 8)
def test_process_directory(self): """Test process_directory() function""" indir = os.path.join(TOPDIR, 'test', 'input', 'gather-inputs') inputs = os.path.join(TOPDIR, 'test', 'input') with utils.temporary_working_directory() as tmpdir: shutil.copy(os.path.join(inputs, 'XXX_mdl.bmiftr'), '.') cryptosite.gather.process_directory(indir) os.unlink('XXX.features') os.unlink('XXX.am')
def test_extract_chains_missing(self): """Test extract_chains() with missing chains""" fname = os.path.join(TOPDIR, 'test', 'input', 'test.pdb') with utils.temporary_working_directory() as tmpdir: tmp_pdb = os.path.join(tmpdir, 'test.pdb') shutil.copy(fname, tmp_pdb) self.assertRaises(cryptosite.setup.MissingChainsError, cryptosite.setup.extract_chains, tmp_pdb, ['A', 'C', 'D'])
def test_process_directory(self): """Test process_directory() function""" indir = os.path.join(TOPDIR, 'test', 'input', 'gather-inputs') inputs = os.path.join(TOPDIR, 'test', 'input') with utils.temporary_working_directory(): shutil.copy(os.path.join(inputs, 'XXX_mdl.bmiftr'), '.') cryptosite.gather.process_directory(indir) os.unlink('XXX.features') os.unlink('XXX.am')
def test_main(self): """Test complete run of predict""" indir = os.path.join(TOPDIR, 'test', 'input') with utils.temporary_working_directory(): shutil.copy(os.path.join(indir, 'XXX.features'), '.') shutil.copy(os.path.join(indir, 'XXX_mdl.pdb'), '.') with utils.mocked_object(pickle, 'load', mock_pickle_load): cryptosite.predict.predict('XXX.features', model='final') os.unlink('XXX.pol.pred') os.unlink('XXX.pol.pred.pdb')
def test_main(self): """Test complete run of predict""" indir = os.path.join(TOPDIR, 'test', 'input') with utils.temporary_working_directory() as tmpdir: shutil.copy(os.path.join(indir, 'XXX.features'), '.') shutil.copy(os.path.join(indir, 'XXX_mdl.pdb'), '.') with utils.mocked_object(pickle, 'load', mock_pickle_load): cryptosite.predict.predict('XXX.features', model='final') os.unlink('XXX.pol.pred') os.unlink('XXX.pol.pred.pdb')
def test_get_cnc_pockets(self): """Test get_cnc() parsing of pocket information""" with utils.temporary_working_directory() as tmpdir: os.mkdir('test_out') shutil.copy(os.path.join(TOPDIR, 'test', 'input', 'test_out.pdb'), 'test_out') shutil.copy(os.path.join(TOPDIR, 'test', 'input', 'test_info.txt'), 'test_out') with utils.mocked_object(subprocess, 'check_call', mock_check_call): res, num = bmi_feature_parser.get_cnc('test') self.assertAlmostEqual(res[('ALA', 2, 'A')], 0.0, places=1) self.assertAlmostEqual(res[('ALA', 1, 'A')], 0.8, places=1)
def test_main(self): """Test simple complete run of am_bmi""" with utils.temporary_working_directory() as tmpdir: shutil.copy(os.path.join(TOPDIR, 'test', 'input', 'pm.pdb.B10010001.pdb'), '.') with open('SnapList.txt', 'w') as fh: fh.write("pm.pdb.B10010001.pdb -100.0\n") fh.write("high-energy.pdb -10.0\n") subprocess.check_call(['cryptosite', 'am_bmi']) with open('am_features.out') as fh: lines = sorted(fh.readlines()) self.assertEqual(len(lines), 12) self.assertEqual(lines[0], 'ALA\t1\tA\t17.328\t12.02\t32.6\t48.0\n')
def test_main(self): """Test simple complete run of am_bmi""" with utils.temporary_working_directory(): shutil.copy( os.path.join(TOPDIR, 'test', 'input', 'pm.pdb.B10010001.pdb'), '.') with open('SnapList.txt', 'w') as fh: fh.write("pm.pdb.B10010001.pdb -100.0\n") fh.write("high-energy.pdb -10.0\n") subprocess.check_call(['cryptosite', 'am_bmi']) with open('am_features.out') as fh: lines = sorted(fh.readlines()) self.assertEqual(len(lines), 12) self.assertEqual(lines[0], 'ALA\t1\tA\t17.328\t12.02\t32.6\t48.0\n')
def test_build_model_no_gaps(self): """Test build_model() with no gaps""" with utils.temporary_working_directory() as tmpdir: with open('alignment.pir', 'w') as fh: fh.write(">P1;XXX\n") fh.write("structureX:input.pdb:1:A:1:A::::\n") fh.write("A*\n") fh.write(">P1;xxx_X\n") fh.write("sequence:input::::::::\n") fh.write("A*\n") with open('input.pdb', 'w') as fh: fh.write(pdb_line + '\n') cleaning.build_model('XXX', ['A']) os.unlink('XXX_mdl.pdb')
def test_parse_blast(self): """Test parse_blast() function""" blast_out = os.path.join(TOPDIR, 'test', 'input', 'XXXA.blast') with utils.temporary_working_directory() as tmpdir: with utils.mocked_object(cryptosite.seq_conservation, 'ucluster', mock_ucluster): # Should get a ValueError if the sequences don't match self.assertRaises(ValueError, cryptosite.seq_conservation.parse_blast, blast_out, 'XXX', 'CC') cryptosite.seq_conservation.parse_blast(blast_out, 'XXX', 'AMENFQKVEKIGEGTYGVVYKARNKLTGEVVALKKIRVPSTAIREISLLKELNHPNIVKLLDVIHTENKLYLVFEFLHQDLKKFMDASALTGIPLPLIKSYLFQLLQGLAFCHSHRVLHRDLKPQNLLINTEGAIKLADFGLARAEVVTLWYRAPEILLGCKYYSTAVDIWSLGCIFAEMVTRRALFPGDSEIDQLFRIFRTLGTPDEVVWPGVTSMPDYKPSFPKWARQDFSKVVPPLDEDGRSLLSQMLHYDPNKRISAKAALAHPFFQDVTKPVPHLRL') os.unlink('XXX.ali') os.unlink('XXX.sqc')
def test_res_parser(self): """Test res_parser() function""" with utils.temporary_working_directory(): shutil.copy(os.path.join(TOPDIR, 'test', 'input', 'pm_XXX.pdb'), 'XXX_mdl.pdb') for inp in ('XXX_mdlA.feat', 'XXX_mdlA.sqc', 'XXX_mdl.sas', 'XXX_mdl.pdb.ptm'): shutil.copy(os.path.join(TOPDIR, 'test', 'input', inp), '.') res_parser_bmi.res_parser('XXX_mdl') with open('XXX_mdl.bmiftr') as fh: data = sorted(fh.readlines()) self.assertEqual(len(data), 3) self.assertEqual( data[1][:50], 'XXX_mdl\tALA\t1\tA\t2.298\t106.4\t-10.77\t0.0\t' 'U\t0.17\t0.0\t')
def test_main(self): """Test simple complete run of pockets""" with utils.temporary_working_directory() as tmpdir: shutil.copy( os.path.join(TOPDIR, 'test', 'input', 'pm.pdb.B10010001.pdb'), '.') with open('SnapList.txt', 'w') as fh: fh.write("pm.pdb.B10010001.pdb -100.0\n") fh.write("high-energy.pdb -10.0\n") subprocess.check_call(['cryptosite', 'pockets']) with open('pockets.out') as fh: lines = fh.readlines() self.assertEqual(len(lines), 13) self.assertEqual(lines[1], 'ALA\t1\tA\t0.0\n') self.assertEqual(lines[2], 'MET\t2\tA\t0.092\n')
def test_res_parser(self): """Test res_parser() function""" with utils.temporary_working_directory() as tmpdir: shutil.copy(os.path.join(TOPDIR, 'test', 'input', 'pm_XXX.pdb'), 'XXX_mdl.pdb') for inp in ('XXX_mdlA.feat', 'XXX_mdlA.sqc', 'XXX_mdl.sas', 'XXX_mdl.pdb.ptm'): shutil.copy(os.path.join(TOPDIR, 'test', 'input', inp), '.') res_parser_bmi.res_parser('XXX_mdl') with open('XXX_mdl.bmiftr') as fh: data = sorted(fh.readlines()) self.assertEqual(len(data), 3) self.assertEqual(data[1][:50], 'XXX_mdl\tALA\t1\tA\t2.298\t106.4\t-10.77\t0.0\t' 'U\t0.17\t0.0\t')
def test_soap_module(self): """Test soap script as a module""" with utils.temporary_working_directory() as tmpdir: for pdb in ('test.pdb', 'pm.pdb0.pdb', 'pm.pdb1.pdb', 'pm.pdb2.pdb', 'pm.pdb.B10010002.pdb'): fname = os.path.join(tmpdir, pdb) with open(fname, 'w') as fh: fh.write(""" ATOM 1 N CYS A 1 18.511 -1.416 15.632 1.00 6.84 C """) with utils.mocked_object(soap_protein_od, 'Scorer', MockScorer): cryptosite.soap.soap_score() with open('SnapList.txt') as fh: data = fh.readlines() # don't know glob order self.assertEqual(len(data), 2) self.assertTrue(re.match('pm\.pdb\d\.pdb\t10\.0', data[0])) self.assertTrue(re.match('pm\.pdb\d\.pdb\t20\.0', data[1]))
def test_HydChrSSE(self): """Test HydChrSSE() function""" with utils.temporary_working_directory() as tmpdir: shutil.copy(os.path.join(TOPDIR, 'test', 'input', 'test.pdb'), '1abc.pdb') hyd_chr_sse.HydChrSSE('1abc', 'A') with open('1ab_mdlA.hcs') as fh: data = fh.read() self.assertEqual( data, """ 1 \tA\t-\t0.17\t0 2 \tY\t-\t-0.94\t0 3 \tV\t-\t0.07\t0 4 \tI\t-\t-0.31\t0 5 \tT\t-\t0.14\t0 6 \tE\tS\t2.02\t-1 7 \tP\tT\t0.45\t0 8 \tC\tT\t-0.24\t0 9 \tI\t-\t-0.31\t0 """)
def test_HydChrSSE(self): """Test HydChrSSE() function""" with utils.temporary_working_directory() as tmpdir: shutil.copy(os.path.join(TOPDIR, 'test', 'input', 'test.pdb'), '1abc.pdb') hyd_chr_sse.HydChrSSE('1abc', 'A') with open('1ab_mdlA.hcs') as fh: data = fh.read() self.assertEqual(data, """ 1 \tA\t-\t0.17\t0 2 \tY\t-\t-0.94\t0 3 \tV\t-\t0.07\t0 4 \tI\t-\t-0.31\t0 5 \tT\t-\t0.14\t0 6 \tE\tS\t2.02\t-1 7 \tP\tT\t0.45\t0 8 \tC\tT\t-0.24\t0 9 \tI\t-\t-0.31\t0 """)
def test_build_model_gaps(self): """Test build_model() with gaps""" import modeller.automodel def mocked_loopmodel_make(self): self.loop.outputs.append({'failure':None, 'name':'input.pdb', 'Normalized DOPE score':-1.}) with utils.temporary_working_directory() as tmpdir: with open('alignment.pir', 'w') as fh: fh.write(">P1;XXX\n") fh.write("structureX:input.pdb:1:A:2:A::::\n") fh.write("A--A*\n") fh.write(">P1;xxx_X\n") fh.write("sequence:input::::::::\n") fh.write("AAAA*\n") with open('input.pdb', 'w') as fh: fh.write(pdb_line + '\n') fh.write(pdb_line[:25] + '2' + pdb_line[26:] + '\n') with utils.mocked_object(modeller.automodel.loopmodel, 'make', mocked_loopmodel_make): cleaning.build_model('XXX', ['A']) os.unlink('XXX_mdl.pdb')
def test_main(self): """Test of complete run of setup""" with utils.temporary_working_directory() as tmpdir: fname = os.path.join(TOPDIR, 'test', 'input', 'test.pdb') with utils.mocked_objects([ (cryptosite.cleaning, 'muscleAlign', mock_muscle_align), (cryptosite.seq_conservation, 'run_blast', mock_run_blast), (cryptosite.seq_conservation, 'parse_blast', mock_parse_blast), (cryptosite.cleaning, 'build_model', mock_build_model), (cryptosite.hyd_chr_sse, 'HydChrSSE', mock_HydChrSSE), (cryptosite.patch_mapper, 'patchmap_feature', mock_patchmap_feature), (cryptosite.bmi_feature_parser, 'gather_features', mock_gather_features), (cryptosite.res_parser_bmi, 'res_parser', mock_res_parser) ]): cryptosite.setup.setup(fname, ['A'], short=True) # Verify that AllosMod inputs were created os.unlink('XXX/align.ali') os.unlink('XXX/XXX.pdb') os.unlink('XXX/input.dat') os.unlink('XXX/list')
def test_main(self): """Test of complete run of setup""" with utils.temporary_working_directory() as tmpdir: fname = os.path.join(TOPDIR, 'test', 'input', 'test.pdb') with utils.mocked_objects( [(cryptosite.cleaning, 'muscleAlign', mock_muscle_align), (cryptosite.seq_conservation, 'run_blast', mock_run_blast), (cryptosite.seq_conservation, 'parse_blast', mock_parse_blast), (cryptosite.cleaning, 'build_model', mock_build_model), (cryptosite.hyd_chr_sse, 'HydChrSSE', mock_HydChrSSE), (cryptosite.patch_mapper, 'patchmap_feature', mock_patchmap_feature), (cryptosite.bmi_feature_parser, 'gather_features', mock_gather_features), (cryptosite.res_parser_bmi, 'res_parser', mock_res_parser)]): cryptosite.setup.setup(fname, ['A'], short=True) # Verify that AllosMod inputs were created os.unlink('XXX/align.ali') os.unlink('XXX/XXX.pdb') os.unlink('XXX/input.dat') os.unlink('XXX/list')
def test_ucluster(self): """Test ucluster() function""" with utils.temporary_working_directory(): with mock_usearch(): clusters = cryptosite.seq_conservation.ucluster('dummy.ali') self.assertEqual(len(clusters), 4)