Skip to content

Feature request: direct access to source fields #6

@xapple

Description

@xapple

When looking at a GenBank entry there often is interesting information in the "source" feature, which actually contains several subfields. From instance below one can see the "host" information:

host

I end up having to wrap the gb_io.Record class with another class to access this information. Also I end up constantly having to replace newlines with spaces.

class GenBankRecord:

    def __init__(self, rec):
        """Get a record instance from gb_io"""
        self.rec = rec

    @functools.cached_property
    def source(self):
        """Parse the first feature which is always 'source'"""
        return next(iter(self.rec.features))

    @functools.cached_property
    def fields(self):
        """Get all subfields of source."""
        return self.source.qualifiers.to_dict()

    @functools.cached_property
    def host(self):
        if 'host' in self.fields:
            return self.fields['host'][0].replace('\n', ' ')
        return ''

It would be nice to just do rec.host no?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions