diff --git a/pybis/src/python/CHANGELOG.md b/pybis/src/python/CHANGELOG.md index ff8d198eb4d4f570f96e36dd2368032998ed7f2e..d12e7004228f3228d4306a705f1523a5cfe8d76c 100644 --- a/pybis/src/python/CHANGELOG.md +++ b/pybis/src/python/CHANGELOG.md @@ -1,3 +1,7 @@ +## Changes with pybis-1.14.4 + +- added new convenience methods: get_experiments, get_projects etc. + ## Changes with pybis-1.14.3 - small bugfix: prevent error diff --git a/pybis/src/python/pybis/__init__.py b/pybis/src/python/pybis/__init__.py index d7e11a06034093f35d3b515b5ec1e23adc9a12c3..a54d5efbef115ca4f9ad9f6747a5f9286ba75f37 100644 --- a/pybis/src/python/pybis/__init__.py +++ b/pybis/src/python/pybis/__init__.py @@ -1,7 +1,7 @@ name = 'pybis' __author__ = 'Swen Vermeul' __email__ = 'swen@ethz.ch' -__version__ = '1.14.3' +__version__ = '1.14.4' from . import pybis from .pybis import DataSet diff --git a/pybis/src/python/pybis/pybis.py b/pybis/src/python/pybis/pybis.py index c42f54a96d4e614f03b4e1ed0ba7a58f7ae075fc..9f304a31cf61fc79d2aa7cfaae0a302c35eb9156 100644 --- a/pybis/src/python/pybis/pybis.py +++ b/pybis/src/python/pybis/pybis.py @@ -2110,13 +2110,13 @@ class Openbis: ) - def get_experiment(self, expId, withAttachments=False, only_data=False): - """ Returns an experiment object for a given identifier (expId). + def get_experiment(self, code, withAttachments=False, only_data=False): + """ Returns an experiment object for a given identifier (code). """ fetchopts = fetch_option['experiment'] - search_request = _type_for_id(expId, 'experiment') + search_request = _type_for_id(code, 'experiment') for option in ['tags', 'properties', 'attachments', 'project', 'samples', 'registrator', 'modifier']: fetchopts[option] = fetch_option[option] @@ -2134,7 +2134,7 @@ class Openbis: } resp = self._post_request(self.as_v3, request) if len(resp) == 0: - raise ValueError("No such experiment: %s" % expId) + raise ValueError(f"No such experiment: {code}") parse_jackson(resp) for id in resp: @@ -2143,7 +2143,7 @@ class Openbis: else: return Experiment( openbis_obj = self, - type = self.get_experiment_type(resp[expId]["type"]["code"]), + type = self.get_experiment_type(resp[code]["type"]["code"]), data = resp[id] ) get_collection = get_experiment # Alias @@ -3637,6 +3637,7 @@ class Openbis: props=props, ) + @staticmethod def decode_attribute(entity, attribute): params = {} diff --git a/pybis/src/python/pybis/space.py b/pybis/src/python/pybis/space.py index fb1acec29b8f50eb48c441ad387a2dac6a9062fd..0f5e7f4246a6e6245c2d9048e22946d22ca15102 100644 --- a/pybis/src/python/pybis/space.py +++ b/pybis/src/python/pybis/space.py @@ -16,9 +16,17 @@ class Space( when using the autocompletion feature (TAB) in Jupyter """ return [ - 'get_projects()', - "new_project()", + 'get_projects()', + 'new_project()', + 'get_project()', + 'get_experiments()', + 'get_experiment()', + 'get_collections()', + 'get_collection()', 'get_samples()', + 'get_sample()', + 'get_objects()', + 'get_object()', 'delete()' ] + super().__dir__() @@ -27,7 +35,6 @@ class Space( def get_samples(self, **kwargs): return self.openbis.get_samples(space=self.code, **kwargs) - get_objects = get_samples # Alias def get_sample(self, sample_code, project_code=None): @@ -40,6 +47,15 @@ class Space( return self.openbis.get_sample('/{}/{}/{}'.format(self.code, project_code, sample_code) ) get_object = get_sample # Alias + def get_project(self, project_code): + if is_identifier(project_code): + return self.openbis.get_project(project_code) + else: + projects = self.openbis.get_projects(code=project_code, space=self.code) + if len(projects) == 0: + raise ValueError(f"No project named {project_code} in space {self.code}") + + return projects[0] def get_projects(self, **kwargs): return self.openbis.get_projects(space=self.code, **kwargs) @@ -47,7 +63,21 @@ class Space( def new_project(self, code, description=None, **kwargs): return self.openbis.new_project(self.code, code, description, **kwargs) + def get_experiments(self, **kwargs): + return self.openbis.get_experiments(space=self.code, **kwargs) + get_collections = get_experiments + + def get_experiment(self, experiment_code): + if is_identifier(experiment_code): + return self.openbis.get_experiment(experiment_code) + else: + experiments = self.openbis.get_experiments(code=experiment_code, space=self.code) + if len(experiments) == 0: + raise ValueError(f"No project named {experiment_code} in space {self.code}") + + return experiments[0] + get_collection = get_experiment + def new_sample(self, **kwargs): return self.openbis.new_sample(space=self, **kwargs) - diff --git a/pybis/src/python/setup.py b/pybis/src/python/setup.py index e788f528455f82bfcc1d50d85023e6d92df95e9f..33c3554717253cb5f9b8aa4fcf0e03a43584036a 100644 --- a/pybis/src/python/setup.py +++ b/pybis/src/python/setup.py @@ -10,7 +10,7 @@ with open("README.md", "r", encoding="utf-8") as fh: setup( name='PyBIS', - version= '1.14.3', + version= '1.14.4', author='Swen Vermeul • ID SIS • ETH Zürich', author_email='swen@ethz.ch', description='openBIS connection and interaction, optimized for using with Jupyter',