码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • Harmony | 超好用的单细胞测序数据合并(3‘和5‘数据合并)(二)


    1写在前面

    对于只有只有部分重叠的datasets,合并方法我们依然可以采用Seurat、Harmony,rliger包,本期介绍一下Harmony包的用法。🤩

    2用到的包

    rm(list = ls())
    library(Seurat)
    library(SeuratDisk)
    library(SeuratWrappers)
    library(patchwork)
    library(harmony)
    library(rliger)
    library(RColorBrewer)
    library(tidyverse)
    library(reshape2)
    library(ggsci)
    library(ggstatsplot)
    • 1

    3示例数据

    这里我们提供1个3’ PBMC dataset和1个whole blood dataset。🥰

    umi_gz <- gzfile("./GSE149938_umi_matrix.csv.gz",'rt')  
    umi <- read.csv(umi_gz,check.names = F,quote = "")

    matrix_3p <- Read10X_h5("./3p_pbmc10k_filt.h5",use.names = T)
    • 1

    创建Seurat对象。🐶

    srat_wb <- CreateSeuratObject(t(umi),project = "whole_blood")
    srat_3p <- CreateSeuratObject(matrix_3p,project = "pbmc10k_3p")
    rm(umi_gz)
    rm(umi)
    rm(matrix_3p)
    srat_wb
    srat_3p
    • 1
    alt

    alt

    4修改metadata

    为了方便后续分析,这里我们对metadata进行一下注释修改。

    colnames(srat_wb@meta.data)[1] <- "cell_type"
    srat_wb@meta.data$orig.ident <- "whole_blood"
    srat_wb@meta.data$orig.ident <- as.factor(srat_wb@meta.data$orig.ident)
    head(srat_wb[[]])
    • 1
    alt

    5初步合并

    5.1 简单合并

    这里我们先用merge将2个数据集简单合并在一起。(这里我们默认做过初步过滤了哈,具体的大家可以看一下上期的教学。)😘

    wb_harmony  <- merge(srat_3p,srat_wb)
    • 1

    5.2 标准操作

    我们在这里做一下Normalization,寻找高变基因等等标准操作。👀

    wb_harmony <- NormalizeData(wb_harmony, verbose = F)
    wb_harmony <- FindVariableFeatures(wb_harmony, selection.method = "vst", nfeatures = 2000, verbose = F)
    wb_harmony <- ScaleData(wb_harmony, verbose = F)
    wb_harmony <- RunPCA(wb_harmony, npcs = 30, verbose = F)
    wb_harmony <- RunUMAP(wb_harmony, reduction = "pca", dims = 1:30, verbose = F)
    • 1

    6harmony合并数据

    6.1 合并前

    p1 <- DimPlot(object = wb_harmony, reduction = "pca", 
    pt.size = .1, group.by = "orig.ident") +
    scale_color_npg()+
    NoLegend()

    p2 <- VlnPlot(object = wb_harmony, features = "PC_1",
    group.by = "orig.ident", pt.size = .1) +
    scale_color_npg()+
    NoLegend()

    p1+p2
    • 1
    alt

    DimPlot(wb_harmony,reduction = "umap",
    group.by = "orig.ident") +
    scale_color_npg()+
    plot_annotation(title = "10k 3' PBMC and whole blood, before integration")
    • 1
    alt

    6.2 开始合并

    wb_harmony <- wb_harmony %>% 
    RunHarmony("orig.ident", plot_convergence = T)
    • 1
    alt

    6.3 查看信息

    harmony_embeddings <- Embeddings(wb_harmony, 'harmony')
    harmony_embeddings[1:5, 1:5]
    • 1
    alt

    6.4 可视化-harmony

    harmony合并后。

    p1 <- DimPlot(object = wb_harmony, reduction = "harmony", pt.size = .1, group.by = "orig.ident") + 
    scale_color_npg()+
    NoLegend()

    p2 <- VlnPlot(object = wb_harmony, features = "harmony_1", group.by = "orig.ident", pt.size = .1) +
    scale_fill_npg()+
    NoLegend()
    p1 +p2
    • 1
    alt

    6.5 可视化-UMAP

    harmony合并后。

    wb_harmony <- SetIdent(wb_harmony,value = "orig.ident")
    DimPlot(wb_harmony,reduction = "umap") +
    scale_color_npg()+
    plot_annotation(title = "10k 3' PBMC and whole blood, after integration (Harmony)")
    • 1
    alt

    7降维与聚类

    7.1 寻找clusters

    wb_harmony <- wb_harmony %>% 
    RunUMAP(reduction = "harmony", dims = 1:30, verbose = F) %>%
    FindNeighbors(reduction = "harmony", k.param = 10, dims = 1:30) %>%
    FindClusters() %>%
    identity()
    • 1
    alt

    wb_harmony <- SetIdent(wb_harmony,value = "seurat_clusters")

    ncluster <- length(unique(wb_harmony[[]]$seurat_clusters))

    mycol <- colorRampPalette(brewer.pal(8, "Set2"))(ncluster)

    DimPlot(wb_harmony,label = T,
    cols = mycol, repel = T) +
    NoLegend()
    • 1
    alt

    7.3 具体查看及可视化

    我们看下各个clusters在两个datasets各有多少细胞。

    count_table <- table(wb_harmony@meta.data$seurat_clusters, wb_harmony@meta.data$orig.ident)
    count_table

    #### 可视化
    count_table %>%
    as.data.frame() %>%
    ggbarstats(x = Var2,
    y = Var1,
    counts = Freq)+
    scale_fill_npg()
    • 1
    alt

    西红柿
    最后祝大家早日不卷!~

    需要示例数据的小伙伴,在公众号回复Merge2获取吧!

    点个在看吧各位~ ✐.ɴɪᴄᴇ ᴅᴀʏ 〰

    📍 往期精彩

    📍 🤨 Google | 谷歌翻译崩了我们怎么办!?(附完美解决方案)
    📍 🤩 scRNA-seq | 吐血整理的单细胞入门教程
    📍 🤔 Reticulate | 如何在Rstudio中优雅地调用Python!?
    📍 🤣 NetworkD3 | 让我们一起画个动态的桑基图吧~
    📍 🤩 RColorBrewer | 再多的配色也能轻松搞定!~
    📍 🧐 rms | 批量完成你的线性回归
    📍 🤒 CMplot | 连Nature上的曼哈顿图都卷起来啦
    📍 🤩 CMplot | 完美复刻Nature上的曼哈顿图
    📍 🤠 Network | 高颜值动态网络可视化工具
    📍 🤗 boxjitter | 完美复刻Nature上的高颜值统计图
    📍 🤫 linkET | 完美解决ggcor安装失败方案(附教程)
    📍 ......

    本文由 mdnice 多平台发布

  • 相关阅读:
    java-php-python-日常办公管理系统计算机毕业设计
    Apple官网的动效
    Trie树/字典树的原理及实现[C/C++]
    Python特征分析重要性的常用方法
    分享一下奶茶店怎么在小程序上做商城功能
    计算机毕业设计Java校园面包超市系统(源码+系统+mysql数据库+Lw文档)
    S2SH小区物业管理理系统计算机毕业论文Java项目源码下载
    图论20(Leetcode1254.统计封闭岛屿的数目)
    Y2期末测试
    安卓毕业设计选题基于Uniapp实现的鲜花购物商城
  • 原文地址:https://blog.csdn.net/m0_72224305/article/details/127628279
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号