news 2026/2/1 1:44:44

SCS 59.单细胞空间转录组空间度量(SPATA2)

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
SCS 59.单细胞空间转录组空间度量(SPATA2)

Spatial Measures

介绍

空间转录组学和图像分析领域中,研究人员试图回答的许多问题都与空间相关。观测值的坐标通常会缩放到当前使用的图像分辨率。以Visium平台为例,如果将10X Visium输出中的tissue_lowres_image.png替换为tissue_hires_image.png,条形码斑点的坐标会相应缩放,以确保坐标与图像保持对齐。因此,坐标可用于回答相对空间问题,但不能用于绝对度量。例如,“坏死区域的面积约为400像素”这一说法是没有意义的。如果以像素为单位,面积将始终取决于图像分辨率。本教程将解释SPATA2如何通过像素比例因子计算Visium平台从像素到SI单位的转换,并提供关于如何利用SI距离进行工作的示例。

library(SPATA2) library(tidyverse)
# load SPATA2 inbuilt example data (and rename an image for this tutorial) object_t275 <- loadExampleObject("UKF275T") %>% renameImage(img_name = "image1", new_img_name = "lowres")
text_size <- theme(text = element_text(size = 17.5)) plotImage(object_t275, img_name = "lowres") + text_size + labs(subtitle = "Normal resolution")

# very_low_res image has been registered using `registerImage()` plotImage(object_t275, img_name = "very_low_res") + text_size + labs(subtitle = "Very low resolution")

2. 像素比例因子

要以绝对数值回答问题,必须将距离转换为国际单位制(SI)单位,即微米、毫米、厘米等。这是可能的,因为大多数空间组学研究都带有真实值。

2.1 Visium

在10X Visium的情况下,此真实值是两个相邻条形码点之间的中心到中心距离,该距离始终为100微米。利用此信息,可通过像素比例因子计算实际距离和面积。该比例因子由initiateSpataObjectVisium()自动计算。(如果您在SPATA2对象中注册了多张图像,请注意,默认情况下会使用活动图像的像素比例因子。)

# how many um is one pixel in side lengths getPixelScaleFactor(object_t275, unit = "um")
## [1] 13.68328 ## attr(,"unit") ## [1] "um/px"
# how many pixel is one um in side lengths getPixelScaleFactor(object_t275, unit = "um", switch = TRUE)
## [1] 0.07308187 ## attr(,"unit") ## [1] "px/um"
# by default the pixel scale factor of the active image is used getImageNames(object_t275)
## [1] "lowres" "very_low_res"
# which is image 'lowres' in this example activeImage(object_t275)
## [1] "lowres"
# how many um is one pixel in side lengths in case of an even lower resolution? getPixelScaleFactor(object_t275, unit = "um", img_name = "very_low_res")
## [1] 78.94202 ## attr(,"unit") ## [1] "um/px"

2.2 MERFISH and Co

像素比例因子这一术语源于SPATA2最初仅被认为适用于Visium数据集的时期。后来,其应用范围已扩展到其他平台,例如MERFISH,该平台提供以微米为单位的细胞坐标。如果平台提供的观测坐标单位为国际单位制(SI)单位,则理论上不需要像素比例因子。但为了使SPATA2代码正常运行,SPATA2object中必须存在该比例因子。因此,它会由相应的initiateSpataObject*()函数自动设置。例如,在MERFISH数据中,x坐标和y坐标以微米(um)为单位提供。因此,通过initiateSpataObjectMERFISH()函数初始化的SPATA2对象的像素比例因子始终为1毫米/像素。

3. 距离的运用

多个函数的参数以某种方式涉及距离度量。SPATA2 使用 units 包来处理距离。除非文档中有其他说明,否则可以将距离以像素或 SI 单位提供。在后台,输入会被转换为像素并与当前分辨率对齐。4.1 距离转换部分给出了如何进行此操作的一些示例。

3.1 处理距离输入和输出

