数据格式转换

本教程将展示如何使用辅助分析流程 SAW convert 来实现基础的文件格式转换。为了让这工具更加简易好用,SAW convert 下设置了子模块用于具体执行转换任务,子模块通常被命名为"A2B",表示从A格式转换到B格式的过程。

为使此流程更加直观易用,在功能描述和命令行使用方式介绍后,给出了基于真实演示数据集的示例。请勿局限于示例中使用的文件及其文件名,因为它们仅供参考。

表达矩阵相关

gef2gem

转换 bin GEFGEM

GEM(Gene Expression Matrix)中记录的特征表达矩阵仅包含有一种 bin size,因此,在进行转换时需要设置明确的 --bin-size 参数。

saw convert gef2gem \
    --gef=/path/to/input/GEF \
    --bin-size=1 \
    --gem=/path/to/output/GEM

##example test
saw convert gef2gem \
    --gef=./C04144D5.tissue.gef \
    --bin-size=20 \
    --gem=./C04144D5.bin20.tissue.gem

转换 cellbin GEF 到 cellbin GEM

特别注意,在转换 cellbin GEFcellbin GEM 的过程中,需要用到每个 DNB 点上的表达信息(即bin1),所以需要加入 bin GEF 文件。

由于 cellbin GEF 的格式受限,转换过程中矩阵可能会丢失少量表达信息。如果想要生成 cellbin GEM,建议使用优化后的 bin2cell

saw convert gef2gem \
    --cellbin-gef=/path/to/input/cellbin/GEF \
    --gef=/path/to/input/bin/GEF \
    --cellbin-gem=/path/to/output/cellbin/GEM

gem2gef

转换 bin GEMbin GEF

  • 如果输入GEMbin1 维度的表达矩阵,则输出的GEF(基因表达文件)将是一个支持可视化的 GEF,其中包括 bin1、5、10、20、50、100、150、200 的表达矩阵信息。
  • 如果输入 GEM 不是 bin1 维度的表达矩阵,输出的 GEF 将只包含特定 bin size 的表达矩阵信息。
saw convert gem2gef \
    --gem=/path/to/input/GEM \
    --gef=/path/to/output/GEF

##example test
saw convert gem2gef \
    --gem=./C04144D5.tissue.gem \
    --gef=./C04144D5.tissue.gef

转换 cellbin GEMcellbin GEF

saw convert gem2gef \
    --cellbin-gem=/path/to/input/cellbin/GEM \
    --cellbin-gef=/path/to/output/cellbin/GEF

##example test
saw convert gem2gef \
    --gem=./C04144D5.adjusted.cellbin.gem \
    --gef=./C04144D5.adjusted.cellbin.gef

bin2tissue

从原始 bin GEF 中提取组织区域下的表达数据。

组织分割mask图对于定义样本的组织轮廓边界至关重要,从而生成组织维度上生成的表达矩阵。

saw convert bin2tissue \
    --gef=/path/to/input/GEF \
    --image=/path/to/cell/segmentation/image \
    --output=/path/to/output/directory

##example test
saw convert bin2tissue \
    --gef=./C04144D5.raw.gef \
    --image=./C04144D5_ssDNA_tissue_cut.tif \
    --output=./tissue_area_result

如果实验过程中没有拍摄显微镜图像,该模块可以直接基于空间转录组表达矩进行组织分割,提取对应组织区域下的表达信息。

saw convert bin2tissue \
    --gef=/path/to/input/GEF \
    --output=/path/to/output/directory

##example test
saw convert bin2tissue \
    --gef=./C04144D5.tissue.gef \
    --output=./tissue_area_result

结果目录下会有组织分割图 bin1_img_tissue_cut.tif 和组织区域下的表达矩阵 <SN>.tissue.gef

bin2cell

转换 bin GEF 到 cellbin GEF。

细胞分割图记录了单个细胞的轮廓信息,可以用于提取细胞维度的表达矩阵文件。

saw convert bin2cell \
    --gef=/path/to/input/GEF \
    --image=/path/to/cell/segmentation/image \
    --cellbin-gef=/path/to/output/cellbin/GEF

##example test    
saw convert bin2cell \
    --gef=./C04144D5.tissue.gef \
    --image=./C04144D5_ssDNA_mask.tif \  ## or C04144D5_ssDNA_mask_edm_dis_10.tif
    --cellbin-gef=./C04144D5.cellbin.gef   ## or C04144D5.adjusted.cellbin.gef

