Applications of BEDOPS > bedops

problem with bedops -n, not an element of


Running Bedops 2.4.14 on Mac OS 10.8.5. Having problems with the following command:

bedops -n 2 RNAPII.USHP.all mask.txt > RNAPII.USHP.masked

The script runs without error. However, for some reason, the very last interval of my mask.txt file is being ignored by this function. The interval is chrY:59034017-59034077, and is preceded by 1,000,000 other intervals, correctly sorted, and including other intervals on the Y chromosome. The -n function removes everything as expected EXCEPT this very last interval. Puzzled as to why this would be the case. If instead I try the following

bedops --element-of 2 RNAPII.USHP.all mask.txt > intersectwithmask.bed

then I see everything as expected, including the intersecting intervals for the chrY:59034017-59034077 region in the RNAPII.USHP.all bed file. So this is not an issue with data already being absent from the reference file, or a data corruption issue in the mask.txt file.

Check that the last line of your sorted BED file (mask.txt) ends with a newline character.

You can use the following command to verify this:

$ tail -1 foo.bed | cat -e

You should see a dollar sign symbol at the end of the line. For example:

$ tail -1 test/vec_test4.bed | cat -e
chr1   3568000   3568150   id-4$

If you don't see that dollar sign, that element does not have the required trailing newline character. See the following thread for suggestions on how to add a newline to the end of a file:

I tried some quick things here and didn't see a problem with -n/-e 2.

Technically, there needs to be newline at the end of the file.  Could you add a --ec to the call and see if bedops -n 2 tells you what the problem is?

Looks like Alex just gave the same advice about the ending newline.  --ec can help to find what's wrong.

Thanks, Alex! Yes, your insight was spot on. The problem was that the last line did not include a newline character.


[0] Message Index

Go to full version