python/methylnet/interpretation_classes.py
def return_top_cpgs(self, classes=[], individuals=[], class_intersect=False, cpg_exclusion_sets=None, cpg_sets=None):
        """Given list of classes and individuals, export a dictionary containing data frames of top CpGs and their SHAP scores.

        Parameters
        ----------
        classes : type
            Higher level classes to extract CpGs from, list of classes to extract top CpGs from.
        individuals : type
            Individual samples to extract top CpGs from.
        class_intersect : type
            Whether the top CpGs should be chosen by aggregating the remaining individual scores.
        cpg_exclusion_sets : type
            Dict of sets of CpGs, where these ones contain CpGs not particular to particular class.
        cpg_sets : type
            Contains top CpGs found for each class.

        Returns
        -------
        Dict
            Top CpGs accessed and returned for further processing.

        """
        top_cpgs={}
        if classes:
            for class_name in classes:
                top_cpg_df = self.extract_class(class_name, class_intersect)
                if cpg_exclusion_sets != None:
                    unique_cpgs = np.array(list(set(top_cpg_df['cpg'].values.tolist())-cpg_exclusion_sets[class_name]))
                    top_cpgs[class_name]= top_cpg_df[np.isin(top_cpg_df['cpg'].values,unique_cpgs)]
                else:
                    top_cpgs[class_name]= top_cpg_df
        if individuals:
            for indiv in individuals:
                class_name,top_cpg_df=self.extract_individual(indiv)
                if cpg_exclusion_sets != None:
                    unique_cpgs = np.array(list(set(top_cpg_df['cpg'].values.tolist())-cpg_exclusion_sets[class_name]))
                    print(len(top_cpg_df['cpg'].values),len(unique_cpgs))
                    top_cpgs['{}_{}'.format(class_name,indiv)]=top_cpg_df[np.isin(top_cpg_df['cpg'].values,unique_cpgs)]
                else:
                    top_cpgs['{}_{}'.format(class_name,indiv)]=top_cpg_df
        if cpg_sets != None:
            print(cpg_sets)
            intersected_cpgs=np.array(list(set.intersection(*list(cpg_sets.values()))))
            top_cpgs['intersection']=pd.DataFrame(intersected_cpgs[:,np.newaxis],columns=['cpg'])
            top_cpgs['intersection']['shapley_value']=-1
        return top_cpgs
Given list of classes and individuals, export a dictionary containing data frames of top CpGs and their SHAP scores.

        Parameters
        ----------
        classes : type
            Higher level classes to extract CpGs from, list of classes to extract top CpGs from.
        individuals : type
            Individual samples to extract top CpGs from.
        class_intersect : type
            Whether the top CpGs should be chosen by aggregating the remaining individual scores.
        cpg_exclusion_sets : type
            Dict of sets of CpGs, where these ones contain CpGs not particular to particular class.
        cpg_sets : type
            Contains top CpGs found for each class.

        Returns
        -------
        Dict
            Top CpGs accessed and returned for further processing.

        
Given list of classes and individuals, export a dictionary containing data frames of top CpGs and their SHAP scores.
Parameters

classes : type
Higher level classes to extract CpGs from, list of classes to extract top CpGs from.
individuals : type
Individual samples to extract top CpGs from.
class_intersect : type
Whether the top CpGs should be chosen by aggregating the remaining individual scores.
cpg_exclusion_sets : type
Dict of sets of CpGs, where these ones contain CpGs not particular to particular class.
cpg_sets : type
Contains top CpGs found for each class.

Returns

