{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "58c958e9",
   "metadata": {},
   "source": [
    "---\n",
    "title: SeekSpace 空间转录组数据分析教程 (Seurat / 小鼠脑)\n",
    "author: SeekGene\n",
    "date: 2026-01-29\n",
    "tags:\n",
    "  - 空间转录组\n",
    "  - 分析指南\n",
    "  - Notebooks\n",
    "  - 基础分析\n",
    "---\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f0bce8f6-7f1c-4f7a-ad17-f2a9a423e100",
   "metadata": {},
   "source": [
    "# SeekSpace 空间转录组数据分析教程 (Seurat / 小鼠脑)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "15209c28-7649-42a9-96aa-69eb3d7cd9cf",
   "metadata": {},
   "source": [
    "## 背景信息\n",
    "本⽂档是关于寻因 SeekSpace 技术所得到的数据及其 Seurat 分析⽅法的说明。<br>\n",
    "寻因 SeekSpace 技术可以检测到单细胞精度的基因表达数据，同时也能定位出每个细胞在组织中的空间坐标。<br>\n",
    "SeekSpace 的数据分析简便易学，能够很方便地兼容常见单细胞转录组的分析软件，例如 Seurat 和 scanpy。<br>\n",
    "本数据为基于 SeekSpace 技术的⼩⿏脑的空间数据。数据中包含 32,758 个细胞的单细胞转录组矩阵，空间坐标矩阵，组织 DAPI 染⾊图⽚和 HE 图片。<br>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e0dde4c3-3ab8-4557-81c7-2f042ddd878f",
   "metadata": {
    "tags": []
   },
   "source": [
    "## ⽂件说明\n",
    "SeekSpace 技术的配套的基础数据处理的软件是 SeekSpace® Tools，该软件可以从测序文库中识别细胞的表达信息，同时可以识别出每个细胞在空间上的位置。<br>\n",
    "经过 SeekSpace® Tools 软件处理之后所得到的结果文件格式如下：\n",
    "\n",
    "├── WTH1092_filtered_feature_bc_matrix # 表达矩阵⽬录，可以使⽤Seurat 的 Read10X 命令进⾏读取<br>\n",
    "│ ├── barcodes.tsv.gz<br>\n",
    "│ ├── features.tsv.gz<br>\n",
    "│ ├── matrix.mtx.gz<br>\n",
    "│ └── cell_locations.tsv.gz 为⼩⿏脑测序数据中细胞的空间坐标⽂件。第 1 列是 barcode，顺序与 matrix 中的 filtered_feature_bc_matrix/barcode 中细胞的顺序⼀致；第 2 列和第 3 列分别为该 barcode 所代表的细胞的空间位置（即空间芯⽚上的像素坐标）。<br>\n",
    "\n",
    "├── WTH1092_aligned_DAPI.png # 为⼩⿏脑组织切⽚的 DAPI 染⾊图⽚<br>\n",
    "├── WTH1092_aligned_HE.png<br>\n",
    "├── WTH1092_aligned_HE_TIMG.png<br>\n",
    "├── seekspace_of_Seurat.ipynb # 为使⽤Seurat 分析该⼩⿏脑空间数据的 jupyter 示例⽂件<br>\n",
    "└── seekspace_of_scanpy.ipynb # 为使⽤scanpy 分析该⼩⿏脑空间数据的 jupyter 示例⽂件<br>\n",
    "SeekSpace 技术中一个像素点的大小是约为 0.2653 微米，将像素点的坐标乘以 0.2653 即可转换计算细胞在真实空间上的距离。<br>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "73dec346-5553-491e-89e7-a21a52b35eec",
   "metadata": {
    "tags": [],
    "vscode": {
     "languageId": "r"
    }
   },
   "outputs": [],
   "source": [
    "library(Seurat)\n",
    "library(tidyverse)\n",
    "library(ggplot2)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "78de97ba-7364-47b0-91f3-5a0faf0f7b4d",
   "metadata": {},
   "source": [
    "## 创建 Seurat 对象\n",
    "读取 SeekSpace 的矩阵⽂件，这里直接使用 Seurat 常用的读入和创建矩阵的方法即可。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9ec085be-3679-48d0-a58b-c5a79658c63f",
   "metadata": {
    "tags": [],
    "vscode": {
     "languageId": "r"
    }
   },
   "outputs": [],
   "source": [
    "mouse_brain.data <- Read10X('./Outs/WTH1092_filtered_feature_bc_matrix')\n",
    "mouse_brain <- CreateSeuratObject(counts=mouse_brain.data,project='mouse_brain')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "31bcc43b-2a62-43b7-bfb8-9fc41db19ef8",
   "metadata": {},
   "source": [
    "## 降维聚类\n",
    "这里使用常见的默认参数进行降维聚类，实际分析的时候，可以按照样品的特征进行相应的修改。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "47b68136-062b-473a-8a5c-7beccf92167c",
   "metadata": {
    "tags": [],
    "vscode": {
     "languageId": "r"
    }
   },
   "outputs": [],
   "source": [
    "mouse_brain <- NormalizeData(mouse_brain, normalization.method = \"LogNormalize\", scale.factor = 10000) %>%\n",
    "FindVariableFeatures(selection.method = \"vst\", nfeatures = 2000) %>%\n",
    "ScaleData() %>%\n",
    "RunPCA() %>%\n",
    "FindNeighbors(dims = 1:15) %>%\n",
    "FindClusters(resolution = seq(0.2, 1.4, 0.3)) %>%\n",
    "RunUMAP(dims = 1:15)\n",
    "Idents(mouse_brain) <- 'RNA_snn_res.0.8'"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fe49df72-752d-4cd2-8bfb-6c8c3f5e3feb",
   "metadata": {
    "tags": []
   },
   "source": [
    "## 添加空间坐标\n",
    "\n",
    "接下来我们使用 Seurat 的 CreateDimReducObject 函数，给 Seurat 对象中的每个细胞添加一个空间的坐标。<br>\n",
    "注意！！<br>\n",
    "CreateDimReducObject 函数读入空间坐标矩阵的细胞的顺序必须与 mouse_brain 里面的 meta.data 里面细胞的顺序相一致，否则在多样品整合分析的时候会出现细胞顺序错乱的情况。<br>\n",
    "这里我们使用了一个简单的一行代码对空间坐标矩阵进行了排序。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7fde5a91-c13e-442b-ac8f-0a029caafedd",
   "metadata": {
    "tags": [],
    "vscode": {
     "languageId": "r"
    }
   },
   "outputs": [],
   "source": [
    "spatial_df <- read.table('./Outs/WTH1092_filtered_feature_bc_matrix/cell_locations.tsv.gz', row.names = 1, sep = '\\t',header = T)\n",
    "colnames(spatial_df) <- c(\"spatial_1\",\"spatial_2\")\n",
    "spatial_matrix <- as.matrix(spatial_df)\n",
    "spatial_matrix_sorted <- spatial_matrix[match(row.names(mouse_brain@meta.data),row.names(spatial_matrix)), ]\n",
    "mouse_brain@reductions$spatial <- CreateDimReducObject(embeddings = spatial_matrix_sorted, key='spatial_', assay='RNA')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e1f4446d-8ce8-4c23-932a-50b296e41d28",
   "metadata": {
    "tags": [],
    "vscode": {
     "languageId": "r"
    }
   },
   "outputs": [],
   "source": [
    "head(mouse_brain@reductions$spatial@cell.embeddings)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "710fa609-34a0-4c9f-a2e7-1c37c424f8a0",
   "metadata": {},
   "source": [
    "经过这步处理之后，我们可以在 Seurat 对象中看到一个新的坐标系”spatial“，这个坐标系即为每个细胞在空间位置上的坐标。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0fdd9972-9a4e-431b-8177-38635176fe49",
   "metadata": {
    "tags": [],
    "vscode": {
     "languageId": "r"
    }
   },
   "outputs": [],
   "source": [
    "str(mouse_brain@reductions$spatial)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cd06e819-bd18-476d-a04e-81c78d0d4828",
   "metadata": {},
   "source": [
    "## 添加组织图像信息\n",
    "\n",
    "下面我们展示一下在空间数据上添加背景图片。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f5217e03-f0e9-402d-bd19-4c72cffe7ef1",
   "metadata": {
    "vscode": {
     "languageId": "r"
    }
   },
   "outputs": [],
   "source": [
    "samplename = 'WTH1092'\n",
    "size_x = 55128\n",
    "size_y = 19906\n",
    "#如果芯片编号的倒数第二个字母是A，则size_x=55128，size_y=19906;\n",
    "#如果芯片编号的倒数第二个字母是B，则size_x=55050，size_y=19906;\n",
    "#如果芯片编号的倒数第二个字母是C，则size_x=55050，size_y=19906.\n",
    "#(可以在samplename_report.html质控报告的Summary Table中查看芯片编号)\n",
    "mouse_brain@misc$info[[`samplename`]]$size_x = as.integer(size_x)\n",
    "mouse_brain@misc$info[[`samplename`]]$size_y = as.integer(size_y)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3ad85090-a844-41b2-ba96-ecf3f144aec7",
   "metadata": {},
   "source": [
    "### 添加 DAPI 图片"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "89ed6579-1e1c-4725-8897-db5f38a57193",
   "metadata": {
    "tags": [],
    "vscode": {
     "languageId": "r"
    }
   },
   "outputs": [],
   "source": [
    "img = './Outs/WTH1092_aligned_DAPI.png'  \n",
    "\n",
    "#base64格式\n",
    "img_64 = base64enc::dataURI(file = img)\n",
    "mouse_brain@misc$info[[`samplename`]]$img = img_64\n",
    "#png格式\n",
    "img_gg <- png::readPNG(img)\n",
    "img_grob <- grid::rasterGrob(img_gg, interpolate = FALSE, width = grid::unit(1,\"npc\"), height = grid::unit(1, \"npc\"))\n",
    "mouse_brain@misc$info[[`samplename`]]$img_gg = img_grob"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c6d73eaf-fb6c-4f52-a256-9cca88fef330",
   "metadata": {},
   "source": [
    "### 添加 HE 图片"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "afa2b878-9fed-4ce5-9716-2d362ac83912",
   "metadata": {
    "tags": [],
    "vscode": {
     "languageId": "r"
    }
   },
   "outputs": [],
   "source": [
    "img = './Outs/WTH1092_aligned_HE_TIMG.png'  \n",
    "\n",
    "#base64格式\n",
    "img_64 = base64enc::dataURI(file = img)\n",
    "mouse_brain@misc$info[[`samplename`]]$img_he = img_64\n",
    "#png格式\n",
    "img_gg <- png::readPNG(img)\n",
    "img_grob <- grid::rasterGrob(img_gg, interpolate = FALSE, width = grid::unit(1,\"npc\"), height = grid::unit(1, \"npc\"))\n",
    "mouse_brain@misc$info[[`samplename`]]$img_he_gg = img_grob"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "de612682-a2b0-40a0-a1c6-0ea2626ea563",
   "metadata": {
    "tags": [],
    "vscode": {
     "languageId": "r"
    }
   },
   "outputs": [],
   "source": [
    "str(mouse_brain@misc$info)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c83557a3-bab8-4813-a309-15ecf98bf074",
   "metadata": {},
   "source": [
    "## 细胞注释结果\n",
    "接下来我们再把细胞的注释结果添加到每个细胞上，这样我们就可以看不同的细胞类型在空间上的分布情况了。<br>\n",
    "SeekSpace 细胞注释的过程，跟普通的单细胞注释的过程完全一致。<br>\n",
    "我们之前已经对 demo 数据进行了大群和亚群的注释，注释的结果文件放在了 anntation.csv 文件中。<br>\n",
    "接下来我们简单的读入处理一下。<br>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5d21f125-761f-4c74-8a44-bf3cdfa2ed22",
   "metadata": {
    "tags": [],
    "vscode": {
     "languageId": "r"
    }
   },
   "outputs": [],
   "source": [
    "anno <- read.csv(\"./annotation.csv\",row.names = 1,header = TRUE)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "40712448-722e-40f5-802d-8b86f8e0be67",
   "metadata": {
    "tags": [],
    "vscode": {
     "languageId": "r"
    }
   },
   "outputs": [],
   "source": [
    "mouse_brain <- AddMetaData(mouse_brain, anno)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bf292783-09d6-4f0b-9e7e-760988b037fd",
   "metadata": {
    "tags": [],
    "vscode": {
     "languageId": "r"
    }
   },
   "outputs": [],
   "source": [
    "head(mouse_brain)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "24c8c80b-d817-4c12-ad59-3c3942817147",
   "metadata": {
    "tags": [],
    "vscode": {
     "languageId": "r"
    }
   },
   "outputs": [],
   "source": [
    "saveRDS(mouse_brain,\"WTH1092_demo_mouse_brain.rds\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3ee18aab-9181-4582-b7f6-cc2c0a049af3",
   "metadata": {},
   "source": [
    "## 结果可视化\n",
    "经过 Seurat 处理后的数据保存为 rds，我们可以继续使用 Seurat 包默认的一系列函数进行绘图\n",
    "### 空间坐标绘图"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "01f565a9-8327-48b2-8c49-1c741ba1f478",
   "metadata": {
    "tags": [],
    "vscode": {
     "languageId": "r"
    }
   },
   "outputs": [],
   "source": [
    "#dimplot umap\n",
    "options(repr.plot.height=7, repr.plot.width=7)\n",
    "DimPlot(mouse_brain, reduction = 'umap')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "473ddb47-a582-4858-8bc1-6b636fbc6f9e",
   "metadata": {
    "tags": [],
    "vscode": {
     "languageId": "r"
    }
   },
   "outputs": [],
   "source": [
    "options(repr.plot.height=10, repr.plot.width=10)\n",
    "FeaturePlot(mouse_brain, reduction = 'umap', features=c('Mbp','Mobp', 'Olig1','Plp1'), pt.size = 1)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "df1c8dc0-6356-48d3-954e-0a058fd78c90",
   "metadata": {},
   "source": [
    "当我们把 DimPlot 函数中的 reduction 参数设置为 \"spatial\" 的时候，我们即可将细胞绘制在空间水平上。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "87b44040-2e10-4727-9f34-e2e656e49bd1",
   "metadata": {
    "tags": [],
    "vscode": {
     "languageId": "r"
    }
   },
   "outputs": [],
   "source": [
    "options(repr.plot.height=7, repr.plot.width=15)\n",
    "DimPlot(mouse_brain, reduction = 'spatial',pt.size = 1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "546699ce-b928-4039-a84b-9a1ce0d1ee24",
   "metadata": {
    "tags": [],
    "vscode": {
     "languageId": "r"
    }
   },
   "outputs": [],
   "source": [
    "options(repr.plot.height=7, repr.plot.width=15)\n",
    "DimPlot(mouse_brain, reduction = 'spatial',pt.size = 1,group.by = \"Sub_CellType\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "15cced14-650b-465b-a3e0-ee91fcb67f3f",
   "metadata": {},
   "source": [
    "同样，我们可以在使用 FeaturePlot 函数时，将 reduction 参数设置为\"spatial\"，来查看基因在空间位置上的表达情况。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9e2e009c-8f09-4958-8b51-0a6d4820bc9e",
   "metadata": {
    "tags": [],
    "vscode": {
     "languageId": "r"
    }
   },
   "outputs": [],
   "source": [
    "options(repr.plot.height=10, repr.plot.width=20)\n",
    "FeaturePlot(mouse_brain, reduction = 'spatial', features = c('Mbp','Mobp', 'Olig1','Plp1'),pt.size = 0.7)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9d622f8e-c59c-4d43-b877-20f26985349c",
   "metadata": {},
   "source": [
    "SeekSpace 数据对 Seurat 的兼容性比较好，取子集等等函数均可运行。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ad6bae8e-c228-4bcb-b714-8001b2eb5ce8",
   "metadata": {
    "tags": [],
    "vscode": {
     "languageId": "r"
    }
   },
   "outputs": [],
   "source": [
    "options(repr.plot.height=7, repr.plot.width=15)\n",
    "sub_mouse_brain <- subset(mouse_brain, Main_CellType == 'Ext')\n",
    "DimPlot(sub_mouse_brain, reduction = 'spatial',pt.size = 1.5, group.by = \"Main_CellType\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "16d6e88f-f43c-48d3-ba06-b4192a7300c6",
   "metadata": {},
   "source": [
    "### 带有 DAPI/HE 的图片绘制\n",
    "自定义了 ImageSpacePlot 和 FeatureSpacePlot 两个函数绘制细胞在空间上的分群信息和细胞连续变量的指标"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d80100af-6755-431e-932b-480b2fa1941a",
   "metadata": {
    "tags": [],
    "vscode": {
     "languageId": "r"
    }
   },
   "outputs": [],
   "source": [
    "######################绘图细胞分群函数\n",
    "ImageSpacePlot = function(obj, group_by, type=\"DAPI\", sample=names(obj@misc$info)[1], size=1, alpha=1,color=MYCOLOR){\n",
    "    MYCOLOR=c(\n",
    "          \"#6394ce\", \"#2a4c87\", \"#eed500\", \"#ed5858\",\n",
    "          \"#f6cbc2\", \"#f5a2a2\", \"#3ca676\", \"#6cc9d8\",\n",
    "          \"#ef4db0\", \"#992269\", \"#bcb34a\", \"#74acf3\",\n",
    "          \"#3e275b\", \"#fbec7e\", \"#ec4d3d\", \"#ee807e\",\n",
    "          \"#f7bdb5\", \"#dbdde6\", \"#f591e1\", \"#51678c\",\n",
    "          \"#2fbcd3\", \"#80cfc3\", \"#fbefd1\", \"#edb8b5\",\n",
    "          \"#5678a8\", \"#2fb290\", \"#a6b5cd\", \"#90d1c1\",\n",
    "          \"#a4e0ea\", \"#837fd3\", \"#5dce8b\", \"#c5cdd9\",\n",
    "          \"#f9e2d6\", \"#c64ea4\", \"#b2dfd6\", \"#dbdfe7\",\n",
    "          \"#dff2ec\", \"#cce8f3\", \"#e74d51\", \"#f7c9c4\",\n",
    "          \"#f29c81\", \"#c9e6e0\", \"#c1c5de\", \"#750000\"\n",
    "          )\n",
    "        \n",
    "        raster_type <- switch(type,\n",
    "                          HE = \"img_he_gg\",\n",
    "                          DAPI = \"img_gg\",\n",
    "                          stop(\"Invalid type. Must be 'HE' or 'DAPI'.\")\n",
    "                             )\n",
    "\n",
    "        spatial_coord1 <- as.data.frame(obj[[group_by]])\n",
    "        colnames(spatial_coord1) <- group_by\n",
    "        spatial_coord2 <- as.data.frame(obj@reductions$spatial@cell.embeddings)\n",
    "        spatial_coord <-cbind(spatial_coord2,spatial_coord1)\n",
    " \n",
    "    \n",
    "        ImageSpacePlot <- ggplot2::ggplot() + ggplot2::annotation_custom(grob = obj@misc$info[[sample]][[raster_type]],\n",
    "        xmin = 0, xmax = obj@misc$info[[sample]]$size_x, \n",
    "        ymin = 0, ymax = obj@misc$info[[sample]]$size_y) +\n",
    "        ggplot2::geom_point(data = spatial_coord, ggplot2::aes(x = spatial_1,y = spatial_2, color = !!sym(group_by), \n",
    "                            fill = !!sym(group_by)), size=size, alpha=alpha)+\n",
    "        labs(size = group_by) + guides(alpha = \"none\")+ \n",
    "        ggplot2::theme_classic()+\n",
    "        scale_color_manual(values = color)+ coord_fixed()\n",
    "    return(ImageSpacePlot)\n",
    "}\n",
    "\n",
    "###################绘图基因表达函数\n",
    "FeatureSpacePlot = function(obj, feature, type=\"DAPI\", sample=names(obj@misc$info)[1], size=1, alpha=c(1,1),color=c(\"lightgrey\",\"blue\")){\n",
    "    raster_type <- switch(type,\n",
    "                          HE = \"img_he_gg\",\n",
    "                          DAPI = \"img_gg\",\n",
    "                          stop(\"Invalid type. Must be 'HE' or 'DAPI'.\")\n",
    "                             )\n",
    "\n",
    "    spatial_coord1 <- as.data.frame(obj@reductions$spatial@cell.embeddings)\n",
    "    spatial_coord2 <- FetchData(obj,feature)\n",
    "    colnames(spatial_coord2) <- feature\n",
    "    spatial_coord <-cbind(spatial_coord1,spatial_coord2)\n",
    "\n",
    "    FeatureSpacePlot <-ggplot2::ggplot() + ggplot2::annotation_custom(grob = obj@misc$info[[sample]][[raster_type]],\n",
    "        xmin = 0, xmax = obj@misc$info[[sample]]$size_x, ymin = 0, ymax = obj@misc$info[[sample]]$size_y) +\n",
    "        ggplot2::geom_point(data = spatial_coord, ggplot2::aes(x = spatial_1, y = spatial_2,color = !!sym(feature),alpha = !!sym(feature)), size=size)+\n",
    "        labs(color = feature)+\n",
    "        guides(alpha = \"none\")+\n",
    "        ggplot2::theme_classic()+\n",
    "        ggplot2::scale_alpha_continuous(range=alpha)+\n",
    "        scale_color_gradient(low=color[1],high = color[2])+ coord_fixed()\n",
    "    return(FeatureSpacePlot)\n",
    "    }"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "20b82128-b3ff-4e5f-86f6-ff3168149717",
   "metadata": {
    "tags": [],
    "vscode": {
     "languageId": "r"
    }
   },
   "outputs": [],
   "source": [
    "# DAPI背景的细胞分群图\n",
    "options(repr.plot.height=7, repr.plot.width=15)\n",
    "ImageSpacePlot(obj=mouse_brain, group_by = \"Sub_CellType\",type=\"DAPI\",size=0.7)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "09b9df7a-1f6c-438d-be6d-6ad35257e157",
   "metadata": {
    "tags": [],
    "vscode": {
     "languageId": "r"
    }
   },
   "outputs": [],
   "source": [
    "# HE背景的细胞分群图\n",
    "options(repr.plot.height=7, repr.plot.width=15)\n",
    "ImageSpacePlot(obj=mouse_brain, group_by = \"Sub_CellType\",type=\"HE\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e21e0c12-61c6-4061-9d1a-13a8d1f68994",
   "metadata": {
    "vscode": {
     "languageId": "r"
    }
   },
   "outputs": [],
   "source": [
    "# DAPI背景的基因表达图\n",
    "options(repr.plot.height=7, repr.plot.width=15)\n",
    "FeatureSpacePlot(obj=mouse_brain, feature=\"Hpca\",type=\"DAPI\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9fff9884-b180-458c-9baa-33998032ad9d",
   "metadata": {
    "tags": [],
    "vscode": {
     "languageId": "r"
    }
   },
   "outputs": [],
   "source": [
    "# HE背景的基因表达图\n",
    "options(repr.plot.height=7, repr.plot.width=15)\n",
    "FeatureSpacePlot(obj=mouse_brain, feature=\"Hpca\",type=\"HE\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3d6f7c35-b846-4db0-a018-011322caa58e",
   "metadata": {
    "vscode": {
     "languageId": "r"
    }
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "r4",
   "language": "R",
   "name": "r4"
  },
  "language_info": {
   "codemirror_mode": "r",
   "file_extension": ".r",
   "mimetype": "text/x-r-source",
   "name": "R",
   "pygments_lexer": "r",
   "version": "4.1.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
