R语言rhdf5怎么读写hdf5并展示文件组织结构和索引数据
导读:本文共1952.5字符,通常情况下阅读需要7分钟。同时您也可以点击右侧朗读,来听本文内容。按键盘←(左) →(右) 方向键可以翻页。
摘要: 前言h6只是一种简单的数据组织格式【层级数据存储格式(HierarchicalDataFormat:HDF)】,该格式被设计用以存储和组织大量数据。在一些单细胞文献中,作者通常会将分析的数据上传到GEO数据库保存为.h6格式文件,而不是我们常见的工程文件(rds文件,表格数据等),所以为了解析利用这些数据需要对hdf5格式的组织结构有一定的了解。(注:在Seur... ...
音频解说
目录
(为您整理了一些要点),点击可以直达。前言
h6只是一种简单的数据组织格式【层级数据存储格式(HierarchicalDataFormat:HDF)】,该格式被设计用以存储和组织大量数据。
在一些单细胞文献中,作者通常会将分析的数据上传到GEO数据库保存为.h6格式文件,而不是我们常见的工程文件(rds文件,表格数据等),所以为了解析利用这些数据需要对hdf5格式的组织结构有一定的了解。
(注:在Seurat包中有现成的函数Seurat::Read10X_h6()
可以用来提取表达矩阵,但似乎此外无法从h6文件中提取更多的信息)。
GEO数据库
在R语言中对HDF5进行操作的软件包为rhdf5
。
安装
install.packages("BiocManager");BiocManager::install("rhdf5");library(rhdf5)
打开.h6文件 和 展示内容的组织结构
h6_file=H5Fopen("new.h6")####如下所示,new.h6文件内创建了一个组(group1_mat)#组内又创建了df和matrix两个层级用以保存矩阵和数据框>h6dump(h6_file,load=FALSE)$group1_mat$group1_mat$dfgroupnameotypedclassdim1/dfH5I_DATASETCOMPOUND5$group1_mat$matrixgroupnameotypedclassdim1/matrixH5I_DATASETFLOAT3x2
数据索引通过“$”符进行
>h6_file$group1_mat$dfC_1C_2C_3name13569xx22860yy38492gg41616ll57425mm
关闭hdf5文件
H5Fclose(h6_file)#关闭当前打开的hdf5文件h6closeAll()#关闭所有打开的hdf5文件
构建自己的hdf5文件
###准备数据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<-"Thisisonehdfstructurefile"###构建.h6文件h6createFile("new.h6")#Savingmatrixinformation.h6createGroup("new.h6","group1_mat")h6write(mdat,"new.h6","group1_mat/matrix")h6write(df,"new.h6","group1_mat/df")#Savingsparse_matrixinformation.mdat.spar<-as(mdat,"dgCMatrix")h6createGroup("new.h6","group2_sparseMTX")h6write(mdat.spar@x,"new.h6","group2_sparseMTX/data")h6write(dim(mdat.spar),"new.h6","group2_sparseMTX/shape")h6write(mdat.spar@i,"new.h6","group2_sparseMTX/indices")#alreadyzero-indexed.h6write(mdat.spar@p,"new.h6","group2_sparseMTX/indptr")#Savingarrayandlistdatah6createGroup("new.h6","group3_aL")h6write(my_list,"new.h6","group3_aL/list")h6write(my_array,"new.h6","group3_aL/array")#Savingstringdatah6createGroup("new.h6","group4_string")h6write(my_string,"new.h6","group4_string/string")h6closeAll()
</div> <div class="zixun-tj-product adv-bottom"></div> </div> </div> <div class="prve-next-news">
本文:
R语言rhdf5怎么读写hdf5并展示文件组织结构和索引数据的详细内容,希望对您有所帮助,信息来源于网络。