Пример #1
0
 def setUp(self):
     self.grid_list = self.make_test_data()
     self.tmp_dir =  join(os.getcwd(), "tmp_gridensemble_test")
     self.grid_paths = glob(join(self.tmp_dir, "test_apolar_*.ccp4"))
     print(self.grid_paths)
     self.grid_ensemble = _GridEnsemble()
     self.grid_ensemble = _GridEnsemble()
     self.max_grid = self.grid_ensemble.from_grid_list(self.grid_list, os.getcwd(), "test", "apolar")
     self.values = self.grid_ensemble.results_array[self.grid_ensemble.results_array.nonzero()]
Пример #2
0
    def from_grid_ensembles(res_list, prot_name, charged=False, mode='max'):
        """
        *Experimental feature*

        Creates ensemble map from a list of Results. Structures in the ensemble have to aligned by the
        binding site of interest prior to the hotspots calculation.

        TODO: Move to the calculation module?

        :param res_list: list of `hotspots.result.Results`
        :param str prot_name: str
        :param str out_dir: path to output directory
        :return: a :class:`hotspots.result.Results` instance
        """
        if charged:
            probe_list = [
                "acceptor", "apolar", "donor", "positive", "negative"
            ]
        else:
            probe_list = ["acceptor", "apolar", "donor"]

        grid_dic = {}

        for p in probe_list:
            grid_list_p = [r.super_grids[p].minimal() for r in res_list]
            ens = _GridEnsemble()
            grid_dic[p] = ens.from_grid_list(grid_list_p,
                                             getcwd(),
                                             prot_name,
                                             p,
                                             mode=mode)

        hr = Results(grid_dic, protein=res_list[0].protein)
        return hr
Пример #3
0
 def test_from_grid_list(self):
     grid_ensemble = _GridEnsemble()
     max_grid = grid_ensemble.from_grid_list(self.grid_list, os.getcwd(), "test", "apolar")
     values = grid_ensemble.results_array[grid_ensemble.results_array.nonzero()]
     self.assertEqual(len(values),
                      988,
                      msg="Check number of values")
     self.assertEqual(grid_ensemble.tup_max_length,
                      len(self.grid_list),
                      msg="Check tup_max_length assigned")
Пример #4
0
 def test_from_hotspot_maps(self):
     # hard coded because 988 values in test set - perhaps there's a better way to test this?
     grid_ensemble = _GridEnsemble()
     max_grid = grid_ensemble.from_hotspot_maps(self.grid_paths, os.getcwd(), "test", "apolar")
     values = grid_ensemble.results_array[grid_ensemble.nonzeros]
     self.assertEqual(len(values),
                      988,
                      msg="Check number of values")
     self.assertEqual(grid_ensemble.tup_max_length,
                      len(self.grid_paths),
                      msg="Check tup_max_length assigned")
Пример #5
0
 def test_from_grid_list(self):
     grid_ensemble = _GridEnsemble()
     max_grid = grid_ensemble.from_grid_list(self.grid_list, os.getcwd(),
                                             "test", "apolar")
     values = grid_ensemble.results_array[grid_ensemble.nonzeros]
     self.assertEqual(
         values.shape, (988, 10),
         msg="Check number of values: expected: {}, observed {}".format(
             (988, 10), values.shape))
     self.assertEqual(grid_ensemble.tup_max_length,
                      len(self.grid_list),
                      msg="Check tup_max_length assigned")
Пример #6
0
    def get_aa_grid(self):
        """
        Returns a grid where points within the VdW radius of e residue are labelled with the residue's index+1
        :return: 
        """
        #pg = self.grid_from_protein()
        if not self.protein:
            self.get_protein()

        res_names = [res.identifier for res in self.protein.residues]
        res_nums = [idx + 1 for (idx, val) in enumerate(res_names)]

        res_gs = [
            self.get_residue_vdw(r, res_nums[i])
            for i, r in enumerate(self.protein.residues)
        ]
        print(len(set(round(g.spacing, 3) for g in res_gs)))
        #res_gs = Grid.common_grid(res_gs, padding=0)
        ge = _GridEnsemble()
        self.aa_grid = ge.from_grid_list(res_gs, os.getcwd(), "NUDT5114",
                                         "acceptor")
        self.aa_grid.write(self.prot_path.replace(".pdb", "_vdw_grid.ccp4"))
