I am trying to use bedtools getfasta on a txt file but some of the chromosome coordinates from big to low, how can I fix this so that all chromosome coordinates are from low to big? I am using command line on Ubuntu.
I expected the command to run properly when running but the bedtools getfasta -fi file.fasta -bed file.txt
the text file looks like this:
ChromosomeName Position1 Position2 ChromosomeName Position1 Position2 ChromosomeName Position1 Position2
Sometimes P1 > P2 which causes the error in the title.
Hope this helps. It sounds like you could either 1) go in manually and fix/delete the positions if you only have a few places to fix. Otherwise 2) if you have a 3 column bed file like this: chrA posA posB, an awk command along the lines of:
awk '{OFS="\t"; if ($3-$2 > 0) {print}' your_file.bed > fixed_file.bed
This will only print out the positions where column 3-column2 (aka posB-posA) is a positive value. If posA is greater than posB, the line won't be printed. You will lose those malformed lines this way though.
-Laura