This is a test version of Biostars. For the public version, visit https://www.biostars.org.
bedops bedmap operation in python

I noticed there is a conda version of bedops bedmap function available. I've been struggling to use it though. Could someone refer me to any documentation of it's usage in a python script please. Have a great day. Thanks in advance.

python bedops bedmap

Uday Rangaswamy

Please do not delete posts that have received feedback/been solved. This one has an accepted answer, and is a valuable resource that should not be deleted.

1 answer

Hi- I'm not sure if there is a python API for bedops (similar to pybedtools, if this is what you mean). However, in a python script you can use the subprocess library to execute external commands. E.g. something like (see also check_call):

import subprocess

p= subprocess.Popen("bedmap ... > out.bed", shell= True, stdout= subprocess.PIPE, stderr= subprocess.PIPE)
stdout, stderr= p.communicate()
if p.returncode != 0:
    print(stderr)
    print('Exit code %s' %(p.returncode))
    sys.exit(1)

There is no Python API but subprocess is the way to go if you run BEDOPS tools in a Python script. The better way is to use the command line interface.

Log in to answer this question.