美文网首页
生信分析软件环境搭建-conda-R-python

生信分析软件环境搭建-conda-R-python

作者: seqyuan | 来源:发表于2024-03-06 09:28 被阅读0次

安装Anaconda

down load anaconda

wget <https://repo.anaconda.com/archive/Anaconda3-2024.02-1-Linux-x86_64.sh>

最新版和历史版本的conda安装程序可以在https://repo.anaconda.com/archive/获得

安装命令

sh Anaconda3-2024.02-1-Linux-x86_64.sh

根据提示按回车键进行默认配置选择,注意在指定anaconda目录时,指定anaconda要安装的目录。

这里示例指定的目录是 /path/scbase

初始化,配置环境变量

/path/scbase/bin/conda init

source ~/.bashrc

conda install jupyter

conda 源

选择一个国内源添加到~/.condarc,加速conda安装软件时的下载速度

vi ~/.condarc,编辑好之后:wq保存

channels:
  - defaults
show_channel_urls: true
channel_alias: <https://mirrors.bfsu.edu.cn/anaconda>
default_channels:
  - <https://mirrors.bfsu.edu.cn/anaconda/pkgs/main>
  - <https://mirrors.bfsu.edu.cn/anaconda/pkgs/free>
  - <https://mirrors.bfsu.edu.cn/anaconda/pkgs/r>
  - <https://mirrors.bfsu.edu.cn/anaconda/pkgs/pro>
  - <https://mirrors.bfsu.edu.cn/anaconda/pkgs/msys2>
custom_channels:
  conda-forge: <https://mirrors.bfsu.edu.cn/anaconda/cloud>
  msys2: <https://mirrors.bfsu.edu.cn/anaconda/cloud>
  bioconda: <https://mirrors.bfsu.edu.cn/anaconda/cloud>
  menpo: <https://mirrors.bfsu.edu.cn/anaconda/cloud>
  pytorch: <https://mirrors.bfsu.edu.cn/anaconda/cloud>
  simpleitk: <https://mirrors.bfsu.edu.cn/anaconda/cloud>

创建新的conda环境

  1. conda create —name seurat4 python=3.8.5
  2. source activate seurat4
  3. conda install mamba -c conda-forge
  4. mamba install r-base=4.3.2

再之后想要在某个环境下安装软件只需要从conda的base环境先source 对应的env name,再安装即可,例如:

  1. source activate seurat4
  2. mamba install scanpy or mamba install r-devtools
# install Seurat v4.4.0
install.packages('devtools')
install.packages("BiocManager")

remotes::install_version("SeuratObject", "4.1.4", repos = c("<https://satijalab.r-universe.dev>", getOption("repos")))
remotes::install_version("Seurat", "4.4.0", repos = c("<https://satijalab.r-universe.dev>", getOption("repos")))

# 在R命令行临时设置CRAN和bioconductor源
options("repos"= c(CRAN="<https://mirrors.pku.edu.cn/CRAN/","http://mirrors.aliyun.com/CRAN>"))
options(BioC_mirror="<https://mirrors.tuna.tsinghua.edu.cn/bioconductor>")

添加到默认设置

echo "options(BioC_mirror='<https://mirrors.tuna.tsinghua.edu.cn/bioconductor>')" >> ~/.Rprofile
echo "options('repos' = c(CRAN='<https://mirrors.tuna.tsinghua.edu.cn/CRAN/>'))" >> ~/.Rprofile

为避免不同软件所依赖的软件包的版本冲突问题

  • 每个大的R或python软件包自行创建一个新conda envenv的名字以软件包的名字命名,例如seurat4和seurat5
  • 新的conda env一般在base环境下创建

安装R包的几种方式

R命令行安装方式:

  • install.packages(c('cowplot', 'ggridges')), 适用于发布在CRAN的R包
  • BiocManager::install(c("HiTC")), 适用于发布在bioconductor的R包
  • devtools::install_github('lchiffon/REmap'), 前为github的用户名,后为仓库名,适用于在github发布或在开发中的R包
  • remotes::[install_github](<https://remotes.r-lib.org/reference/install_github.html>)(repo = 'satijalab/seurat', ref = 'develop'),适用于在github开发中的R包,同devtools::install_github
  • devtools::install_local('./seurat.zip'), 适用于网络不好的时候,把R包下载到本地安装

linux命令行conda安装方式:

  • conda/mamba install r-cowplot,此为linux命令,非R命令,使用对应R环境下的conda或mamba安装,适用于依赖较多通过以上几种方法安装失败的时候(一般会优选这种方式,因为安装速度快,相关依赖包的解决好)
  • conda install -c bioconda bioconductor-hitc,适用于依赖较多的时候,安装发布在bioconductor的R包,示例中的-c参数为

如果要用conda安装某个R包,但是不知道这个R包用哪个channel,可以在anacoanda这个网址https://anaconda.org/bioconda/ 的搜索框搜索R包的名字,就会出现对应的完整conda安装命令行。

下面以clusterProfiler为例做展示:

image.png

python包安装指定源

可以通过pip的-i参数指定源

pip install -i https://mirrors.bfsu.edu.cn/pypi/web/simple package-name

以下源地址可供选择:

相关文章

网友评论

      本文标题:生信分析软件环境搭建-conda-R-python

      本文链接:https://www.haomeiwen.com/subject/tzljzdtx.html