4
$\begingroup$

I am trying to use bedtools and fetch sequences from a whole genome fasta file inside the script I get region coordinates as variables. For example:

chr_ = "chr1"
start = 3000
end = 3402

I am not sure how to wrap my function, because the example provided by BedTool.sequence only uses coordinates in a string form.

Can you please help me to have something like this?

a = pybedtools.BedTool(chr_, start, end, from_variables=True)
$\endgroup$
2
$\begingroup$

You have to take your variables and make them into a single string variable.

for example:

chr_ = "chr1"
start = 3000
end = 3402
as_str = ' '.join([chr_, str(start), str(end)])
# or 
as_str2 = "{} {} {}".format(chr_, start, end)

Once you have the string built you can use the example in the bedTool docs.

a = BedTool(as_str, from_string=True)
$\endgroup$
  • $\begingroup$ If you like an answer please accept it so future users know it worked. $\endgroup$ – Bioathlete May 31 '18 at 17:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.