大數(shù)據(jù)量單細(xì)胞數(shù)據(jù)處理方式

單細(xì)胞數(shù)據(jù)爆發(fā),現(xiàn)在細(xì)胞數(shù)據(jù)隨便就是萬和百萬級(jí)別纹腌,除了有許多專門開發(fā)出來快速處理百萬級(jí)的工具包(例如Cumulus等)和down sample的思想外,為了減輕個(gè)人PC內(nèi)存有限的問題滞磺,其實(shí)方法還蠻多的壶笼,例如ArchR處理scATAC數(shù)據(jù)一樣,就是將數(shù)據(jù)放在硬盤里面調(diào)用雁刷,而不是全部一股腦讀入內(nèi)存,這種思想在大數(shù)據(jù)處理時(shí)還蠻常見的保礼。

以SCE(SingleCellExperiment)對(duì)象為例沛励,主要實(shí)現(xiàn)方法就是HDF5Array包,將數(shù)據(jù)以h5的格式存儲(chǔ)在硬盤上炮障,然后sce對(duì)象靈活訪問和調(diào)用目派,減輕內(nèi)存負(fù)荷。

In the context of a SingleCellExperiment object, the file path linked with the assays can be used to efficiently manage large datasets by storing the assay data on disk rather than in memory. This is particularly useful when dealing with large single-cell RNA sequencing datasets.

The HDF5Array package in Bioconductor allows you to store assay data in HDF5 files, which can then be linked to a SingleCellExperiment object. This approach helps manage memory usage efficiently. Here's how you can create a SingleCellExperiment object with assay data stored in an HDF5 file:

1. 工具包配置:

if (!requireNamespace("BiocManager", quietly = TRUE))
    install.packages("BiocManager")
BiocManager::install(c("SingleCellExperiment", "HDF5Array"))

library(SingleCellExperiment)
library(HDF5Array)

SingleCellExperiment對(duì)象本質(zhì)也是R的S4類對(duì)象胁赢,和Suerat object還有scanpy的anndata都是可以靈活轉(zhuǎn)化的企蹭,非常簡(jiǎn)潔。
SCE對(duì)象的官方教程:Chapter 4 The SingleCellExperiment class | Introduction to Single-Cell Analysis with Bioconductor

2. 創(chuàng)建基因x細(xì)胞的表達(dá)矩陣智末,且存為h5文件

# Create some example data
# 如果你有 這里換成讀入
counts <- matrix(rpois(100, lambda = 10), nrow = 10, ncol = 10)
rownames(counts) <- paste0("Gene", 1:10)
colnames(counts) <- paste0("Cell", 1:10)

# Save the counts matrix to an HDF5 file
h5file <- tempfile(fileext = ".h5")
writeHDF5Array(counts, filepath = h5file, name = "counts")

如果是10X之類的數(shù)據(jù)谅摄,對(duì)應(yīng)讀入就好了,不需要自己手動(dòng)構(gòu)建系馆。

3. 創(chuàng)建SCE對(duì)象

# Load the HDF5 file as an HDF5Array
counts_h5 <- HDF5Array(filepath = h5file, name = "counts")

# Create the SingleCellExperiment object
sce <- SingleCellExperiment(assays = list(counts = counts_h5))

# Add row data (gene metadata)
rowData(sce) <- DataFrame(GeneID = rownames(counts))

# Add column data (cell metadata)
colData(sce) <- DataFrame(CellID = colnames(counts))

# Accessing the data
counts(sce)
rowData(sce)
colData(sce)

In this example, the counts matrix is stored in an HDF5 file, and the SingleCellExperiment object links to this file for the assay data. This approach is particularly useful for large datasets, as it avoids loading the entire dataset into memory.

You can access and manipulate the assay data in the SingleCellExperiment object just like any other assay, but the data will be read from and written to the HDF5 file on disk as needed.

然后你就會(huì)發(fā)現(xiàn)送漠,你可以隨意訪問counts矩陣,但是這個(gè)sce對(duì)象卻非常小由蘑,具體來看闽寡,其實(shí)會(huì)發(fā)現(xiàn)它內(nèi)部的sce@assays@data@listData[["counts"]]@seed@seed@filepath其實(shí)只是一個(gè)矩陣路徑,而不是真實(shí)的數(shù)據(jù)尼酿。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
禁止轉(zhuǎn)載爷狈,如需轉(zhuǎn)載請(qǐng)通過簡(jiǎn)信或評(píng)論聯(lián)系作者。
  • 序言:七十年代末裳擎,一起剝皮案震驚了整個(gè)濱河市涎永,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌句惯,老刑警劉巖土辩,帶你破解...
    沈念sama閱讀 218,682評(píng)論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異抢野,居然都是意外死亡拷淘,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,277評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門指孤,熙熙樓的掌柜王于貴愁眉苦臉地迎上來启涯,“玉大人贬堵,你說我怎么就攤上這事〗嵬荩” “怎么了黎做?”我有些...
    開封第一講書人閱讀 165,083評(píng)論 0 355
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)松忍。 經(jīng)常有香客問我蒸殿,道長(zhǎng),這世上最難降的妖魔是什么鸣峭? 我笑而不...
    開封第一講書人閱讀 58,763評(píng)論 1 295
  • 正文 為了忘掉前任宏所,我火速辦了婚禮,結(jié)果婚禮上摊溶,老公的妹妹穿的比我還像新娘爬骤。我一直安慰自己,他們只是感情好莫换,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,785評(píng)論 6 392
  • 文/花漫 我一把揭開白布霞玄。 她就那樣靜靜地躺著,像睡著了一般拉岁。 火紅的嫁衣襯著肌膚如雪坷剧。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,624評(píng)論 1 305
  • 那天喊暖,我揣著相機(jī)與錄音听隐,去河邊找鬼。 笑死哄啄,一個(gè)胖子當(dāng)著我的面吹牛雅任,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播咨跌,決...
    沈念sama閱讀 40,358評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼沪么,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來了锌半?” 一聲冷哼從身側(cè)響起禽车,我...
    開封第一講書人閱讀 39,261評(píng)論 0 276
  • 序言:老撾萬榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎刊殉,沒想到半個(gè)月后殉摔,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,722評(píng)論 1 315
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡记焊,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,900評(píng)論 3 336
  • 正文 我和宋清朗相戀三年逸月,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片遍膜。...
    茶點(diǎn)故事閱讀 40,030評(píng)論 1 350
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡碗硬,死狀恐怖瓤湘,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情恩尾,我是刑警寧澤弛说,帶...
    沈念sama閱讀 35,737評(píng)論 5 346
  • 正文 年R本政府宣布,位于F島的核電站翰意,受9級(jí)特大地震影響木人,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜冀偶,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,360評(píng)論 3 330
  • 文/蒙蒙 一虎囚、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧蔫磨,春花似錦、人聲如沸圃伶。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,941評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽窒朋。三九已至搀罢,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間侥猩,已是汗流浹背榔至。 一陣腳步聲響...
    開封第一講書人閱讀 33,057評(píng)論 1 270
  • 我被黑心中介騙來泰國(guó)打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留欺劳,地道東北人唧取。 一個(gè)月前我還...
    沈念sama閱讀 48,237評(píng)論 3 371
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像划提,于是被迫代替她去往敵國(guó)和親枫弟。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,976評(píng)論 2 355

推薦閱讀更多精彩內(nèi)容