예제 #1
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))
예제 #2
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 %s differs" % k)
예제 #3
0
 def test_true_positive_1(self):
     contact = Contact(1, 2, 1.0)
     self.assertFalse(contact.true_positive)
     contact.true_positive = True
     self.assertTrue(contact.true_positive)
예제 #4
0
 def test_status_1(self):
     contact = Contact(1, 2000000, 1.0)
     self.assertEqual(ContactMatchState.unknown.value, contact.status)
     contact.true_positive = True
     self.assertEqual(ContactMatchState.true_positive.value, contact.status)
예제 #5
0
    def _read(self, structure, f_id, distance_cutoff, atom_type):
        """Read a contact file

        Parameters
        ----------
        structure
           A :obj:`~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:`~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.true_positive = True
                        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]