Exemplo n.º 1
0
    def get_score(self, ref):
        """Assigns scores (lrmsd, irmsd, fnat, dockQ, bin_class, capri_class) to a protein graph

        Args:
            ref (path): path to the reference structure required to compute the different score
        """

        ref_name = os.path.splitext(os.path.basename(ref))[0]
        sim = StructureSimilarity(self.pdb, ref)

        # Input pre-computed zone files
        if os.path.exists(ref_name + '.lzone'):
            self.score['lrmsd'] = sim.compute_lrmsd_fast(method='svd',
                                                         lzone=ref_name +
                                                         '.lzone')
            self.score['irmsd'] = sim.compute_irmsd_fast(method='svd',
                                                         izone=ref_name +
                                                         '.izone')

        # Compute zone files
        else:
            self.score['lrmsd'] = sim.compute_lrmsd_fast(method='svd')
            self.score['irmsd'] = sim.compute_irmsd_fast(method='svd')

        self.score['fnat'] = sim.compute_fnat_fast()
        self.score['dockQ'] = sim.compute_DockQScore(self.score['fnat'],
                                                     self.score['lrmsd'],
                                                     self.score['irmsd'])
        self.score['bin_class'] = self.score['irmsd'] < 4.0

        self.score['capri_class'] = 5
        for thr, val in zip([6.0, 4.0, 2.0, 1.0], [4, 3, 2, 1]):
            if self.score['irmsd'] < thr:
                self.score['capri_class'] = val
Exemplo n.º 2
0
def __compute_target__(decoy, targrp):
    """Calculate DOCKQ.

    Args:
        decoy(bytes): pdb data of the decoy
        targrp(hdf5 file handle): HDF5 'targets' group
    """
    tarname = 'DOCKQ'
    if tarname in targrp.keys():
        del targrp[tarname]
        warnings.warn(f"Removed old {tarname} from {targrp.parent.name}")

    tarelems = ['FNAT', 'LRMSD', 'IRMSD']
    vals = {}
    for tarelem in tarelems:
        # if target element exist, then use its value; otherwise calculate it
        if tarelem not in targrp:
            _ = rmsd_fnat.__compute_target__(decoy, targrp, tarelem)
        # empty dataset
        elif targrp[tarelem][()].shape is None:
            _ = rmsd_fnat.__compute_target__(decoy, targrp, tarelem)

        # get the value
        vals[tarelem] = targrp[tarelem][()]

    dockQ = StructureSimilarity.compute_DockQScore(
            vals['FNAT'], vals['LRMSD'], vals['IRMSD'])
    targrp.create_dataset(tarname, data=np.array(dockQ))
Exemplo n.º 3
0
    def get_score(self, ref):

        ref_name = os.path.splitext(os.path.basename(ref))[0]
        sim = StructureSimilarity(self.pdb, ref)

        self.score['lrmsd'] = sim.compute_lrmsd_fast(
            method='svd', lzone=ref_name+'.lzone')
        self.score['irmsd'] = sim.compute_irmsd_fast(
            method='svd', izone=ref_name+'.izone')
        self.score['fnat'] = sim.compute_fnat_fast()
        self.score['dockQ'] = sim.compute_DockQScore(
            self.score['fnat'], self.score['lrmsd'], self.score['irmsd'])
        self.score['binclass'] = self.score['irmsd'] < 4.0
