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.
1 answer
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.
Log in to answer this question.
or
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