def test_write_6(self): contact_file = ContactFile('RR') contact_map = ContactMap('1') contact_file.add(contact_map) for c in [('A', 1, 'B', 9, 0, 8, 0.7), ('A', 1, 'B', 10, 0, 8, 0.7), ('A', 2, 'B', 8, 0, 8, 0.9), ('A', 3, 'B', 12, 0, 8, 0.4)]: contact = Contact(c[1], c[3], c[6], distance_bound=(c[4], c[5])) contact.res1_chain = c[0] contact.res2_chain = c[2] contact_map.add(contact) contact_map.sequence = Sequence( '1', 'HLEGSIGILLKKHEIVFDGCHDFGRTYIWQMSDHLEGSIGILLKKHEIVFDGCHDFGRTYIWQMSD' ) f_name = create_tmp_f() with open(f_name, 'w') as f_out: CaspParser().write(f_out, contact_file) content = [ "PFRMAT RR", "MODEL 1", "HLEGSIGILLKKHEIVFDGCHDFGRTYIWQMSDHLEGSIGILLKKHEIVF", "DGCHDFGRTYIWQMSD", "A1 B9 0 8 0.700000", "A1 B10 0 8 0.700000", "A2 B8 0 8 0.900000", "A3 B12 0 8 0.400000", "ENDMDL", "END", ] with open(f_name, 'r') as f_in: output = f_in.read().splitlines() self.assertEqual(content, output) os.unlink(f_name)
def test_write_1(self): contact_file = ContactFile("RR") contact_file.target = "R9999" contact_file.author = "1234-5678-9000" contact_file.remark = ["Predictor remarks"] contact_file.method = ["Description of methods used", "Description of methods used"] contact_map = ContactMap("1") contact_file.add(contact_map) for c in [(1, 9, 0, 8, 0.7), (1, 10, 0, 8, 0.7), (2, 8, 0, 8, 0.9), (3, 12, 0, 8, 0.4)]: contact = Contact(c[0], c[1], c[4], distance_bound=(c[2], c[3])) contact_map.add(contact) contact_map.sequence = Sequence("1", "HLEGSIGILLKKHEIVFDGCHDFGRTYIWQMSD") contact_map.set_sequence_register() f_name = self.tempfile() with open(f_name, "w") as f_out: MemBrainParser().write(f_out, contact_file) content = [ "Helix Position Residue Helix Position Residue Probability", "Hx 1 H Hx 9 L 0.700000", "Hx 1 H Hx 10 L 0.700000", "Hx 2 L Hx 8 I 0.900000", "Hx 3 E Hx 12 K 0.400000", ] with open(f_name, "r") as f_in: output = f_in.read().splitlines() self.assertEqual(content, output)
def test_write_2(self): contact_file = ContactFile('RR') contact_map = ContactMap('1') contact_file.add(contact_map) for c in [(1, 9, 0, 8, 0.7), (1, 10, 0, 8, 0.7), (2, 8, 0, 8, 0.9), (3, 12, 0, 8, 0.4)]: contact = Contact(c[0], c[1], c[4], distance_bound=(c[2], c[3])) contact_map.add(contact) contact_map.sequence = Sequence('1', 'HLEGSIGILLKKHEIVFDGCHDFGRTYIWQMSD') f_name = create_tmp_f() with open(f_name, 'w') as f_out: CaspParser().write(f_out, contact_file) content = [ "PFRMAT RR", "MODEL 1", "HLEGSIGILLKKHEIVFDGCHDFGRTYIWQMSD", "1 9 0 8 0.700000", "1 10 0 8 0.700000", "2 8 0 8 0.900000", "3 12 0 8 0.400000", "ENDMDL", "END", ] with open(f_name, 'r') as f_in: output = f_in.read().splitlines() self.assertEqual(content, output) os.unlink(f_name)
def test_write_5(self): contact_file = ContactFile('RR') contact_map = ContactMap('1') contact_file.add(contact_map) for c in [(1, 9, 0, 8, 1.5), (1, 10, 0, 8, -0.3), (2, 8, 0, 8, 0.9), (3, 12, 0, 8, 0.4)]: contact = Contact(c[0], c[1], c[4], distance_bound=(c[2], c[3])) contact_map.add(contact) contact_map.sequence = Sequence( '1', 'HLEGSIGILLKKHEIVFDGCHDFGRTYIWQMSDHLEGSIGILLKKHEIVFDGCHDFGRTYIWQMSD' ) f_name = create_tmp_f() with open(f_name, 'w') as f_out: CaspParser().write(f_out, contact_file) content = [ "PFRMAT RR", "MODEL 1", "HLEGSIGILLKKHEIVFDGCHDFGRTYIWQMSDHLEGSIGILLKKHEIVF", "DGCHDFGRTYIWQMSD", "1 9 0 8 1.000000", "1 10 0 8 0.000000", "2 8 0 8 0.666667", "3 12 0 8 0.388889", "ENDMDL", "END", "", ] content = os.linesep.join(content) with open(f_name, 'r') as f_in: data = "".join(f_in.readlines()) self.assertEqual(content, data) os.unlink(f_name)
def test_write_1(self): contact_file = ContactFile('RR') contact_file.target = 'R9999' contact_file.author = '1234-5678-9000' contact_file.remark = ['Predictor remarks'] contact_file.method = [ 'Description of methods used', 'Description of methods used' ] contact_map = ContactMap('1') contact_file.add(contact_map) for c in [(1, 9, 0, 8, 0.7), (1, 10, 0, 8, 0.7), (2, 8, 0, 8, 0.9), (3, 12, 0, 8, 0.4)]: contact = Contact(c[0], c[1], c[4], distance_bound=(c[2], c[3])) contact_map.add(contact) contact_map.sequence = Sequence('1', 'HLEGSIGILLKKHEIVFDGCHDFGRTYIWQMSD') contact_map.set_sequence_register() f_name = create_tmp_f() with open(f_name, 'w') as f_out: ComsatParser().write(f_out, contact_file) content = [ "1 H 9 L Hx-Hx", "1 H 10 L Hx-Hx", "2 L 8 I Hx-Hx", "3 E 12 K Hx-Hx", ] with open(f_name, 'r') as f_in: output = f_in.read().splitlines() self.assertEqual(content, output) os.unlink(f_name)
def test_write_1(self): contact_file = ContactFile("test") contact_map = ContactMap("1") contact_file.add(contact_map) for c in [(1, 9, 0, 8, 0.7), (1, 10, 0, 8, 0.7), (2, 8, 0, 8, 0.9), (3, 12, 0, 8, 0.4)]: contact = Contact(c[0], c[1], c[4], distance_bound=(c[2], c[3])) contact_map.add(contact) contact_map.sequence = Sequence( "1", "HLEGSIGILLKKHEIVFDGCHDFGRTYIWQMSDHLEGSIGILLKKHEIVFDGCHDFGRTYIWQMSD" ) f_name = self.tempfile() # Not sure if bug in Python3 numpy or intended purpose [Implemented: 21.11.2016] mode = "wb" if sys.version_info.major == 3 else "w" with open(f_name, mode) as f_out: CCMpredParser().write(f_out, contact_file) content = [ "0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t6.999999999999999556e-01\t6.999999999999999556e-01\t0.000000000000000000e+00\t0.000000000000000000e+00", "0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t9.000000000000000222e-01\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00", "0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t4.000000000000000222e-01", "0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00", "0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00", "0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00", "0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00", "0.000000000000000000e+00\t9.000000000000000222e-01\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00", "6.999999999999999556e-01\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00", "6.999999999999999556e-01\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00", "0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00", "0.000000000000000000e+00\t0.000000000000000000e+00\t4.000000000000000222e-01\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00", ] with open(f_name, "r") as f_in: output = f_in.read().splitlines() self.assertEqual(content, output)
def test_write_1(self): contact_file = ContactFile('test') contact_map = ContactMap('A') contact_file.add(contact_map) for c in [(1, 9, 0, 8, 0.7), (1, 10, 0, 8, 0.7), (2, 8, 0, 8, 0.9), (3, 12, 0, 8, 0.4)]: contact = Contact(c[0], c[1], c[4], distance_bound=(c[2], c[3])) contact_map.add(contact) contact_map.sequence = Sequence('1', 'HLEGSIGILLKKHEIVFDGCHDFGRTYIWQMSDHLEGSIGILLKKHEIVFDGCHDFGRTYIWQMSD') contact_map.assign_sequence_register() f_name = create_tmp_f() with open(f_name, 'w') as f_out: GremlinParser().write(f_out, contact_file) content = [ "i j i_id j_id r_sco s_sco prob", "1 9 1_H 9_L 0.7 1.0 1.0", "1 10 1_H 10_L 0.7 1.0 1.0", "2 8 2_L 8_I 0.9 1.3 1.0", "3 12 3_E 12_K 0.4 0.6 1.0", "", ] content = os.linesep.join(content) with open(f_name, 'r') as f_in: data = "".join(f_in.readlines()) self.assertEqual(content, data) os.unlink(f_name)
def test_write_1(self): contact_file = ContactFile('RR') contact_file.target = 'R9999' contact_file.author = '1234-5678-9000' contact_file.remark = ['Predictor remarks'] contact_file.method = ['Description of methods used', 'Description of methods used'] contact_map = ContactMap('1') contact_file.add(contact_map) for c in [(1, 9, 0, 8, 0.7), (1, 10, 0, 8, 0.7), (2, 8, 0, 8, 0.9), (3, 12, 0, 8, 0.4)]: contact = Contact(c[0], c[1], c[4], distance_bound=(c[2], c[3])) contact_map.add(contact) contact_map.sequence = Sequence('1', 'HLEGSIGILLKKHEIVFDGCHDFGRTYIWQMSD') contact_map.assign_sequence_register() f_name = create_tmp_f() with open(f_name, 'w') as f_out: PsicovParser().write(f_out, contact_file) content = [ "1 9 0 8 0.700000", "1 10 0 8 0.700000", "2 8 0 8 0.900000", "3 12 0 8 0.400000", "", ] content = os.linesep.join(content) with open(f_name, 'r') as f_in: data = "".join(f_in.readlines()) self.assertEqual(content, data) os.unlink(f_name)
def test_write_1(self): contact_file = ContactFile('test') contact_map = ContactMap('1') contact_file.add(contact_map) for c in [(1, 9, 0, 8, 0.7), (1, 10, 0, 8, 0.7), (2, 8, 0, 8, 0.9), (3, 12, 0, 8, 0.4)]: contact = Contact(c[0], c[1], c[4], distance_bound=(c[2], c[3])) contact_map.add(contact) contact_map.sequence = Sequence( '1', 'HLEGSIGILLKKHEIVFDGCHDFGRTYIWQMSDHLEGSIGILLKKHEIVFDGCHDFGRTYIWQMSD' ) f_name = create_tmp_f() # Not sure if bug in Python3 numpy or intended purpose [Implemented: 21.11.2016] mode = 'wb' if sys.version_info.major == 3 else 'w' with open(f_name, mode) as f_out: CCMpredParser().write(f_out, contact_file) content = [ '0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t6.999999999999999556e-01\t6.999999999999999556e-01\t0.000000000000000000e+00\t0.000000000000000000e+00', '0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t9.000000000000000222e-01\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00', '0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t4.000000000000000222e-01', '0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00', '0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00', '0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00', '0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00', '0.000000000000000000e+00\t9.000000000000000222e-01\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00', '6.999999999999999556e-01\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00', '6.999999999999999556e-01\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00', '0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00', '0.000000000000000000e+00\t0.000000000000000000e+00\t4.000000000000000222e-01\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00\t0.000000000000000000e+00' ] with open(f_name, 'r') as f_in: output = f_in.read().splitlines() self.assertEqual(content, output) os.unlink(f_name)
def test_write_1(self): contact_file = ContactFile("test") contact_map = ContactMap("A") contact_file.add(contact_map) for c in [(1, 9, 0, 8, 0.7), (1, 10, 0, 8, 0.7), (2, 8, 0, 8, 0.9), (3, 12, 0, 8, 0.4)]: contact = Contact(c[0], c[1], c[4], distance_bound=(c[2], c[3])) contact_map.add(contact) contact_map.sequence = Sequence( "1", "HLEGSIGILLKKHEIVFDGCHDFGRTYIWQMSDHLEGSIGILLKKHEIVFDGCHDFGRTYIWQMSD" ) contact_map.set_sequence_register() f_name = self.tempfile() with open(f_name, "w") as f_out: GremlinParser().write(f_out, contact_file) content = [ "i j i_id j_id r_sco s_sco prob", "1 9 1_H 9_L 0.7 1.0 1.0", "1 10 1_H 10_L 0.7 1.0 1.0", "2 8 2_L 8_I 0.9 1.3 1.0", "3 12 3_E 12_K 0.4 0.6 1.0", ] with open(f_name, "r") as f_in: output = f_in.read().splitlines() self.assertEqual(content, output)
def test_write_5(self): contact_file = ContactFile("RR") contact_map = ContactMap("1") contact_file.add(contact_map) for c in [(1, 9, 0, 8, 1.5), (1, 10, 0, 8, -0.3), (2, 8, 0, 8, 0.9), (3, 12, 0, 8, 0.4)]: contact = Contact(c[0], c[1], c[4], distance_bound=(c[2], c[3])) contact_map.add(contact) contact_map.sequence = Sequence( "1", "HLEGSIGILLKKHEIVFDGCHDFGRTYIWQMSDHLEGSIGILLKKHEIVFDGCHDFGRTYIWQMSD" ) f_name = self.tempfile() with open(f_name, "w") as f_out: CaspParser().write(f_out, contact_file) content = [ "PFRMAT RR", "MODEL 1", "HLEGSIGILLKKHEIVFDGCHDFGRTYIWQMSDHLEGSIGILLKKHEIVF", "DGCHDFGRTYIWQMSD", "1 9 0 8 1.000000", "1 10 0 8 0.000000", "2 8 0 8 0.666667", "3 12 0 8 0.388889", "ENDMDL", "END", ] with open(f_name, "r") as f_in: output = f_in.read().splitlines() self.assertEqual(content, output)
def test_write_1(self): contact_file = ContactFile('RR') contact_file.target = 'R9999' contact_file.author = '1234-5678-9000' contact_file.remark = ['Predictor remarks'] contact_file.method = [ 'Description of methods used', 'Description of methods used' ] contact_map = ContactMap('1') contact_file.add(contact_map) for c in [(1, 9, 0, 8, 0.7), (1, 10, 0, 8, 0.7), (2, 8, 0, 8, 0.9), (3, 12, 0, 8, 0.4)]: contact = Contact(c[0], c[1], c[4], distance_bound=(c[2], c[3])) contact_map.add(contact) contact_map.sequence = Sequence('sequence_1', 'HLEGSIGILLKKHEIVFDGCHDFGRTYIWQMSD') contact_map.assign_sequence_register() f_name = create_tmp_f() with open(f_name, 'w') as f_out: PconsParser().write(f_out, contact_file) content = [ "##############################################################################", "PconsC3 result file", "Generated using ConKit", "##############################################################################", "Sequence number: 1", "Sequence name: sequence_1", "Sequence length: 33 aa.", "Sequence:", "HLEGSIGILLKKHEIVFDGCHDFGRTYIWQMSD", "", "", "Predicted contacts:", "Res1 Res2 Score", " 1 9 0.700000", " 1 10 0.700000", " 2 8 0.900000", " 3 12 0.400000", "", "##############################################################################", "", ] content = os.linesep.join(content) with open(f_name, 'r') as f_in: data = "".join(f_in.readlines()) self.assertEqual(content, data) os.unlink(f_name)
def test_write_1(self): contact_file = ContactFile("RR") contact_file.target = "R9999" contact_file.author = "1234-5678-9000" contact_file.remark = ["Predictor remarks"] contact_file.method = [ "Description of methods used", "Description of methods used" ] contact_map = ContactMap("1") contact_file.add(contact_map) for c in [(1, 9, 0, 8, 0.7), (1, 10, 0, 8, 0.7), (2, 8, 0, 8, 0.9), (3, 12, 0, 8, 0.4)]: contact = Contact(c[0], c[1], c[4], distance_bound=(c[2], c[3])) contact_map.add(contact) contact_map.sequence = Sequence("sequence_1", "HLEGSIGILLKKHEIVFDGCHDFGRTYIWQMSD") contact_map.set_sequence_register() f_name = self.tempfile() with open(f_name, "w") as f_out: PconsParser().write(f_out, contact_file) content = [ "##############################################################################", "PconsC3 result file", "Generated using ConKit", "##############################################################################", "Sequence number: 1", "Sequence name: sequence_1", "Sequence length: 33 aa.", "Sequence:", "HLEGSIGILLKKHEIVFDGCHDFGRTYIWQMSD", "", "", "Predicted contacts:", "Res1 Res2 Score", " 1 9 0.700000", " 1 10 0.700000", " 2 8 0.900000", " 3 12 0.400000", "", "##############################################################################", ] with open(f_name, "r") as f_in: output = f_in.read().splitlines() self.assertEqual(content, output)
def test_write_1(self): contact_file = ContactFile("RR") contact_file.target = "R9999" contact_file.author = "1234-5678-9000" contact_file.remark = ["Predictor remarks"] contact_file.method = ["Description of methods used", "Description of methods used"] contact_map = ContactMap("1") contact_file.add(contact_map) for c in [(1, 9, 0, 8, 0.7), (1, 10, 0, 8, 0.7), (2, 8, 0, 8, 0.9), (3, 12, 0, 8, 0.4)]: contact = Contact(c[0], c[1], c[4], distance_bound=(c[2], c[3])) contact_map.add(contact) contact_map.sequence = Sequence("1", "HLEGSIGILLKKHEIVFDGCHDFGRTYIWQMSD") contact_map.set_sequence_register() f_name = self.tempfile() with open(f_name, "w") as f_out: ComsatParser().write(f_out, contact_file) content = ["1 H 9 L Hx-Hx", "1 H 10 L Hx-Hx", "2 L 8 I Hx-Hx", "3 E 12 K Hx-Hx"] with open(f_name, "r") as f_in: output = f_in.read().splitlines() self.assertEqual(content, output)
def test_write_2(self): contact_file = ContactFile("test") contact_map = ContactMap("1") contact_file.add(contact_map) for c in [(1, 9, 0, 8, 0.7), (1, 10, 0, 8, 0.7), (2, 8, 0, 8, 0.9), (3, 12, 0, 8, 0.4)]: contact = Contact(c[0], c[1], c[4], distance_bound=(c[2], c[3])) contact_map.add(contact) contact_map.sequence = Sequence( "1", "HLEGSIGILLKKHEIVFDGCHDFGRTYIWQMSDHLEGSIGILLKKHEIVFDGCHDFGRTYIWQMSD" ) f_name = self.tempfile() # Not sure if bug in Python3 numpy or intended purpose [Implemented: 21.11.2016] with open(f_name, "w") as f_out: if sys.version_info.major == 3: with self.assertRaises(TypeError): CCMpredParser().write(f_out, contact_file) else: self.assertTrue(True)
def test_write_1(self): contact_file = ContactFile('RR') contact_file.target = 'R9999' contact_file.author = '1234-5678-9000' contact_file.remark = ['Predictor remarks'] contact_file.method = [ 'Description of methods used', 'Description of methods used' ] contact_map = ContactMap('1') contact_file.add(contact_map) for c in [(1, 9, 0, 8, 0.7), (1, 10, 0, 8, 0.7), (2, 8, 0, 8, 0.9), (3, 12, 0, 8, 0.4)]: contact = Contact(c[0], c[1], c[4], distance_bound=(c[2], c[3])) contact_map.add(contact) contact_map.sequence = Sequence('1', 'HLEGSIGILLKKHEIVFDGCHDFGRTYIWQMSD') contact_map.set_sequence_register() f_name = create_tmp_f() with open(f_name, 'w') as f_out: CaspParser().write(f_out, contact_file) content = [ "PFRMAT RR", "TARGET R9999", "AUTHOR 1234-5678-9000", "REMARK Predictor remarks", "METHOD Description of methods used", "METHOD Description of methods used", "MODEL 1", "HLEGSIGILLKKHEIVFDGCHDFGRTYIWQMSD", "1 9 0 8 0.700000", "1 10 0 8 0.700000", "2 8 0 8 0.900000", "3 12 0 8 0.400000", "ENDMDL", "END", ] with open(f_name, 'r') as f_in: output = f_in.read().splitlines() self.assertEqual(content, output) os.unlink(f_name)
def as_contactmap(self, distance_cutoff=8): """Create a :obj:`~conkit.core.contactmap.ContactMap` instance with the contacts present in this :obj:`~conkit.core.distogram.Distogram` instance. Parameters ---------- distance_cutoff : int, float The distance cutoff used to consider a residue pair within contact of each other Returns ------- :obj:`~conkit.core.contactmap.ContactMap` A contactmap with the contacts present in this distogram instance. """ contactmap = ContactMap("map_1") for dist in self: if dist.predicted_distance <= distance_cutoff: contact = dist.as_contact(distance_cutoff) contactmap.add(contact) if self.sequence is not None: contactmap.sequence = self.sequence._inplace(False) return contactmap
def test_write_6(self): contact_file = ContactFile("RR") contact_map = ContactMap("1") contact_file.add(contact_map) for c in [ ("A", 1, "B", 9, 0, 8, 0.7), ("A", 1, "B", 10, 0, 8, 0.7), ("A", 2, "B", 8, 0, 8, 0.9), ("A", 3, "B", 12, 0, 8, 0.4), ]: contact = Contact(c[1], c[3], c[6], distance_bound=(c[4], c[5])) contact.res1_chain = c[0] contact.res2_chain = c[2] contact_map.add(contact) contact_map.sequence = Sequence( "1", "HLEGSIGILLKKHEIVFDGCHDFGRTYIWQMSDHLEGSIGILLKKHEIVFDGCHDFGRTYIWQMSD" ) f_name = self.tempfile() with open(f_name, "w") as f_out: CaspParser().write(f_out, contact_file) content = [ "PFRMAT RR", "MODEL 1", "HLEGSIGILLKKHEIVFDGCHDFGRTYIWQMSDHLEGSIGILLKKHEIVF", "DGCHDFGRTYIWQMSD", "A1 B9 0 8 0.700000", "A1 B10 0 8 0.700000", "A2 B8 0 8 0.900000", "A3 B12 0 8 0.400000", "ENDMDL", "END", ] with open(f_name, "r") as f_in: output = f_in.read().splitlines() self.assertEqual(content, output)
def read(self, f_handle, f_id="pcons"): """Read a contact file Parameters ---------- f_handle Open file handle [read permissions] f_id : str, optional Unique contact file identifier Returns ------- :obj:`ContactFile <conkit.core.contactfile.ContactFile>` """ contact_file = ContactFile(f_id) contact_map = ContactMap("1") contact_file.add(contact_map) lines = iter([l.rstrip() for l in f_handle if l.rstrip()]) done = object() line = next(lines, done) seq = '' seq_id = 'seq_1' while line is not done: if not line: pass elif RE_GENERATED.match(line): contact_file.remark = line elif RE_SEQUENCE_NAME.match(line): seq_id = RE_SEQUENCE_NAME.match(line).group(1) elif RE_SEQUENCE.match(line): line = next(lines, done) while line is not done: if not line: break elif RE_CONTACT_HEADER.match(line): break elif RE_PRED_CONTACTS.match(line): break elif RE_CONTACT.match(line): break else: seq += line line = next(lines, done) if RE_CONTACT.match(line): res1_seq, res2_seq, raw_score = line.split() contact = Contact(int(res1_seq), int(res2_seq), float(raw_score)) contact_map.add(contact) line = next(lines, done) if seq: contact_map.sequence = Sequence(seq_id, seq) contact_file.method = 'Contact map predicted using Pcons' return contact_file
def read(self, f_handle, f_id="casp"): """Read a contact file into a :obj:`conkit.core.contactfile.ContactFile` instance Parameters ---------- f_handle Open file handle [read permissions] f_id : str, optional Unique contact file identifier Returns ------- :obj:`ContactFile <conkit.core.contactfile.ContactFile>` """ lines = [l.strip() for l in f_handle.readlines()] contact_file = ContactFile(f_id) it = iter(lines) while True: try: line = next(it) except StopIteration: break if RE_PRFMAT.match(line): continue elif RE_TARGET.match(line): contact_file.remark = RE_TARGET.match(line).group(1) elif RE_AUTHOR.match(line): contact_file.author = RE_AUTHOR.match(line).group(1) elif RE_REMARK.match(line): contact_file.remark = RE_REMARK.match(line).group(1) elif RE_METHOD.match(line): contact_file.method = RE_METHOD.match(line).group(1) elif RE_MODEL.match(line): contact_map = ContactMap(RE_MODEL.match(line).group(1)) seq_chunks = [] while True: try: line = next(it) except StopIteration: break if not line: break if RE_ENDMDL.match(line): break elif RE_END.match(line): break elif RE_SEQ.match(line): seq_chunks.append(line) else: res1_entry, res2_entry, lb, ub, raw_score = RE_SPLIT.split(line) # Split in case we have chain in inter-molecular scenarios res1_split = RE_RES.split(res1_entry) if len(res1_split) == 1: res1_chain, res1_seq = '', res1_split[0] elif len(res1_split) == 4: res1_chain, res1_seq = res1_split[1], res1_split[2] res2_split = RE_RES.split(res2_entry) if len(res2_split) == 1: res2_chain, res2_seq = '', res2_split[0] elif len(res2_split) == 4: res2_chain, res2_seq = res2_split[1], res2_split[2] contact = Contact(int(res1_seq), int(res2_seq), float(raw_score), distance_bound=(float(lb), float(ub))) contact.res1_chain = res1_chain contact.res2_chain = res2_chain contact.res1_altseq = int(res1_seq) contact.res2_altseq = int(res2_seq) contact_map.add(contact) if seq_chunks: seq = "".join(seq_chunks) sequence = Sequence('seq_{0}'.format(contact_map.id), seq) contact_map.sequence = sequence contact_map.assign_sequence_register() contact_file.add(contact_map) elif RE_END.match(line): break else: raise ValueError('Unrecognized line type. Please report this issue') return contact_file
def _read(self, structure, f_id, distance_cutoff, atom_type): """Read a contact file Parameters ---------- structure A :obj:`Structure <Bio.PDB.Structure.Structure>` instance f_id : str Unique contact file identifier distance_cutoff : int Distance cutoff for which to determine contacts atom_type : str Atom type between which distances are calculated Returns ------- :obj:`ContactFile <conkit.core.contactfile.ContactFile>` """ hierarchies = [] for model in structure: hierarchy = ContactFile(f_id + '_' + str(model.id)) chains = list(chain for chain in model) for chain in chains: self._remove_hetatm(chain) self._remove_atom(chain, atom_type) for chain1, chain2 in itertools.product(chains, chains): if chain1.id == chain2.id: # intra contact_map = ContactMap(chain1.id) else: # inter contact_map = ContactMap(chain1.id + chain2.id) for (atom1, atom2, distance) in self._chain_contacts(chain1, chain2): contact = Contact( atom1.resseq, atom2.resseq, round(1.0 - (distance / 100), 6), distance_bound=(0., float(distance_cutoff))) contact.res1_altseq = atom1.resseq_alt contact.res2_altseq = atom2.resseq_alt contact.res1 = atom1.resname contact.res2 = atom2.resname contact.res1_chain = atom1.reschain contact.res2_chain = atom2.reschain if distance_cutoff == 0 or distance < distance_cutoff: contact.define_match() contact_map.add(contact) if contact_map.empty: del contact_map else: if len(contact_map.id) == 1: contact_map.sequence = self._build_sequence(chain1) assert len(contact_map.sequence.seq) == len(chain1) else: contact_map.sequence = self._build_sequence(chain1) \ + self._build_sequence(chain2) assert len(contact_map.sequence.seq) \ == len(chain1) + len(chain2) hierarchy.add(contact_map) hierarchy.method = 'Contact map extracted from PDB ' + str(model.id) hierarchy.remark = [ 'The model id is the chain identifier, i.e XY equates to chain X and chain Y.', 'Residue numbers in column 1 are chain X, and numbers in column 2 are chain Y.' ] hierarchies.append(hierarchy) if len(hierarchies) > 1: msg = "Super-level to contact file not yet implemented. " \ "Parser returns hierarchy for top model only!" warnings.warn(msg, FutureWarning) return hierarchies[0]