atarashansky / self-assembling-manifold

The Self-Assembling-Manifold (SAM) algorithm.
MIT License
41 stars 11 forks source link

The weighted gene expression matrix #15

Closed fenghuijian closed 5 years ago

fenghuijian commented 5 years ago

Hi! How do I extract the weighted gene expression matrix. The sam.adata.X should be the input gene expression matrix

atarashansky commented 5 years ago

Hello,

The data used as input to PCA is stored in sam.adata.uns['X_processed']. Note that this particular matrix has already been standardized/normalized prior to PCA.

If you would like the full expression matrix rescaled by all the weights, without standardization, then you'll have to calculate it yourself:

w = sam.adata.var['weights'].get_values()
weighted_matrix = sam.adata.X.multiply(w).tocsr()
fenghuijian commented 5 years ago

So, Doesn't the gene expression matrix get iterated? I think the gene expression matrix gets iterated.

atarashansky commented 5 years ago

The gene weights get iterated. Each iteration, they are used to rescale the original gene expression matrix prior to PCA.

fenghuijian commented 5 years ago

So, sam.adata.X is the weighted gene expression matrix for n-1 iterations, right? (n is the number of iterations)

atarashansky commented 5 years ago

sam.adata.X is the original expression matrix which gets rescaled by the weights prior to PCA. The weights and the nearest neighbor graph are the only objects getting updated each iteration.

fenghuijian commented 5 years ago

weighted_matrix = sam.adata.X.multiply(w).tocsr() This function is just multiplying the weights by the original expression matrix. And it isn't the weight gene expression matrix of the last iteration.

atarashansky commented 5 years ago

Those weights are the output of the final iteration! SAM iteratively updates the gene weights and nearest neighbor graph -- not the expression data. To get the weighted gene expression matrix used in the last iteration, simply multiply those weights into the gene expression matrix. Sorry for the confusion.

fenghuijian commented 5 years ago

Thank you very much for your reply