Extract Sequence From Record And Feature Location
1
4
Entering edit mode
14.0 years ago
Atalon1 ▴ 40

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 • 7.9k views
ADD COMMENT
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

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...

ADD REPLY
10
Entering edit mode
14.0 years ago

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

ADD COMMENT
0
Entering edit mode

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)
ADD REPLY
0
Entering edit mode

sorry I forgot : thanks for the answer!

ADD REPLY
0
Entering edit mode

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.

ADD REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

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]

ADD REPLY

Login before adding your answer.

Traffic: 2608 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