is it possible to get the length of an axis directly in a biom.Table object?

87 Views Asked by At

Is it possible to directly lookup the length of an axis in a biom.Table object, or do you need to do something like the following, where t is a Table object:

if axis == 'sample':
    length = t.shape[0]
elif axis == 'observation':
    length = t.shape[1]
else:
   raise UnknownAxisError(axis)

It seems like a better way to do this would be with a method like t.length(axis). Does functionality like that exist?

1

There are 1 best solutions below

1
On BEST ANSWER

The best method right now would be:

>>> from biom import example_table
>>> axis = 'sample'
>>> print example_table.ids(axis).size
3

__len__ currently isn't overloaded because it isn't clear what axis should be returned. It may make sense to have a length method though, and if you think it would be clearer to have, the best next step would be to create an issue on the github project.