예제 #1
0
    def as_contact(self, distance_cutoff):
        """Create a :obj:`~conkit.core.contact.Contact` instance with the information in this
        :obj:`~conkit.core.distance.Distance` instance.

        Parameters
        ----------
        distance_cutoff : int, float
           The distance cutoff used to consider a residue pair within contact of each other

        Returns
        -------
        :obj:`~conkit.core.contact.Contact`
            A contact with the information present in this distance instance.
        """
        if self.predicted_distance > distance_cutoff:
            contact = Contact(self.res1_seq,
                              self.res2_seq,
                              0,
                              distance_bound=(0, distance_cutoff))
        else:
            contact = Contact(self.res1_seq,
                              self.res2_seq,
                              self.raw_score,
                              distance_bound=(0, distance_cutoff))
        for attr in self.__slots__:
            if hasattr(contact, attr):
                setattr(contact, attr, getattr(self, attr))
        return contact
예제 #2
0
 def test_res1_chain_1(self):
     contact = Contact(1, 2, 1.0)
     self.assertEqual('', contact.res1_chain)
     contact.res1_chain = 'A'
     self.assertEqual('A', contact.res1_chain)
     contact.res1_chain = 'd'
     self.assertEqual('d', contact.res1_chain)
예제 #3
0
 def test__to_dict_1(self):
     contact = Contact(1, 2, 1.0)
     answer_dict = {
         'id': (1, 2),
         'is_match': False,
         'is_mismatch': False,
         'is_unknown': True,
         'distance_bound': (0.0, 8.0),
         'lower_bound': 0.0,
         'upper_bound': 8.0,
         'raw_score': 1.0,
         'res1': 'X',
         'res2': 'X',
         'res1_chain': '',
         'res2_chain': '',
         'res1_seq': 1,
         'res2_seq': 2,
         'res1_altseq': 0,
         'res2_altseq': 0,
         'scalar_score': 0.0,
         'status': 0,
         'weight': 1.0,
     }
     contact_dict = contact._to_dict()
     for k in answer_dict.keys():
         self.assertEqual(answer_dict[k], contact_dict[k],
                          "Key %s differs" % k)
예제 #4
0
    def read(self, f_handle, f_id="freecontact"):
        """Read a contact file

        Parameters
        ----------
        f_handle
           Open file handle [read permissions]
        f_id : str, optional
           Unique contact file identifier

        Returns
        -------
        :obj:`~conkit.core.contactfile.ContactFile`

        """
        hierarchy = ContactFile(f_id)
        contact_map = ContactMap("map_1")
        hierarchy.add(contact_map)
        for line in f_handle:
            line = line.strip()
            if line:
                res1_seq, res1, res2_seq, res2, raw_score, _ = RE_SPLIT.split(
                    line)
                contact = Contact(int(res1_seq), int(res2_seq),
                                  float(raw_score))
                contact.res1 = res1
                contact.res2 = res2
                contact_map.add(contact)
        hierarchy.method = "Contact map predicted using FreeContact"
        return hierarchy
예제 #5
0
 def test__to_dict_2(self):
     contact = Contact(1, 2, 1.0)
     contact.true_positive = True
     contact.lower_bound = 4
     answer_dict = {
         "id": (1, 2),
         "true_positive": True,
         "false_positive": False,
         "status_unknown": False,
         "distance_bound": (4.0, 8.0),
         "lower_bound": 4.0,
         "upper_bound": 8.0,
         "raw_score": 1.0,
         "res1": "X",
         "res2": "X",
         "res1_chain": "",
         "res2_chain": "",
         "res1_seq": 1,
         "res2_seq": 2,
         "res1_altseq": 0,
         "res2_altseq": 0,
         "scalar_score": 0.0,
         "status": 1,
         "weight": 1.0,
     }
     contact_dict = contact._to_dict()
     for k in answer_dict.keys():
         self.assertEqual(answer_dict[k], contact_dict[k],
                          "Key {} differs".format(k))
예제 #6
0
 def test_res2_chain_1(self):
     contact = Contact(1, 2, 1.0)
     self.assertEqual('', contact.res2_chain)
     contact.res2_chain = 'b'
     self.assertEqual('b', contact.res2_chain)
     contact.res2_chain = 'X'
     self.assertEqual('X', contact.res2_chain)
