当前位置:网站首页>「小技巧」给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数据,因此,如果分析过程中发现内存空间吃惊,也可以先通过这个小技巧释放下内存空间。等跑完一些占内存的操作后,再恢复即可。
边栏推荐
- 使用 NSProxy 实现消息转发
- Introduction to random and threadlocalrandom analysis
- Implementation mode and technical principle of MT4 cross platform merchandising system (API merchandising, EA merchandising, nj4x Merchandising)
- Vit (vision transformer) principle and code elaboration
- DC-5靶机
- Pat 1059 prime factors (25 points) prime table
- C language function
- Fastlane one click package / release app - usage record and stepping on pit
- Uva536 binary tree reconstruction tree recovery
- PostgreSQL 9.1 飞升之路
猜你喜欢

Communication tutorial | overview of the first, second and third generation can bus

Hongke case study on storm impact in coastal areas of North Carolina using lidar

MDK在头文件中使用预编译器时,#ifdef 无效的问题

01. Basics - MySQL overview

vim 出现 Another program may be editing the same file. If this is the case 的解决方法

ArgMiner:一个用于对论点挖掘数据集进行处理、增强、训练和推理的 PyTorch 的包

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

A taste of node JS (V), detailed explanation of express module

美团·阿里关于多模态召回的应用实践

轻松玩转三子棋
随机推荐
ArcGis利用栅格处理工具进行影像裁剪
C language: find the length of string
C語言函數
Hongke case study on storm impact in coastal areas of North Carolina using lidar
BackgroundWorker用法示例
Definition of cognition
Globalsign's SSL certificate products
Sort merge sort
C language: the sorting problem of circle number reporting
Two dimensional code coding theory
Daily Mathematics Series 57: February 26
二分查找的简单理解
《天天数学》连载57:二月二十六日
数据库锁表?别慌,本文教你如何解决
Tableau makes data summary after linking the database, and summary exceptions occasionally occur.
ISO 27001 Information Security Management System Certification
Can Console. Clear be used to only clear a line instead of whole console?
从0到1建设智能灰度数据体系:以vivo游戏中心为例
22 API design practices
Unity performance optimization reading notes - explore performance issues -profiler (2.1)