網(wǎng)站首頁 編程語言 正文
前言
h5只是一種簡單的數(shù)據(jù)組織格式【層級數(shù)據(jù)存儲格式(HierarchicalDataFormat:HDF)】,該格式被設(shè)計用以存儲和組織大量數(shù)據(jù)。
在一些單細胞文獻中,作者通常會將分析的數(shù)據(jù)上傳到GEO數(shù)據(jù)庫保存為.h5格式文件,而不是我們常見的工程文件(rds文件,表格數(shù)據(jù)等),所以為了解析利用這些數(shù)據(jù)需要對hdf5格式的組織結(jié)構(gòu)有一定的了解。
(注:在Seurat包中有現(xiàn)成的函數(shù)Seurat::Read10X_h5()
可以用來提取表達矩陣,但似乎此外無法從h5文件中提取更多的信息)。
GEO數(shù)據(jù)庫
在R語言中對HDF5進行操作的軟件包為rhdf5
。
安裝
install.packages("BiocManager");BiocManager::install("rhdf5");library(rhdf5)
打開.h5文件 和 展示內(nèi)容的組織結(jié)構(gòu)
h5_file= H5Fopen("new.h5") ####如下所示,new.h5文件內(nèi)創(chuàng)建了一個組(group1_mat) #組內(nèi)又創(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
關(guān)閉hdf5文件
H5Fclose(h5_file)#關(guān)閉當(dāng)前打開的hdf5文件 h5closeAll()#關(guān)閉所有打開的hdf5文件
構(gòu)建自己的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" ###構(gòu)建.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)
原文鏈接:https://www.jianshu.com/p/ff488c2804de
相關(guān)推薦
- 2022-04-16 python?import模塊時有錯誤紅線的原因_python
- 2022-10-03 React如何實現(xiàn)全屏監(jiān)聽Esc鍵_React
- 2022-10-17 Go?WaitGroup及Cond底層實現(xiàn)原理_Golang
- 2024-01-15 IDEA 常量字符串過長問題
- 2022-03-21 SQL?查詢連續(xù)登錄的用戶情況_MsSql
- 2023-10-11 MP、MybatisPlus、聯(lián)表查詢、自定義sql、Constants.WRAPPER、ew (二
- 2023-07-16 spring boot 多環(huán)境配置
- 2022-04-28 WPF使用Grid網(wǎng)格面板布局_實用技巧
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支