首先我們來看看對AUcell的介紹
AUCell可以識別單細胞RNA序列數據中具有活躍基因集(例如signatures,基因模塊...)的細胞。 AUCell使用“曲線下面積”(AUC)來計算輸入基因集的關鍵子集是否在每個細胞的表達基因中富集。 AUC分數在所有細胞中的分布允許探索特征的相對表達。 由于計分方法是基于排名的,因此AUCell不受基因表達單位和標準化程序的影響。 此外,由于對cell進行了單獨評估,因此可以輕松地將其應用于更大的數據集,并根據需要對表達式矩陣進行分組。
那也就是說,AUcell是分析感興趣的基因集在所有細胞是否存在富集,道理很簡單,我們來看看主要分析內容
用AUcell進行分析分三步:
1、 Build the rankings
2、Calculate the Area Under the Curve (AUC)
3、Set the assignment thresholds
我們首先來分析第一步:AUcell首先是對cell怎么排序的。
For each cell, the genes are ranked from highest to lowest value. The genes with same expression value are shuffled. Therefore, genes with expression ‘0’ are randomly sorted at the end of the ranking. It is important to check that most cells have at least the number of expressed/detected genes that are going to be used to calculate the AUC (aucMaxRank in calcAUC()). The histogram provided by AUCell_buildRankings() allows to quickly check this distribution. plotGeneCount(exprMatrix) allows to obtain only the plot before building the rankings.
這個地方我們可以看出,對于每個基因,從高到底進行排名,也就是說每個細胞的每個基因都有一個排名,得到一個排名的矩陣。
接下來第二步:
- Calculate enrichment for the gene signatures (AUC)
首先我們要知道什么是AUC曲線:
AUC(Area Under Curve)被定義為ROC下與坐標軸圍成的面積,顯然這個面積的數值不會大于1。又由于ROC曲線一般都處于y=x這條直線的上方,所以AUC的取值范圍在0.5和1之間。AUC越接近1.0,檢測方法真實性越高;等于0.5時,則真實性最低,無應用價值。
那么什么是ROC曲線呢?
一、 ROC曲線的由來
很多學習器是為測試樣本產生一個實值或概率預測,然后將這個預測值與一個分類閾值進行比較,若大于閾值則分為正類,否則為反類。例如,神經網絡在一般情形下是對每個測試樣本預測出一個[0.0,1.0]之間的實值,然后將這個值與閾值0.5進行比較,大于0.5則判為正例,否則為反例。這個閾值設置的好壞,直接決定了學習器的泛化能力。
在不同的應用任務中,我們可根據任務需求來采用不同的閾值。例如,若我們更重視“查準率”,則可以把閾值設置的大一些,讓分類器的預測結果更有把握;若我們更重視“查全率”,則可以把閾值設置的小一些,讓分類器預測出更多的正例。因此,閾值設置的好壞,體現了綜合考慮學習器在不同任務下的泛化性能的好壞。為了形象的描述這一變化,在此引入ROC曲線,ROC曲線則是從閾值選取角度出發來研究學習器泛化性能的有力工具。
如果你還對“查準率”和“查全率”不了解,看我之前的文章【錯誤率、精度、查準率、查全率和F1度量】詳細介紹
二、 什么是ROC曲線
ROC全稱是“受試者工作特征”(Receiver OperatingCharacteristic)曲線。我們根據學習器的預測結果,把閾值從0變到最大,即剛開始是把每個樣本作為正例進行預測,隨著閾值的增大,學習器預測正樣例數越來越少,直到最后沒有一個樣本是正樣例。在這一過程中,每次計算出兩個重要量的值,分別以它們為橫、縱坐標作圖,就得到了“ROC曲線”。
** ROC曲線的縱軸是“真正例率”(True Positive Rate, 簡稱TPR),橫軸是“假正例率”(False Positive Rate,簡稱FPR),**基于上篇文章《錯誤率、精度、查準率、查全率和F1度量》的表1中符號,兩者分別定義為:
顯示ROC曲線的圖稱為“ROC圖”。圖1給出了一個示意圖,顯然,對角線對應于“隨機猜測”模型,而點(0,1)則對應于將所有正例預測為真正例、所有反例預測為真反例的“理想模型”。
圖1:ROC曲線與AUC面積
現實任務中通常是利用有限個測試樣例來繪制ROC圖,此時僅能獲得有限個(真正例率,假正例率)坐標對,無法產生圖1中的光滑ROC曲線,只能繪制出圖2所示的近似ROC曲線。繪制過程很簡單:給定m+ 個正例和m-個反例,根據學習器預測結果對樣例進行排序,然后把分類閾值設置為最大,即把所有樣例均預測為反例,此時真正例率和假正例率均為0,在坐標(0,0)處標記一個點。然后,將分類閾值依次設為每個樣例的預測值,即依次將每個樣例劃分為正例。設前一個標記點坐標為
三、 ROC曲線的意義
(1)主要作用
1. ROC曲線能很容易的查出任意閾值對學習器的泛化性能影響。
2.有助于選擇最佳的閾值。ROC曲線越靠近左上角,模型的查全率就越高。最靠近左上角的ROC曲線上的點是分類錯誤最少的最好閾值,其假正例和假反例總數最少。
3.可以對不同的學習器比較性能。將各個學習器的ROC曲線繪制到同一坐標中,直觀地鑒別優劣,靠近左上角的ROC曲所代表的學習器準確性最高。
(2)優點
1. 該方法簡單、直觀、通過圖示可觀察分析方法的準確性,并可用肉眼作出判斷。ROC曲線將真正例率和假正例率以圖示方法結合在一起,可準確反映某種學習器真正例率和假正例率的關系,是檢測準確性的綜合代表。
2. 在生物信息學上的優點:ROC曲線不固定閾值,允許中間狀態的存在,利于使用者結合專業知識,權衡漏診與誤診的影響,選擇一個更加的閾值作為診斷參考值。
四、 AUC面積的由來
如果兩條ROC曲線沒有相交,我們可以根據哪條曲線最靠近左上角哪條曲線代表的學習器性能就最好。但是,實際任務中,情況很復雜,如果兩條ROC曲線發生了交叉,則很難一般性地斷言誰優誰劣。在很多實際應用中,我們往往希望把學習器性能分出個高低來。在此引入AUC面積。
在進行學習器的比較時,若一個學習器的ROC曲線被另一個學習器的曲線完全“包住”,則可斷言后者的性能優于前者;若兩個學習器的ROC曲線發生交叉,則難以一般性的斷言兩者孰優孰劣。此時如果一定要進行比較,則比較合理的判斷依據是比較ROC曲線下的面積,即AUC(Area Under ROC Curve),如圖1圖2所示。
五、 什么是AUC面積
** AUC就是ROC曲線下的面積,衡量學習器優劣的一種性能指標。**從定義可知,AUC可通過對ROC曲線下各部分的面積求和而得。假定ROC曲線是由坐標為的點按序連接而形成,參見圖2,則AUC可估算為公式3。
六、 AUC面積的意義
AUC是衡量二分類模型優劣的一種評價指標,表示預測的正例排在負例前面的概率。
看到這里,是不是很疑惑,根據AUC定義和計算方法,怎么和預測的正例排在負例前面的概率扯上聯系呢?如果從定義和計算方法來理解AUC的含義,比較困難,實際上AUC和Mann-WhitneyU test(曼-慧特尼U檢驗)有密切的聯系。從Mann-Whitney U statistic的角度來解釋,AUC就是從所有正樣本中隨機選擇一個樣本,從所有負樣本中隨機選擇一個樣本,然后根據你的學習器對兩個隨機樣本進行預測,把正樣本預測為正例的概率p1,把負樣本預測為正例的概率p2,p1 > p2的概率就等于AUC。所以AUC反映的是分類器對樣本的排序能力。根據這個解釋,如果我們完全隨機的對樣本分類,那么AUC應該接近0.5。
另外值得注意的是,AUC的計算方法同時考慮了學習器對于正例和負例的分類能力,在樣本不平衡的情況下,依然能夠對分類器做出合理的評價。AUC對樣本類別是否均衡并不敏感,這也是不均衡樣本通常用AUC評價學習器性能的一個原因。例如在癌癥預測的場景中,假設沒有患癌癥的樣本為正例,患癌癥樣本為負例,負例占比很少(大概0.1%),如果使用準確率評估,把所有的樣本預測為正例便可以獲得99.9%的準確率。但是如果使用AUC,把所有樣本預測為正例,TPR為1,FPR為1。這種情況下學習器的AUC值將等于0.5,成功規避了樣本不均衡帶來的問題。
最后,我們在討論一下:在多分類問題下能不能使用ROC曲線來衡量模型性能?
我的理解:ROC曲線用在多分類中是沒有意義的。只有在二分類中Positive和Negative同等重要時候,適合用ROC曲線評價。如果確實需要在多分類問題中用ROC曲線的話,可以轉化為多個“一對多”的問題。即把其中一個當作正例,其余當作負例來看待,畫出多個ROC曲線。
回到我們生信分析的第二步,對于AUC的計算
To determine whether the gene set is enriched at the top of the gene-ranking for each cell, AUCell uses the “Area Under the Curve” (AUC) of the recovery curve.
In order to calculate the AUC, by default only the top 5% of the genes in the ranking are used (i.e. checks whether the genes in the gene-set or signature are within the top 5%). This allows faster execution on bigger datasets, and reduce the effect of the noise at the bottom of the ranking (e.g. where many genes might be tied at 0 counts). The percentage to take into account can be modified with the argument aucMaxRank. For datasets where most cells express many genes (e.g. a filtered dataset), or these have high expression values, it might be good to increase this threshold. Check the histogram provided by AUCell_buildRankings to get an estimation on where this threshold lies within the dataset.
這里我們深入理解一下,對于一個細胞進行基因排序之后,得到下面的圖:
也就是說,看看排名前250位的基因在排名慢慢變大的過程中,包含基因集數量的變化,而形成了一條曲線,曲線下面的面積,就是我們得到的富集分數。(似乎和剛才講的ROC沒什么關系~~)
The AUC estimates the proportion of genes in the gene-set that are highly expressed in each cell. Cells expressing many genes from the gene-set will have higher AUC values than cells expressing fewer (i.e. compensating for housekeeping genes, or genes that are highly expressed in all the cells in the dataset). Since the AUC represents the proportion of expressed genes in the signature, we can use the relative AUCs across the cells to explore the population of cells that are present in the dataset according to the expression of the gene-set.
However, determining whether the signature is active (or not) in a given cell is not always trivial. The AUC is not an absolute value, but it depends on the the cell type (i.e. sell size, amount of transcripts), the specific dataset (i.e. sensitivity of the measures) and the gene-set. It is often not straight forward to obtain a pruned signature of clear marker genes that are completely “on” in the cell type of interest and off" in every other cell. In addition, at single-cell level, most genes are not expressed or detected at a constant level.
The ideal situation will be a bi-modal distribution, in which most cells in the dataset have a low “AUC” compared to a population of cells with a clearly higher value (i.e. see “Oligodendrocites” in the next figure). This is normally the case on gene sets that are active mostly in a population of cells with a good representation in the dataset (e.g. ~ 5-30% of cells in the dataset). Similar cases of “marker” gene sets but with different proportions of cells in the datasets are the “neurons” and “microglia” (see figure). When there are very few cells within the dataset, the distribution might look normal-like, but with some outliers to the higher end (e.g. microglia). While if the gene set is marker of a high percentage of cells in the dataset (i.e. neurons), the distribution might start approaching the look of a gene-set of housekeeping genes. As example, the ‘housekeeping’ gene-set in the figure includes genes that are detected in most cells in the dataset.
Note that the size of the gene-set will also affect the results. With smaller gene-genes (fewer genes), it is more likely to get cells with AUC = 0. While this is the case of the “perfect markers” it is also easier to get it by chance with smal datasets. (i.e. Random gene set with 50 genes in the figure). Bigger gene-sets (100-2k) can be more stable and easier to evaluate, as big random gene sets will approach the normal distibution.
To ease the exploration of the distributions, the function AUCell_exploreThresholds() automatically plots all the histograms and calculates several thresholds that could be used to consider a gene-set ‘active’ (returned in aucThr). The distributions are plotted as dotted lines over the histogram and the corresponding thresholds as vertical bars in the matching color. The thicker vertical line indicates the threshold selected by default (
而將具有較高AUC值反映到細胞中,可以得到
至于代碼很簡單:
library(AUCell)
cells_rankings <- AUCell_buildRankings(exprMatrix)##基因排序
cells_AUC <- AUCell_calcAUC(geneSets, cells_rankings, aucMaxRank=nrow(cells_rankings)*0.05) ##計算AUC值。
cells_assignment <- AUCell_exploreThresholds(cells_AUC, plotHist=TRUE, nCores=1,assign=TRUE)##挑選閾值
至于基因集的選擇,可以借助于hallmark,用于研究腫瘤特征分析。