#将分组文件加载到环境中,分组信息第一列为样本名,第二列为分组信息如“high”“low”
./1-QC") setwd("./1-QC") # 如果过滤的太狠,就需要去修改这个过滤代码 source('.. /scRNA_scripts/check-all-markers.R') setwd('../') getwd() dir.create('check-by-0.2') setwd('check-by /scRNA_scripts/check-all-markers.R') setwd('../') getwd() dir.create('check-by-0.8') setwd('check-by /scRNA_scripts/check-all-markers.R') setwd('../') getwd() last_markers_to_check 那就直接选择0.2进行后续的命名吧! /scRNA_scripts/check-all-markers.R') setwd('../') getwd() } phe=sce.all.int@meta.data save(phe,
./1-QC") setwd("./1-QC") # 如果过滤的太狠,就需要去修改这个过滤代码 source('.. /scRNA_scripts/qc.R') sce.all.filt = basic_qc(sce.all) print(dim(sce.all)) print(dim(sce.all.filt)) setwd sce.all.int$RNA_snn_res.0.1) table(sce.all.int$RNA_snn_res.0.8) getwd() dir.create('check-by-0.1') setwd /scRNA_scripts/check-all-markers.R') setwd('../') getwd() dir.create('check-by-0.8') setwd('check-by /scRNA_scripts/check-all-markers.R') setwd('../') getwd() 然后就是合理的生物学命名了 我给大家准备的基因列表主要是针对肿瘤单细胞的第一层次降维聚类分群
TCGAbiolinks) library(dplyr) library(tidyr) library(tibble) library(edgeR) library(limma) rm(list=ls()) setwd ################################################################################# rm(list=ls()) setwd # ########################################################################################### setwd index,] row.names(mRNA_exprSet) <- mRNA_exprSet$gene_name mRNA_exprSet$gene_name <- NULL setwd('D:\ Barcode == 'T') mRNA_exprSet <- mRNA_exprSet[,which(colnames(mRNA_exprSet) %in% metadata$barcode)] setwd
./1-QC") setwd("./1-QC") # 如果过滤的太狠,就需要去修改这个过滤代码 source('.. /scRNA_scripts/check-all-markers.R') setwd('../') getwd() dir.create('check-by-0.5') setwd('check-by /scRNA_scripts/check-all-markers.R') setwd('../') getwd() dir.create('check-by-0.8') setwd('check-by /scRNA_scripts/check-all-markers.R') setwd('../') getwd() last_markers_to_check Sys.time() ###### /scRNA_scripts/check-all-markers.R') setwd('../') getwd() phe=sce.all.int@meta.data save(phe
./1-QC") setwd("./1-QC") # 如果过滤的太狠,就需要去修改这个过滤代码 source('.. /scRNA_scripts/qc.R') sce.all.filt = basic_qc(sce.all) print(dim(sce.all)) print(dim(sce.all.filt)) setwd sce.all.int$RNA_snn_res.0.1) table(sce.all.int$RNA_snn_res.0.8) getwd() dir.create('check-by-0.1') setwd /scRNA_scripts/check-all-markers.R') setwd('../') getwd() dir.create('check-by-0.8') setwd('check-by /scRNA_scripts/check-all-markers.R') setwd('../') getwd() 然后就是合理的生物学命名了 前面强调了研究团队做单细胞转录组的时候,筛选了免疫细胞
./1-QC") setwd("./1-QC") # 如果过滤的太狠,就需要去修改这个过滤代码 source('../../.. /scRNA_scripts/check-all-markers.R') setwd('../') getwd() dir.create('check-by-0.5') setwd('check-by /scRNA_scripts/check-all-markers.R') setwd('../') getwd() dir.create('check-by-0.8') setwd('check-by /scRNA_scripts/check-all-markers.R') setwd('../') getwd() 可以看到,这个时候取了子集后的单细胞转录组数据对象,仍然是进行了harmony整合哦 /com_go_kegg_ReactomePA_mice.R') com_go_kegg_ReactomePA_human(symbols_list, pro='b' ) setwd('../')
============= # # # # =================================================== rm(list=ls()) setwd <- merge( metadata, dt, by='id') 第二步: 循环绘图 # =================================================== setwd ============================ library(dplyr) library(tidyr) library(tidyverse) rm(list=ls()) setwd Barcode', "Grade") dt <- merge(sur, dt, by='Barcode') dt$Grade <- as.factor(as.character(dt$Grade)) setwd
BD单个样本 1 在r中读取并理解数据 # 导入必要的包 library(data.table) dir.create("~/gzh/20240405_gse201088_pbmc_covid/") setwd qc.R') sce.all.filt = basic_qc(sce.all) print(dim(sce.all)) print(dim(sce.all.filt)) print(getwd()) setwd 来去除批次效应---- sce.all.filt head(sce.all.filt@meta.data) if(T){ dir.create("2-harmony") getwd() setwd ('../') getwd() #####整合完成之后,查看0.5分辨率------ dir.create('check-by-0.5') setwd('check-by-0.5') sel.clust ('../') getwd() #####整合完成之后,查看0.8分辨率------ dir.create('check-by-0.8') setwd('check-by-0.8') sel.clust
./1-QC") setwd("./1-QC") # 如果过滤的太狠,就需要去修改这个过滤代码 source('.. /scRNA_scripts/qc.R') sce.all.filt = basic_qc(sce.all) print(dim(sce.all)) print(dim(sce.all.filt)) setwd ('../') ###### step3: harmony整合多个单细胞样品 ###### dir.create("2-harmony") getwd() setwd("2-harmony") source sce.all.int$RNA_snn_res.0.1) table(sce.all.int$RNA_snn_res.0.8) getwd() dir.create('check-by-0.1') setwd /scRNA_scripts/check-all-markers.R') setwd('../') getwd() dir.create('check-by-0.8') setwd('check-by
/scRNA_scripts/qc.R') sce.all.filt = basic_qc(sce.all) print(dim(sce.all)) print(dim(sce.all.filt)) setwd /scRNA_scripts/check-all-markers.R') setwd('../') getwd() dir.create('check-by-0.8') setwd('check-by /scRNA_scripts/check-all-markers.R') setwd('../') getwd() last_markers_to_check step5: 确定单细胞亚群生物学名字 .0.1.pdf') gplots::balloonplot(table(sce.all.int$RNA_snn_res.0.1,sce.all.int$orig.ident)) dev.off() setwd /scRNA_scripts/check-all-markers.R') setwd('../') getwd() } image.png step6:热图可视化 getwd() #step6
./1-QC") setwd("./1-QC") # 如果过滤的太狠,就需要去修改这个过滤代码 source('.. /scRNA_scripts/qc.R') sce.all.filt = basic_qc(sce.all) print(dim(sce.all)) print(dim(sce.all.filt)) setwd sce.all.int$RNA_snn_res.0.1) table(sce.all.int$RNA_snn_res.0.8) getwd() dir.create('check-by-0.1') setwd /scRNA_scripts/check-all-markers.R') setwd('../') getwd() dir.create('check-by-0.8') setwd('check-by /scRNA_scripts/check-all-markers.R') setwd('../') getwd() 然后就是合理的生物学命名了 我给大家准备的基因列表主要是针对肿瘤单细胞的第一层次降维聚类分群
R笔记基本操作 getwd() 得出文件路径 setwd() setwd(dir= "/Users/PhD/Rdata/") 设定文件路径 list.files() dir() 得出文件夹全部文件 x
./1-QC.loose") setwd("./1-QC.loose") # 如果过滤的太狠,就需要去修改这个过滤代码 source('.. ###### step3: harmony整合多个单细胞样品 ###### if(T){ dir.create("2-harmony.loose") getwd() setwd /scRNA_scripts/check-all-markers.R') setwd('../') getwd() } #### strict version: { sce.all.filt /scRNA_scripts/check-all-markers.R') setwd('../') getwd() 提取髓系细胞亚群重新进行标准化以及降维聚类分群 在0.1的分辨率下,也提取了髓系免疫细胞 /scRNA_scripts/check-paper-myeloid-markers.R') setwd('../') getwd() phe=sce_myeloid@meta.data
./1-QC") setwd("./1-QC") # 如果过滤的太狠,就需要去修改这个过滤代码 source('.. ('../') sp='human' ###### step3: harmony整合多个单细胞样品 ###### dir.create("2-harmony") getwd() setwd("2- /scRNA_scripts/check-all-markers.R') setwd('../') getwd() dir.create('check-by-0.8') setwd('check-by /scRNA_scripts/check-all-markers.R') setwd('../') getwd() dir.create('check-by-0.5') setwd('check-by /scRNA_scripts/check-all-markers.R') setwd('../') getwd() last_markers_to_check scanpy版本的python代码
TCGAbiolinks) library(dplyr) library(tidyr) library(tibble) library(edgeR) library(limma) rm(list=ls()) setwd # ########################################################################################### setwd index,] row.names(mRNA_exprSet) <- mRNA_exprSet$gene_name mRNA_exprSet$gene_name <- NULL setwd('D:\ TCGAbiolinks) library(dplyr) library(tidyr) library(tibble) library(edgeR) library(limma) rm(list=ls()) setwd ################################# options(stringsAsFactors = F) library(stringr) rm(list=ls()) setwd
./1-QC") setwd("./1-QC") # 如果过滤的太狠,就需要去修改这个过滤代码 source('../../.. /scRNA_scripts/qc.R') sce.all.filt = basic_qc(sce.all) print(dim(sce.all)) print(dim(sce.all.filt)) setwd ../') getwd() ###### step3: harmony整合多个单细胞样品 ###### if(T){ dir.create("2-harmony") getwd() setwd # 默认 ScaleData 没有添加"nCount_RNA", "nFeature_RNA" # 默认的 sce.all.int = run_harmony(sce.all.filt) setwd /scRNA_scripts/check-all-markers.R') setwd('../') getwd() 这个时候很明显的可以看到上皮细胞的降维聚类分群居然是出现了淋巴系和髓系免疫细胞的干扰哦
其他使用者会报错; 如果在脚本开发过程中进行了其他配置,如stringsAsFactors = FALSE,而未在脚本中声明,则其他使用者也会报错; 可能外部读取使用了相对路径,而在命令行中直接修改了路径setwd (这也是不建议使用setwd 的原因) 一些改善的策略: 用R studio 等可以通过project 为单位管理脚本的开发工具,可以很方便的每次在Rproj 文件所在的位置即设定为工作目录,而且可以非常方便的切换到其他的项目 ; 避免在脚本中使用rm(list=ls())、setwd(),可以使用rs.restartR() 替代rm(list=ls()); 将重要的对象导出到output 文件夹内,保存为.Rdata,其他脚本中如果需要使用可以直接读取
./1-QC") setwd("./1-QC") # 如果过滤的太狠,就需要去修改这个过滤代码 source('.. /scRNA_scripts/qc.R') sce.all.filt = basic_qc(sce.all) print(dim(sce.all)) print(dim(sce.all.filt)) setwd sce.all.int$RNA_snn_res.0.1) table(sce.all.int$RNA_snn_res.0.8) getwd() dir.create('check-by-0.1') setwd /scRNA_scripts/check-all-markers.R') setwd('../') getwd() dir.create('check-by-0.8') setwd('check-by /scRNA_scripts/check-all-markers.R') setwd('../') getwd() 然后就是合理的生物学命名了 前面强调了研究团队做单细胞转录组的时候,筛选了免疫细胞
============== rm(list = ls(all.names = TRUE)) options(stringsAsFactors = F) library(Matrix) setwd ', new='-', x=data$sample) setwd('D:\\SCIwork\\F38KRT\\s3') group <- read.csv('group2.csv', header )) out$gene <- rownames(dt_Con) # out <- out %>% # dplyr::filter(log2_FC > 0.5 & Pvalue < 0.05) setwd log2FC,p value和FDR,共3列; out<- as.data.frame(cbind(log2_FC,Pvalue,fdr)) out$gene <- rownames(dt_Con) setwd log2FC,p value和FDR,共3列; out<- as.data.frame(cbind(log2_FC,Pvalue,fdr)) out$gene <- rownames(dt_Con) setwd