R语言常用代码

这篇博客涵盖了R语言的多种实用技巧,包括单细胞基因过滤、数据框查看、R包安装、数据重塑、分组操作、图片处理、多核处理以及文件转换等。此外,还涉及到了生存曲线分析、热图绘制、PCA和TSNE等统计方法的应用。
摘要由CSDN通过智能技术生成
my R
# Calculate gene signature score
### ---------------
###
### Create: Yuan.Sh
### Date: 2021-11-22 16:35:19
### Email: yuansh3354@163.com
### Blog: https://blog.csdn.net/qq_40966210
### Fujian Medical University
### Ref : https://github.com/carmonalab/UCell_demo
###
### ---------------

############# Step.00 ############# 
# clean
rm(list = ls())
gc()

# packages
library(Seurat)
library(stringr)
library(scales)
library(magrittr)
library(RColorBrewer)
library(ggplot2)
library(UCell)

# myfunctions 
myhead = function(x,DT=FALSE){
   
  print(paste('Data dimension: ',dim(x)[1],dim(x)[2]))
  if(dim(x)[2]>5){
   print(x[1:5,1:5])}
  else(print(head(x)))
  if(DT){
   DT::datatable(x,filter='top')}
}

mycolors = c("#1a476f","#90353b","#55752f","#e37e00","#6e8e84",
             "#c10534","#938dd2","#cac27e","#a0522d","#7b92a8",
             "#2d6d66","#9c8847","#bfa19c","#ffd200","#d9e6eb",
             "#4DBBD5B2", "#00A087B2", "#3C5488B2", 
             "#F39B7FB2", "#8491B4B2","#91D1C2B2","#DC0000B2",
             "#7E6148B2","#E64B35B2",'#698EC3')
show_col(mycolors)


# options
options(stringsAsFactors = F)
options(as.is = T)
setwd('/media/yuansh/14THHD/BscModel-V4/supplementary materials/DEGs')

# main
df = read.csv('GSE131907-Cancer_absolute_scale_wilcoxon.csv',row.names = 1)
df = df[which( (abs(df$logfoldchanges) > 2) & (df$pvals_adj < 0.05) ),]
############# 
单细胞基因过滤
### ---------------
### Create: Yuan.Sh, MD (ORCID: 0000-0002-6028-0185)
### Date: Aug. 30, 2022
### Email: yuansh3354@163.com
### Blog: https://blog.csdn.net/qq_40966210
### Github: https://github.com/yuansh3354/
### Fujian Medical University. No. 1 Xue Yuan Road,University Town, 350122 FuZhou Fujian, China
### National Center for Nanoscience and Technology (NCNST). No.11 ZhongGuanCun BeiYiTiao, 100190 Beijing, China
### ---------------

############# Step.00 ############# 
Pseudogenes = read.csv('Result/Pseudogenes.csv')
eliminate_genes = function(sce.obj,Pseudogenes){
  
  sce.obj[["percent.mt"]]  = PercentageFeatureSet(sce.obj, pattern = "^MT-")
  if(sum(grepl('^MT-',rownames(sce.obj))) > 0){
    sce.obj = sce.obj[!grepl('^MT-',rownames(sce.obj)),] # 过滤线粒体
  }
  
  ids = intersect(Pseudogenes[,1],rownames(sce.obj)) %>% setdiff(rownames(sce.obj),.)
  
  if(length(ids)>0){sce.obj = sce.obj[ids,]}
  
  if(sum(grepl('\\.[0-9]+$&#
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值