예제 #7
0
 def test_res1_chain_1(self):
     contact = Contact(1, 2, 1.0)
     self.assertEqual("", contact.res1_chain)
     contact.res1_chain = "A"
     self.assertEqual("A", contact.res1_chain)
     contact.res1_chain = "d"
     self.assertEqual("d", contact.res1_chain)
예제 #8
0
 def test_res2_chain_1(self):
     contact = Contact(1, 2, 1.0)
     self.assertEqual("", contact.res2_chain)
     contact.res2_chain = "b"
     self.assertEqual("b", contact.res2_chain)
     contact.res2_chain = "X"
     self.assertEqual("X", contact.res2_chain)
예제 #9
0
 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)
예제 #10
0
 def test_res2_seq_1(self):
     contact = Contact(1, 2000000, 1.0)
     self.assertEqual(2000000, contact.res2_seq)
     contact.res2_seq = 1
     self.assertEqual(1, contact.res2_seq)
     contact.res2_seq = 2000
     self.assertEqual(2000, contact.res2_seq)
     contact.res2_seq = 5
     self.assertEqual(5, contact.res2_seq)
예제 #11
0
 def test_res1_seq_1(self):
     contact = Contact(1, 2, 1.0)
     self.assertEqual(1, contact.res1_seq)
     contact.res1_seq = 2
     self.assertEqual(2, contact.res1_seq)
     contact.res1_seq = 5
     self.assertEqual(5, contact.res1_seq)
     contact.res1_seq = 1
     self.assertEqual(1, contact.res1_seq)
예제 #12
0
 def test_raw_score_1(self):
     contact = Contact(1, 2, 1.0)
     self.assertEqual(1.0, contact.raw_score)
     contact.raw_score = 0.3
     self.assertEqual(0.3, contact.raw_score)
     contact.raw_score = -0.1
     self.assertEqual(-0.1, contact.raw_score)
     contact.raw_score = 1.0
     self.assertEqual(1.0, contact.raw_score)
예제 #13
0
 def test_distance_bound_3(self):
     contact = Contact(1, 2, 1.0)
     try:
         contact.distance_bound = (1, 100)
     except TypeError:
         self.fail("contact.distance_bound raised TypeError unexpectedly")
     with self.assertRaises(TypeError):
         contact.distance_bound = 8
     with self.assertRaises(TypeError):
         contact.distance_bound = "test"
예제 #14
0
    def read(self, f_handle, f_id="epcmap"):
        """Read a contact file

        Parameters
        ----------
        f_handle
           Open file handle [read permissions]
        f_id : str, optional
           Unique contact file identifier

        Returns
        -------
        :obj:`~conkit.core.contactfile.ContactFile`

        """

        hierarchy = ContactFile(f_id)
        _map = ContactMap("map_1")
        hierarchy.add(_map)

        for line in f_handle:
            line = line.strip().split()

            if not line or line[0].isalpha():
                continue

            elif line[0].isdigit():
                _contact = Contact(
                    int(line[0]), int(line[1]), float(line[4]), distance_bound=(float(line[2]), float(line[3]))
                )
                _map.add(_contact)

        hierarchy.method = "Contact map predicted using EPC-Map"

        return hierarchy
예제 #15
0
    def read(self, f_handle, f_id="ccmpred"):
        """Read a contact file

        Parameters
        ----------
        f_handle
           Open file handle [read permissions]
        f_id : str, optional
           Unique contact file identifier

        Returns
        -------
        :obj:`~conkit.core.contactfile.ContactFile`

        """
        contact_file = ContactFile(f_id)
        contact_file.method = "Contact map predicted using CCMpred"
        contact_map = ContactMap("map_1")
        contact_file.add(contact_map)

        # Bits ripped from Stefan Seemayer's script shipped with CCMpred
        mat = np.loadtxt(f_handle)
        if mat.size > 0:
            raw_contacts = self._get_contact_pairs(mat)
            for res1_seq, res2_seq, raw_score in zip(raw_contacts[0],
                                                     raw_contacts[1],
                                                     mat[raw_contacts]):
                if res1_seq > res2_seq:
                    continue
                # Matrix starts count at 0 so increment numbers by one straight away
                contact = Contact(int(res1_seq + 1), int(res2_seq + 1),
                                  float(raw_score))
                contact_map.add(contact)

        return contact_file
