More performant way of accessing children of objects pybis?

Dear openBIS enthusiasts,

for some processing we need to check if objects of type ‘SAMPLE’ have a child of a certain type. The child object in question is many hierarchical levels further down. Currently we access the children using pybis as follows:

# Get objects of type 'SAMPLE' and store them in a DataFrame.
samples = o.get_samples(type='SAMPLE').df

# Iterate over the rows of the 'samples' DataFrame.
    for row in samples.iterrows():

        # Get an object using the identifier from the current row.
        obj = o.get_object(row[1].identifier)

        # Iterate through the children of the current object.
        for child in obj.children:
            # Get the child object.
            obj1 = o.get_object(child)
            for child2 in obj1.children:
                obj2 = o.get_object(child2)
                ... repeat and eventually check some condition

Currently, this is not very performant, especially since we have many objects of the type ‘SAMPLE’.
Is there any more performant way you can think of, how we can improve this query?

Thanks in advance and cheers
Friedemann

One possibility would be to search for the specific condition and iterate through those results. It may be quicker if you have very few samples that match the requirement.

Another way could be to use jython within python to iterate. The java API is faster.

The last solution could be using tags. You could add those manually with one python script, which would spare you some time afterwards. Or run an entity validation script. You could also add a non editable changeable dynamic property to every object, but this could be quite interrupting.

Another possibility to still use python is to construct a specific query using JSON directly. You could have a look at how pybis does searches internally and modify the code to achieve this:

A good way to see how search queries are built is to start a global search in the ELN/LIMS UI and intercept the API calls using your browser’s developer tools.

In general, your use case shows that there needs to be an advanced python API which mirrors the Java/Javascript V3 API

1 Like