日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Heart_deconvolution giotto解卷积

發(fā)布時(shí)間:2023/12/8 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Heart_deconvolution giotto解卷积 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

title: “Heart_deconvolution”
#https://github.com/rdong08/spatialDWLS_dataset
output: html_document

#https://github.com/rdong08/spatialDWLS_dataset/blob/main/codes/Heart_ST_tutorial_spatialDWLS.Rmd

##Import library

```{r}

library(Giotto)
library(ggplot2)
library(scatterpie)
library(data.table)
#getwd() path="G:/silicosis/sicosis/gitto/heart_visu_deconv/" setwd(path) ##Here is an example for tutorial by using spatial transcriptomic data of Sample 10, W6 in Asp et al. ##Identification of marker gene expression in single cell #{r}
#sc_meta<-read.table("…/datasets/heart_development_ST/sc_meta.txt",header = F,row.names = 1)
#sc_data<-read.table("…/datasets/heart_development_ST/all_cells_count_matrix_filtered.tsv",header = T,row.names = 1)

sc_meta=read.table(“G:/silicosis/sicosis/gitto/heart_visu_deconv/sc_meta.txt”,
header =FALSE,row.names = 1)
head(sc_meta)

sc_data<-read.table(“G:/silicosis/sicosis/gitto/heart_visu_deconv/all_cells_count_matrix_filtered.tsv/all_cells_count_matrix_filtered.tsv”,
header = T,row.names = 1)
head(sc_data)


my_python_path = “python path”
instrs = createGiottoInstructions(python_path = my_python_path)
heart_sc <- createGiottoObject(raw_exprs = sc_data,
instructions = instrs)

heart_sc <- normalizeGiotto(gobject = heart_sc, scalefactor = 6000, verbose = T)

heart_sc <- calculateHVG(gobject = heart_sc)

gene_metadata = fDataDT(heart_sc)
featgenes = gene_metadata[hvg == ‘yes’]$gene_ID

heart_sc <- runPCA(gobject = heart_sc, genes_to_use = featgenes, scale_unit = F)
signPCA(heart_sc, genes_to_use = featgenes, scale_unit = F)

#######calculate Sig for deconvolution, This step use DEG function implemented in Giotto

heart_sc@cell_metadata$leiden_clus <- as.character(sc_meta$V3)

scran_markers_subclusters = findMarkers_one_vs_all(gobject = heart_sc,
method = ‘scran’,
expression_values = ‘normalized’,
cluster_column = ‘leiden_clus’)

Sig_scran <- unique(scran_markers_subclustersgenes[which(scranmarkerssubclustersgenes[which(scran_markers_subclustersgenes[which(scranm?arkerss?ubclustersranking <= 100)])

########Calculate median expression value of signature genes in each cell type

norm_exp<-2^(heart_sc@norm_expr)-1

id<-heart_sc@cell_metadata$leiden_clus
ExprSubset<-norm_exp[Sig_scran,]

Sig_exp<-NULL

for (i in unique(id)){
Sig_exp<-cbind(Sig_exp,(apply(ExprSubset,1,function(y) mean(y[which(id==i)]))))
}
colnames(Sig_exp)<-unique(id)
#```

##Spatial transcriptomic data analysis
#```{r}
##The heart spatial transcriptomic data is from Asp et al “A Spatiotemporal Organ-Wide Gene Expression and Cell Atlas of the Developing Human Heart”.
spatial_loc<-read.table(file="…/datasets/heart_development_ST/sample10_w6_loc.txt",header = F)

spatial_exp<-read.table(file="…/datasets/heart_development_ST/sample10_w6_exp.txt",header = T,row.names = 1)

##Transform ensemble gene to official gene name
ens2gene<-read.table(file="…/datasets/heart_development_ST/ens2symbol.txt",row.names = 1)

inter_ens<-intersect(rownames(spatial_exp),rownames(ens2gene))

filter_spatial_exp<-spatial_exp[inter_ens,]
rownames(filter_spatial_exp)<-as.character(ens2gene[inter_ens,])

##Generate Giotto objects and cluster spots
heart_w6_sample10_st <- createGiottoObject(raw_exprs = filter_spatial_exp,spatial_locs = spatial_loc,
instructions = instrs)
heart_w6_sample10_st <- filterGiotto(gobject = heart_w6_sample10_st,
expression_threshold = 1,
gene_det_in_min_cells = 10,
min_det_genes_per_cell = 200,
expression_values = c(‘raw’),
verbose = T)

heart_w6_sample10_st <- normalizeGiotto(gobject = heart_w6_sample10_st)
heart_w6_sample10_st <- calculateHVG(gobject = heart_w6_sample10_st)
gene_metadata = fDataDT(heart_w6_sample10_st)

featgenes = gene_metadata[hvg == ‘yes’]$gene_ID
heart_w6_sample10_st <- runPCA(gobject = heart_w6_sample10_st, genes_to_use = featgenes, scale_unit = F)
signPCA(heart_w6_sample10_st, genes_to_use = featgenes, scale_unit = F)

heart_w6_sample10_st <- createNearestNetwork(gobject = heart_w6_sample10_st, dimensions_to_use = 1:10, k = 10)
heart_w6_sample10_st <- doLeidenCluster(gobject = heart_w6_sample10_st, resolution = 0.4, n_iterations = 1000)
##Deconvolution based on signature gene expression and Giotto object
heart_w6_sample10_st <- runDWLSDeconv(gobject = heart_w6_sample10_st, sign_matrix = Sig_exp)
##The result for deconvolution is stored in heart_w6_sample10_st@spatial_enrichmentDWLS.Thefollowingcodesarevisualizationdeconvolutionresultsusingpieplotplotdata<?as.data.frame(heartw6sample10st@spatialenrichmentDWLS. The following codes are visualization deconvolution results using pie plot plot_data <- as.data.frame(heart_w6_sample10_st@spatial_enrichmentDWLS.Thefollowingcodesarevisualizationdeconvolutionresultsusingpieplotplotd?ata<?as.data.frame(heartw?6s?ample10s?t@spatiale?nrichmentDWLS)[-1]
plot_col <- colnames(plot_data)

plot_datax<?as.numeric(as.character(heartw6sample10st@spatiallocsx <- as.numeric(as.character(heart_w6_sample10_st@spatial_locsx<?as.numeric(as.character(heartw?6s?ample10s?t@spatiall?ocssdimx))
plot_datay<?as.numeric(as.character(heartw6sample10st@spatiallocsy <- as.numeric(as.character(heart_w6_sample10_st@spatial_locsy<?as.numeric(as.character(heartw?6s?ample10s?t@spatiall?ocssdimy))
min_x <- min(plot_datax)plotdatax) plot_datax)plotd?ataradius <- 0.4

df <- data.frame()
p <- ggplot(df) + geom_point() + xlim(min(plot_datax)?1,max(plotdatax)-1, max(plot_datax)?1,max(plotd?atax)+1) + ylim(min(plot_datay)?1,max(plotdatay)-1, max(plot_datay)?1,max(plotd?atay)+1)
p + geom_scatterpie(aes(x=x, y=y, r=radius), data=plot_data, cols=plot_col, color=NA, alpha=.8) +
geom_scatterpie_legend(plot_data$radius, x=1, y=1) + theme_classic()
#``

總結(jié)

以上是生活随笔為你收集整理的Heart_deconvolution giotto解卷积的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。