This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How do I pass options to pybedtools getfasta

I am trying to use pybedtools getfasta functionality. Here is an example given in the docs:

>>> a = pybedtools.BedTool("""
... chr1 1 10
... chr1 50 55""", from_string=True)
>>> fasta = pybedtools.example_filename('test.fa')
>>> a = a.sequence(fi=fasta)
>>> print open(a.seqfn).read()
>chr1:1-10
GATGAGTCT
>chr1:50-55
CCATC

This works fine. But I am wondering how can we pass the options here? I want to use -s option to force strandedness

pybedtools python bedtools

1 answer

Isn't the fi=fasta equivalent to passing -fi test.fa? You could try passing s=true along with fi=fasta

Yes. its s=True. The name of the getfasta wrapper sequence is little bit confusing.

I have printed the command that would be executed.

['bedtools', 'getfasta', '-s', '-fo', '/tmp/pybedtools.c6E0te.tmp', '-fi', 'genome.fasta', '-bed', '/tmp/pybedtools.oQDQu8.tmp']

But its not printing the reverse compliment. I will look into it. Thanks.

Glad you figured it out!

I appreciate this question and answer. It's been helpful as I try to learn how to use pybedtools.

However, I'm having the same problem. The extracted sequences are not being reverse complemented. How was this resolved? My code is as follows:

SLOPBED = BedTool('tmpbedfiles/' + QUERY + '.slop')
FASTA = SLOPBED.sequence(fi=GENOME, s=True)

GENOME and QUERY are variables within a loop in the overall script.

Please ignore this question. I found my problem. The strand information (+ or -) was in the wrong column of my bed file.

Log in to answer this question.