SAW 8.2 开始,bin2cell 提供了一种改进的方法,可以从raw bin GEF 直接生成 cellbin GEM,如果需要使用cellbin GEM开展下游分析,建议使用此模块的方法。

saw convert bin2cell \
    --gef=/path/to/input/bin/GEF \  ## if concerned about tissue area, use <SN>.tissue.gef
    --image=/path/to/input/cell/segmentation/TIFF \
    --cellbin-gef=/path/to/output/cellbin/GEF \
    --cellbin-gem=/path/to/output/cellbin/GEM

##example test
saw convert bin2cell \
    --gef=./C04144D5.tissue.gef \
    --image=./C04144D5_ssDNA_mask.tif \  ## or C04144D5_ssDNA_mask_edm_dis_10.tif
    --cellbin-gef=./C04144D5.cellbin.gef \  ## or C04144D5.adjusted.cellbin.gef
    --cellbin-gem=./C04144D5.cellbin.gem  ## or C04144D5.adjusted.cellbin.ge

visualization

转换原始 GEF 为 支持可视化的 GEF。

原始 GEF(Gene Expression File)仅在 bin1 维度上储存基因表达信息,是为了防止输出文件过大。然而,要在 StereoMap 中进行可视化,需要包含不同 bin size 的表矩阵信息,通常使用的 bin size 列表 [1, 5, 10, 20, 50, 100, 150, 200]。

saw convert visualization \
    --gef=/path/to/input/GEF \
    --bin-size=1,5,10,20,50,100,150,200 \
    --visualization-gef=/path/to/output/visualization/GEF

##example test
saw convert visualization \
    --gef=./C04144D5.raw.gef \
    --bin-size=1,5,10,20,50,100,150,200 \
    --visualization-gef=./C04144D5.gef

gef2h5ad

转换 bin GEF 到 AnnData H5AD。

AnnData H5AD 是被广泛引用于下游分析的数据格式。AnnData包版本 >= 0.8.0。

saw convert gef2h5ad \
    --gef=/path/to/input/GEF \
    --bin-size=20 \
    --h5ad=/path/to/output/h5ad

##example test
saw convert gef2h5ad \
    --gef=./C04144D5.tissue.gef \
    --bin-size=20 \
    --h5ad=./C04144D5.bin20.h5ad

转换 cellbin GEF 到 AnnData H5AD。

saw convert gef2h5ad \
    --cellbin-gef=/path/to/input/cellbin/GEF \
    --h5ad=/path/to/output/h5ad

##example test
saw convert gef2h5ad \
    --cellbin-gef=./C04144D5.cellbin.gef \
    --h5ad=./C04144D5.cellbin.h5ad

gem2h5ad

转换 bin GEM 到 AnnData H5AD。

saw convert gem2h5ad \
    --gem=/path/to/input/GEM \
    --bin-size=20 \
    --h5ad=/path/to/output/h5ad

##example test
saw convert gem2h5ad \
    --gem=./C04144D5.tissue.gem \
    --bin-size=20 \
    --h5ad=./C04144D5.bin20.h5ad

转换 cellbin GEM 到 AnnData h5ad。

saw convert gem2h5ad \
    --cellbin-gem=/path/to/input/cellbin/GEM \
    --h5ad=/path/to/output/h5ad

##example test
saw convert gem2h5ad \
    --cellbin-gem=./C04144D5.cellbin.gem \
    --h5ad=./C04144D5.cellbin.h5ad

gef2rds

转化 bin GEF 为 RDS 格式文件。

RDS 文件格式是一种序列化数据结构,用于保存和加载 R 中的 Seurat 数据对象。

saw convert gef2rds \
    --gef=/path/to/input/bin/GEF \
    --bin-size=20 \
    --rds=/path/to/output/seurat/rds

##example test  
saw convert gef2rds \
    --gef=./C04144D5.tissue.gef \
    --bin-size=20 \
    --rds=./C04144D5.bin20.tissue.rds

转化 cellbin GEF 为 RDS 格式文件。

saw convert gef2rds \
    --cellbin-gef=/path/to/input/cellbin/GEF \
    --rds=/path/to/output/seurat/rds

##example test  
saw convert gef2rds \
    --cellbin-gef=./C04144D5.cellbin.gef \
    --rds=./C04144D5.cellbin.rds

gem2rds

转化 bin GEM 为 RDS 格式文件。

saw convert gem2rds \
    --gem=/path/to/input/bin/GEM \
    --bin-size=20 \
    --rds=/path/to/output/seurat/rds

##example test  
saw convert gem2rds \
    --gem=./C04144D5.tissue.gem \
    --bin-size=20 \
    --rds=./C04144D5.bin20.tissue.rds

