R語言rhdf5讀寫hdf5并展示文件組織結構和索引數(shù)據(jù)
前言
h5只是一種簡單的數(shù)據(jù)組織格式【層級數(shù)據(jù)存儲格式(HierarchicalDataFormat:HDF)】,該格式被設計用以存儲和組織大量數(shù)據(jù)。
在一些單細胞文獻中,作者通常會將分析的數(shù)據(jù)上傳到GEO數(shù)據(jù)庫保存為.h5格式文件,而不是我們常見的工程文件(rds文件,表格數(shù)據(jù)等),所以為了解析利用這些數(shù)據(jù)需要對hdf5格式的組織結構有一定的了解。
(注:在Seurat包中有現(xiàn)成的函數(shù)Seurat::Read10X_h5()
可以用來提取表達矩陣,但似乎此外無法從h5文件中提取更多的信息)。
GEO數(shù)據(jù)庫
在R語言中對HDF5進行操作的軟件包為rhdf5
。
安裝
install.packages("BiocManager");BiocManager::install("rhdf5");library(rhdf5)
打開.h5文件 和 展示內容的組織結構
h5_file= H5Fopen("new.h5") ####如下所示,new.h5文件內創(chuàng)建了一個組(group1_mat) #組內又創(chuàng)建了df和matrix兩個層級用以保存矩陣和數(shù)據(jù)框 > h5dump(h5_file,load=FALSE) $group1_mat $group1_mat$df group name otype dclass dim 1 / df H5I_DATASET COMPOUND 5 $group1_mat$matrix group name otype dclass dim 1 / matrix H5I_DATASET FLOAT 3 x 2
數(shù)據(jù)索引通過“$”符進行
> h5_file$group1_mat$df C_1 C_2 C_3 name 1 3 5 69 xx 2 2 8 60 yy 3 8 4 92 gg 4 1 6 16 ll 5 7 4 25 mm
關閉hdf5文件
H5Fclose(h5_file)#關閉當前打開的hdf5文件 h5closeAll()#關閉所有打開的hdf5文件
構建自己的hdf5文件
###準備數(shù)據(jù) mdat <- matrix(c(0,2,3, 11,12,13), nrow = 2, ncol = 3, byrow = TRUE,dimnames = list(c("row1", "row2"),c("C.1", "C.2", "C.3"))) df <- data.frame(C_1 = c(3,2,8,1,7),C_2 = c(5,8,4,6,4),C_3 = round(runif(n = 5), 2) * 100,name = c("xx","yy","gg",'ll','mm')) mdat.spar <- Matrix::Matrix(mdat, sparse = TRUE) my_array <- array(seq(0.1,2.0,by=0.1),dim=c(5,2,2)) my_list <- list(my_array[,,1],my_array[,,2]) my_string <- "This is one hdf structure file" ###構建.h5文件 h5createFile("new.h5") # Saving matrix information. h5createGroup("new.h5","group1_mat") h5write(mdat, "new.h5", "group1_mat/matrix") h5write(df, "new.h5", "group1_mat/df") # Saving sparse_matrix information. mdat.spar <- as(mdat, "dgCMatrix") h5createGroup("new.h5","group2_sparseMTX") h5write(mdat.spar@x, "new.h5", "group2_sparseMTX/data") h5write(dim(mdat.spar), "new.h5", "group2_sparseMTX/shape") h5write(mdat.spar@i, "new.h5", "group2_sparseMTX/indices") # already zero-indexed. h5write(mdat.spar@p, "new.h5", "group2_sparseMTX/indptr") # Saving array and list data h5createGroup("new.h5","group3_aL") h5write(my_list, "new.h5", "group3_aL/list") h5write(my_array, "new.h5", "group3_aL/array") # Saving string data h5createGroup("new.h5","group4_string") h5write(my_string, "new.h5", "group4_string/string") h5closeAll()
參考官方說明 rhdf5 - HDF5 interface for R (bioconductor.org)
以上就是R語言rhdf5讀寫hdf5并展示文件組織結構和索引數(shù)據(jù)的詳細內容,更多關于R語言rhdf5讀寫hdf5的資料請關注腳本之家其它相關文章!
相關文章
R語言實現(xiàn)將分類變量轉換為啞變量(dummy vairable)
這篇文章主要介紹了R語言實現(xiàn)將分類變量轉換為啞變量(dummy vairable),具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2021-04-04R語言數(shù)據(jù)可視化分析天貓雙十一銷售額增長率
這篇文章主要為大家介紹了R語言數(shù)據(jù)可視化來分析天貓雙十一銷售額增長率,來一探多年來歷年雙十一銷售額數(shù)據(jù)是否有造假,有需要的朋友可以借鑒參考下,希望能夠有所幫助2021-11-11R語言實現(xiàn)ggplot重繪天貓雙十一銷售額曲線圖過程
這篇文章主要為大家介紹了如何使用ggplot繪制天貓雙十一銷售額曲線圖的實現(xiàn)過程,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2021-11-11R語言包ggplot實現(xiàn)分面去掉小標題的灰色底色小技巧
這篇文章主要為大家介紹了R語言繪制圖形統(tǒng)計包ggplot來實現(xiàn)分面去掉小標題灰色底色的小技巧,有需要的朋友可以借鑒參考下,希望能夠有所幫助2021-11-11