Exemplo n.º 4
0
def __compute_target__(decoy, targrp):
    """Calculate CAPRI class.

        CAPRI class name and ID:
            - 'high': 0
            - 'medium': 1
            - 'accepetable': 2
            - 'incorrect': 3

    Args:
        decoy(bytes): pdb data of the decoy
        targrp(hdf5 file handle): HDF5 'targets' group
    """
    categories = {'high': 0, 'medium': 1, 'accepetable': 2, 'incorrect': 3}

    tarname = 'CAPRI_CLASS'
    if tarname in targrp.keys():
        del targrp[tarname]
        warnings.warn(f"Removed old {tarname} from {targrp.parent.name}")

    tarelems = ['FNAT', 'LRMSD', 'IRMSD']
    vals = {}
    for tarelem in tarelems:
        # if target element exist, then use its value; otherwise calculate it
        if tarelem not in targrp:
            _ = rmsd_fnat.__compute_target__(decoy, targrp, tarelem)
        # empty dataset
        elif targrp[tarelem][()].shape is None:
            _ = rmsd_fnat.__compute_target__(decoy, targrp, tarelem)

        # get the value
        vals[tarelem] = targrp[tarelem][()]

    label = StructureSimilarity.compute_CapriClass(vals['FNAT'], vals['LRMSD'],
                                                   vals['IRMSD'])
    targrp.create_dataset(tarname, data=np.array(categories[label]))
Exemplo n.º 5
0
def __compute_target__(decoy, targrp, tarname, save_file=False):
    """Calcuate CAPRI metric IRMSD, LRMSD or FNAT.

    Args:
        decoy(bytes): pdb data of the decoy
        targrp(hdf5 file handle): HDF5 'targets' group
        tarnames(str): it must be IRMSD, LRMSD or FNAT.
        save_file(bool): save .izone, .lzone or .ref_pairs file or not,
            defaults to False.

    Returns:
        float: value of IRMSD, LRMSD or FNAT.

    Raises:
        ValueError: Wrong target name
        ValueError: native complex not exist
        ValueError: native complex has empty dataset

    Examples:
        >>> f = h5py.File('1LFD.hdf5')
        >>> decoy = f['1LFD_9w/complex'][()]
        >>> targrp = f['1LFD_9w/targets']
    """
    # check tarname
    tarname = tarname.upper()
    if tarname not in ("IRMSD", "LRMSD", "FNAT"):
        raise ValueError(f'Target name is wrong: {tarname}. '
                         f'It must be "IRMSD", "LRMSD", "FNAT"')

    # fet the mol group
    molgrp = targrp.parent
    molname = molgrp.name

    if save_file:
        path = os.path.dirname(os.path.realpath(__file__))
        ZONE = path + '/zones/'

        if not os.path.isdir(ZONE):
            os.mkdir(ZONE)

    if tarname in targrp.keys():
        del targrp[tarname]
        warnings.warn(f"Removed old {tarname} from {molname}")

    # if we have a ref
    if '_' not in molname:
        if tarname in ("IRMSD", "LRMSD"):
            target = 0.0
        elif tarname == "FNAT":
            target = 1.0

        targrp.create_dataset(tarname, data=np.array(target))
        warnings.warn(
            f"{molname} is a native/reference complex "
            f"without '_' in filename. Assign {target} for {tarname}")

    # or it's a decoy
    else:
        if 'native' not in molgrp:
            raise ValueError(
                f"'native' not exist for {molname}. "
                f"You must provide reference pdb for computing targets")
        elif molgrp['native'][()].shape is None:
            raise ValueError(
                f"'native' dataset is empty for {molname}. "
                f"You must provide reference pdb for computing targets")

        molname = molname.split('_')[0]

        # init the class
        decoy = molgrp['complex'][()]
        ref = molgrp['native'][()]
        sim = StructureSimilarity(decoy, ref)

        # comppute the izone/lzone/ref_pairs
        if tarname == "IRMSD":
            if save_file:
                izone = ZONE + molname + '.izone'
            else:
                izone = None
            target = sim.compute_irmsd_fast(method='svd', izone=izone)

        elif tarname == "LRMSD":
            if save_file:
                lzone = ZONE + molname + '.lzone'
            else:
                lzone = None
            target = sim.compute_lrmsd_fast(method='svd', lzone=lzone)

        elif tarname == "FNAT":
            target = sim.compute_fnat_fast()

        targrp.create_dataset(tarname, data=np.array(target))

    return target