Question: How to run bedtools from inside a python program
0
gravatar for banerjeeshayantan
3 months ago by
banerjeeshayantan190 wrote:

I have been using the bedtools to extract fasta sequences based on genomic positions mentioned in a bed file. The command that I usually use os the following:

bedtools getfasta -fi input.fa -bed input.bed -fo out.fa

Now I want to implement the same command line from a python program. This is mainly because I will be doing some downstream analysis using the "bedtools getfasta" output and that part has been entirely written in python. Both the input and the output can be pandas dataframes. I am aware of the "pybedtools" module but my question also extends to integration of other command line tools as well.

commandline python bedtools • 239 views
ADD COMMENTlink modified 3 months ago by Joe18k • written 3 months ago by banerjeeshayantan190
cmd = "bedtools getfasta -fi "+ input.fa + "-bed" +  input.bed + "-fo" + out.fa  
subprocess.call(cmd, shell=True)

or

bedtools="/home/Apps/bedtools"
cmd = bedtools + "getfasta -fi "+ input.fa + "-bed" +  input.bed + "-fo" + out.fa  
subprocess.call(cmd, shell=True)

You may need to pre-define input.fa, input.bed and out.fa before calling them.

Search for cmd in the link below, and see some examples:

https://sourceforge.net/p/fun4me/code/ci/master/tree/fun4me.py

ADD REPLYlink modified 3 months ago • written 3 months ago by Fatima930
1
gravatar for Joe
3 months ago by
Joe18k
United Kingdom
Joe18k wrote:

Use pybedtools if at all possible as its designed for this purpose.

Or run the commands via the subprocess module which is part of the standard library (or some combination of the two if pybedtools doesn't give you what you want).

Subprocess is the general solution to running commandlines in python though.

ADD COMMENTlink modified 3 months ago • written 3 months ago by Joe18k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1025 users visited in the last hour
_