NeurodataWithoutBorders / matnwb

A Matlab interface for reading and writing NWB files
BSD 2-Clause "Simplified" License
49 stars 32 forks source link

[Feature]: Allow `toTable()` on extension subtypes of `DynamicTable` #418

Closed rly closed 1 year ago

rly commented 2 years ago

What would you like to see added to MatNWB?

I have an NWB extension that includes a type that extends DynamicTable. I want to be able to visualize this table in MatNWB.

For example, in the ndx-events extension, AnnotatedEventsTable extends DynamicTable. However the following code does not work:

>> annotated_events = types.ndx_events.AnnotatedEventsTable()

annotated_events = 

  AnnotatedEventsTable with properties:

    event_description: []
          event_times: []
    event_times_index: []
                label: []
             colnames: []
          description: []
                   id: []
           vectordata: [0×1 types.untyped.Set]

>> annotated_events.toTable()
Unrecognized method, property, or field 'toTable' for class 'types.ndx_events.AnnotatedEventsTable'.

Is your feature request related to a problem?

No response

What solution would you like?

Add support for toTable() to extension types that extend DynamicTable.

Do you have any interest in helping implement the feature?

No.

Code of Conduct

rly commented 2 years ago

Actually, does the toTable() method referenced in the DynamicTable tutorial still work for DynamicTable objects?

>> my_table = types.hdmf_common.DynamicTable

my_table = 

  DynamicTable with properties:

       colnames: []
    description: []
             id: []
     vectordata: [0×1 types.untyped.Set]

>> my_table.toTable()
Unrecognized method, property, or field 'toTable' for class 'types.hdmf_common.DynamicTable'.
lawrence-mbf commented 2 years ago

That's interesting, the file generation does have a toTable method in version 2.4.0 and in master. Which MatNWB version is this?

lawrence-mbf commented 2 years ago

Testing out your code with ndx-events: the toTable method is included in the AnnotatedEventsTable but I do see an error when the table is empty:

Dot indexing is not supported for variables of this type.

Error in types.util.dynamictable.nwbToTable (line 35)
if isa(DynamicTable.id.data, 'types.untyped.DataStub')...

Error in types.hdmf_common.DynamicTable/toTable (line 123)
        table = types.util.dynamictable.nwbToTable(obj, varargin{:});

I'll open a PR fix for that. Can you try this on your machine using the tip of master?

lawrence-mbf commented 1 year ago

Can confirm that the provided code works in the newest release. If there are further issues, make a new ticket.