def identify_marker_genes_ratio(self, labels=None):
        """
        Ranks marker genes for each cluster using a SAM-weighted
        expression-ratio approach (works quite well). 

        Parameters
        ----------

        labels - numpy.array or str, optional, default None
            Cluster labels to use for marker gene identification. If None,
            assumes that one of SAM's clustering algorithms has been run. Can
            be a string (i.e. 'louvain_clusters', 'kmeans_clusters', etc) to
            specify specific cluster labels in adata.obs.

        """
        if(labels is None):
            try:
                keys = np.array(list(self.adata.obs_keys()))
                lbls = self.adata.obs[ut.search_string(
                    keys, '_clusters')[0][0]].get_values()
            except KeyError:
                print("Please generate cluster labels first or set the "
                      "'labels' keyword argument.")
                return
        elif isinstance(labels, str):
            lbls = self.adata.obs[labels].get_values().flatten()
        else:
            lbls = labels

        all_gene_names = np.array(list(self.adata.var_names))

        markers={}

        s = np.array(self.adata.layers['X_disp'].sum(0)).flatten()
        lblsu=np.unique(lbls)
        for i in lblsu:
            d = np.array(self.adata.layers['X_disp']
                         [lbls == i, :].sum(0)).flatten()
            rat = np.zeros(d.size)
            rat[s > 0] = d[s > 0]**2 / s[s > 0] * \
                self.adata.var['weights'].values[s > 0]
            x = np.argsort(-rat)
            markers[i] = all_gene_names[x[:]]

        self.adata.uns['marker_genes_ratio'] = markers

        return markers
def identify_marker_genes_ratio ( self , labels = None ) : if ( labels is None ) : try : keys = np . array ( list ( self . adata . obs_keys ( ) ) ) lbls = self . adata . obs [ ut . search_string ( keys , '_clusters' ) [ 0 ] [ 0 ] ] . get_values ( ) except KeyError : print ( "Please generate cluster labels first or set the " "'labels' keyword argument." ) return elif isinstance ( labels , str ) : lbls = self . adata . obs [ labels ] . get_values ( ) . flatten ( ) else : lbls = labels all_gene_names = np . array ( list ( self . adata . var_names ) ) markers = { } s = np . array ( self . adata . layers [ 'X_disp' ] . sum ( 0 ) ) . flatten ( ) lblsu = np . unique ( lbls ) for i in lblsu : d = np . array ( self . adata . layers [ 'X_disp' ] [ lbls == i , : ] . sum ( 0 ) ) . flatten ( ) rat = np . zeros ( d . size ) rat [ s > 0 ] = d [ s > 0 ] ** 2 / s [ s > 0 ] * self . adata . var [ 'weights' ] . values [ s > 0 ] x = np . argsort ( - rat ) markers [ i ] = all_gene_names [ x [ : ] ] self . adata . uns [ 'marker_genes_ratio' ] = markers return markers
Ranks marker genes for each cluster using a SAM-weighted
        expression-ratio approach (works quite well). 

        Parameters
        ----------

        labels - numpy.array or str, optional, default None
            Cluster labels to use for marker gene identification. If None,
            assumes that one of SAM's clustering algorithms has been run. Can
            be a string (i.e. 'louvain_clusters', 'kmeans_clusters', etc) to
            specify specific cluster labels in adata.obs.