Example #1
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
Example #2
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)
Example #3
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
Example #4
0
 def test_top_map_3(self):
     contact_file = ContactFile("test")
     contact_map1 = ContactMap("foo")
     contact_map2 = ContactMap("bar")
     contact_file.add(contact_map1)
     contact_file.add(contact_map2)
     self.assertEqual(contact_map1, contact_file.top_map)
Example #5
0
 def test_method_3(self):
     contact_file = ContactFile("test")
     contact_file.method = "Hello"
     contact_file.method = "5"
     contact_file.method = "World"
     contact_file.method = "!"
     self.assertEqual(["Hello", "5", "World", "!"], contact_file.method)
Example #6
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)
Example #7
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)
Example #8
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
Example #9
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)
Example #10
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)
Example #11
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
Example #12
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)
Example #13
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
Example #14
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
Example #15
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)
Example #16
0
 def test_remark_3(self):
     contact_file = ContactFile("test")
     contact_file.remark = "Hello"
     contact_file.remark = "5"
     contact_file.remark = "World"
     contact_file.remark = "!"
     self.assertEqual(["Hello", "5", "World", "!"], contact_file.remark)
Example #17
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)
Example #18
0
 def test_sort_4(self):
     contact_file = ContactFile("test")
     for map in [ContactMap("foo"), ContactMap("bar"), ContactMap("doe")]:
         contact_file.add(map)
     contact_file_sorted = contact_file.sort("id",
                                             reverse=True,
                                             inplace=True)
     self.assertEqual(["foo", "doe", "bar"],
                      [m.id for m in contact_file_sorted])
     self.assertEqual(contact_file, contact_file_sorted)
