PyBis: accessing parents?

Dear all,

in my ongoing quest to get familiar with openBIS, I’ve entered a range of measurements, each measrement is associated with the corresponding sample and the preparation method as parents - all entered via the ELN in the webbrowser.
This shows up in the webbrowser and I can, e.g. click on a parent and get to that object (see screenshot below)

Now I want to make a plot in python, I can get the object and the measured value shows up as well - but the parent relation is empty?
The permID fits, so it should be the same object…

print(objects[0].attrs.all)
<bound method AttrHolder.all of attribute            value
-------------------  -------------------------------------------------------------
code                 MEASURE_POINT98
permId               20230328174747567-154
identifier           /ULRICHKERZEL/MG_ALLOY_ANALYSIS/MEASURE_POINT98
type                 POINT_MEASUREMENT
project              /ULRICHKERZEL/MG_ALLOY_ANALYSIS
parents
children
components           []
space                ULRICHKERZEL
experiment           /ULRICHKERZEL/MG_ALLOY_ANALYSIS/MG_ALLOY_ANALYSIS_VOLFRACTION
tags                 []
registrator          ulrichkerzel
registrationDate     2023-03-28 17:47:48
modifier             ulrichkerzel
modificationDate     2023-03-30 12:23:36
container
frozen               False
frozenForComponents  False
frozenForChildren    False
frozenForParents     False
frozenForDataSets    False>

When I do try to access the parents anyway, I get an exception:

print(objects[0].get_parents())

AttributeError                            Traceback (most recent call last)
Cell In[49], line 1
----> 1 print(objects[0].get_parents())

File ~/.cache/pypoetry/virtualenvs/openbis-qARisZC2-py3.10/lib/python3.10/site-packages/pybis/attribute.py:736, in AttrHolder.get_parents(self, **kwargs)
    732 def get_parents(self, **kwargs):
    733     """get the current parents and return them as a list (Things/DataFrame)
    734     or return empty list
    735     """
--> 736     return getattr(self._openbis, "get_" + self._entity.lower())(
    737         self.parents, **kwargs
    738     )

File ~/.cache/pypoetry/virtualenvs/openbis-qARisZC2-py3.10/lib/python3.10/site-packages/pybis/pybis.py:4648, in Openbis.get_sample(self, sample_ident, only_data, withAttachments, props, **kvals)
   4646         identifiers.append(_type_for_id(ident, "sample"))
   4647 else:
-> 4648     identifiers.append(_type_for_id(sample_ident, "sample"))
   4650 fetchopts = get_fetchoption_for_entity("sample")
   4651 options = [
   4652     "tags",
   4653     "properties",
   (...)
   4659     "dataSets",
   4660 ]
...
    225     }
    226     """
    227     # Tags have strange permIds...

AttributeError: 'NoneType' object has no attribute 'strip'

Any ideas what I might do wrong?
Many thanks in advance
best wishes
Ulrich

As an addendum, the object does show up with parents in the “other” openBIS web view, so I suspect it’s more related to accessing the object with python?

Another addendum…

If I access the object directly via its permID, I do get the parents…?

obj = oBis.get_object('20230328174747567-154')
attribute            value
-------------------  -------------------------------------------------------------
code                 MEASURE_POINT98
permId               20230328174747567-154
identifier           /ULRICHKERZEL/MG_ALLOY_ANALYSIS/MEASURE_POINT98
type                 POINT_MEASUREMENT
project              /ULRICHKERZEL/MG_ALLOY_ANALYSIS
parents              ['/METHODS/PROTOCOLS/CAST95', '/MATERIALS/SAMPLES/SAMPLE69']
children             []
components           []
space                ULRICHKERZEL
experiment           /ULRICHKERZEL/MG_ALLOY_ANALYSIS/MG_ALLOY_ANALYSIS_VOLFRACTION
tags                 []
registrator          ulrichkerzel
registrationDate     2023-03-28 17:47:48
modifier             ulrichkerzel
modificationDate     2023-03-30 12:23:36
container
frozen               False
frozenForComponents  False
frozenForChildren    False
frozenForParents     False
frozenForDataSets    False

and

print(obj.parents)
['/METHODS/PROTOCOLS/CAST95', '/MATERIALS/SAMPLES/SAMPLE69']

Should I then get the permID first and then retrieve the object again?

Many thanks
Ulrich

Hello Ulrich,

downloading parent/children relationship is time-consuming, therefore it is by default disabled in the get_objects/get_samples methods (in get_object/get_sample it is enabled, that’s why you got different results). In order to include this information, you need it to explicitly specify these attributes in the calling method, like this:

samples = openbis_instance.get_samples('20230407070122991-46', attrs=["parents", "children"])

    identifier             permId                type               registrator    registrationDate     modifier    modificationDate     parents                    children
--  ---------------------  --------------------  -----------------  -------------  -------------------  ----------  -------------------  -------------------------  ----------
 0  /DEFAULT/DEFAULT/EXP1  20230407070122991-46  EXPERIMENTAL_STEP  admin          2023-04-07 09:01:23  admin       2023-04-07 09:02:22  ['/DEFAULT/DEFAULT/EXP2']  []

After checking the documentation, I realized this piece of information was not properly pointed out. It will be refactored as soon as possible.

Best regards,
Adam

2 Likes