用户工具

站点工具


个性化条目:细胞组分分析_music分析

使用方法

./MuSic --fpkm /TJPROJ6/RNA_SH/personal_dir/zhangxin/jiaoben/cibersort/fpkm.xls --condition /TJPROJ6/RNA_SH/personal_dir/zhangxin/jiaoben/cibersort/group.txt --prefix test --sc_file /TJPROJ6/RNA_SH/personal_dir/zhangxin/jiaoben/MuSiC/MuSic_scRNA-seq_data/biaoda.xls --sc_condition /TJPROJ6/RNA_SH/personal_dir/zhangxin/jiaoben/MuSiC/MuSic_scRNA-seq_data/pData.xls
#!/TJPROJ6/RNA_SH/personal_dir/zhangxin/miniconda/envs/R_3.6.0/bin/Rscript

suppressMessages({
library(MuSiC)
library(xbioc)
library(Biobase)
library(argparser)})

argv <- arg_parser('')
argv <- add_argument(argv,"--fpkm", help="the fpkm file")
argv <- add_argument(argv,"--sample", help="the sample name")
argv <- add_argument(argv,"--condition", help="the condition file")
argv <- add_argument(argv,"--prefix", help="the prefix")
argv <- add_argument(argv,"--sc_file", help="the sc expression file, eg:MuSic_scRNA-seq_data/biaoda.xls")
argv <- add_argument(argv,"--sc_condition", help="the sc sample condition, eg:MuSic_scRNA-seq_data/pData.xls")
argv <- parse_args(argv)

fpkm <- argv$fpkm
sample <- strsplit(argv$sample,",")[[1]]
condition <- argv$condition
prefix <- argv$prefix
sc_file <- argv$sc_file
sc_condition <- argv$sc_condition

#file
if (!is.na(sample)){
        stat <- read.delim(fpkm, header=T, sep='\t', quote='')
        stat <- stat[,c('gene_name',sample)]
        stat$gene_name <- toupper(as.character(stat$gene_name))
        if (ncol(stat) > 2){
                stat <- stat[order(rowSums(stat[,2:ncol(stat)]),decreasing=T),]
        }else{
                stat <- stat[order(stat[,2],decreasing=T),]
        }
        stat <- stat[!duplicated(stat$gene_name),]
}else if (!is.na(condition)){
        condition <- read.delim(condition, header=T, sep='\t', quote='')
        sample <- as.character(condition$sample)
        stat <- read.delim(fpkm, header=T, sep='\t', quote='')
        stat <- stat[,c('gene_name',sample)]
        stat$gene_name <- toupper(as.character(stat$gene_name))
        if (ncol(stat) > 2){
                stat <- stat[order(rowSums(stat[,2:ncol(stat)]),decreasing=T),]
        }else{
                stat <- stat[order(stat[,2],decreasing=T),]
        }
        stat <- stat[!duplicated(stat$gene_name),]
}else{
        stat <- read.delim(fpkm, header=T, sep='\t', quote='')
        stat[,1] <- as.character(stat[,1])
        if (ncol(stat) > 2){
                stat <- stat[order(rowSums(stat[,2:ncol(stat)]),decreasing=T),]
        }else{
                stat <- stat[order(stat[,2],decreasing=T),]
        }
        stat <- stat[!duplicated(stat$gene_name),]
}
rownames(stat) <- stat[,1]
stat <- stat[,-1]
rna_eset <- new("ExpressionSet", exprs = as.matrix(stat))

sc_condition_df <- read.delim(sc_condition,header=T,sep='\t',row.names=1,quote='')
sc_sample <- rownames(sc_condition_df)
sc_condition_df_ad <- new("AnnotatedDataFrame", data=sc_condition_df)
sc_fpkm <- read.delim(sc_file,header=T,sep='\t',row.names=1,quote='')
sc_stat <- sc_fpkm[,sc_sample]
sc_eset <- new("ExpressionSet", exprs = as.matrix(sc_stat), phenoData = sc_condition_df_ad)

res <- music_prop(bulk.eset = rna_eset, sc.eset = sc_eset, clusters = 'cellType',samples = 'sampleID', select.ct = c('alpha', 'beta', 'delta', 'gamma','acinar', 'ductal'), verbose = F)

MuSiC_cell_type <- res$Est.prop.weighted
MuSiC_cell_type <- data.frame(sample=rownames(MuSiC_cell_type),MuSiC_cell_type)
NNLS_cell_type <- res$Est.prop.allgene
NNLS_cell_type <- data.frame(sample=rownames(NNLS_cell_type),NNLS_cell_type)
MuSiC_estimated_weight_gene <- res$Weight.gene
MuSiC_estimated_weight_gene <- data.frame(gene_name=rownames(MuSiC_estimated_weight_gene),MuSiC_estimated_weight_gene)
write.table(MuSiC_cell_type,file=paste0(prefix,"_MuSiC_cell_type.xls"),sep='\t',row.names=F,quote=F)
write.table(NNLS_cell_type,file=paste0(prefix,"_NNLS_cell_type.xls"),sep='\t',row.names=F,quote=F)
write.table(MuSiC_estimated_weight_gene,file=paste0(prefix,"_MuSiC_estimated_weight_gene.xls"),sep='\t',row.names=F,quote=F)
个性化条目/细胞组分分析_music分析.txt · 最后更改: 2023/03/16 07:45 由 fengjie