Example #19
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)
Example #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 = 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)
Example #21
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)
Example #22
0
    def read(self, f_handle, f_id="ncont"):
        """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 RE_CONTACT.match(line):
                matches = RE_CONTACT.match(line)
                res1_seq = int(matches.group(2))
                res2_seq = int(matches.group(5))
                lb = ub = float(matches.group(7))

                if (res1_seq, res2_seq) in contact_map:
                    msg = (
                        "This parser cannot handle multiple atoms of the same residue. "
                        "If your contact map contains such entries, only the first will be stored!"
                    )
                    warnings.warn(msg, Warning)
                    continue

                contact = Contact(res1_seq,
                                  res2_seq,
                                  1.0,
                                  distance_bound=(lb, ub))
                contact.res1_chain = matches.group(1)
                contact.res2_chain = matches.group(4)
                contact.res1 = matches.group(3)
                contact.res2 = matches.group(6)
                contact_map.add(contact)

        contact_file.method = "Contact map generated using Ncont"
        return contact_file
Example #23
0
    def read(self, f_handle, f_id="bbcontacts", del_one_two=False):
        """Read a contact file

        Parameters
        ----------
        f_handle
           Open file handle [read permissions]
        f_id : str, optional
           Unique contact file identifier
        del_one_two : bool
           Remove one- & two-strand sheets

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

        """

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

        previous = "first"
        for line in f_handle:
            line = line.strip()

            if line and not line.startswith("#"):
                _, _, _, raw_score, _, current, res2_seq, res1_seq = line.split(
                )
                if del_one_two and previous == "first" and current == "last":
                    contact_map.child_list.pop()
                elif any(value == "NA"
                         for value in [raw_score, res2_seq, res1_seq]):
                    pass
                else:
                    contact = Contact(int(res1_seq), int(res2_seq),
                                      float(raw_score))
                    contact_map.add(contact)
                previous = current

        if del_one_two and previous == "first" and len(contact_map) > 0:
            contact_map.child_list.pop()

        contact_file.method = "Contact map predicted using Bbcontacts"

        return contact_file
Example #24
0
 def test_write_3(self):
     contact_file = ContactFile("TEST")
     contact_maps = [ContactMap("A"), ContactMap("AB"), ContactMap("B")]
     contacts = [
         (Contact(1, 9, 0.7), Contact(1, 10, 0.7), Contact(2, 8, 0.9),
          Contact(3, 12, 0.4)),
         (Contact(1, 9, 0.7), Contact(1, 10, 0.7), Contact(2, 8, 0.9),
          Contact(3, 12, 0.4)),
         (Contact(1, 9, 0.7), Contact(1, 10, 0.7), Contact(2, 8, 0.9),
          Contact(3, 12, 0.4)),
     ]
     chains = [("A", "A"), ("A", "B"), ("B", "B")]
     for contact_map, contacts, chain in zip(contact_maps, contacts,
                                             chains):
         contact_file.add(contact_map)
         for c in contacts:
             c.res1_chain = chain[0]
             c.res2_chain = chain[1]
             contact_map.add(c)
         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	gene	i_id	j_id	r_sco	s_sco	prob	I_prob",
         "1	9	A	1_H	9_L	0.7	1.0	1.0	N/A",
         "1	10	A	1_H	10_L	0.7	1.0	1.0	N/A",
         "2	8	A	2_L	8_I	0.9	1.3	1.0	N/A",
         "3	12	A	3_E	12_K	0.4	0.6	1.0	N/A",
         "1	9	AB	1_H	9_L	0.7	1.0	1.0	N/A",
         "1	10	AB	1_H	10_L	0.7	1.0	1.0	N/A",
         "2	8	AB	2_L	8_I	0.9	1.3	1.0	N/A",
         "3	12	AB	3_E	12_K	0.4	0.6	1.0	N/A",
         "1	9	B	1_H	9_L	0.7	1.0	1.0	N/A",
         "1	10	B	1_H	10_L	0.7	1.0	1.0	N/A",
         "2	8	B	2_L	8_I	0.9	1.3	1.0	N/A",
         "3	12	B	3_E	12_K	0.4	0.6	1.0	N/A",
     ]
     with open(f_name, "r") as f_in:
         output = f_in.read().splitlines()
     self.assertEqual(content, output)
Example #25
0
    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
Example #26
0
 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)
Example #27
0
 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)
     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_X	9_X	0.7	1.0	1.0",
         "1	10	1_X	10_X	0.7	1.0	1.0",
         "2	8	2_X	8_X	0.9	1.3	1.0",
         "3	12	3_X	12_X	0.4	0.6	1.0",
     ]
     with open(f_name, "r") as f_in:
         output = f_in.read().splitlines()
     self.assertEqual(content, output)
Example #28
0
 def test_write_3(self):
     contact_file = ContactFile('TEST')
     contact_maps = [ContactMap('A'), ContactMap('AB'), ContactMap('B')]
     contacts = [(Contact(1, 9, 0.7), Contact(1, 10, 0.7), Contact(2, 8, 0.9), Contact(3, 12, 0.4)),
                 (Contact(1, 9, 0.7), Contact(1, 10, 0.7), Contact(2, 8, 0.9), Contact(3, 12, 0.4)),
                 (Contact(1, 9, 0.7), Contact(1, 10, 0.7), Contact(2, 8, 0.9), Contact(3, 12, 0.4))]
     chains = [('A', 'A'), ('A', 'B'), ('B', 'B')]
     for contact_map, contacts, chain in zip(contact_maps, contacts, chains):
         contact_file.add(contact_map)
         for c in contacts:
             c.res1_chain = chain[0]
             c.res2_chain = chain[1]
             contact_map.add(c)
         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	gene	i_id	j_id	r_sco	s_sco	prob	I_prob",
         "1	9	A	1_H	9_L	0.7	1.0	1.0	N/A",
         "1	10	A	1_H	10_L	0.7	1.0	1.0	N/A",
         "2	8	A	2_L	8_I	0.9	1.3	1.0	N/A",
         "3	12	A	3_E	12_K	0.4	0.6	1.0	N/A",
         "1	9	AB	1_H	9_L	0.7	1.0	1.0	N/A",
         "1	10	AB	1_H	10_L	0.7	1.0	1.0	N/A",
         "2	8	AB	2_L	8_I	0.9	1.3	1.0	N/A",
         "3	12	AB	3_E	12_K	0.4	0.6	1.0	N/A",
         "1	9	B	1_H	9_L	0.7	1.0	1.0	N/A",
         "1	10	B	1_H	10_L	0.7	1.0	1.0	N/A",
         "2	8	B	2_L	8_I	0.9	1.3	1.0	N/A",
         "3	12	B	3_E	12_K	0.4	0.6	1.0	N/A",
         "",
     ]
     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)
Example #29
0
 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)
     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_X	9_X	0.7	1.0	1.0",
         "1	10	1_X	10_X	0.7	1.0	1.0",
         "2	8	2_X	8_X	0.9	1.3	1.0",
         "3	12	3_X	12_X	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)
Example #30
0
    def read(self, f_handle, f_id="comsat"):
        """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.rstrip()

            if not line:
                continue

            else:
                res1_seq, res1, res2_seq, res2, _ = RE_SPLIT.split(line)
                contact = Contact(int(res1_seq), int(res2_seq), 0.0)
                contact.res1 = res1
                contact.res2 = res2

                contact_map.add(contact)

        contact_file.method = "Contact map predicted using COMSAT"

        return contact_file