转化 cellbin GEM 为 RDS 格式文件。

saw convert gem2rds \
    --cellbin-gem=/path/to/input/cellbin/GEM \
    --rds=/path/to/output/seurat/rds

##example test  
saw convert gem2rds \
    --cellbin-gem=./C04144D5.cellbin.gem \
    --rds=./C04144D5.cellbin.rds

h5ad2rds

转化 AnnData H5AD 为 RDS 格式文件,用于 Seurat 软件中的下游分析。

saw convert h5ad2rds \
    --h5ad=/path/to/input/anndata/h5ad \
    --rds=/path/to/output/rds/file

##example test  
saw convert h5ad2rds \
    --h5ad=./C04144D5.cellbin.h5ad \
    --rds=./C04144D5.cellbin.rds

gef2img

生成 bin GEF 的灰度热图,采用灰度图展示特征表达矩阵。

saw convert gef2img \
    --gef=/path/to/input/GEF \
    --bin-size=1 \
    --image=/path/to/output/heatmap/TIFF/image

##example test  
saw convert gef2img \
    --gef=./SS200000135TL_D1.raw.gef \
    --bin-size=1 \
    --image=./res_bin1.tif

图像相关

tar2img

从压缩图像 .tar.gz 文件中提取 TIFF 图像,其中通常包含与表达矩阵配准后的显微镜图像,组织分割图像,和细胞分割图像。自动算法或手动处理的图像结果都记录在图像 .tar.gz 文件中。

saw convert tar2img \
    --image-tar=/path/to/input/image/tar \
    --image=/path/to/output/folder

##example test
saw convert tar2img \
    --image-tar=./SS200000135TL_D1_SC_20240711_105908_4.1.0.tar.gz \
    --image=./SS200000135TL_D1_image_results

img2rpi

合成 TIFF 图像为 RPI 文件,用于 StereoMap 可视化展示。

Layer 图层的名字可以随意命名,但需遵从如下规则:<stain_type>/<image_type>,例如:DAPI/TissueMask。如果是细胞分割结果相关的图层,建议名称前缀为"CellMask",程序会自动将其转换为细胞轮廓进行展示。

saw convert img2rpi \
    --image=/path/to/input/image1,/path/to/input/image2,/path/to/input/image3... \
    --layers=DAPI/Image,DAPI/TissueMask,DAPI/CellMask... \
    --rpi=/path/to/output/rpi

##example test
saw convert img2rpi \
    --image=./SS200000135TL_D1_ssDNA_regist.tif,./SS200000135TL_D1_ssDNA_mask.tif \
    --layers=ssDNA/Image,ssDNA/CellMask... \
    --rpi=./SS200000135TL_D1.rpi

merge

合并多张图为一张图像(至多3张图)。

请注意,图像输入的顺序代表其颜色通道 R-G-B。

saw convert merge \
    --image=/path/to/input/image1,/path/to/input/image2,/path/to/input/image3 \ 
    --merged-image=/path/to/output/multichannel/image

##example test 
saw convert merge \
    --image=./SS200000135TL_D1_ssDNA_regist.tif,./SS200000135TL_D1_ssDNA_tissue_cut.tif \ 
    --merged-image=./SS200000135TL_D1.merged.tif

合并显微镜图像 ssDNA_SS200000135TL_D1_regist.tif 和组织分割图 ssDNA_SS200000135TL_D1_tissue_cut.tif,可用于评估组织分割的效果。

显微镜图像 ssDNA_SS200000135TL_D1_regist.tif 和细胞分割图 ssDNA_SS200000135TL_D1_mask.tif 合并结果的部分区域,用于评估细胞分割的效果。

overlay

将通过矩阵推导的模板点叠加到图像上,用以检查图像 QC 识别到的图像模板点是否准确。

矩阵模板文件 <stain_type>_matrix_template.txt 可在 可视化文件 visualization.tar.gz 中找到。

saw convert overlay \
    --image=/path/to/input/image \
    --template=/path/to/input/template/txt \
    --overlaid-image=/path/to/output/overlaid/image

##example test  
saw convert overlay \
    --image=./SS200000135TL_D1_regist.tif \
    --template=./ssDNA_matrix_template.txt \
    --overlaid-image=./SS200000135TL_D1.overlay.tif

将矩阵模板点叠加到 ssDNA_SS200000135TL_D1_regist.tif 图像上,用以检查配准效果。

© 2025 STOmics Tech. All rights reserved.Modified: 2025-12-29 19:47:43

results matching ""

    No results matching ""