隔离的第九天,孤独仍在,但亦师亦友,今天我们来回顾一下10X空间转录组聚类的分析软件SpaGCN,这个软件之前分享过,文章在10X空间转录组聚类分析之图卷积网络(graph convolutional network),但当时分享的时候文章还是预印版,现在文章正式发表,在SpaGCN: Integrating gene expression, spatial location and histology to identify spatial domains and spatially variable genes by graph convolutional network,发表于Nature Methods,IF28.547,我们来回顾一下算法原理和示例代码
Overview of SpaGCN and evaluation.
SpaGCN首先构建一个图来表示考虑空间位置和组织学信息的所有点的关系。 接下来,SpaGCN 利用图卷积层来聚合来自相邻点的基因表达信息。 然后,SpaGCN 使用聚合表达式矩阵使用无监督迭代聚类算法对点进行聚类。 每个clusters被视为一个空间域,SpaGCN 然后从中检测通过 DE 分析在域中丰富的 SVG。 当单个基因不能标记一个域的表达模式时,SpaGCN 会构建一个meta基因,由多个基因组合形成,来代表该域的表达模式。
示例代码
Outline
-
- Installation
-
- Import modules
-
- Read in data
-
- Integrate gene expression and histology into a Graph
-
- Spatial domain detection using SpaGCN
-
- Identify SVGs
-
- Identify Meta Gene
-
- Multiple tissue sections analysis
Installation
pip3 install SpaGCN
#Note: you need to make sure that the pip is for python3,or we should install SpaGCN by
python3 -m pip install SpaGCN
pip3 install SpaGCN
#If you do not have permission (when you get a permission denied error), you should install SpaGCN by
pip3 install --user SpaGCN
Import python modules
import os,csv,re
import pandas as pd
import numpy as np
import scanpy as sc
import math
import SpaGCN as spg
from scipy.sparse import issparse
import random, torch
import warnings
warnings.filterwarnings("ignore")
import matplotlib.colors as clr
import matplotlib.pyplot as plt
import SpaGCN as spg
#In order to read in image data, we need to install some package. Here we recommend package "opencv"
#inatll opencv in python
#!pip3 install opencv-python
import cv2
Read in data
The current version of SpaGCN requres three input data:
- The gene expression matrix(n by k): expression_matrix.h5(我们就读这个就可以);
- Spatial coordinateds of samplespositions.txt;
- Histology image(optional): histology.tif, can be tif or png or jepg.
The gene expreesion data can be stored as an AnnData object. AnnData stores a data matrix .X together with annotations of observations .obs, variables .var and unstructured annotations .uns.