This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Extract Sequence From Record And Feature Location

Hi,

What is the quikcest way to get a slice of my sequence corresponding to the location of a specific feature extracted from a genbank file?

I have a SeqRecord and its sequence (SeqRecord Object):

my_record.seq

the location of the specific feature I am interested in (SeqFeature Location object):

my_record.feature[2].location

I would expect a slice like:

my_record.seq[12:456]

Where 12:456 correspond to the feature location but I need integers for the slice, not a location object!!

Do I have to get into the location object to fetch the start and end....until I get integers or is there a quickest way?

Thanks

biopython feature

You should pick the answer to your question, not edit the question and add "Solved" to the headline.

Sorry; I did not get the point... it's my first post on stackexchange! Maybe a a howto in the FAQ to explain what to do when we have the anwser (excepted if it already exist and I did not see it) would be usefull as it took me 2 minutes to understand the procedure...

1 answer

Just use

your_sequence[feature[i].location.start.position:feature[i].location.end.position]

Then again, you probably would have found this out by looking into the BioPython wiki or Google for 2 minutes ;)

source exercise 11.15

I have already used the code using start and end positions of the feature.

My question was rather to know if there was a quickest (integrated function) to get the same result without having to write the slice with start and end positions as the ".location" property of the feature object contains both. Something like:

getSequence(SeqRecord object, feature.location object)

sorry I forgot : thanks for the answer!

As far as I know, there is no other (or shorter) way to retrieve sequence parts by feature. Of course, you could still write a wrapper for this type of parsing if you need it a lot. On the other hand, the standard way already allows for a 1-line extraction so this would probably not make much sense.

I will write a small wrapper... thanks for the link beccause it's much more complete than the biopython cookbook!!!

Glad I could help. Please mark the answer als solved if you feel that way :)

@atalon : to mark the answer as solved you have to use click the check image below the notation of Michael answer and NOT to edit the title of your question and adding [solved]

atalon : to mark the answer as solved you have to click the check image below the notation of Michael answer and NOT to edit the title of your question and adding [solved]

@atalon : to mark the answer as solved you have to click the check image below the notation of Michael answer and NOT to edit the title of your question and adding [solved]

Log in to answer this question.