【富集分析】

富集分析方法

过表征分析 (over representation analysis, ORA)

基因富集分析 (gene set enrichment analysis, GSEA)

ORA与GAEA

基因集的分析策略可以分成兩類: over-representation analysis (ORA)與gene-set enrichment analysis (GSEA)。這兩種方法最大的差別是,ORA會先經過篩選,挑出我們有興趣的基因,而GSEA則不經過篩選基因的動作。以轉錄體資料為例,實驗設計上,通常會比較兩種狀態,並利用統計方法找出哪些基因具有「表現差異」,可能會設定統計檢定的p值或fold-change,來決定這是我們有興趣的基因,接著就針對這群基因做解讀。這樣篩選的過程,p值或fold-change如何設定才能抓出真正具有「生物意義」的基因,且這種方法把每個基因都視為同等重要,然而每個基因的貢獻程度也許是不同的(即表現量差異大的可能比較重要)。而GSEA不做任何篩選動作,將所有實驗資料放入分析。

……ORA的方法……我們關心的是:有興趣的基因中(genes of interest),與某個基因集(gene set),共同基因有幾個(K值)……我們可以用超幾何分布(Hypergeometric distribution)或二項式分佈(binomial distribution)來計算觀察值k的機率。

……GSEA的概念……首先將高通量實驗所量測到的基因排序,排列的順序是根據實驗量測到的數值決定……GSEA採用一個稱random walk的方法,也就是從基因列表的頭走到尾,如果碰到是基因集的基因就加分,不是則扣分。走完一趟後,回頭看走到哪兒時,分數最高(或最低),這個分數就是所謂的enrichment score (ES)……GSEA利用permutation testing的方法,也就是隨機抓取同等數量的基因當基因集,並計算得到隨機的ES,去估算實際觀察到的ES的P值,如果P值小於所設定的統計條件,就可以確保這ES並不是隨機就會發生。

数据格式

对于过表征分析 (over representation analysis, ORA), 我们需要的是一个包含基因ID的向量,基因ID可以从差异表达分析获得(例如 DESeq2 包)。

对于基因富集分析 (gene set enrichment analysis, GSEA), 我们需要一个经排序的基因列表,在这里我们调用 DOSE 包中的示例数据 geneList。

写在最后:为了完整了了解富集分析可以参考两篇文章链接: 功能富集分析概述.
富集分析.

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
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 ``` 该代码使用了NumPy和SciPy库进行计算。在使用时,需要将基因表达谱和基因集传递给`ssgsea`函数。此外,还可以设置其他参数,例如是否进行置换和置换次数等。函数返回一个包含富集分析结果的字典。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值