生信常见报错排查:20条错误与解决方案
生信分析中报错种类繁多——文件权限、内存溢出、软件依赖、流程逻辑。本文按 文件/权限 → 内存/OOM → 软件/依赖 → R/Python → 流程逻辑 分类,整理 20 个常见错误,每条附错误原文、原因分析和解决方案。
全部在 Debian 13 上复现并验证。
一、文件与权限类
错误1:Permission denied
bash: ./run_pipeline.sh: Permission denied原因: 文件没有执行权限。
排查:
ls -la run_pipeline.sh# -rw-r--r-- 1 user user 1234 Mar 1 10:00 run_pipeline.sh# ^ 没有 x(执行位)解决:
chmod +x run_pipeline.sh如果是从 Windows 传过来的脚本,还要检查换行符:
# 查看是否有 ^M(\r)换行符cat -A run_pipeline.sh | head -5
# 转换sed -i 's/\r$//' run_pipeline.sh错误2:No such file or directory
$ samtools view -bS alignment.sam[E::hts_open_format] Failed to open file "alignment.sam" : No such file or directory排查清单(按顺序):
# 1. 文件真的不存在?ls -la alignment.sam
# 2. 你在正确的目录吗?pwd
# 3. 文件名拼错了?(大小写!)ls -la Ali* # 检查是否有大小写差异
# 4. 路径有空格或特殊字符?# 永远用双引号包裹路径samtools view -bS "alignment.sam"最常见的原因: 上一步的输出写到了另一个目录,或者文件名带了 _sorted 后缀而你没注意到。
错误3:No space left on device
$ gzip raw_data.fastqgzip: raw_data.fastq: No space left on device排查:
df -h .# Filesystem Size Used Avail Use% Mounted on# /dev/sda1 97G 93G 0 100% /opt/data
# 找大文件du -sh /opt/data/* | sort -rh | head -20解决:
# 紧急清理(删除 conda 缓存)conda clean --all -y
# 清理临时文件rm -rf /tmp/bioinfo_* /tmp/samtools_*
# 清理旧日志find . -name "*.log" -mtime +30 -delete错误4:软链接断掉(broken symbolic link)
$ ls -la reference/hg38.falrwxrwxrwx 1 user user 42 Mar 1 10:00 reference/hg38.fa -> ../../old_path/hg38.fa# 文件显示红色(在 ls --color 中),说明目标不存在排查:
readlink -f reference/hg38.fa # 空输出表示断了ls -laL reference/hg38.fa # -L 会报错如果断了解决: 重新创建链接或直接放文件副本。
# 不要用软链接管理大参考基因组——用硬链接或直接复制ln -f /opt/refs/GRCh38.primary.fa reference/hg38.fa # 硬链接# 或cp /opt/refs/GRCh38.primary.fa reference/hg38.fa二、内存与系统资源类
错误5:Killed(OOM Killer)
$ STAR --genomeDir star_index --readFilesIn sample.fastq.gz... running for 2 hours ...Killed这是 Linux 内核的 OOM(Out of Memory)Killer。当系统内存耗尽时,内核会杀死占用内存最大的进程。
排查:
# 事后检查dmesg | grep -i "out of memory" | tail -20dmesg | grep -i "killed process" | tail -10
# 会看到类似:# Out of memory: Killed process 28473 (STAR) total-vm:52GB ...解决:
# 方案1:加内存(废话但有效)# 方案2:减少线程(线程越多内存越大,不是线性关系!)STAR --runThreadN 4 ... # 从 16 降到 4
# 方案3:限制 STAR 内存STAR --limitBAMsortRAM 10000000000 ... # 限制排序内存 10GB
# 方案4:用 swap(临时救急)sudo fallocate -l 32G /swapfilesudo chmod 600 /swapfilesudo mkswap /swapfilesudo swapon /swapfile| 软件 | 每线程内存 | 建议线程数 |
|---|---|---|
| STAR | ~30-40GB (人类) | 4-8 |
| HISAT2 | ~8-10GB | 8-16 |
| Bowtie2 | ~4GB | 8-16 |
| BWA-MEM | ~6-8GB | 8-12 |
错误6:Bus error (core dumped)
$ hisat2 -x genome_index -1 R1.fq -2 R2.fq -S output.samBus error (core dumped)原因: 内存硬件故障或文件读取越界。生信中常见于索引文件损坏。
排查:
# 1. 检查索引完整性md5sum genome_index.*.ht2# 与官网提供的 md5 对比
# 2. 重建索引hisat2-build reference.fa genome_index错误7:Too many open files
$ parallel -j 50 samtools sort .../bin/bash: error while loading shared libraries: libtinfo.so.6:cannot open shared object file: Too many open files原因: Linux 限制每个进程可同时打开的文件数(默认 1024)。生信并行任务频繁触发。
解决:
# 查看当前限制ulimit -n# 1024
# 临时提升ulimit -n 65536
# 永久生效(/etc/security/limits.conf)echo "* soft nofile 65536" | sudo tee -a /etc/security/limits.confecho "* hard nofile 65536" | sudo tee -a /etc/security/limits.conf错误8:GLIBCXX_3.4.30 not found
$ samtoolssamtools: /lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.30' not found原因: Conda 装的包动态链接了新版 libstdc++,但系统里的是旧版。
排查:
# 看系统和 conda 各有什么版本的 GLIBCXXstrings /usr/lib/x86_64-linux-gnu/libstdc++.so.6 | grep GLIBCXX | tail -5strings $CONDA_PREFIX/lib/libstdc++.so.6 | grep GLIBCXX | tail -5解决:
# 临时:让程序优先用 conda 的库export LD_LIBRARY_PATH=$CONDA_PREFIX/lib:$LD_LIBRARY_PATH
# 根本:在 conda 环境内装 libstdcxx-ngmamba install -c conda-forge libstdcxx-ng -y三、软件与依赖类
错误9:samtools: command not found
$ samtools view-bash: samtools: command not found原因: 没装或环境没激活。
排查三步走:
# 1. 检查环境是否激活conda env list | grep '*'# 如果 base 前面没有 *,说明 conda 没 init
# 2. 用 which 定位which samtools # 无输出 = 没装
# 3. 检查是否在正确环境里conda list | grep samtools错误10:conda 装包卡住 Solving environment
参见 Conda环境冲突全攻略 第 7 节。核心解决:
# 把 conda 换成 mambamamba install -c bioconda package_name -y
# 或者指定精确版本缩小搜索空间mamba install -c bioconda package_name=1.2.3 -y错误11:pip 覆盖了 conda 的包
$ conda install -c conda-forge numpy$ pip install scikit-learn # pip 升级了 numpy$ python -c "import numpy; print(numpy.__version__)"# numpy 崩溃或版本回退解决: 优先用 conda 装所有依赖;必须用 pip 时加 --no-deps:
pip install --no-deps scikit-learn如果已经崩了,重建环境:
mamba env remove -n myenvmamba create -n myenv -c conda-forge python=3.10 numpy scipy pandas matplotlib -ypip install --no-deps scikit-learn错误12:Java 版本不兼容(Picard/GATK)
$ java -jar picard.jar MarkDuplicates ...Error: A JNI error has occurred, please check your installationException in thread "main" java.lang.UnsupportedClassVersionError原因: Picard/GATK 需要特定 Java 版本。Picard 2.27+ 需要 Java 17。
排查:
java -version# openjdk version "11.0.21" <- 太旧了解决:
mamba install -c conda-forge openjdk=17 -yjava -version # 确认版本四、R 语言类
错误13:there is no package called 'xxx'
> library(DESeq2)Error in library(DESeq2) : there is no package called 'DESeq2'解决三步走:
# 1. 检查是否装过installed.packages()[,"Package"] %>% grep("DESeq2", ., value = TRUE)
# 2. 没装就装if (!requireNamespace("BiocManager", quietly = TRUE)) install.packages("BiocManager")BiocManager::install("DESeq2")
# 3. 确认 .libPaths()——你可能装了但 R 找不到.libPaths()# 如果 conda 环境里的 R 在用系统的 library path,修正:# export R_LIBS_USER=$CONDA_PREFIX/lib/R/library错误14:cannot allocate vector of size X Gb
> deseq2_results <- DESeq(dds)Error: cannot allocate vector of size 8.5 Gb原因: R 默认把所有数据装入内存。
解决:
# 方案1:写一个 swap 文件(给 Linux 额外虚拟内存)sudo fallocate -l 32G /swapfilesudo mkswap /swapfile && sudo swapon /swapfile
# 方案2:减少数据量(预过滤低表达基因)keep <- rowSums(counts(dds) >= 10) >= 3dds <- dds[keep, ]
# 方案3:用内存友好的替代# Seurat 用 BPCells,DESeq2 没有——只能加内存或过滤错误15:R 版本与包不兼容
> install.packages("tidyverse")ERROR: this R is version 4.2.3, package 'tidyverse' requires R >= 4.3解决:
# conda 环境里升级 Rmamba install -c conda-forge r-base=4.3 -y
# 或者用 conda 装匹配版本的包(conda 会处理好 R 版本)mamba install -c conda-forge r-tidyverse -y错误16:Bioconductor 版本不匹配
> BiocManager::install("DESeq2")Error: Bioconductor version 3.16 (R 4.2) is not compatible with R 4.3解决:
# 升级 Bioconductor 到与 R 匹配的版本BiocManager::install(version = "3.18") # R 4.3 对应 3.18
# 对照表:# R 4.2 → Bioc 3.16# R 4.3 → Bioc 3.18# R 4.4 → Bioc 3.19五、流程逻辑与数据类
错误17:BAM 的 Read Group 缺失
$ gatk HaplotypeCaller -R ref.fa -I sample.bam -O variants.vcfA USER ERROR has occurred: Read groups are missing in the BAM file解决: 比对时就用 -R 加 Read Group 信息。
# BWA-MEMbwa mem -R '@RG\tID:sample1\tSM:sample1\tPL:ILLUMINA' ref.fa R1.fq R2.fq > aln.sam
# STARSTAR --outSAMattrRGline ID:sample1 SM:sample1 PL:ILLUMINA ...
# 也可以事后补(samtools addreplacerg)samtools addreplacerg -r '@RG\tID:sample1\tSM:sample1' -o fixed.bam original.bam错误18:featureCounts 分配的 reads 数异常低
$ featureCounts -a genes.gtf -o counts.txt sample.bam# Successfully assigned: 12.3% ← 太低!正常 RNA-seq 的分配率应该 >70%(人类/小鼠)。排查:
# 1. BAM 和 GTF 的染色体名一致吗?samtools idxstats sample.bam | head -5grep -oP '^chr[^"]+' genes.gtf | sort -u | head -5# chr1 vs 1 ——这就是问题!BAM 是 chr1,GTF 是 1
# 2. GTF 和 BAM 的 strand 信息一致吗?# featureCounts 默认 -s 0(unstranded)# 如果你的数据是 stranded 但 GTF 没标注,用 -s 2featureCounts -s 2 -a genes.gtf -o counts.txt sample.bam错误19:DESeq2 的 model matrix is not full rank
> dds <- DESeq(dds)Error: the model matrix is not full rank原因: 实验设计矩阵中存在线性依赖。最常见:某个 factor 的所有样本和另一个 factor 完全一致。
排查:
# 查看 design formula 的混淆table(dds$condition, dds$batch)# 如果你看到类似:# batch1 batch2# ctrl 3 0# treat 0 3# 这意味着 condition 和 batch 完全混淆——DESeq2 无法区分解决: 调整 design formula 去掉混淆的项,或合并 factor。
# 如果 batch 和 condition 不混淆,把 design 改成design(dds) <- ~ batch + condition错误20:SAM/BAM 的 header 错乱导致下游崩溃
$ samtools index sample.bam[E::hts_idx_push] Unsorted positions on sequence chr1原因: BAM 没排序或排序参数不对。
解决:
# 按坐标排序samtools sort -o sample_sorted.bam sample.bamsamtools index sample_sorted.bam
# 如果要按名字排序(某些工具需要)samtools sort -n -o sample_qname.bam sample.bam六、通用排查技巧
技巧1:看日志的最后一行
# 大多数生信工具的最后一行是总结或错误码tail -5 pipeline.log
# 如果只有 Killed,看 dmesgdmesg | tail -30 | grep -iE "error|killed|oom|fail"技巧2:检查退出码
# 脚本里加这行some_commandecho "Exit code: $?"# 0 = 成功,1 = 通用错误,134 = SIGABRT,137 = SIGKILL(OOM),139 = SIGSEGV技巧3:临时文件残留
# 生信软件经常在 /tmp 下创建临时文件,崩溃后不清理ls -la /tmp/samtools_* /tmp/STAR_* /tmp/hisat2_*
# 清理(谨慎!)find /tmp -maxdepth 1 -name 'samtools_*' -mtime +1 -deletefind /tmp -maxdepth 1 -name 'STAR_*' -mtime +1 -delete技巧4:环境变量问题
# 很多生信软件通过环境变量指定参考基因组等配置echo $BOWTIE2_INDEXESecho $STAR_GENOME_DIR
# 如果为空且工具报 "index not found",在 ~/.bashrc 里加:export BOWTIE2_INDEXES="/opt/refs/bowtie2"本文覆盖了 20 个常见生信错误。如果你遇到了不在列表中的报错,把错误信息丢给搜索引擎 + “biostars” 或 “seqanswers”,大概率能找到。
本文于 2025-09-05 在 Debian 13 上复现验证。
文章分享
如果这篇文章对你有帮助,欢迎分享给更多人!