Пример #1
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
Пример #2
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
Пример #3
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
Пример #4
0
 def test_res1_3(self):
     contact = Contact(1, 2, 1.0)
     with self.assertRaises(ValueError):
         contact.res1 = "8"
Пример #5
0
 def test_res1_2(self):
     contact = Contact(1, 2, 1.0)
     contact.res1 = "T"
     self.assertEqual("T", contact.res1)
Пример #6
0
 def test_res1_1(self):
     contact = Contact(1, 2, 1.0)
     contact.res1 = "ALA"
     self.assertEqual("A", contact.res1)
Пример #7
0
 def test_res1_2(self):
     contact = Contact(1, 2, 1.0)
     contact.res1 = 'T'
     self.assertEqual('T', contact.res1)
Пример #8
0
 def test_res1_1(self):
     contact = Contact(1, 2, 1.0)
     contact.res1 = 'ALA'
     self.assertEqual('A', contact.res1)
Пример #9
0
    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]