bam格式转bigWig

时间:2022-07-22
本文章向大家介绍bam格式转bigWig,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

当我们需要在UCSC browser中可视化的时候,将bam文件转化为bigwig文件会更加方便。而deeptools中的bamCoverage可以方便的实现这个功能。

1. 安装

conda或者pip安装:

conda install -c bioconda deeptools
# 或者
pip install deeptools

github源代码安装:

 git clone https://github.com/deeptools/deepTools.git
wget https://github.com/deeptools/deepTools/archive/1.5.12.tar.gz
tar -xzvf
python setup.py install --prefix /User/Tools/deepTools2.0

一定要注意一下的依赖包必须满足要求:

如果不满足要求的话,bam2Coverage可能会引发如下错误: "The XXX file does not have BAM or CRAM format"; "ModuleNotFoundError: No module named 'numpy.core._multiarray_umath'"等等。

2. bam2Coverage

必需参数:

需指定输入文件,输出文件名。输出文件格式默认为bigwig,如果想输出bedgraph文件需指定。

非必需参数:

此外还有Read coverage normalization options和Read coverage normalization options,有具体需要可以查阅。

ChIP-seq的例子:

bamCoverage --bam a.bam -o a.SeqDepthNorm.bw 
    --binSize 10
    --normalizeUsing RPGC
    --effectiveGenomeSize 2150570000
    --ignoreForNormalization chrX
    --extendReads

RNA-seq的例子:

bamCoverage -b a.bam -o a.bw

当我们需要分离正负链时(单端):

bamCoverage -b a.bam -o forward.bw --filterRNAstrand forward
bamCoverage -b a.bam -o reverse.bw --filterRNAstrand reverse

# 如果在2.2版本之前:
bamCoverage -b a.bam -o a.fwd.bw --samFlagExclude 16
bamCoverage -b a.bam -o a.rev.bw --samFlagInclude 16

相当于我们做了如下操作:

samtools view -@ 8 a.bam | 
awk -F 't' '$2==0' | 
bamCoverage -b a.bam -o a.fwd.bw