当前位置:网站首页>「小技巧」给Seurat对象瘦瘦身
「小技巧」给Seurat对象瘦瘦身
2022-07-04 12:34:00 【徐洲更】
我们在使用Seurat处理单细胞数据的时候,会发现Seurat对象会不断变大,一不小心就成为内存无底洞,
例如我的一个Seurat对象就占了22.3的内存空间
old_size <- object.size(seu.obj)
format(old_size, units="Gb")
# 22.3 Gb
如果我中途需要关闭Rstudio,那么为了保证自己的工作连续性,我就需要将内存中的20多G的数据保存到磁盘上,并在下次分析加载会内存。这一来一回,考虑到磁盘的读写速度,耗时可能就需要10多分钟。
考虑到你可能要把数据上传到网盘或者GEO数据库,那么这20多G数据所需要花费的时间,就更加超出你的想象了。
那有没有办法给Seurat对象瘦身呢? 其实很简单,因为Seurat主要是在Scale这一步,将原本的稀疏矩阵变成了普通的矩阵,同时里面的元素都是浮点型,极其占用空间。只要我们在保存数据之前先把这个归一化的矩阵给清空,就可以让Seurat一下子瘦下来。
[email protected][email protected] <- matrix()
new_size <- object.size(seu.obj)
format(new_size, units="Gb")
# 5Gb
上面的操作,让内存占用降低到只有原来的20%左右。但是,问题来了,内存降低的代价是什么呢?代价就是,你需要对加载的数据进行scale,复原Seurat中的scale.data。
all.genes <- rownames(seu.obj)
seu.obj <- ScaleData(seu.obj, features = all.genes)
这就是计算机科学中常见思路,要么是空间换时间,要么是时间换空间。
这个小技巧除了能加速Seurat对象的保存和读写外,还有什么其他应用吗?因为scale后数据主要是给主成分分析(PCA)提供输入。后续的非线性降维(UMAP), 聚类分析(Cluster)都是基于PCA,而不是基于scale数据,因此,如果分析过程中发现内存空间吃惊,也可以先通过这个小技巧释放下内存空间。等跑完一些占内存的操作后,再恢复即可。
边栏推荐
- Paper notes ACL 2020 improving event detection via open domain trigger knowledge
- ArcGis利用栅格处理工具进行影像裁剪
- Iterm tab switching order
- CA:用于移动端的高效坐标注意力机制 | CVPR 2021
- PKCs 5: password based cryptography specification version 2.1 Chinese Translation
- After installing vscode, the program runs (an include error is detected, please update the includepath, which has been solved for this translation unit (waveform curve is disabled) and (the source fil
- C语言:围圈报号排序问题
- When synchronized encounters this thing, there is a big hole, pay attention!
- Wechat video Number launches "creator traffic package"
- 敏捷开发/敏捷测试感受
猜你喜欢
22 API design practices
面向个性化需求的在线云数据库混合调优系统 | SIGMOD 2022入选论文解读
Ml and NLP are still developing rapidly in 2021. Deepmind scientists recently summarized 15 bright research directions in the past year. Come and see which direction is suitable for your new pit
Daily Mathematics Series 57: February 26
《天天数学》连载57:二月二十六日
R language -- readr package reads and writes data
AI 绘画极简教程
01. Basics - MySQL overview
强化学习-学习笔记1 | 基础概念
2022, 6G is heating up
随机推荐
runc hang 导致 Kubernetes 节点 NotReady
[Android kotlin] lambda return statement and anonymous function
Error: Failed to download metadata for repo ‘AppStream‘: Cannot download repomd. XML solution
Jetson TX2 configures common libraries such as tensorflow and pytoch
Pat 1059 prime factors (25 points) prime table
C语言函数
Global and Chinese markets of digital PCR and real-time PCR 2022-2028: Research Report on technology, participants, trends, market size and share
Transformer principle and code elaboration (pytorch)
It's hard to hear C language? Why don't you take a look at this (V) pointer
C语言数组
WPF double slider control and forced capture of mouse event focus
[notes] in depth explanation of assets, resources and assetbundles
Flet教程之 02 ElevatedButton高级功能(教程含源码)(教程含源码)
分布式事务相关概念与理论
面试官:Redis 过期删除策略和内存淘汰策略有什么区别?
Is the main thread the same as the UI thread- Is main thread the same as UI thread?
PKCs 5: password based cryptography specification version 2.1 Chinese Translation
Flet教程之 按钮控件 ElevatedButton入门(教程含源码)
Runc hang causes the kubernetes node notready
Introduction to random and threadlocalrandom analysis