validUnitsOfLength()
## nanometer micrometer millimeter centimeter decimeter meter pixel ## "nm" "um" "mm" "cm" "dm" "m" "px"
# wrappers around units::set_units() as_micrometer(input = "4mm")
## 4000 [um]
as_millimeter(input = "4cm")
## 40 [mm]
### convert from si -> pixel # example 1: a simple string works as_pixel(input = "4mm", object = object_t275)
## [1] 292.3275 ## attr(,"unit") ## [1] "px"
# example 2: a unit object works, too unit_input <- units::set_units(x = 4, value = "mm") unit_input
## 4 [mm]
class(unit_input)
## [1] "units"
as_pixel(input = unit_input, object = object_t275)
## [1] 292.3275 ## attr(,"unit") ## [1] "px"
### convert from pixel -> si # example 1: simple numeric input is interpreted as pixel as_millimeter( input = c(100, 200, 300), object = object_t275 )
## Units: [mm] ## [1] 1.368328 2.736657 4.104985
# example 2: strings with px suffix work, too as_micrometer( input = c("50px", "200px", "800px"), object = object_t275 )
## Units: [um] ## [1] 684.1642 2736.6568 10946.6271

3.2 Examples

以下是一些实际距离可能发挥作用的例子。

# specifying x- and y-range while handling images xrange = c("2.5mm", "6.5mm") yrange = c("0.5mm", "4.5mm") # where to set the breaks is a measure of distance, too breaks <- str_c(0:8, "mm") # vector of valid distance inputs print(breaks)
## [1] "0mm" "1mm" "2mm" "3mm" "4mm" "5mm" "6mm" "7mm" "8mm"
axes_add_on <- ggpLayerAxesSI(object_t275, unit = "mm", breaks = breaks) rect_add_on <- ggpLayerRect( object = object_t275, xrange = xrange, yrange = yrange ) plotImage(object = object_t275) + rect_add_on + axes_add_on + text_size

