2

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?

El Developer
  • 3,345
  • 1
  • 21
  • 40
gregcaporaso
  • 444
  • 4
  • 11

1 Answers1

3

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.

daniel
  • 2,568
  • 24
  • 32
  • Thanks, that is definitely cleaner than what I was suggesting. I think a ``length`` method would be useful - I created [an issue here](https://github.com/biocore/biom-format/issues/548). – gregcaporaso Sep 26 '14 at 16:35