Пример #7
0
    def make_selectivity_maps(self):
        """
        Creates the selectivity maps for the polar and apolar probes. 
        :return: 
        """
        diff_maps = self.make_difference_maps()

        probes_list = ['donor', 'acceptor', 'apolar', 'positive', 'negative']
        polar_probes = ['donor', 'acceptor', 'positive', 'negative']
        apolar_probes = ['apolar']

        for probe in probes_list:
            try:
                dmap = diff_maps[probe]

                if probe in polar_probes:
                    # Find the percentile threshold, if specified
                    perc = np.percentile(
                        dmap[dmap > 0],
                        self.settings.polar_percentile_threshold)

                    # Find clusters in the target and off-target maps
                    clust_map_on = _GridEnsemble.HDBSCAN_cluster(
                        dmap * (dmap > perc),
                        min_cluster_size=self.settings.min_points_cluster_polar
                    )
                    clust_map_off = _GridEnsemble.HDBSCAN_cluster(
                        dmap * (dmap < -perc),
                        min_cluster_size=self.settings.min_points_cluster_polar
                    )

                elif probe in apolar_probes:
                    # Find the percentile threshold, if specified
                    perc = np.percentile(
                        dmap[dmap > 0],
                        self.settings.apolar_percentile_threshold)

                    # Find clusters in the target and off-target maps
                    clust_map_on = _GridEnsemble.HDBSCAN_cluster(
                        dmap * (dmap > perc),
                        min_cluster_size=self.settings.
                        min_points_cluster_apolar,
                        allow_single_cluster=True)
                    clust_map_off = _GridEnsemble.HDBSCAN_cluster(
                        dmap * (dmap < -perc),
                        min_cluster_size=self.settings.
                        min_points_cluster_apolar,
                        allow_single_cluster=True)

                else:
                    print("Probe type {} not recognised as polar or apolar".
                          format(probe))
                    continue

                #Get the center of mass coordinates for the target and off-target
                coords = self.get_clusters_center_mass(dmap, clust_map_on)
                minus_coords = self.get_clusters_center_mass(
                    dmap, clust_map_off)

                for k in coords.keys():
                    for i in minus_coords.keys():
                        dist = self.get_distance(coords[k],
                                                 minus_coords[i]) * 0.5
                        # print("Plus clust: {}, minus_clust: {}, distance: {}".format(k, i, dist))
                        if dist < self.settings.cluster_distance_cutoff:
                            self.remove_cluster(clust_map_on, k)
                            self.remove_cluster(clust_map_off, i)

                # Remove any clusters that don't make the medmian cutoff
                for c in set(clust_map_on[clust_map_on > 0]):
                    med = np.median(dmap[clust_map_on == c])

                    if med < self.settings.minimal_cluster_score:
                        self.remove_cluster(clust_map_on, c)

                for c in set(clust_map_off[clust_map_off > 0]):
                    min_med = np.median(dmap[clust_map_off == c])

                    if min_med > -self.settings.minimal_cluster_score:
                        self.remove_cluster(clust_map_off, c)

                ge = _GridEnsemble(dimensions=self.common_grid_dimensions,
                                   shape=self.common_grid_nsteps)

                self.selectivity_maps[probe] = ge.as_grid(
                    (clust_map_on > 0) * dmap)

            except KeyError:
                continue

        self.selectivity_result = Results(super_grids=self.selectivity_maps,
                                          protein=self.target.protein)
Пример #8
0
    def make_ensemble_maps(self, save_grid_ensembles=True):
        """
        Creates summary maps for the ensemble based on the settings provided.
        :return: 
        """
        probes_list = ['donor', 'acceptor', 'apolar']
        polar_probes = ['donor', 'acceptor']
        apolar_probes = ['apolar']

        for probe in probes_list:

            try:
                # Don't need to create the ensemble array each time (eg if pickled GridEnsembles have been supplied)
                if probe in self.grid_ensembles.keys():
                    ge = self.grid_ensembles[probe]
                else:
                    #probe_grids = [hs.super_grids[probe].max_value_of_neighbours() for hs in self.hotspot_results]
                    probe_grids = [
                        hs.super_grids[probe] for hs in self.hotspot_results
                    ]
                    ge = _GridEnsemble()
                    ge.make_ensemble_array(probe_grids)

                if save_grid_ensembles:
                    self.grid_ensembles[probe] = ge

                if probe in polar_probes:
                    if self.settings.combine_mode == 'median':
                        ens_grid = ge.as_grid(
                            ge.get_median_frequency_map(
                                threshold=self.settings.
                                polar_frequency_threshold))

                    # The mean and max modes don't currently take into account the frequency
                    elif self.settings.combine_mode in ['mean', 'max']:
                        ens_grid = ge.make_summary_grid(
                            mode=self.settings.combine_mode)

                    else:
                        print(
                            'Unrecognised mode for combining grids in {} {}: {}'
                            .format(self.ensemble_id, probe,
                                    self.settings.combine_mode))
                        continue

                elif probe in apolar_probes:
                    ens_grid = ge.make_summary_grid(
                        mode=self.settings.combine_mode)

                else:
                    print(
                        "Probe type {} in ensemble {} not recognised as polar or apolar"
                        .format(probe, self.ensemble_id))
                    continue

                print(probe, ens_grid.nsteps)

                self.ensemble_maps[probe] = ens_grid

            # In case of no charged probes
            except KeyError:
                continue
        try:
            self.ensemble_hotspot_result = Results(
                super_grids=self.ensemble_maps,
                protein=self.hotspot_results[0].protein,
                buriedness=None,
                pharmacophore=False)
        except TypeError:
            self.ensemble_hotspot_result = Results(
                super_grids=self.ensemble_maps,
                protein=None,
                buriedness=None,
                pharmacophore=False)