How can I extract a feature from a genbank file by label?

443 Views Asked by At

I'm trying to parse a genbank file to find a specific feature. I can pull it out if I know the feature type (e.g. repeat_region) - eg if I'm looking for this feature:

 repeat_region   5623..5756
                 /label=5' ITR
                 /note="5' ITR"

I know that I can find it using:

for feature in reference.features:
if feature.type == "repeat_region":
    print(feature.location)

But I don't trust that it will always be a repeat_region. Instead, I'd like to look for it by label (5' ITR). I can seem to find a way to parse that from the feature object. Any suggestions?

1

There are 1 best solutions below

1
Cindy Fang On

I would suggest to try using the ElementTree library; it will parse the genbank xml file into a dictionary and then you should be able to access the /label tag as a key.