예제 #16
0
    def read(self, f_handle, f_id="plmdca"):
        """Read a contact file

        Parameters
        ----------
        f_handle
           Open file handle [read permissions]
        f_id : str, optional
           Unique contact file identifier

        Returns
        -------
        :obj:`~conkit.core.contactfile.ContactFile`

        """

        contact_file = ContactFile(f_id)
        contact_map = ContactMap("map_1")
        contact_file.add(contact_map)

        for line in f_handle:
            line = line.strip()

            if not line or line[0].isalpha():
                continue

            elif line[0].isdigit():
                res1_seq, res2_seq, raw_score = line.split(',')
                contact = Contact(int(res1_seq), int(res2_seq),
                                  float(raw_score))
                contact_map.add(contact)

        contact_file.method = 'Contact map predicted using plmDCA'

        return contact_file
예제 #17
0
 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)
예제 #18
0
 def test_write_3(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)
     f_name = create_tmp_f()
     with open(f_name, 'w') as f_out:
         CaspParser().write(f_out, contact_file)
     content = [
         "PFRMAT RR",
         "MODEL  1",
         "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)
예제 #19
0
    def read(self, f_handle, f_id="map_align"):
        """Read a contact file

        Parameters
        ----------
        f_handle
           Open file handle [read permissions]
        f_id : str, optional
           Unique contact file identifier

        Returns
        -------
        :obj:`~conkit.core.contactfile.ContactFile`

        """

        hierarchy = ContactFile(f_id)
        _map = ContactMap("map_1")
        hierarchy.add(_map)

        for line in f_handle:
            line = line.strip().split()

            if line[0] == "CON" and line[1].isdigit() and line[2].isdigit():
                _contact = Contact(int(line[1]), int(line[2]), float(line[3]))
                _map.add(_contact)

        hierarchy.method = "Contact map compatible with map_algin"

        return hierarchy
예제 #20
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:
         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)
예제 #21
0
 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)
예제 #22
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.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)
예제 #23
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.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)
예제 #24
0
    def read(self, f_handle, f_id="map_align"):
        """Read a contact file

        Parameters
        ----------
        f_handle
           Open file handle [read permissions]
        f_id : str, optional
           Unique contact file identifier
        Returns
        -------
        :obj:`~conkit.core.contactfile.ContactFile`
        """

        hierarchy = ContactFile(f_id)
        _map = ContactMap("map_1")
        hierarchy.add(_map)

        for line in f_handle:
            line = line.strip().split()

            if len(line) == 2 and line[0].isdigit() and line[1].isdigit():
                # Al-eigen has no score field so we assume score=0.5
                _contact = Contact(int(line[0]), int(line[1]), 0.5)
                _map.add(_contact)

        hierarchy.method = "Contact map compatible with Al-Eigen"

        return hierarchy
예제 #25
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)
예제 #26
0
 def test__reconstruct_1(self):
     hierarchy = Parser._reconstruct(Contact(1, 3, 1.0))
     self.assertTrue(isinstance(hierarchy, ContactFile))
     self.assertTrue(isinstance(hierarchy[0], ContactMap))
     self.assertTrue(isinstance(hierarchy[0][0], Contact))
     self.assertEqual((1, 3),
                      (hierarchy[0][0].res1_seq, hierarchy[0][0].res2_seq))
예제 #27
0
 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)
예제 #28
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)
예제 #29
0
 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)
예제 #30
0
파일: membrain.py 프로젝트: nissmogt/conkit
    def read(self, f_handle, f_id="membrain"):
        """Read a contact file

        Parameters
        ----------
        f_handle
           Open file handle [read permissions]
        f_id : str, optional
           Unique contact file identifier

        Returns
        -------
        :obj:`~conkit.core.contactfile.ContactFile`

        """

        hierarchy = ContactFile(f_id)
        contact_map = ContactMap("map_1")
        hierarchy.add(contact_map)

        for line in f_handle:
            line = line.rstrip()

            if not line:
                continue

            if RE_HEADER.match(line):
                continue

            else:
                _, res1_seq, res1, _, res2_seq, res2, raw_score = RE_SPLIT.split(
                    line)

                contact = Contact(int(res1_seq), int(res2_seq),
                                  float(raw_score))
                contact.res1 = res1
                contact.res2 = res2
                contact_map.add(contact)

        hierarchy.method = 'Contact map predicted using MemBrain'

        return hierarchy