python/methylnet/interpretation_classes.py
def jaccard_similarity_top_cpgs(self,class_names,individuals=False,overall=False, cooccurrence=False):
        """Calculate Jaccard Similarity matrix between classes and individuals within those classes based on how they share sets of CpGs.

        Parameters
        ----------
        class_names : type
            Classes to include.
        individuals : type
            Individuals to include.
        overall : type
            Whether to use overall class top CpGs versus aggregate.
        cooccurrence : type
            Output cooccurence instead of jaccard.

        Returns
        -------
        pd.DataFrame
            Similarity matrix.

        """
        from itertools import combinations
        from functools import reduce
        x={}
        if class_names[0]=='all':
            class_names=list(self.shapley_data.top_cpgs['by_class'].keys())
        for class_name in class_names:
            if overall:
                x[class_name]=self.shapley_data.top_cpgs['by_class'][class_name]['overall']['cpg'].values.tolist()
            if individuals:
                for indiv,df in list(self.shapley_data.top_cpgs['by_class'][class_name]['by_individual'].items()):
                    x['{}_{}'.format(class_name,indiv)]=df['cpg'].values.tolist()
        indivs=list(x.keys())
        similarity_matrix=pd.DataFrame(np.eye(len(x)),index=indivs,columns=indivs)
        for i,j in combinations(indivs,r=2):
            similarity_matrix.loc[i,j] = (round(jaccard_similarity(x[i],x[j]),3) if not cooccurrence else cooccurrence_fn(x[i],x[j]))
            similarity_matrix.loc[j,i] = similarity_matrix.loc[i,j]
        if cooccurrence:
            for i in indivs:
                similarity_matrix.loc[i,i]=len(x[i])
        return similarity_matrix
Calculate Jaccard Similarity matrix between classes and individuals within those classes based on how they share sets of CpGs.

        Parameters
        ----------
        class_names : type
            Classes to include.
        individuals : type
            Individuals to include.
        overall : type
            Whether to use overall class top CpGs versus aggregate.
        cooccurrence : type
            Output cooccurence instead of jaccard.

        Returns
        -------
        pd.DataFrame
            Similarity matrix.

        
Calculate Jaccard Similarity matrix between classes and individuals within those classes based on how they share sets of CpGs.
Parameters

class_names : type
Classes to include.
individuals : type
Individuals to include.
overall : type
Whether to use overall class top CpGs versus aggregate.
cooccurrence : type
Output cooccurence instead of jaccard.

Returns


Calculate Jaccard Similarity matrix between classes and individuals within those classes based on how they share sets of CpGs . Parameters class_names : type Classes to include . individuals : type Individuals to include . overall : type Whether to use overall class top CpGs versus aggregate . cooccurrence : type Output cooccurence instead of jaccard . Returns
def jaccard_similarity_top_cpgs(self,class_names,individuals=False,overall=False, cooccurrence=False):
        from itertools import combinations
        from functools import reduce
        x={}
        if class_names[0]=='all':
            class_names=list(self.shapley_data.top_cpgs['by_class'].keys())
        for class_name in class_names:
            if overall:
                x[class_name]=self.shapley_data.top_cpgs['by_class'][class_name]['overall']['cpg'].values.tolist()
            if individuals:
                for indiv,df in list(self.shapley_data.top_cpgs['by_class'][class_name]['by_individual'].items()):
                    x['{}_{}'.format(class_name,indiv)]=df['cpg'].values.tolist()
        indivs=list(x.keys())
        similarity_matrix=pd.DataFrame(np.eye(len(x)),index=indivs,columns=indivs)
        for i,j in combinations(indivs,r=2):
            similarity_matrix.loc[i,j] = (round(jaccard_similarity(x[i],x[j]),3) if not cooccurrence else cooccurrence_fn(x[i],x[j]))
            similarity_matrix.loc[j,i] = similarity_matrix.loc[i,j]
        if cooccurrence:
            for i in indivs:
                similarity_matrix.loc[i,i]=len(x[i])
        return similarity_matrix
def jaccard_similarity_top_cpgs ( self , class_names , individuals = False , overall = False , cooccurrence = False ) : from itertools import combinations from functools import reduce x = { } if class_names [ 0 ] == 'all' : class_names = list ( self . shapley_data . top_cpgs [ 'by_class' ] . keys ( ) ) for class_name in class_names : if overall : x [ class_name ] = self . shapley_data . top_cpgs [ 'by_class' ] [ class_name ] [ 'overall' ] [ 'cpg' ] . values . tolist ( ) if individuals : for indiv , df in list ( self . shapley_data . top_cpgs [ 'by_class' ] [ class_name ] [ 'by_individual' ] . items ( ) ) : x [ '{}_{}' . format ( class_name , indiv ) ] = df [ 'cpg' ] . values . tolist ( ) indivs = list ( x . keys ( ) ) similarity_matrix = pd . DataFrame ( np . eye ( len ( x ) ) , index = indivs , columns = indivs ) for i , j in combinations ( indivs , r = 2 ) : similarity_matrix . loc [ i , j ] = ( round ( jaccard_similarity ( x [ i ] , x [ j ] ) , 3 ) if not cooccurrence else cooccurrence_fn ( x [ i ] , x [ j ] ) ) similarity_matrix . loc [ j , i ] = similarity_matrix . loc [ i , j ] if cooccurrence : for i in indivs : similarity_matrix . loc [ i , i ] = len ( x [ i ] ) return similarity_matrix
Calculate Jaccard Similarity matrix between classes and individuals within those classes based on how they share sets of CpGs.
Calculate Jaccard Similarity matrix between classes and individuals within those classes based on how they share sets of CpGs .
"""Calculate Jaccard Similarity matrix between classes and individuals within those classes based on how they share sets of CpGs.

        Parameters
        ----------
        class_names : type
            Classes to include.
        individuals : type
            Individuals to include.
        overall : type
            Whether to use overall class top CpGs versus aggregate.
        cooccurrence : type
            Output cooccurence instead of jaccard.

        Returns
        -------
        pd.DataFrame
            Similarity matrix.

        """
self
class_names
individuals
overall
cooccurrence