bam格式转bigWig

作者: 生信编程日常 | 来源:发表于2020-07-20 22:58 被阅读0次

    当我们需要在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
    

    对于strand-specific的双端数据(常用的的d-UTP,--rf型, 1+-,1-+;2++,2--):

    # 得到forward-strand
    # exclude reads that are mapped to the reverse strand (16)
    $ samtools view -b -f 128 -F 16 a.bam > a.fwd1.bam
    
    # exclude reads that are mapped to the reverse strand (16) and
    # first in a pair (64): 64 + 16 = 80
    $ samtools view -b -f 80 a.bam > a.fwd2.bam
    
    # combine the temporary files
    $ samtools merge -f fwd.bam a.fwd1.bam a.fwd2.bam
    
    # index the filtered BAM file
    $ samtools index fwd.bam
    
    # run bamCoverage
    $ bamCoverage -b fwd.bam -o a.fwd.bigWig
    
    # remove the temporary files
    $ rm a.fwd*.bam
    
    
    # 得到reverse-strand:
    # and are second in a pair (16): 128 + 16 = 144
    $ samtools view -b -f 144 a.bam > a.rev1.bam
    
    # include reads that are first in a pair (64), but
    # exclude those ones that map to the reverse strand (16)
    $ samtools view -b -f 64 -F 16 a.bam > a.rev2.bam
    
    # merge the temporary files
    $ samtools merge -f rev.bam a.rev1.bam a.rev2.bam
    
    # index the merged, filtered BAM file
    $ samtools index rev.bam
    
    # run bamCoverage
    $ bamCoverage -b rev.bam -o a.rev.bw
    
    # remove temporary files
    $ rm a.rev*.bam
    

    欢迎关注!


    相关文章

      网友评论

        本文标题:bam格式转bigWig

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