예제 #1
0
 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)
예제 #2
0
 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:
         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",
     ]
     with open(f_name, 'r') as f_in:
         output = f_in.read().splitlines()
     self.assertEqual(content, output)
     os.unlink(f_name)
예제 #3
0
 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)
예제 #4
0
 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 = 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",
         "",
         "##############################################################################",
     ]
     with open(f_name, 'r') as f_in:
         output = f_in.read().splitlines()
     self.assertEqual(content, output)
     os.unlink(f_name)
예제 #5
0
 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)
예제 #6
0
 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:
         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)
예제 #7
0
    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:`~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_{}".format(contact_map.id), seq)
                    contact_map.sequence = sequence
                    contact_map.set_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