示例#1
0
    def _ccc(self, mapname, modelname, res):
        path_test = "./"
        m = os.path.join(path_test, mapname)
        emmap1 = MapParser.readMRC(m)
        p = os.path.join(path_test, modelname)
        structure_instance = PDBParser.read_PDB_file('pdbfile',
                                                     p,
                                                     hetatm=False,
                                                     water=False)
        blurrer = StructureBlurrer()

        t = 1.5
        c1 = None
        c2 = None
        #calculate map contour
        zeropeak, ave, sigma1 = emmap1._peak_density()
        if not zeropeak is None: c1 = zeropeak + (t * sigma1)

        mt = 0.1
        if res > 20.0: mt = 2.0
        elif res > 10.0: mt = 1.0
        elif res > 6.0: mt = 0.5

        #emmap2 = blurrer.gaussian_blur(structure_instance, res, densMap=emmap1)
        emmap2 = blurrer.gaussian_blur_real_space(structure_instance,
                                                  res,
                                                  sigma_coeff=0.187,
                                                  densMap=emmap1,
                                                  normalise=True)

        # calculate model contour - emmap1 apparently?
        c2 = mt * emmap2.std()

        sc = ScoringFunctions()
        _, ovr = sc.CCC_map(emmap1, emmap2, c1, c2, 3, cmode=False)
        ccc, _ = sc.CCC_map(emmap1, emmap2, c1, c2, cmode=False)

        print("Printing CCC", ccc, ovr, c1, c2)

        return (ccc, ovr)
