scverse/scirpy

`AirrCell` to retrieve chain field attribute values directly like a dictionary of nested values

zktuong opened this issue · 2 comments

The behaviour i'm after is something like

tmp_cell = AirrCell(...)
tmp_cell["c_call"]

I would get

['TRBC1', 'TRAC', 'TRAC']

So would something like this be ok?:

def __getitem__(self, key):
        if key == "cell_id":
            return self._cell_attrs[key]
        else:
            chain_field_attrs = []
            for sub_dict in self._chains:
                if key in sub_dict:
                    chain_field_attrs.append(sub_dict[key])
            return chain_field_attrs
grst commented

I'm not a big fan of [xxx] returning different types (list vs single value) depending on the key...
Could you briefly elaborate on your use-case? I initially intended AirrCell just as an intermediate data structure for constructing the awkward array.

Can you defer access to "c_call" until you already have the awkward array? The awkward array can be sliced for single fields easily and efficiently.

ah ok fair enough. didn't know that works.