I am trying to covert my bam file into bedgraph using bedtools
. For that I sorted the bam file by names, and then run the follwoing commands:
bedtools bamtobed -bedpe -i IgG_H3K4m3.sortedByName.bam > IgG_H3K4m3.bed
awk '$1==$4 && $6-$2 < 1000 {print $0}' IgG_H3K4m3.bed > IgG_H3K4m3.clean.bed
cut -f 1,2,6 IgG_H3K4m3.clean.bed | sort -k1,1 -k2,2n -k3,3n > IgG_H3K4m3.frag.bed
bedtools genomecov -bg -i IgG_H3K4m3.frag.bed -g Mmu.GrCm38.chromSize > IgG_H3K4m3.bedgraph
But with the last command I get the following error
Input error: Chromosome 12 found in non-sequential lines. This suggests that the input file is not sorted correctly.
When I look what the command before last is doing ( the sorting steps) I can see a strange behavior of sort
:
cut -f 1,2,6 P193/Mmu.GrCm38/bowtie2/IgG_H3K4m3.clean.bed | sort -k1,1 -k2,2n -k3,3n| cut -f 1 | uniq
10
1
11
12
1
14
15
16
1
18
2
3
5
6
9
MT
X
Somehow it can't sort chromosome 1 correctly. Is there any wat to explain this ( or even better to correct it).
thanks
Output of
sort --version
?sort (GNU coreutils) 8.22