plotImage( object = object_t275, xrange = xrange, # crop the image with distance input yrange = yrange # crop the image with distance input ) + text_size

plotImage(object_t275) + ggpLayerAxesSI(object_t275, unit = "mm", breaks = breaks) + ggpLayerSpatAnnOutline(object_t275, ids = "img_ann_1", fill = "orange") + ggpLayerHorizonSAS(object_t275, id = "img_ann_1", distance = "1mm") + ggpLayerScaleBarSI(object_t275, sb_dist = "1mm", sb_pos = c("5.5mm", "7.5mm"), text_size = 15, text_nudge_y = 10) + text_size

4. 与区域相关的工作

除了距离之外,还可以计算面积。这在例如图像注释的面积与生物学问题相关时会变得有趣。

4.1 处理区域输入和输出

validUnitsOfArea()
## [1] "nm2" "um2" "mm2" "cm2" "dm2" "m2" "px"
validUnitsOfAreaSI()
## [1] "nm2" "um2" "mm2" "cm2" "dm2" "m2"
getPixelScaleFactor(object_t275, unit = "um2", img_name = "lowres")
## [1] 187.2323 ## attr(,"unit") ## [1] "um2/px"
# more um2 per pixel in the very low resolution image # -> pixels are smaller getPixelScaleFactor(object_t275, unit = "um2", img_name = "very_low_res")
## [1] 6231.843 ## attr(,"unit") ## [1] "um2/px"
# numeric input is interpreted as pixel as_millimeter2(input = c(200, 400, 4000, 50000), object = object_t275)
## Units: [mm^2] ## [1] 0.03744645 0.07489290 0.74892903 9.36161289
# if character, different units can be specified as input as_centimeter2(input = c("4mm2", "400px"), object = object_t275)
## Units: [cm^2] ## [1] 0.040000000 0.000748929

4.2 Examples

# process the diet example object object_t313 <- identifyTissueOutline(example_data$object_UKF313T_diet)
# set ids of example spatial annotations ids <- c("necrotic_area", "necrotic_edge", "necrotic_edge2") plotSpatialAnnotations(object_t313, ids = ids, nrow = 1)

# process the diet example object object_mouse <- loadExampleObject("LMU_MCI") object_mouse <- identifyTissueOutline(object_mouse)
# get tissue area by tisse section getTissueArea(object_mouse, unit = "mm2")
## Units: [mm^2] ## tissue_section_1 tissue_section_2 ## 6.349445 7.945489
getTissueArea(object_t313, unit = "mm2")
## 29.67623 [mm^2]
# left plotImage(object_t313, unit = "mm") + ggpLayerTissueOutline(object_t313)

# right plotImage(object_mouse, unit = "mm") + ggpLayerTissueOutline(object_mouse)

# use the three necrotic ids from above spat_ann_areas <- getSpatAnnArea(object = object_t313, ids = ids, unit = "mm2") print(spat_ann_areas)
## Units: [mm^2] ## necrotic_area necrotic_edge necrotic_edge2 ## 6.1849516 0.4618869 0.6252351
threshold <- units::set_units(x = 1, value = "mm2") # keep only those with an area smaller than 1mm2 print(spat_ann_areas[spat_ann_areas < threshold])
## Units: [mm^2] ## necrotic_edge necrotic_edge2 ## 0.4618869 0.6252351
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/1/30 16:20:02

Java计算机毕设之基于java+springboot博客管理系统设计和实现基于springboot个人博客系统的设计与实现(完整前后端代码+说明文档+LW,调试定制等)

博主介绍&#xff1a;✌️码农一枚 &#xff0c;专注于大学生项目实战开发、讲解和毕业&#x1f6a2;文撰写修改等。全栈领域优质创作者&#xff0c;博客之星、掘金/华为云/阿里云/InfoQ等平台优质作者、专注于Java、小程序技术领域和毕业项目实战 ✌️技术范围&#xff1a;&am…

作者头像 李华
网站建设 2026/1/26 2:22:49

Java计算机毕设之基于springboot大学生心理健康分析及干预平台基于springboot高校心理健康评测与服务系统(完整前后端代码+说明文档+LW,调试定制等)

博主介绍&#xff1a;✌️码农一枚 &#xff0c;专注于大学生项目实战开发、讲解和毕业&#x1f6a2;文撰写修改等。全栈领域优质创作者&#xff0c;博客之星、掘金/华为云/阿里云/InfoQ等平台优质作者、专注于Java、小程序技术领域和毕业项目实战 ✌️技术范围&#xff1a;&am…

作者头像 李华
网站建设 2026/1/30 8:33:34

Java计算机毕设之基于springboot高校师资管理系统基于springboot高校师资资源管理系统(完整前后端代码+说明文档+LW,调试定制等)

博主介绍&#xff1a;✌️码农一枚 &#xff0c;专注于大学生项目实战开发、讲解和毕业&#x1f6a2;文撰写修改等。全栈领域优质创作者&#xff0c;博客之星、掘金/华为云/阿里云/InfoQ等平台优质作者、专注于Java、小程序技术领域和毕业项目实战 ✌️技术范围&#xff1a;&am…

作者头像 李华
网站建设 2026/1/22 19:05:05

Arknights-UI:H5复刻明日方舟游戏主界面完整指南

Arknights-UI&#xff1a;H5复刻明日方舟游戏主界面完整指南 【免费下载链接】arknights-ui H5 复刻版明日方舟游戏主界面 项目地址: https://gitcode.com/gh_mirrors/ar/arknights-ui Arknights-UI是一个基于H5和CSS技术实现的明日方舟游戏主界面复刻项目&#xff0c;为…

作者头像 李华
网站建设 2026/1/29 13:01:32

计算机Java毕设实战-基于SpringBoot+Vue工厂生产设备维护管理系统springboot工厂生产设备维护管理系统的设计【完整源码+LW+部署说明+演示视频,全bao一条龙等】

博主介绍&#xff1a;✌️码农一枚 &#xff0c;专注于大学生项目实战开发、讲解和毕业&#x1f6a2;文撰写修改等。全栈领域优质创作者&#xff0c;博客之星、掘金/华为云/阿里云/InfoQ等平台优质作者、专注于Java、小程序技术领域和毕业项目实战 ✌️技术范围&#xff1a;&am…

作者头像 李华
网站建设 2026/1/31 20:26:51

MYSQL数据库------多表查询

多表查询1&#xff0c;多表关系1.1&#xff0c;一对多&#xff08;多对一&#xff09;1.2&#xff0c;多对多1.3&#xff0c;一对一1&#xff0c;多表关系 项目开发中&#xff0c;在进行数据库表结构设计时&#xff0c;会根据业务需求以及业务模块之间的关系&#xff0c;分析并…

作者头像 李华