This is a test version of Biostars. For the public version, visit https://www.biostars.org.
how to get -nms for bedtools

I'd like to merge bed files and preserve the names of the merged features using bedtools -nms option.

However, this option (-nms) is deprecated in the newer bedtools.

The documentation says I can use -o option to get -nms behavior.

How do I get translate the new bedtools merge command to get:

bedtools merge -i file.bed -nms
bedtools

Thanks for bringing this up. I will try to improve the docs...

2 answers

If your name field is the 4th column (as expected for BED format), you would do the following. This assumes your BED file is sorted by chromosome and then by start position.

bedtools merge -i file.bed -c 4 -o collapse

If the names are in the fourth column, here's one way to get a unique list of names that map across merged elements, where the input is sorted:

$ sort-bed unsorted.file.bed > file.bed
$ bedops --merge file.bed \
    | bedmap --echo --echo-map-id-uniq --delim '\t' - file.bed \
    > answer.bed

Mapped IDs will be in the fourth column of answer.bed.

Log in to answer this question.