def run(self,<EOL>max_iter=<NUM_LIT:10>,<EOL>verbose=True,<EOL>projection='<STR_LIT>',<EOL>stopping_condition=<NUM_LIT>,<EOL>num_norm_avg=<NUM_LIT:50>,<EOL>k=<NUM_LIT:20>,<EOL>distance='<STR_LIT>',<EOL>preprocessing='<STR_LIT>',<EOL>proj_kwargs={}):
self.distance = distance<EOL>D = self.adata.X<EOL>self.k = k<EOL>if(self.k < <NUM_LIT:5>):<EOL><INDENT>self.k = <NUM_LIT:5><EOL><DEDENT>elif(self.k > <NUM_LIT:100>):<EOL><INDENT>self.k = <NUM_LIT:100><EOL><DEDENT>if(self.k > D.shape[<NUM_LIT:0>] - <NUM_LIT:1>):<EOL><INDENT>self.k = D.shape[<NUM_LIT:0>] - <NUM_LIT:2><EOL><DEDENT>numcells = D.shape[<NUM_LIT:0>]<EOL>n_genes = <NUM_LIT><EOL>if numcells > <NUM_LIT> and n_genes > <NUM_LIT>:<EOL><INDENT>n_genes = <NUM_LIT><EOL><DEDENT>elif numcells > <NUM_LIT> and n_genes > <NUM_LIT>:<EOL><INDENT>n_genes = <NUM_LIT><EOL><DEDENT>elif numcells > <NUM_LIT:1000> and n_genes > <NUM_LIT>:<EOL><INDENT>n_genes = <NUM_LIT><EOL><DEDENT>elif n_genes > <NUM_LIT>:<EOL><INDENT>n_genes = <NUM_LIT><EOL><DEDENT>npcs = None<EOL>if npcs is None and numcells > <NUM_LIT>:<EOL><INDENT>npcs = <NUM_LIT><EOL><DEDENT>elif npcs is None and numcells > <NUM_LIT>:<EOL><INDENT>npcs = <NUM_LIT><EOL><DEDENT>elif npcs is None and numcells > <NUM_LIT:1000>:<EOL><INDENT>npcs = <NUM_LIT><EOL><DEDENT>elif npcs is None:<EOL><INDENT>npcs = <NUM_LIT><EOL><DEDENT>tinit = time.time()<EOL>edm = sp.coo_matrix((numcells, numcells), dtype='<STR_LIT:i>').tolil()<EOL>nums = np.arange(edm.shape[<NUM_LIT:1>])<EOL>RINDS = np.random.randint(<EOL><NUM_LIT:0>, numcells, (self.k - <NUM_LIT:1>) * numcells).reshape((numcells, <EOL>(self.k - <NUM_LIT:1>)))<EOL>RINDS = np.hstack((nums[:, None], RINDS))<EOL>edm[np.tile(np.arange(RINDS.shape[<NUM_LIT:0>])[:, None],<EOL>(<NUM_LIT:1>, RINDS.shape[<NUM_LIT:1>])).flatten(), RINDS.flatten()] = <NUM_LIT:1><EOL>edm = edm.tocsr()<EOL>print('<STR_LIT>')<EOL>W = self.dispersion_ranking_NN(<EOL>edm, num_norm_avg=<NUM_LIT:1>)<EOL>old = np.zeros(W.size)<EOL>new = W<EOL>i = <NUM_LIT:0><EOL>err = ((new - old)**<NUM_LIT:2>).mean()**<NUM_LIT:0.5><EOL>if max_iter < <NUM_LIT:5>:<EOL><INDENT>max_iter = <NUM_LIT:5><EOL><DEDENT>nnas = num_norm_avg<EOL>self.Ns=[edm]<EOL>self.Ws = [W]<EOL>while (i < max_iter and err > stopping_condition):<EOL><INDENT>conv = err<EOL>if(verbose):<EOL><INDENT>print('<STR_LIT>' + str(i) + '<STR_LIT>' + str(conv))<EOL><DEDENT>i += <NUM_LIT:1><EOL>old = new<EOL>W, wPCA_data, EDM, = self.calculate_nnm(<EOL>D, W, n_genes, preprocessing, npcs, numcells, nnas)<EOL>new = W<EOL>err = ((new - old)**<NUM_LIT:2>).mean()**<NUM_LIT:0.5><EOL>self.Ns.append(EDM)<EOL>self.Ws.append(W)<EOL><DEDENT>W, wPCA_data, EDM, = self.calculate_nnm(<EOL>D, W, n_genes, preprocessing, npcs, numcells, nnas)<EOL>self.Ns.append(EDM)<EOL>all_gene_names = np.array(list(self.adata.var_names))<EOL>indices = np.argsort(-W)<EOL>ranked_genes = all_gene_names[indices]<EOL>self.corr_bin_genes(number_of_features=<NUM_LIT:1000>)<EOL>self.adata.uns['<STR_LIT>'] = ranked_genes<EOL>self.adata.obsm['<STR_LIT>'] = wPCA_data<EOL>self.adata.uns['<STR_LIT>'] = {}<EOL>self.adata.uns['<STR_LIT>']['<STR_LIT>'] = EDM<EOL>if(projection == '<STR_LIT>'):<EOL><INDENT>print('<STR_LIT>')<EOL>self.run_tsne(**proj_kwargs)<EOL><DEDENT>elif(projection == '<STR_LIT>'):<EOL><INDENT>print('<STR_LIT>')<EOL>self.run_umap(**proj_kwargs)<EOL><DEDENT>elif(projection == '<STR_LIT>'):<EOL><INDENT>print('<STR_LIT>')<EOL>self.run_diff_umap(**proj_kwargs)<EOL><DEDENT>elapsed = time.time() - tinit<EOL>if verbose:<EOL><INDENT>print('<STR_LIT>' + str(elapsed) + '<STR_LIT>')<EOL><DEDENT>
Runs the Self-Assembling Manifold algorithm.

        Parameters
        ----------
        k - int, optional, default 20
            The number of nearest neighbors to identify for each cell.

        distance : string, optional, default 'correlation'
            The distance metric to use when constructing cell distance
            matrices. Can be any of the distance metrics supported by
            sklearn's 'pdist'.

        max_iter - int, optional, default 10
            The maximum number of iterations SAM will run.

        stopping_condition - float, optional, default 5e-3
            The stopping condition threshold for the RMSE between gene weights
            in adjacent iterations.

        verbose - bool, optional, default True
            If True, the iteration number and error between gene weights in
            adjacent iterations will be displayed.

        projection - str, optional, default 'umap'
            If 'tsne', generates a t-SNE embedding. If 'umap', generates a UMAP
            embedding. Otherwise, no embedding will be generated.

        preprocessing - str, optional, default 'Normalizer'
            If 'Normalizer', use sklearn.preprocessing.Normalizer, which
            normalizes expression data prior to PCA such that each cell has
            unit L2 norm. If 'StandardScaler', use
            sklearn.preprocessing.StandardScaler, which normalizes expression
            data prior to PCA such that each gene has zero mean and unit
            variance. Otherwise, do not normalize the expression data. We
            recommend using 'StandardScaler' for large datasets and
            'Normalizer' otherwise.

        num_norm_avg - int, optional, default 50
            The top 'num_norm_avg' dispersions are averaged to determine the
            normalization factor when calculating the weights. This prevents
            genes with large spatial dispersions from skewing the distribution
            of weights.

        proj_kwargs - dict, optional, default {}
            A dictionary of keyword arguments to pass to the projection
            functions.