如何合并两个或多个bed files

作者: Ternq8 | 来源:发表于2017-11-10 07:42 被阅读7次

    目的:把两组bed files 分别pool成一个bed file,而且叠加到序列区间要merge起来。
    合并:cat *.bed > output.bed
    软件:需要 bedtools
    issue:当merge bed files时候出现了error,
    ERROR: input file: (oLT.pooled.broadPeak) is not sorted by chrom then start. The start coordinate at line 2 is less than the start at line 1

    解决办法:bedfile 如果想进行bedtools merge需要先sort。

    1. 把reps pool到一起
    [ye.liu@n201 removed_01_02_10]$ cat *iMT* > ./pooled/iMT.pooled.broadPeak
    [ye.liu@n201 removed_01_02_10]$ cat *oLT* > ./pooled/oLT.pooled.broadPeak
    
    1. 参考下面例子进行sort
    $ more foo.bed
    chr1    1       2
    chr4    7       8
    chrX    100     101
    chr11   9       100
    chr11   9       99
    chr20   11      12
    chr2    3       4
    chr3    5       6
    

    chr start end 都升序排列

    $ sort -k1,1n -k2,2n -k3,3n foo.bed
    chr1    1    2
    chr2    3    4
    chr3    5    6
    chr4    7    8
    chr11    9    99
    chr11    9    100
    chr20    11    12
    chrX    100    101
    

    这样chr start 升序排列

    $ sort -k1,1n -k2,2n foo.bed
    chr1    1    2
    chr2    3    4
    chr3    5    6
    chr4    7    8
    chr11    9    100
    chr11    9    99
    chr20    11    12
    chrX    100    101
    

    我做的,

    [ye.liu@n201 pooled]$ sort -k1,1n -k2,2n -k3,3n iMT.pooled.broadPeak > sort.iMT.pooled.broadPeak
    [ye.liu@n201 pooled]$ sort -k1,1n -k2,2n -k3,3n oLT.pooled.broadPeak > sort.oLT.pooled.broadPeak
    

    另一种这样子比较好,

    [ye.liu@n201 pooled]$ sortBed -i iMT.pooled.broadPeak > sort.iMT.pooled.broadPeak
    [ye.liu@n201 pooled]$ sortBed -i oLT.pooled.broadPeak > sort.oLT.pooled.broadPeak
    [ye.liu@n201 pooled]$ bedtools merge -i sort.iMT.pooled.broadPeak > pool.sort.iMT.pooled.broadPeak
    [ye.liu@n201 pooled]$ bedtools merge -i sort.oLT.pooled.broadPeak > pool.sort.oLT.pooled.broadPeak
    

    相关文章

      网友评论

        本文标题:如何合并两个或多个bed files

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