def test_basic(self): """ nothing is specified """ path1 = DIRNAME + '/data/sample1.pdb' path2 = DIRNAME + '/data/sample2.pdb' p = PDBParser(PERMISSIVE=1) query_struct = p.get_structure(os.path.basename(path1), path1) against_struct = p.get_structure(os.path.basename(path2), path2) query_complex = Complex(query_struct) against_complex = Complex(against_struct) query_complex.get_fp() against_complex.get_fp() query_fp_string = query_complex.fp2str() against_fp_string = against_complex.fp2str() query = FPWithComplex(query_complex, query_fp_string) against = FPWithComplex(against_complex, against_fp_string) score1, score2, score3 = similarity_between(query, against) expected = {"score1": 118.00269647021572, "score3": 20, "score2": -8} actual = {"score1": score1, "score3": score2, "score2": score3} self.assertEqual(actual, expected)
def test_basic_with_epitope(self): """ epitope is specified """ path1 = DIRNAME + '/data/sample1.pdb' path2 = DIRNAME + '/data/sample2.pdb' p = PDBParser(PERMISSIVE=1) query_struct = p.get_structure(os.path.basename(path1), path1) against_struct = p.get_structure(os.path.basename(path2), path2) query_complex = Complex( query_struct, epitope=[211, 213, 214, 224, 225, 226, 227, 228, 229]) against_complex = Complex(against_struct, epitope=[216, 217, 218, 219, 220, 221]) query_complex.get_fp() against_complex.get_fp() query_fp_string = query_complex.fp2str() against_fp_string = against_complex.fp2str() query = FPWithComplex(query_complex, query_fp_string) against = FPWithComplex(against_complex, against_fp_string) score1, score2, score3 = similarity_between(query, against) expected = {'score1': 34.705754203703862, 'score3': 0, 'score2': 6} actual = {"score1": score1, "score2": score2, "score3": score3} self.assertEqual(actual, expected)
def test_basic_with_another_spinimage(self): """ non-default spinimage """ path1 = DIRNAME + '/data/sample1.pdb' path2 = DIRNAME + '/data/sample2.pdb' p = PDBParser(PERMISSIVE=1) query_struct = p.get_structure(os.path.basename(path1), path1) against_struct = p.get_structure(os.path.basename(path2), path2) query_complex = Complex(query_struct) against_complex = Complex(against_struct) query_complex.get_fp(spin_image_radius_step=2, spin_image_height_step=2, sphere_radius_step=2) against_complex.get_fp(spin_image_radius_step=2, spin_image_height_step=2, sphere_radius_step=2) query_fp_string = query_complex.fp2str() against_fp_string = against_complex.fp2str() query = FPWithComplex(query_complex, query_fp_string) against = FPWithComplex(against_complex, against_fp_string) score1, score2, score3 = similarity_between(query, against) expected = {'score1': 129.68169758476202, 'score3': 5, 'score2': 20} actual = {"score1": score1, "score2": score2, "score3": score3} self.assertEqual(actual, expected)
def test_with_epitope_another_cutoff(self): """ the similarity calculation cutoff is set to 5 """ path1 = DIRNAME + '/data/sample1.pdb' path2 = DIRNAME + '/data/sample2.pdb' p = PDBParser(PERMISSIVE=1) query_struct = p.get_structure(os.path.basename(path1), path1) against_struct = p.get_structure(os.path.basename(path2), path2) query_complex = Complex(query_struct) against_complex = Complex(against_struct) query_complex.get_fp() against_complex.get_fp() query_fp_string = query_complex.fp2str() against_fp_string = against_complex.fp2str() query = FPWithComplex(query_complex, query_fp_string) against = FPWithComplex(against_complex, against_fp_string) score1, score2, score3 = similarity_between(query, against, cutoff=5) expected = {"score1": 119.75339423551459, "score3": -8, "score2": 20} actual = {"score1": score1, "score2": score2, "score3": score3} self.assertEqual(actual, expected)
def score(query_pdb_path, against_pdb_path, query_fp_path=None, against_fp_path=None, query_epitope=[], against_epitope=[], spin_image_height_step=5, spin_image_radius_step=2, sphere_radius_step=2, cutoff=20.0, spin_image_radius_range=(0, 20), spin_image_height_range=(-30, 10), sphere_radius_range=(0, 20), callback=write_score_to_file, cbargs=[]): p = PDBParser(PERMISSIVE=1) query_struct = p.get_structure(os.path.basename(query_pdb_path), query_pdb_path) against_struct = p.get_structure(os.path.basename(against_pdb_path), against_pdb_path) query_complex = Complex(query_struct, query_epitope) against_complex = Complex(against_struct, against_epitope) if query_fp_path is None or against_fp_path is None: #if fp is not given query_complex.get_fp(spin_image_radius_step=spin_image_radius_step, spin_image_height_step=spin_image_height_step, sphere_radius_step=sphere_radius_step) against_complex.get_fp(spin_image_radius_step=spin_image_radius_step, spin_image_height_step=spin_image_height_step, sphere_radius_step=sphere_radius_step) query_fp_string = query_complex.fp2str() against_fp_string = against_complex.fp2str() else: #if fp is given, read them with open(query_fp_path, 'r') as f1, open(against_fp_path, 'r') as f2: query_fp_string = f1.read() against_fp_string = f2.read() query = FPWithComplex(query_complex, query_fp_string) against = FPWithComplex(against_complex, against_fp_string) score1, score2, score3 = similarity_between(query, against, cutoff=cutoff) #z1, z2, z3 = similarity_between (query, query, cutoff = cutoff) #the normalization constant #print score1, score2, score3 if callback is not None: callback((score1, score2, score3), *cbargs) return score1, score2, score3
def test_bitlength_230 (self): """ radius step is set to 2, test whether the legnth is 230 """ path = DIRNAME + '/data/sample1.pdb' p = PDBParser(PERMISSIVE=1) struct = p.get_structure(os.path.basename (path), path) complex = Complex (struct) complex.get_fp (spin_image_height_step = 2) actual_length = len(complex.fp2str ().split ('\n') [0].split (' ')) expected = 230 self.assertEqual (actual_length, expected)
def test_with_epitope_another_spinimage(self): """ Epitope is specified and non-default spinimage """ path1 = DIRNAME + '/data/sample1.pdb' path2 = DIRNAME + '/data/sample2.pdb' p = PDBParser(PERMISSIVE=1) query_struct = p.get_structure(os.path.basename(path1), path1) against_struct = p.get_structure(os.path.basename(path2), path2) query_complex = Complex( query_struct, epitope=[211, 213, 214, 224, 225, 226, 227, 228, 229]) against_complex = Complex(against_struct, epitope=[216, 217, 218, 219, 220, 221]) query_complex.get_fp(spin_image_radius_step=2, spin_image_height_step=2, sphere_radius_step=2) against_complex.get_fp(spin_image_radius_step=2, spin_image_height_step=2, sphere_radius_step=2) query_fp_string = query_complex.fp2str() against_fp_string = against_complex.fp2str() query = FPWithComplex(query_complex, query_fp_string) against = FPWithComplex(against_complex, against_fp_string) score1, score2, score3 = similarity_between(query, against) expected = {'score1': 35.771598481467343, 'score3': 2, 'score2': 6} actual = {"score1": score1, "score2": score2, "score3": score3} self.assertEqual(actual, expected)
def score (query_pdb_path, against_pdb_path, query_fp_path = None, against_fp_path = None, query_epitope = [], against_epitope = [], spin_image_height_step = 5, spin_image_radius_step = 2, sphere_radius_step = 2, cutoff = 20.0, spin_image_radius_range = (0, 20), spin_image_height_range = (-30, 10), sphere_radius_range = (0, 20), callback = write_score_to_file, cbargs=[]): p = PDBParser(PERMISSIVE=1) query_struct = p.get_structure(os.path.basename (query_pdb_path), query_pdb_path) against_struct = p.get_structure(os.path.basename (against_pdb_path), against_pdb_path) query_complex = Complex (query_struct, query_epitope) against_complex = Complex (against_struct, against_epitope) if query_fp_path is None or against_fp_path is None:#if fp is not given query_complex.get_fp(spin_image_radius_step = spin_image_radius_step, spin_image_height_step = spin_image_height_step, sphere_radius_step = sphere_radius_step) against_complex.get_fp(spin_image_radius_step = spin_image_radius_step, spin_image_height_step = spin_image_height_step, sphere_radius_step = sphere_radius_step) query_fp_string = query_complex.fp2str () against_fp_string = against_complex.fp2str () else: #if fp is given, read them with open (query_fp_path, 'r') as f1, open(against_fp_path, 'r') as f2: query_fp_string = f1.read () against_fp_string = f2.read () query = FPWithComplex (query_complex, query_fp_string) against = FPWithComplex (against_complex, against_fp_string) score1, score2, score3 = similarity_between (query, against, cutoff = cutoff) #z1, z2, z3 = similarity_between (query, query, cutoff = cutoff) #the normalization constant #print score1, score2, score3 if callback is not None: callback ((score1, score2, score3), *cbargs) return score1, score2, score3
def test_bitlength_110 (self): """ nothing is specified, test whether the legnth is 110 """ path = DIRNAME + '/data/sample1.pdb' p = PDBParser(PERMISSIVE=1) struct = p.get_structure(os.path.basename (path), path) complex = Complex (struct) complex.get_fp () actual_length = len(complex.fp2str ().split ('\n') [0].split (' ')) expected = 110 self.assertEqual (actual_length, expected) actual = complex.fp2str ()