最近在跑的方法需要.h5作为输入文件,就学习了一下怎么创建.h5文件,原有数据结构如下:

生成单组学.h5文件的代码如下:

library(rhdf5)
library(dplyr)
library(patchwork)
rna.data <- Read10X(data.dir='Processed_dataset/RNA',gene.column = 1)
atac.data <- Read10X(data.dir='Processed_dataset/ATAC',gene.column = 1)dim(rna.data)
dim(atac.data)
###构建.h5文件
h5createFile("SNARE_cellline_atac.h5")
# Saving matrix information.
h5createGroup("SNARE_cellline_atac.h5","matrix")
h5write(atac.data@Dimnames[[2]] , "SNARE_cellline_atac.h5", "matrix/barcodes")
h5write(atac.data@x, "SNARE_cellline_atac.h5", "matrix/data")
dim(atac.data)
h5createGroup("SNARE_cellline_atac.h5","matrix/features")
h5write("genome", "SNARE_cellline_atac.h5", "matrix/features/_all_tag_keys")
Peaks <- rep("Peaks", length(atac.data@Dimnames[[1]]))
h5write(Peaks,"SNARE_cellline_atac.h5", "matrix/features/feature_type")
Genome <- rep("hg38", length(atac.data@Dimnames[[1]]))
h5write(Genome,"SNARE_cellline_atac.h5", "matrix/features/genome")
h5write(atac.data@Dimnames[[1]],"SNARE_cellline_atac.h5", "matrix/features/id")
h5write(atac.data@Dimnames[[1]],"SNARE_cellline_atac.h5", "matrix/features/name")
h5write(atac.data@i, "SNARE_cellline_atac.h5", "matrix/indices") # already zero-indexed.
h5write(atac.data@p, "SNARE_cellline_atac.h5", "matrix/indptr")
h5write(dim(atac.data), "SNARE_cellline_atac.h5", "matrix/shape")
h5closeAll()
atac_file= H5Fopen("SNARE_cellline_atac.h5")
atac_h5 <- h5dump(atac_file,load=FALSE)
##############################################################################
###构建.h5文件
h5createFile("SNARE_cellline_rna.h5")
# Saving matrix information.
h5createGroup("SNARE_cellline_rna.h5","matrix")
h5write(rna.data@Dimnames[[2]] , "SNARE_cellline_rna.h5", "matrix/barcodes")
h5write(rna.data@x, "SNARE_cellline_rna.h5", "matrix/data")
h5createGroup("SNARE_cellline_rna.h5","matrix/features")
h5write("genome", "SNARE_cellline_rna.h5", "matrix/features/_all_tag_keys")
Genes <- rep("Gene Expression", length(rna.data@Dimnames[[1]]))
h5write(Genes,"SNARE_cellline_rna.h5", "matrix/features/feature_type")
Genome <- rep("hg38", length(rna.data@Dimnames[[1]]))
h5write(Genome,"SNARE_cellline_rna.h5", "matrix/features/genome")
h5write(rna.data@Dimnames[[1]],"SNARE_cellline_rna.h5", "matrix/features/id")
h5write(rna.data@Dimnames[[1]],"SNARE_cellline_rna.h5", "matrix/features/name")
h5write(rna.data@i, "SNARE_cellline_rna.h5", "matrix/indices") # already zero-indexed.
h5write(rna.data@p, "SNARE_cellline_rna.h5", "matrix/indptr")
h5write(dim(rna.data), "SNARE_cellline_rna.h5", "matrix/shape")
h5closeAll()
rna_file= H5Fopen("SNARE_cellline_rna.h5")
rna_h5 <- h5dump(rna_file,load=FALSE)

创建好的.h5文件结构如下,和10X提供的.h5文件结构是一样的

生成多组学.h5文件的代码如下:

