科研环境配置

conda环境配置

安装

  • 删除原来的环境
1
conda env remove -n phylo
  • 从头安装环境和软件
1
2
mamba env create -n phylo -f envs/phylo.yml
conda activate phylo # 或:mamba activate phylo
  • 更新环境中的软件
1
2
mamba env update -n phylo -f envs/phylo.yml --prune
conda activate phylo # 或:mamba activate phylo(如果你的 shell 支持)
  • 关于mamba
1
2
3
4
5
6
7
8
9
10
11
12
13
# 1. 安装 mamba
conda install -n base -c conda-forge mamba

# 2. 安装 fastp
mamba install -c bioconda fastp

# 3. 更新 fastp
mamba update fastp

# 4. 查找 fastp 安装位置
which fastp
conda list fastp

  • conda环境下安装R包
1
mamba install -c conda-forge -c bioconda bioconductor-tximport bioconductor-rtracklayer r-readr r-dplyr

修复 Conda 镜像配置

请按照以下步骤操作,即可修复问题。

第一步:查看并移除错误的镜像地址

  1. 查看您当前的频道列表,确认一下错误的地址确实存在。

    Bash

    1
    conda config --show channels

    您的输出中应该会包含 https://mirrors.tuna.tsinghua.edu.cn/conda-forge 这一行。

  2. 移除这个错误的地址。请精确复制并运行下面的命令:

    Bash

    1
    conda config --remove channels https://mirrors.tuna.tsinghua.edu.cn/conda-forge

    您可能还需要移除其他指向 mirrors.tuna.tsinghua.edu.cn 的旧地址,如果它们存在的话。重复此步骤即可。

第二步:添加正确的新镜像地址

现在您的配置干净了,接下来我们把正确的地址加回去。这里给您两个选择:

选项 A:使用 Conda 官方默认源 (最稳定)

如果您不追求极致的下载速度,或者清华源不稳定,直接用官方源是最省心的。

1
2
3
4
5
6
7
8
# 添加 conda-forge 官方源
conda config --add channels conda-forge

# 添加 bioconda 官方源 (后续生物信息分析会用到)
conda config --add channels bioconda

# (推荐) 设置频道优先级为严格,可以有效避免依赖冲突
conda config --set channel_priority strict

选项 B:使用正确的清华镜像源 (速度快)

清华大学镜像站的 Conda 服务更新了地址结构。以下是当前推荐的配置方法:

1
2
3
4
5
6
7
8
9
# 依次添加清华大学的镜像频道
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
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 channel_priority strict

第三步:验证并重试

  1. 再次检查您的频道配置,确保它们现在是正确的。

    Bash

    1
    conda config --show channels

    输出应该显示您刚刚添加的新地址。

  2. 清空 Conda 缓存,以防旧的索引文件造成干扰。

    Bash

    1
    conda clean -all

    根据提示输入 y 确认。

  3. 现在,重新运行您最初的创建环境命令

    1
    mamba install -c conda-forge -c bioconda r-base r-tidyverse r-data.table r-optparse r-stringr r-reshape2 r-gridextra r-patchwork r-readxl r-rlang r-glue r-tibble r-ggplot2 r-ggsci r-ggrepel r-scales r-viridis r-pheatmap bioconductor-complexheatmap r-circlize r-ggpubr bioconductor-clusterprofiler bioconductor-enrichplot bioconductor-annotationdbi bioconductor-go.db bioconductor-gosemsim bioconductor-dose bioconductor-qvalue r-yulab.utils r-gson bioconductor-deseq2 bioconductor-apeglm r-ape r-phytools bioconductor-treeio bioconductor-ggtree

安装字体

  1. 激活您的 Conda 环境:

    1
    conda activate your_env_name
  2. 使用 Conda 安装字体文件 (如果还没装的话):

    1
    conda install -c conda-forge mscorefonts
  3. 确保 Ghostscript 也已安装 (PDF嵌入字体需要):

    1
    conda install -c conda-forge ghostscript
  4. 进入 R 环境:

    1
    R
  5. 在 R 中执行一次性的字体注册:

    1
    2
    3
    4
    5
    6
    7
    8
    # (如果还没装)
    install.packages("extrafont")

    # 加载
    library(extrafont)

    # 扫描并导入字体 (只需做一次,会花几分钟)
    font_import()
  6. 退出 R 环境:

    1
    q()
  7. 最后,正常运行您的分析脚本:

    1
    ./run_enrich_module.sh

完成以上一次性配置后,您的 R 环境就永久性地知道了 Arial 字体的存在。之后再运行您的 run_enrich_module.sh 脚本,就不会再出现找不到字体的警告或错误了。

安装go.db

1
2
3
4
if (!requireNamespace("BiocManager", quietly = TRUE))
install.packages("BiocManager")

BiocManager::install("GO.db")

科研环境配置
https://oldstory.cn/2025/12/20/ke_yan_huan_jing_pei_zhi/
作者
Ricardo
发布于
2025年12月20日
许可协议