Struct

class hail.representation.Struct(attributes)[source]

Nested annotation structure.

>>> bar = Struct({'foo': 5, '1kg': 10})

Struct elements are treated as both ‘items’ and ‘attributes’, which allows either syntax for accessing the element “foo” of struct “bar”:

>>> bar.foo
>>> bar['foo']

Note that it is possible to use Hail to define struct fields inside of a key table or variant dataset that do not match python syntax. The name “1kg”, for example, will not parse to python because it begins with an integer, which is not an acceptable leading character for an identifier. There are two ways to access this field:

>>> getattr(bar, '1kg')
>>> bar['1kg']

The pprint module can be used to print nested Structs in a more human-readable fashion:

>>> from pprint import pprint
>>> pprint(bar)
Parameters:attributes (dict) – struct members.

Methods

__init__ x.__init__(…) initializes x; see help(type(x)) for signature
get Get an item, or return a default value if the item is not found.
get(item, default=None)[source]

Get an item, or return a default value if the item is not found.

Parameters:
  • item (str) – Name of attribute.
  • default – Default value.
Returns:

Value of item if found, or default value if not.