library(rhdf5)
library(dplyr)
library(Seurat)
library(patchwork)
library(reticulate)
rna.data <- Read10X(data.dir='Processed_dataset/RNA',gene.column = 1)
atac.data <- Read10X(data.dir='Processed_dataset/ATAC',gene.column = 1)length(rna.data@Dimnames[[2]])
cell_name <- rna.data@Dimnames[[2]]
new_cell_name <- sample(cell_name,size= 0.2*length(rna.data@Dimnames[[2]]))rna.data <- rna.data[,rna.data@Dimnames[[2]] %in% new_cell_name]
atac.data <- atac.data[,atac.data@Dimnames[[2]] %in% new_cell_name]
##########################################################################################
multi.data <- rbind(rna.data,atac.data)
###构建.h5文件
h5createFile("SNARE_cellline_train.h5")
# Saving matrix information.
h5createGroup("SNARE_cellline_train.h5","matrix")
h5write(multi.data@Dimnames[[2]] , "SNARE_cellline_train.h5", "matrix/barcodes")
h5write(multi.data@x, "SNARE_cellline_train.h5", "matrix/data")h5createGroup("SNARE_cellline_train.h5","matrix/features")
key <- c('genome','interval')
h5write(key, "SNARE_cellline_train.h5", "matrix/features/_all_tag_keys")
Genes <- rep('Gene Expression', length(rna.data@Dimnames[[1]]))
Peaks <- rep("Peaks", length(atac.data@Dimnames[[1]]))
Features <- c(Genes,Peaks)
h5write(Features,"SNARE_cellline_train.h5", "matrix/features/feature_type")
Genome <- rep("GRCh38", length(multi.data@Dimnames[[1]]))
h5write(Genome,"SNARE_cellline_train.h5", "matrix/features/genome")
h5write(multi.data@Dimnames[[1]],"SNARE_cellline_train.h5", "matrix/features/id")
# cc <- c()
# h5write(cc,"SNARE_cellline_train.h5", "matrix/features/interval")
h5write(multi.data@Dimnames[[1]],"SNARE_cellline_train.h5", "matrix/features/name")
h5write(multi.data@i, "SNARE_cellline_train.h5", "matrix/indices") # already zero-indexed.
h5write(multi.data@p, "SNARE_cellline_train.h5", "matrix/indptr")
h5write(dim(multi.data), "SNARE_cellline_train.h5", "matrix/shape")
h5closeAll()
multi_file= H5Fopen("SNARE_cellline_train.h5")
multi_h5 <- h5dump(multi_file,load=FALSE)

