Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get Loop tags without category #110

Closed
varioustoxins opened this issue Aug 8, 2022 · 5 comments
Closed

get Loop tags without category #110

varioustoxins opened this issue Aug 8, 2022 · 5 comments

Comments

@varioustoxins
Copy link

it doesn't appear to be possible to get the tags for a loop without the category?

if I am right it would be nice to have

class Loop:
    ...
    def get_tag_names(no_category: bool =False) -> List[str]:
       ...

?

@varioustoxins
Copy link
Author

alternatively tags should be declares as part of the public interface of Loop, or am I missing something?

anyways here is a simple patch

class Loop:

    ...
    def get_tag_names(self, no_category: bool) -> List[str]:

        """ Return the tag names for this entry with the category
        included. Throws ValueError if the category was never set.

        To fetch tag values use get_tag()."""

        if not self.category:
            raise ValueError("You never set the category of this loop.")

        if no_category:
            result = list(self.tags)
        else:
            result = [self.category + "." + x for x in self.tags]
        return result

@varioustoxins
Copy link
Author

I presume tags shouldn't be modified externally...

@jonwedell
Copy link
Member

You can access the tags without the category using the .tag attribute of an instance of a Loop:

>>> a = pynmrstar.Entry.from_database(15000)
>>> a[0][0].tags
['Ordinal', 'Given_name', 'Family_name', 'First_initial', 'Middle_initials', 'Family_title', 'ORCID', 'Entry_ID']

get_tag_names was added in case you want the loop category included, since it isn't present in the .tag attribute. I like your suggestion of modifying get_tag_names to support excluding the category using an optional argument for sake of consistency.

I will consider adding it for the next release.

@varioustoxins
Copy link
Author

Hi!

Thanks John I made a guess at doing what you suggested and it worked. However, ...

it wasn't clear as tag isn't in the api in the documentation,
also its not clear if its modifiable or not

as a naive user ;-)

@dmaziuk
Copy link

dmaziuk commented Aug 8, 2022

We probably should have called them "dbtable" and "dbcolumn" instead of "tag category" and "tag name" back when we switched to this convention (we didn't use it in NMR-STAR v.2) because that's what they actually are. Plain STAR doesn't have "tag category": whatever's between the underscore and whitespace is just "tag".

jonwedell pushed a commit that referenced this issue Mar 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants