特别感谢作者的答疑
一、简介
DESC是用于对scRNA-seq数据进行聚类的无监督深度学习算法。该算法通过基于深度神经网络的迭代学习cluster特定基因表达表示和cluster分配,构造了从原始scRNA-seq数据空间到低维特征空间的非线性映射函数。此迭代过程将每个细胞移至最接近的cluster,平衡cluster之间的生物学和技术差异,并减少分批效应的影响。DESC还可以通过为每个细胞分配特定于cluster的概率来实现软聚类,这有助于以较高的置信度识别聚类的细胞并解释结果。
使用desc的作用
- 预处理各种格式的单细胞基因表达数据。
- 建立单细胞基因表达数据的低维表示。
- 获取细胞的软cluster分配。
- 可视化细胞聚类结果和基因表达模式。
二、文献:
- Deep learning enables accurate clustering and batch effect removal in single-cell RNA-seq analysis
- 开源实现 https://eleozzr.github.io/desc/
为了防止影响到正常生产用的服务器环境,所有操作都在Docker容器中进行
docker run -it -p 8785:8787 -v /share/nas1/Data/Users/luohb/Docker:/root/luohb 17077ba23c0d /bin/bash
adduser --home /home/luohb1 luohb1
rstudio-server start #开启Rstudio的服务器版本
su - luohb1 #切换用户
sh Miniconda3-latest-Linux-x86_64.sh # 安装miniconda
添加清华conda镜像源:
luohb1@dff49a57f49a:~$ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
luohb1@dff49a57f49a:~$ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
luohb1@dff49a57f49a:~$ conda config --set show_channel_urls yes
创建Python3.6 conda环境
conda create -n DESC python=3.5.3
# activate your environment
luohb1@dff49a57f49a:~$ conda activate DESC
(DESC) luohb1@dff49a57f49a:~$ which python
/home/luohb1/miniconda3/envs/DESC/bin/python
(DESC) luohb1@dff49a57f49a:~$ python --version
Python 3.5.3 :: Continuum Analytics, Inc.
三、安装desc的Python库
- 确保python版本为 3.5.x或3.6.x
- 增加当前用户的sudo权限
- 查看pip的版本、添加多个pip国内镜像(推荐豆瓣镜像)
https://www.cnblogs.com/night-xing/p/12094099.html
(DESC) luohb1@dff49a57f49a:~$ which python
/home/luohb1/miniconda3/envs/DESC/bin/python
(DESC) luohb1@dff49a57f49a:~$ which pip
/home/luohb1/miniconda3/envs/DESC/bin/pip
(DESC) luohb1@dff49a57f49a:~$ pip --version
(DESC) luohb1@dff49a57f49a:~$ pip 9.0.1 from /home/luohb1/miniconda3/envs/DESC/lib/python3.5/site-packages (python 3.5)
(DESC) luohb1@dff49a57f49a:~$ vim ~/.pip/pip.conf
(DESC) luohb1@dff49a57f49a:~$ sudo apt-get install llvm
安装desc的Python库
(DESC) luohb1@dff49a57f49a:~$ pip install --upgrade pip
(DESC) luohb1@dff49a57f49a:~$ pip install desc
默认的国外镜像会很慢,而且很容易失败
遇到的报错
Collecting tables
Downloading http://pypi.doubanio.com/packages/2b/32/847ee3f521aae6a0be380d923a736162d698586f444df1ac24b98c65025c/tables-3.6.1.tar.gz (4.6 MB)
|████████████████████████████████| 4.6 MB 4.7 MB/s
ERROR: Command errored out with exit status 1:
collect2: error: ld returned 1 exit status
* Using Python 3.5.3 |Continuum Analytics, Inc.| (default, Mar 6 2017, 11:58:13)
* USE_PKGCONFIG: False
* Found conda env: ``/home/luohb1/miniconda3/envs/DESC``
.. ERROR:: Could not find a local HDF5 installation.
You may need to explicitly state where your local HDF5 headers and
library can be found by setting the ``HDF5_DIR`` environment
variable or by using the ``--hdf5`` command-line option.
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
解决:
#重新安装这个HDF5这个库
conda install HDF5
检查
(DESC) luohb1@dff49a57f49a:~$ python
Python 3.5.3 |Continuum Analytics, Inc.| (default, Mar 6 2017, 11:58:13)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import platform
>>> platform.python_version()
'3.5.3'
>>> import tensorflow as tf
>>> tf.__version__
'1.15.2'
载入desc这个包发生的报错:
>>> import desc
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/luohb1/miniconda3/envs/DESC/lib/python3.5/site-packages/desc/__init__.py", line 2, in <module>
from . import tools
File "/home/luohb1/miniconda3/envs/DESC/lib/python3.5/site-packages/desc/tools/__init__.py", line 2, in <module>
from scanpy.api.pp import normalize_per_cell, highly_variable_genes, log1p, scale
File "/home/luohb1/miniconda3/envs/DESC/lib/python3.5/site-packages/scanpy/__init__.py", line 3, in <module>
from .utils import check_versions, annotate_doc_types
File "/home/luohb1/miniconda3/envs/DESC/lib/python3.5/site-packages/scanpy/utils.py", line 18, in <module>
from ._settings import settings
File "/home/luohb1/miniconda3/envs/DESC/lib/python3.5/site-packages/scanpy/_settings.py", line 351
f'{k} = {v!r}'
解决:
由于desc依赖scanpy,而scanpy又依赖anndata,需要scanpy和anndata的版本相匹配,为此找到另外一篇简书文章:【简书】scanpy分析单细胞数据 查看包的版本
(DESC) luohb1@dff49a57f49a:~$ pip install scanpy==1.4 #让它自己自动寻找匹配的anndata库
保存镜像,以作迁移
docker commit -m "desc_integrated_analysis" -a "luohb" dff49a57f49a desc_rstudio
重新启动进入Docker的方法
$docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fb9848f16fa0 c5d48e81b986 "/bin/bash" 2 days ago Exited (0) 2 days ago elegant_wilbur
8f92805510be c5d48e81b986 "/bin/bash" 2 days ago Up 2 days hardcore_lovelace
dc65d1fa43cc c5d48e81b986 "/bin/bash" 2 days ago Up 2 days friendly_johnson
dff49a57f49a 17077ba23c0d "/bin/bash" 5 days ago Up 3 days 0.0.0.0:8785->8787/tcp silly_gagarin
c2cef88ff61b 17077ba23c0d "/bin/bash" 9 days ago Exited (0) 6 days ago condescending_booth
565ff6a9f91d 093105f858b4 "/bin/bash" 10 days ago Up 10 days kind_curie
e506a9842fbc 17077ba23c0d "/bin/bash" 11 days ago Exited (130) 9 days ago sweet_einstein
$docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
cellassign_rstudio_debian latest 17077ba23c0d 11 days ago 6.71GB
centos/cellassign-rvm-rstudio latest cf5394785a34 2 weeks ago 6.55GB
centos_sshd latest d1923b501fa4 2 weeks ago 365MB
matlab_robustclone_v1 latest 093105f858b4 3 weeks ago 84.2GB
rocker/rstudio latest ff5a9f0a1d1b 3 weeks ago 1.46GB
centos latest 470671670cac 3 months ago 237MB
gregoryschwartz/too-many-cells 0.2.2.0 997aeeb90727 6 months ago 1.28GB
centos 7.3.1611 c5d48e81b986 13 months ago 192MB
$docker run -i -t -v /share/nas1/Data/Users/luohb/Personalization/result2/DESC:/home/luohb1/desc -p 8785:8787 08e3683cab26 /bin/bash
$docker attach dff49a57f49a
(base) luohb1@dff49a57f49a:~/.local/lib/python3.5/Python-3.5.6$
- 根据教程测试:
>>> import desc
>>> desc.run_desc_test()
遇到缺失的依赖包的话,conda安装回去就好
最开始遇到的报错:
(base) luohb1@dff49a57f49a:~/.local/lib/python3.5/Python-3.5.6/bin$ which python
/home/luohb1/miniconda3/bin/python
(base) luohb1@dff49a57f49a:~/.local/lib/python3.5/Python-3.5.6/bin$ which pip
/home/luohb1/miniconda3/bin/pip
(base) luohb1@dff49a57f49a:~/.local/lib/python3.5/Python-3.5.6/bin$ python
Python 3.6.10 |Anaconda, Inc.| (default, Jan 7 2020, 21:14:29)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> importdesc
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'importdesc' is not defined
>>> import desc
/home/luohb1/miniconda3/lib/python3.6/site-packages/anndata/_core/anndata.py:21: FutureWarning: pandas.core.index is deprecated and will be removed in a future version. The public classes are available in the top-level namespace.
from pandas.core.index import RangeIndex
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/luohb1/miniconda3/lib/python3.6/site-packages/desc/__init__.py", line 2, in <module>
from . import tools
File "/home/luohb1/miniconda3/lib/python3.6/site-packages/desc/tools/__init__.py", line 2, in <module>
from scanpy.api.pp import normalize_per_cell, highly_variable_genes, log1p, scale
File "/home/luohb1/miniconda3/lib/python3.6/site-packages/scanpy/__init__.py", line 27, in <module>
check_versions()
File "/home/luohb1/miniconda3/lib/python3.6/site-packages/scanpy/utils.py", line 37, in check_versions
if anndata.__version__ < LooseVersion('0.6.10'):
File "/home/luohb1/miniconda3/lib/python3.6/distutils/version.py", line 64, in __gt__
c = self._cmp(other)
File "/home/luohb1/miniconda3/lib/python3.6/distutils/version.py", line 335, in _cmp
if self.version == other.version:
AttributeError: 'Version' object has no attribute 'version'
解决方案
- 根据这篇文章 【CSDN】distutils 'module' object has no attribute 'version' 发现不行
- 发现是conda环境问题
四、安装启动Jupyter Notebook
安装与启动
(DESC) luohb1@dff49a57f49a:~$ conda install jupyter
- 教程、出现的报错和解决方法:
后面发现因为docker的映射端口被占用了,没办法分给Jupyter Notebook 8888端口,于是只能改用Rstudio-server运行Python脚本
其实为什么我不想直接写Python脚本的原因是因为我希望能看到每一步的变化和方便debug
解决:
jupyter notebook --ip 0.0.0.0 --no-browser --allow-root &
五、启动Rstudio-server,运行Python
- 教程、报错与解决:
当然其实也可以用VScode的服务器版本,但是今天不想折腾了。
$rstudio-server start &