TCGA 数据分析实战 —— GSVA、ssGSEA 和单基因富集分析

TCGA 数据分析实战 —— GSVA、ssGSEA 和单基因富集分析

前言

前面,我们介绍过了差异基因的功能富集分析,今天,我们对这部分的内容作一些补充

主要介绍一下 GEVAssGSEA 和单基因的富集分析

GSVA

我们知道,GSEA 富集分析方法是针对两组样本来进行评估的,也就是说对基因列表的排列方式是根据基因与表型的相关度(例如,FC 值)来计算的,无法对单个样本使用

其富集分数(Enrichment ScoreES)的计算方式为

依次判断基因列表中的基因是否在基因集合中,如果在基因集合中,则 ES 加上该基因与表型的相关度,如果不是集合中的基因,则减去对应的值,最后可以计算出一个最大 ES

Gene Set Variation AnalysisGSVA)与 GSEA 的原理类似,只是计算每个基因集合在每个样本中的 enrichment statisticES,或 GSVA score),其算法流程如下

不同于 GSEA 之处在于,对于不同的数据类型(只支持 log 表达值或原始的 read counts 值),假设了不同的累积密度函数(cumulative density functionCDF

  1. 芯片数据:正态分布密度函数
  2. RNA-seq 数据:泊松分布密度函数

而且,GSVA 是为每个样本的每个基因计算对应的 CDF 值,然后根据该值对基因进行排序,这样,每个样本都有一个从大到小排序的基因列表

对于某一基因集合,计算其在每个样本中的 ES 值,也就是评估基因集合在基因列表中的富集情况。

例如,我们有一个排序后的样本

基因集合包含:BEH,我们可以绘制这样一张 K-S 分布图

x 轴为排序后的基因顺序,依照这一顺序,如果基因在集合内,则累积和会加上该基因的值(与基因的顺序有关,排名越靠前值越大),否则累积和不变。

将基因列表分为基因集内核基因集外两个集合,就可以绘制两个分布(红色和绿色曲线),分别计算两个分布之间的最大间距,以基因集内的分布值更大视为正间距(即红色曲线更高),两个最大间距之和即为该基因集的 ES

这样,就把基因水平的表达矩阵转换成了基因集水平的评分矩阵,可以使用差异表达基因识别算法,寻找显著差异的基因集,从而达到类似功能富集的作用

GSVA 分析

先获取基因表达矩阵,我们使用 TCGA 肺腺癌和肺鳞癌各 10 个样本的 read counts 数据

library(TCGAbiolinks)

get_prep <- function(cancer) {
   
  query <- GDCquery(
    project = cancer,
    data.category = "Transcriptome Profiling", 
    data.type = "Gene Expression Quantification", 
    workflow.type = "STAR - Counts",
    sample.type = c("Primary Tumor"),
  )
  # 选择 20 个样本
  query$results[[1]] <-  query$results[[1]][1:20,]
  GDCdownload(query)
  # 获取 read count
  exp.count <- GDCprepare(
    query,
    summarizedExperiment = TRUE,
  )
  return(exp.count)
}

luad.count <- get_prep("TCGA-LUAD")
lusc.count <- get_prep("TCGA-LUSC")

dataPrep_luad <- TCGAanalyze_Preprocessing(
  object = luad.count,
  cor.cut = 0.6,
  datatype = "unstranded"
)

dataPrep_lusc <- TCGAanalyze_Preprocessing(
  object = lusc.count,
  cor.cut = 0.6,
  datatype = "unstranded"
)
# 合并数据并使用 gcContent 方法进行标准化
dataNorm <- TCGAanalyze_Normalization(
  tabDF = cbind(dataPrep_luad, dataPrep_lusc),
  geneInfo = TCGAbiolinks::geneInfoHT,
  method = "gcContent"
)
# 分位数过滤
dataFilt <- TCGAanalyze_Filtering(
  tabDF = dataNorm,
SSGSEA(Single-sample Gene Set Enrichment Analysis)是一种基于基因富集分析的方法,可以对个样本进行基因表达谱的分析。以下是一个Python实现的SSGSEA富集分析代码示例: ```python import numpy as np from scipy.stats import norm def ssgsea(gene_exp, gene_sets, nperm=1000, weighted_score_type=1, permutation=True, min_size=1, max_size=5000, verbose=False, seed=None): """ :param gene_exp: array-like, shape (n_samples, n_features) Gene expression matrix (rows are samples and columns are features). :param gene_sets: dict Gene sets in the format of dictionary. Keys are pathway names and values are gene lists. :param nperm: int, optional The number of permutations for calculating the p-value. Default is 1000. :param weighted_score_type: int, optional The weighting score type. Default is 1. :param permutation: bool, optional Whether to do permutation for calculating the p-value. Default is True. :param min_size: int, optional The minimum number of genes in a gene set to be considered. Default is 1. :param max_size: int, optional The maximum number of genes in a gene set to be considered. Default is 5000. :param verbose: bool, optional Whether to print the progress. Default is False. :param seed: int, optional The seed for the random number generator. Default is None. :return: dict A dictionary of pathway names and enrichment scores. """ # Initialize the random number generator if seed is not None: np.random.seed(seed) # Prepare the gene expression matrix gene_exp = np.array(gene_exp) # Prepare the gene set list gene_sets = {k: v for k, v in gene_sets.items() if min_size <= len(v) <= max_size} # Compute the gene set scores pathways = {} for pathway, genes in gene_sets.items(): # Compute the gene set score for each sample gss = [] for i in range(gene_exp.shape[0]): # Get the gene expression values for the pathway genes pathway_exp = gene_exp[i, np.isin(gene_exp.columns, genes)] # Compute the gene set score if weighted_score_type == 0: gss.append(pathway_exp.sum()) elif weighted_score_type == 1: gss.append(pathway_exp.mean()) elif weighted_score_type == -1: gss.append(pathway_exp.abs().mean()) # Compute the enrichment score and p-value if permutation: null_gss = [] for i in range(nperm): # Shuffle the gene expression values shuffle_exp = gene_exp.apply(np.random.permutation, axis=1) # Compute the gene set score for each sample null_gss.append(shuffle_exp.apply(lambda x: x[np.isin(gene_exp.columns, genes)].mean(), axis=1)) null_gss = pd.concat(null_gss, axis=1) null_es = null_gss.apply(lambda x: (x > gss).mean() - (x < gss).mean()) es = (gss - null_es.mean()) / null_es.std() pval = (null_es < gss).mean() else: es = (gss - gss.mean()) / gss.std() pval = 1 - norm.cdf(es) pathways[pathway] = {'es': es, 'pval': pval} if verbose: print('%s: ES = %.3f, p-value = %.3f' % (pathway, es, pval)) return pathways ``` 该代码使用了NumPySciPy库进行计算。在使用时,需要将基因表达谱基因集传递给`ssgsea`函数。此外,还可以设置其他参数,例如是否进行置换置换次数等。函数返回一个包含富集分析结果的字典。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

名本无名

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值