R语言:利用rhdf5包分别创建单组学,多组学.h5文件相关推荐

  1. R语言使用forestploter包绘制单组及双组森林图

    R语言使用forestploter包绘制单组及双组森林图 您可以使用 forestplot 包绘制单组和双组森林图.该包提供了一个简单的方法来绘制证据汇总图,并可以在一个图中显示多种证据来源的结果. ...

  2. R语言使用randomForest包构建随机森林模型的步骤和流程、随机森林算法包括抽样样本(观察)和变量来创建大量的决策树(多个树,构成了森林,而且通过样本抽样和变量抽样,让多个树尽量不同)

    R语言使用randomForest包中的randomForest函数构建随机森林模型的步骤和流程(Random forests).随机森林算法包括抽样样本(观察)和变量来创建大量的决策树(多个树,构成 ...

  3. R语言使用fs包的dir_create函数在指定路径下创建新的文件夹、使用file_create函数在指定文件夹下创建文件

    R语言使用fs包的dir_create函数在指定路径下创建新的文件夹.使用file_create函数在指定文件夹下创建文件 目录

  4. R语言使用magick包的image_animate函数和image_morph函数创建一个由n个图像组成的序列,逐渐将一个图像转换成另一个图像(sequence of image morph by)

    R语言使用magick包的image_animate函数和image_morph函数创建一个由n个图像组成的序列,逐渐将一个图像转换成另一个图像(Creates a sequence of n ima ...

  5. R语言使用random包生成随机数或者随机字符串实战:randomNumbers函数创建随机整数的数据集(包含重复项)、randomSequence函数创建不含重复项的随机序列数据集、创建随机字符串

    R语言使用random包生成随机数或者随机字符串实战:randomNumbers函数创建随机整数的数据集(包含重复项).randomSequence函数创建不含重复项的随机序列数据集.创建随机字符串 ...

  6. R语言使用forestplot包绘制森林图:编码创建森林图仿真数据、汇总线修改、元素位置调整、垂直线、字体、风格、置信区间、线型、图例、刻度、标签等

    R语言使用forestplot包绘制森林图:编码创建森林图仿真数据.汇总线修改.元素位置调整.垂直线.字体.风格.置信区间.线型.图例.刻度.标签等 目录

  7. R语言使用compareGroups包compareGroups函数生成表统计表、createTable函数创建二元表、并导出结果到文档(doc、csv、xlsx、pdf)

    R语言使用compareGroups包compareGroups函数生成表统计表.createTable函数创建二元表.并导出结果到文档(doc.csv.xlsx.pdf) 目录 R语言使用compa ...

  8. R语言使用econocharts包创建微观经济或宏观经济图、ptvalue函数可视化前景理论价值函数(Prospect theory value function)

    R语言使用econocharts包创建微观经济或宏观经济图.ptvalue函数可视化前景理论价值函数(Prospect theory value function) 目录

  9. R语言使用econocharts包创建微观经济或宏观经济图:需求曲线、供给曲线、供需曲线、无差异曲线、Laffer曲线、前景理论价值函数曲线、税收图、生产可能性边界线、劳动力供给曲线、计算曲线交叉点等

    R语言使用econocharts包创建微观经济或宏观经济图:需求曲线.供给曲线.供需曲线.无差异曲线.Laffer曲线.前景理论价值函数曲线.税收图.生产可能性边界线.劳动力供给曲线.计算曲线交叉点等 ...

最新文章

  1. [云炬创业基础笔记]第二章创业者测试22
  2. 记录爬取信用中国,里面的行政许可内容,行政处罚,守信激励的内容,并以excel形式显示
  3. 数据库面试题【五、索引的优缺点,什么时候使用索引,什么时候不能使用索引】
  4. oracle导出导入数据库
  5. 华为无盘服务器,无盘服务器操作系统
  6. 记录——《C Primer Plus (第五版)》第八章编程练习第四题
  7. 《MapReduce 2.0源码分析与编程实战》一1.5 看,大象也会跳舞
  8. 文件i/o函数 open/close
  9. 未在此计算机上注册ActiveX控件!!!
  10. 计算机管理找不到防火墙,电脑没有防火墙怎么办
  11. 微软拼音输入法调整状态栏水平/垂直选项失效解决办法
  12. JAVA布局管理器导包_在 Java 中,要使用布局管理器,必须导入下列( )包。_计算机网络基础答案_学小易找答案...
  13. foxmail收件箱按照每个人进行划分
  14. 单字双字三字_单字写法-单字怎么读-双字繁体字怎么写
  15. JDK8 十大新特性详解
  16. NX二次开发-NXOPEN C# Part.GetPreviewImage读取prt文件预览图
  17. 同济大学计算机考研资料汇总
  18. [有人@你]请查收你的年终总结报告
  19. Spreadsheet与FineReport数据集对比
  20. 西安网络教育学院计算机答案,北语网院20秋《计算机基础》作业4题目及答案

热门文章

  1. Android Sqlite数据库多表联合查询
  2. 【雷达通信】基于Matlab GUI中频PD雷达仿真系统【含Matlab源码 1055期】
  3. 让文章排版看起来更舒服的方法
  4. Android面试题算法篇
  5. 色情网站的光棍节“福利”:加密式挂马玩转流氓推广
  6. NIO蔚来?NO! 没有特斯拉的命却有特斯拉的病
  7. 随机生成名字c语言代码,CC++实现的游戏角色名称名字随机生成代码(138页)-原创力文档...
  8. Java设计模式:抽象工厂模式
  9. 天津中德应用技术大学计算机专业,天津中德应用技术大学高职专业介绍(一)...
  10. 大学3年身家已逾500万