python/methylnet/interpretation_classes.py
def extract_methylation_array(self, methyl_arr, classes_only=True, global_vals=False, n_extract=1000, class_name=''):
        """Subset MethylationArray Beta values by some top SHAP CpGs from classes or overall.

        Parameters
        ----------
        methyl_arr : type
            MethylationArray.
        classes_only : type
            Setting this to False will include the overall top CpGs per class and the top CpGs for individuals in that class.
        global_vals : type
            Use top CpGs overall, across the entire dataset.
        n_extract : type
            Number of top CpGs to subset.
        class_name : type
            Which class to subset top CpGs from? Blank to use union of all top CpGs.

        Returns
        -------
        MethylationArray
            Stores methylation beta and pheno data, reduced here by queried CpGs.

        """
        from functools import reduce
        total_cpgs=[]
        if global_vals:
            all_cpgs=self.shapley_data.top_cpgs['overall']['cpg'].values
            if n_extract < len(all_cpgs):
                all_cpgs=all_cpgs[:n_extract]
        else:
            if class_name:
                class_names = [class_name]
            else:
                class_names = list(self.shapley_data.top_cpgs['by_class'].keys())
            for class_name in class_names:
                cpgs=np.array(list(self.shapley_data.top_cpgs['by_class'][class_name]['overall'].values[:,0]))
                if n_extract < len(cpgs):
                    cpgs=cpgs[:n_extract]
                if not classes_only:
                    cpgs = reduce(np.union1d,[cpgs]+[self.shapley_data.top_cpgs['by_class'][class_name]['by_individual'][individual].values[:,0]
                                              for individual in self.shapley_data.top_cpgs['by_class'][class_name]['by_individual'].keys()])
                total_cpgs.append(cpgs)
            all_cpgs = reduce(np.union1d,total_cpgs)
        methyl_arr.beta=methyl_arr.beta.loc[:,all_cpgs]
        return methyl_arr
Subset MethylationArray Beta values by some top SHAP CpGs from classes or overall.

        Parameters
        ----------
        methyl_arr : type
            MethylationArray.
        classes_only : type
            Setting this to False will include the overall top CpGs per class and the top CpGs for individuals in that class.
        global_vals : type
            Use top CpGs overall, across the entire dataset.
        n_extract : type
            Number of top CpGs to subset.
        class_name : type
            Which class to subset top CpGs from? Blank to use union of all top CpGs.

        Returns
        -------
        MethylationArray
            Stores methylation beta and pheno data, reduced here by queried CpGs.

        
Subset MethylationArray Beta values by some top SHAP CpGs from classes or overall.
Parameters



Returns

MethylationArray
Stores methylation beta and pheno data, reduced here by queried CpGs.
Subset MethylationArray Beta values by some top SHAP CpGs from classes or overall . Parameters Returns MethylationArray Stores methylation beta and pheno data reduced here by queried CpGs .
def extract_methylation_array(self, methyl_arr, classes_only=True, global_vals=False, n_extract=1000, class_name=''):
        from functools import reduce
        total_cpgs=[]
        if global_vals:
            all_cpgs=self.shapley_data.top_cpgs['overall']['cpg'].values
            if n_extract < len(all_cpgs):
                all_cpgs=all_cpgs[:n_extract]
        else:
            if class_name:
                class_names = [class_name]
            else:
                class_names = list(self.shapley_data.top_cpgs['by_class'].keys())
            for class_name in class_names:
                cpgs=np.array(list(self.shapley_data.top_cpgs['by_class'][class_name]['overall'].values[:,0]))
                if n_extract < len(cpgs):
                    cpgs=cpgs[:n_extract]
                if not classes_only:
                    cpgs = reduce(np.union1d,[cpgs]+[self.shapley_data.top_cpgs['by_class'][class_name]['by_individual'][individual].values[:,0]
                                              for individual in self.shapley_data.top_cpgs['by_class'][class_name]['by_individual'].keys()])
                total_cpgs.append(cpgs)
            all_cpgs = reduce(np.union1d,total_cpgs)
        methyl_arr.beta=methyl_arr.beta.loc[:,all_cpgs]
        return methyl_arr
def extract_methylation_array ( self , methyl_arr , classes_only = True , global_vals = False , n_extract = 1000 , class_name = '' ) : from functools import reduce total_cpgs = [ ] if global_vals : all_cpgs = self . shapley_data . top_cpgs [ 'overall' ] [ 'cpg' ] . values if n_extract < len ( all_cpgs ) : all_cpgs = all_cpgs [ : n_extract ] else : if class_name : class_names = [ class_name ] else : class_names = list ( self . shapley_data . top_cpgs [ 'by_class' ] . keys ( ) ) for class_name in class_names : cpgs = np . array ( list ( self . shapley_data . top_cpgs [ 'by_class' ] [ class_name ] [ 'overall' ] . values [ : , 0 ] ) ) if n_extract < len ( cpgs ) : cpgs = cpgs [ : n_extract ] if not classes_only : cpgs = reduce ( np . union1d , [ cpgs ] + [ self . shapley_data . top_cpgs [ 'by_class' ] [ class_name ] [ 'by_individual' ] [ individual ] . values [ : , 0 ] for individual in self . shapley_data . top_cpgs [ 'by_class' ] [ class_name ] [ 'by_individual' ] . keys ( ) ] ) total_cpgs . append ( cpgs ) all_cpgs = reduce ( np . union1d , total_cpgs ) methyl_arr . beta = methyl_arr . beta . loc [ : , all_cpgs ] return methyl_arr
Subset MethylationArray Beta values by some top SHAP CpGs from classes or overall.
Subset MethylationArray Beta values by some top SHAP CpGs from classes or overall .
"""Subset MethylationArray Beta values by some top SHAP CpGs from classes or overall.

        Parameters
        ----------
        methyl_arr : type
            MethylationArray.
        classes_only : type
            Setting this to False will include the overall top CpGs per class and the top CpGs for individuals in that class.
        global_vals : type
            Use top CpGs overall, across the entire dataset.
        n_extract : type
            Number of top CpGs to subset.
        class_name : type
            Which class to subset top CpGs from? Blank to use union of all top CpGs.

        Returns
        -------
        MethylationArray
            Stores methylation beta and pheno data, reduced here by queried CpGs.

        """
self
methyl_arr
classes_only
global_vals
n_extract
class_name