示例#2
0
    def rank_fit_ensemble(self,ensemble_list,score,res_target_map,sigma_coeff,number_top_mod=0,\
                          write=False,targetMap=False,cont_targetMap=None):
        """
          
            RMSD clustering of the multiple "fits" accordingly with a chosen score.
            Cluster the fits based on Calpha RMSD (starting from the best scoring model)            
                Arguments:
                    *ensemble_list*
                        Input list of Structure Instances.
                    *targetMap*
                        Target Map Instance.
                    *score*
                        Scoring function to use. 
                        See ScoringFunctions class for a list of the available Scoring Function.
                        E.g. set score='CCC' to use the Cross-correlation coefficient.
                        
                        Score option are:
                        
                        i    'CCC' - Cross-correlation coefficient; 
                        
                        ii    'LAP' - Laplacian-filtered cross-correlation coefficient:  useful for maps with resolutions worse than 10-15 A;
                        
                        iii   'MI' - Mutual information score: a good and robust score but relatively slow to calculate; 
                        
                        iv    'ENV' - Envelope score: the fastest score to calculate due to binarisation of the map. 
                        
                        v-vii  'NV','NV_Sobel','NV_Laplace'- Normal vector score: a vector-based surface superimposition score with or without Sobel/Laplace filter.

                        viii 'CD' - Chamfer Distance: a score used in computer vision algorithms as a fast similarity metric 
                                                                                         

                    *rms_cutoff*
                        float,  the Calpha RMSD cutoff based on which you want to cluster the solutions. For example 3.5 (for 3.5 A).
                    *res_target_map*
                        the resolution, in Angstroms, of the target Map.
                    *sigma_coeff*
                        the sigma value (multiplied by the resolution) that controls the width of the Gaussian. 
                        Default values is 0.356.
                
                        Other values used :
                
                            0.187R corresponding with the Gaussian width of the Fourier transform falling to half the maximum at 1/resolution, as used in Situs (Wriggers et al, 1999);
                    
                            0.225R which makes the Fourier transform of the distribution fall to 1/e of its maximum value at wavenumber 1/resolution, the default in Chimera (Petterson et al, 2004)
                    
                            0.356R corresponding to the Gaussian width at 1/e maximum height equaling the resolution, an option in Chimera (Petterson et al, 2004);
                    
                            0.425R the fullwidth half maximum being equal to the resolution, as used by FlexEM (Topf et al, 2008);
                                
                            0.5R the distance between the two inflection points being the same length as the resolution, an option in Chimera (Petterson et al, 2004);
                                
                            1R where the sigma value simply equal to the resolution, as used by NMFF (Tama et al, 2004).

                    *number_top_mod*
                        Number of Fits to cluster. Default is all.
                    *write*
                        True will write out a file that contains the list of the structure instances representing different fits scored and clustered.
                        note the lrms column is the Calpha RMSD of each fit from the first fit in its class
        
        
        """
        blurrer = StructureBlurrer()

        scorer = ScoringFunctions()

        cluster = Cluster()

        count = 0
        dict_ensembl = {}
        list_to_order = []
        #print targetMap
        if targetMap == False:
            #targetMap = self.protMap(prot, min(resolution/4., 3.5), resolution)
            print("WARNING:Need target map")
            sys.exit()
        if score not in [
                'CCC', 'LAP', 'MI', 'NV', 'NV_Sobel', 'NV_Laplace', 'ENV', 'CD'
        ]:
            print('Incorrect Scoring Function: %s', score)
            print(
                'Please select from one of the following scoring functions: %s',
                ''.join([
                    'CCC', 'LAP', 'MI', 'NV', 'NV_Sobel', 'NV_Laplace', 'ENV',
                    'CD'
                ]))
            sys.exit()

        targetMap = targetMap.copy()
        if score == 'CCC':
            for mod1 in ensemble_list:
                count += 1
                name_mod = mod1[0]
                mod = mod1[1]

                sim_map = blurrer.gaussian_blur(mod,
                                                res_target_map,
                                                densMap=targetMap,
                                                sigma_coeff=sigma_coeff)
                if not cont_targetMap is None:
                    score_mod = scorer.CCC_map(
                        sim_map, targetMap, 0.5 * sim_map.fullMap.std(),
                        cont_targetMap, 2, True)[0]  #CCC(sim_map,targetMap)
                else:
                    score_mod = scorer.CCC_map(sim_map, targetMap, 0.0, 0.0,
                                               True)[0]
                #else: score_mod=scorer.CCC(sim_map,targetMap)
                #'name_file','structure_instance','score','lrmsd','class'
                list_to_order.append([name_mod, mod, score_mod, 0, 0])
        if score == 'LAP':
            for mod1 in ensemble_list:
                count += 1
                name_mod = mod1[0]
                mod = mod1[1]
                sim_map = blurrer.gaussian_blur(mod,
                                                res_target_map,
                                                densMap=targetMap,
                                                sigma_coeff=sigma_coeff)
                score_mod = scorer.laplace_CCC(sim_map, targetMap)
                #'name_file','structure_instance','score','lrmsd','class'
                list_to_order.append([name_mod, mod, score_mod, 0, 0])
        if score == 'MI':
            for mod1 in ensemble_list:
                count += 1
                name_mod = mod1[0]
                mod = mod1[1]
                sim_map = blurrer.gaussian_blur(mod,
                                                res_target_map,
                                                densMap=targetMap,
                                                sigma_coeff=sigma_coeff)
                if not cont_targetMap is None:
                    score_mod = scorer.MI(sim_map, targetMap,
                                          0.5 * sim_map.fullMap.std(),
                                          cont_targetMap, 1)
                else:
                    score_mod = scorer.MI(sim_map, targetMap)
                list_to_order.append([name_mod, mod, score_mod, 0, 0])
        if score == 'NV':
            for mod1 in ensemble_list:
                count += 1
                name_mod = mod1[0]
                mod = mod1[1]
                #These two values should be calculated for the experimental map, and only
                #need to be calculated once, at the beginning
                sim_map = blurrer.gaussian_blur(mod,
                                                res_target_map,
                                                densMap=targetMap,
                                                sigma_coeff=sigma_coeff)
                if not cont_targetMap is None:
                    score_mod = scorer.normal_vector_score(
                        targetMap,
                        sim_map,
                        cont_targetMap - (0.1 * targetMap.std()),
                        cont_targetMap + (0.1 * targetMap.std()),
                        Filter=None)
                else:
                    min_thr = targetMap.get_primary_boundary(
                        mod.get_prot_mass_from_atoms(), targetMap.min(),
                        targetMap.max())
                    points = targetMap.get_point_map(min_thr, percentage=0.2)

                    max_thr = targetMap.get_second_boundary(min_thr,
                                                            points,
                                                            min_thr,
                                                            targetMap.max(),
                                                            err_percent=1)
                    score_mod = scorer.normal_vector_score(targetMap,
                                                           sim_map,
                                                           min_thr,
                                                           max_thr,
                                                           Filter=None)
                score_mod = 1 - (score_mod / 3.14)
                list_to_order.append([name_mod, mod, score_mod, 0, 0])
        if score == 'NV_Sobel':

            for mod1 in ensemble_list:
                count += 1
                name_mod = mod1[0]
                mod = mod1[1]
                sim_map = blurrer.gaussian_blur(mod,
                                                res_target_map,
                                                densMap=targetMap,
                                                sigma_coeff=sigma_coeff)
                if not cont_targetMap is None:
                    score_mod = scorer.normal_vector_score(
                        targetMap,
                        sim_map,
                        cont_targetMap - (0.1 * targetMap.std()),
                        cont_targetMap + (0.1 * targetMap.std()),
                        Filter='Sobel')
                else:
                    min_thr = targetMap.get_primary_boundary(
                        mod.get_prot_mass_from_atoms(), targetMap.min(),
                        targetMap.max())
                    points = targetMap.get_point_map(min_thr, percentage=0.2)
                    max_thr = targetMap.get_second_boundary(min_thr,
                                                            points,
                                                            min_thr,
                                                            targetMap.max(),
                                                            err_percent=1)
                    score_mod = scorer.normal_vector_score(targetMap,
                                                           sim_map,
                                                           min_thr,
                                                           max_thr,
                                                           Filter='Sobel')
                score_mod = 1 - (score_mod / 3.14)
                list_to_order.append([name_mod, mod, score_mod, 0, 0])
        if score == 'NV_Laplace':
            for mod1 in ensemble_list:
                count += 1
                name_mod = mod1[0]
                mod = mod1[1]
                sim_map = blurrer.gaussian_blur(mod,
                                                res_target_map,
                                                densMap=targetMap,
                                                sigma_coeff=sigma_coeff)
                if not cont_targetMap is None:
                    score_mod = scorer.normal_vector_score(
                        targetMap,
                        sim_map,
                        cont_targetMap - (0.1 * targetMap.std()),
                        cont_targetMap + (0.1 * targetMap.std()),
                        Filter='Laplace')
                else:
                    min_thr = targetMap.get_primary_boundary(
                        mod.get_prot_mass_from_atoms(), targetMap.min(),
                        targetMap.max())
                    points = targetMap.get_point_map(min_thr, percentage=0.2)
                    max_thr = targetMap.get_second_boundary(min_thr,
                                                            points,
                                                            min_thr,
                                                            targetMap.max(),
                                                            err_percent=1)
                    score_mod = scorer.normal_vector_score(targetMap,
                                                           sim_map,
                                                           min_thr,
                                                           max_thr,
                                                           Filter='Laplace')
                score_mod = 1 - (score_mod / 3.14)
                list_to_order.append([name_mod, mod, score_mod, 0, 0])
        if score == 'ENV':
            for mod1 in ensemble_list:
                count += 1
                name_mod = mod1[0]
                mod = mod1[1]
                min_thr = targetMap.get_primary_boundary(
                    mod.get_prot_mass_from_atoms(), targetMap.min(),
                    targetMap.max())
                score_mod = scorer.envelope_score(targetMap, min_thr, mod)
                #'name_file','structure_instance','score','lrmsd','class'
                list_to_order.append([name_mod, mod, score_mod, 0, 0])
        if score == 'CD':
            for mod1 in ensemble_list:
                count += 1
                name_mod = mod1[0]
                mod = mod1[1]
                sim_map = blurrer.gaussian_blur(mod,
                                                res_target_map,
                                                densMap=targetMap,
                                                sigma_coeff=sigma_coeff)
                if not cont_targetMap is None:
                    score_mod = scorer._surface_distance_score(
                        sim_map, targetMap, 0.5 * sim_map.fullMap.std(),
                        cont_targetMap, 'Minimum')
                else:
                    min_thr = targetMap.get_primary_boundary(
                        mod.get_prot_mass_from_atoms(), targetMap.min(),
                        targetMap.max())
                    points = targetMap.get_point_map(min_thr, percentage=0.2)
                    max_thr = targetMap.get_second_boundary(min_thr,
                                                            points,
                                                            min_thr,
                                                            targetMap.max(),
                                                            err_percent=1)
                    score_mod = scorer.chamfer_distance(sim_map,
                                                        targetMap,
                                                        min_thr,
                                                        max_thr,
                                                        kdtree=None)
                    score_mod = 1 / score_mod
                list_to_order.append([name_mod, mod, score_mod, 0, 0])

        if score in ['NV', 'NV_Sobel', 'NV_Laplace']:
            list_ordered = sorted(
                list_to_order, key=lambda x: x[2],
                reverse=True)  #was false when NV was negative
        else:
            list_ordered = sorted(list_to_order,
                                  key=lambda x: x[2],
                                  reverse=True)
        if number_top_mod == 0:
            if write == True:
                return cluster._print_results_cluster2(list_ordered, write)
            return list_ordered
        else:
            x = int(number_top_mod)
            if write == True:
                return cluster._print_results_cluster2(list_ordered[:x], write)
            return list_ordered[:x]
