conda管理生信软件

conda管理生信软件

写在前面的话:

linux作为非图形化操作系统,软件下载及管理相对于windows更加复杂。对于生信分析,conda能够很好的解决大部分软件的下载、安装及管理。最重要的是conda能够解决不同软件间的环境冲突。(miniconda是anaconda的轻量级替代,足够我们使用)

conda下载

  1. 清华大学开源软件镜像站:miniconda安装包查找

  2. 根据不同的电脑系统选择所需要的版本(windows, linux, MacOSX)

  3. 下载最新的linux版本示例:
1
wget -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda2-latest-Linux-x86_64.sh

miniconda安装

安装最新版linux示例:

1
bash Miniconda2-latest-Linux-x86_64.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
安装过程中可能会遇到下面的提示:

Please, press ENTER to continue
>>>
# 此处直接点击enter即可
===================================
Miniconda End User License Agreement
===================================
.......
# 这⾥点击好⼏次空格键,直到出现下⾯⾏
Do you accept the license terms? [yes|no]
[no] >>>
# 这⾥输⼊yes,点击enter
# 如果输⼊错误,⽐如输⼊yess,⼜删除不了,此时你应该按enter,重新输⼊yes即可
[/home/you/miniconda2] >>>
# 遇到此处时,直接enter即可
# 这⾥的绝对路径是指miniconda2的安装路径
installation finished.
Do you wish the installer to initialize Miniconda2
in your /home/you/.bashrc ? [yes|no]
[no] >>>
# 这⾥输⼊yes
# 刚开始学的⼈最好输⼊yes,⽬的是让conda⾃动给你配置环境变量
# 输⼊yes的结果是:~/.bashrc这⾥⽂件⾥最后⼏⾏多了conda的配置信息
# less ~/.bashrc,多出来的配置信息第⼀⾏如下:
# added by Miniconda2 4.5.12 installer
.......
Thank you for installing Miniconda2!
# 出现这个代表安装成功
# 执⾏下⾯语句
source ~/.bashrc

miniconda配置镜像

conda安装软件需要从就近的镜像中查找安装包,因此软件安装成功后必须配置镜像(这里用的是清华镜像源,也可以选择其他的镜像源,具体可百度)

1
2
3
4
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda
conda config --set show_channel_urls yes

配置信息保存在 ~/.condarc

创建小环境

创建小环境相当于在屋子里安装一个柜子,可以把物品放在柜子里,柜子坏了可以直接丢掉。如果直接在大环境里安装软件如果破坏了主环境,恢复的代价就会更高。

1
2
3
4
5
6
7
8
9
10
11
12
# 1.创建名为rna的小环境
conda create -n rna
# 2.安装python2版本(可以根据需要选择python版本)
conda install python=2
## 可以合并两个命令
conda create -n rna python=2


# 查看已经存在的小环境(多个命令都可实现)
conda info -e
conda inf0 --envs
conda env list

进入小环境

创建小环境后,安装软件或者使用小环境内软件进行分析,一定要进入/激活小环境,否则只会在当前账户环境下运行。

1
2
# 激活名rna的小环境
source activate rna

查找软件

软件会有不同的版本,不同版本之间也会有不同的环境要求,在安装之前可以进行查找。

  1. 在conda网页内查找

  2. 直接运行命令查询

    1
    2
    # 查找stringtie软件安装包
    conda search stringtie

安装软件

1
2
3
4
5
6
# 安装sra-tools、trim-galore两个软件,默认安装最新版
conda install -y sra-tools trim-galore

# 选择安装版本
conda install numpy=1.11 :即安装能模糊匹配到numpy版本为1.11
conda install numpy==1.11 :即精确安装numpy为1.11的版本

 卸载软件

1
conda uninstall bwa

更新软件

1
2
3
4
5
# 更新conda
conda update conda

# 更新bwa
conda update bwa

查看当前环境已安装软件

1
conda list

退出小环境

1
conda deactivate

移除小环境

1
2
# 移除名为rna的小环境
conda env remove -n rna

镜像源

国内访问国外conda官网较慢,所以需要替换国内镜像源

1
2
3
4
5
6
7
8
# 显示目前conda源信息
conda info

# 删除并恢复默认的conda源
conda config --remove-key channels

# 设置安装包时,显示镜像来源(个人需求)
conda config --set show_channel_urls yes

设置清华镜像源

1
2
3
4
5
6
7
8
9
10
11
12
conda config --add channels r 
conda config --add channels defaults
conda config --add channels conda-forge
conda config --add channels bioconda
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
# Anocanda 清华镜像
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/cond-forge
# 清华通道, 最高优先级
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/
conda config --set show_channel_urls yes

如果镜像源出现问题,可还原使用

1
2
conda config --remove-key channels
conda config --append channels conda-forge --append channels bioconda --append channels defaults