Author Topic: problem with bedops -n, not an element of  (Read 4518 times)

cohendm

  • Newbie
  • *
  • Posts: 5
problem with bedops -n, not an element of
« on: May 22, 2015, 05:55:57 AM »
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.

AlexReynolds

  • Administrator
  • Jr. Member
  • *****
  • Posts: 72
Re: problem with bedops -n, not an element of
« Reply #1 on: May 22, 2015, 04:23:47 PM »
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:

http://unix.stackexchange.com/questions/31947/how-to-add-a-newline-to-the-end-of-a-file
« Last Edit: May 22, 2015, 04:26:32 PM by AlexReynolds »

sjn

  • Administrator
  • Jr. Member
  • *****
  • Posts: 72
Re: problem with bedops -n, not an element of
« Reply #2 on: May 22, 2015, 04:24:52 PM »
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?

<edit>
Looks like Alex just gave the same advice about the ending newline.  --ec can help to find what's wrong.
« Last Edit: May 22, 2015, 04:26:47 PM by sjn »

cohendm

  • Newbie
  • *
  • Posts: 5
Re: problem with bedops -n, not an element of
« Reply #3 on: May 25, 2015, 05:52:10 PM »
Thanks, Alex! Yes, your insight was spot on. The problem was that the last line did not include a newline character.