示例#3
0
    Name1, emmap1, c1 = map_contour(m, t=1.5)
else:
    Name1 = os.path.basename(m).split('.')[0]
    emmap1 = MapParser.readMRC(m)

dict_scores_hits = {}
list_models_calc = []
for pfile in list_to_check:
    Name2, emmap2, c2 = model_contour(pfile, res=r, emmap=emmap1, t=0.5)
    if None in [Name1, Name2]:
        sys.exit('Calculation failed, check input map and model files')
    print '#Scoring...', Name2
    sc = ScoringFunctions()
    #OVR
    try:
        ccc_mask, ovr = sc.CCC_map(emmap1, emmap2, c1, c2, 3, meanDist=True)
        print 'Percent overlap:', ovr
        if ovr < 0.0: ovr = 0.0
    except:
        print 'Exception for lccc and overlap score'
        print_exc()
        ovr = 0.0
    if ovr < 0.02:
        print "Maps do not overlap: ", Name2
        continue
    #SCCC
    print 'Local correlation score: ', ccc_mask
    if ccc_mask < -1.0 or ccc_mask > 1.0:
        ccc_mask = 0.0
    #LMI
    try:
示例#4
0
    Name1 = os.path.basename(m).split('.')[0]
    emmap1 = MapParser.readMRC(m)
if r is None:
    sys.exit('Input a map, a model, map resolution and contours (optional)')
if p is None:
    sys.exit('Input a map, a model, map resolution and contours (optional)')
#print 'reading model'
Name2, emmap2, c2 = model_contour(p, res=r, emmap=emmap1, t=0.5)

#print 'Scoring...'
if not None in [Name1, Name2]:
    scores = {}
    sc = ScoringFunctions()
    #OVR
    try:
        ccc_mask, ovr = sc.CCC_map(emmap1, emmap2, c1, c2, 3)
        print 'Percent overlap:', ovr
        if ovr < 0.0: ovr = 0.0
    except:
        print 'Exception for lccc and overlap score'
        print_exc()
        ovr = 0.0
    scores['overlap'] = ovr
    if ovr < 0.02:
        sys.exit("Maps do not overlap.")
    #SCCC
    print 'Local correlation score: ', ccc_mask
    if ccc_mask < -1.0 or ccc_mask > 1.0:
        ccc_mask = 0.0
    scores['local_correlation'] = ccc_mask
    #LMI