Danko-Lab / BayesPrism

A Fully Bayesian Inference of Tumor Microenvironment composition and gene expression
147 stars 46 forks source link

Using known cell type fractions #90

Closed oriolpich closed 2 months ago

oriolpich commented 3 months ago

Dear Tinyi,

Thanks so much for developing (and maintaining) such great software. This is more of a question rather than an issue. We were wondering whether it would be possible to start from known fractions and use BayesPrism to do in sillico gene expression purification of the different cell-types.

Thanks so much in advance.

Best wishes,

Oriol

tinyi commented 3 months ago

Hi Oriol,

Apologize for the delay.

Thank you for your interest in our method. To answer your question, it is generally not recommended to use the known fractions due to the reason that the cell type fraction inferred by BayesPrism represents reads% from each cell type rather than cell count%. I assume that the known fraction you mentioned would represent cell count%, so if you would like to rely on this information to impute gene expression, you may need to first convert it to reads% by multiplying a cell size factor, e.g. inferred from scRNA-seq. After this, you can then compute the expected mean of cell type-specifc gene expression conditional on bulk data and reads% of each cell type using the following function, which is essentially a part of the Gibbs sampling of BayesPrism .

' function to compute E[Z | X, theta, phi], the expected cell

type-specific gene expression Z

' conditional on observed mixture X, cell type fraction theta and

scRNA-seq reference phi

'

' @param X, observed mixture, a N-by-G matrix

' @param theta, MAP estimator of cell type fraction, a N-by-K matrix

' @param phi, scRNA-seq reference, a K-by-G matrix

E.Z <- function(X, theta, phi){

N <- nrow(X) G <- ncol(phi) K <- nrow(phi)

Z <- array(NA,c(N, G, K), dimnames=list(rownames(X),colnames(X),rownames(phi)))

X_over_theta_phi <- X / (theta %% phi) #NG

for(n in 1:N) { Z[n,,] <- t(phi theta[n,]) X_over_theta_phi[n,] }

return(Z) }

Best,

Tinyi

On Wed, Jun 19, 2024 at 5:57 AM Oriol Pich @.***> wrote:

Dear Tinyi,

Thanks so much for developing (and maintaining) such great software. This is more of a question rather than an issue. We were wondering whether it would be possible to start from known fractions and use BayesPrism to do in sillico gene expression purification of the different cell-types.

Thanks so much in advance.

Best wishes,

Oriol

— Reply to this email directly, view it on GitHub https://github.com/Danko-Lab/BayesPrism/issues/90, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB4NHS4IWOT6JPP5GD7RMDTZIFIYPAVCNFSM6AAAAABJRW5BUKVHI2DSMVQWIX3LMV43ASLTON2WKOZSGM3DCOJRHA2TINQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

oriolpich commented 2 months ago

Fantastic, thanks Tinyi!