Dict
Top CpGs accessed and returned for further processing.
Given list of classes and individuals export a dictionary containing data frames of top CpGs and their SHAP scores . Parameters classes : type Higher level classes to extract CpGs from list of classes to extract top CpGs from . individuals : type Individual samples to extract top CpGs from . class_intersect : type Whether the top CpGs should be chosen by aggregating the remaining individual scores . cpg_exclusion_sets : type Dict of sets of CpGs where these ones contain CpGs not particular to particular class . cpg_sets : type Contains top CpGs found for each class . Returns Dict Top CpGs accessed and returned for further processing .
def return_top_cpgs(self, classes=[], individuals=[], class_intersect=False, cpg_exclusion_sets=None, cpg_sets=None):
        top_cpgs={}
        if classes:
            for class_name in classes:
                top_cpg_df = self.extract_class(class_name, class_intersect)
                if cpg_exclusion_sets != None:
                    unique_cpgs = np.array(list(set(top_cpg_df['cpg'].values.tolist())-cpg_exclusion_sets[class_name]))
                    top_cpgs[class_name]= top_cpg_df[np.isin(top_cpg_df['cpg'].values,unique_cpgs)]
                else:
                    top_cpgs[class_name]= top_cpg_df
        if individuals:
            for indiv in individuals:
                class_name,top_cpg_df=self.extract_individual(indiv)
                if cpg_exclusion_sets != None:
                    unique_cpgs = np.array(list(set(top_cpg_df['cpg'].values.tolist())-cpg_exclusion_sets[class_name]))
                    print(len(top_cpg_df['cpg'].values),len(unique_cpgs))
                    top_cpgs['{}_{}'.format(class_name,indiv)]=top_cpg_df[np.isin(top_cpg_df['cpg'].values,unique_cpgs)]
                else:
                    top_cpgs['{}_{}'.format(class_name,indiv)]=top_cpg_df
        if cpg_sets != None:
            print(cpg_sets)
            intersected_cpgs=np.array(list(set.intersection(*list(cpg_sets.values()))))
            top_cpgs['intersection']=pd.DataFrame(intersected_cpgs[:,np.newaxis],columns=['cpg'])
            top_cpgs['intersection']['shapley_value']=-1
        return top_cpgs
def return_top_cpgs ( self , classes = [ ] , individuals = [ ] , class_intersect = False , cpg_exclusion_sets = None , cpg_sets = None ) : top_cpgs = { } if classes : for class_name in classes : top_cpg_df = self . extract_class ( class_name , class_intersect ) if cpg_exclusion_sets != None : unique_cpgs = np . array ( list ( set ( top_cpg_df [ 'cpg' ] . values . tolist ( ) ) - cpg_exclusion_sets [ class_name ] ) ) top_cpgs [ class_name ] = top_cpg_df [ np . isin ( top_cpg_df [ 'cpg' ] . values , unique_cpgs ) ] else : top_cpgs [ class_name ] = top_cpg_df if individuals : for indiv in individuals : class_name , top_cpg_df = self . extract_individual ( indiv ) if cpg_exclusion_sets != None : unique_cpgs = np . array ( list ( set ( top_cpg_df [ 'cpg' ] . values . tolist ( ) ) - cpg_exclusion_sets [ class_name ] ) ) print ( len ( top_cpg_df [ 'cpg' ] . values ) , len ( unique_cpgs ) ) top_cpgs [ '{}_{}' . format ( class_name , indiv ) ] = top_cpg_df [ np . isin ( top_cpg_df [ 'cpg' ] . values , unique_cpgs ) ] else : top_cpgs [ '{}_{}' . format ( class_name , indiv ) ] = top_cpg_df if cpg_sets != None : print ( cpg_sets ) intersected_cpgs = np . array ( list ( set . intersection ( * list ( cpg_sets . values ( ) ) ) ) ) top_cpgs [ 'intersection' ] = pd . DataFrame ( intersected_cpgs [ : , np . newaxis ] , columns = [ 'cpg' ] ) top_cpgs [ 'intersection' ] [ 'shapley_value' ] = - 1 return top_cpgs
Given list of classes and individuals, export a dictionary containing data frames of top CpGs and their SHAP scores.
Given list of classes and individuals export a dictionary containing data frames of top CpGs and their SHAP scores .
"""Given list of classes and individuals, export a dictionary containing data frames of top CpGs and their SHAP scores.

        Parameters
        ----------
        classes : type
            Higher level classes to extract CpGs from, list of classes to extract top CpGs from.
        individuals : type
            Individual samples to extract top CpGs from.
        class_intersect : type
            Whether the top CpGs should be chosen by aggregating the remaining individual scores.
        cpg_exclusion_sets : type
            Dict of sets of CpGs, where these ones contain CpGs not particular to particular class.
        cpg_sets : type
            Contains top CpGs found for each class.

        Returns
        -------
        Dict
            Top CpGs accessed and returned for further processing.

        """
self
classes
individuals
class_intersect
cpg_exclusion_sets
cpg_sets