How do I pass options to pybedtools getfasta
1
0
Entering edit mode
9.2 years ago

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 • 4.7k views
ADD COMMENT
1
Entering edit mode
9.2 years ago
Ram 43k

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

ADD COMMENT
1
Entering edit mode

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.

ADD REPLY
0
Entering edit mode

Glad you figured it out!

ADD REPLY
0
Entering edit mode

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.

ADD REPLY
0
Entering edit mode

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

ADD REPLY

Login before adding your answer.

Traffic: 1979 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6