diff --git a/src/python/OBis/obis/dm/config.py b/src/python/OBis/obis/dm/config.py index 4a552de59e0f8f535c729335b880eef5eba040ae..da0aaa36a556c4c846617d617009aba2b4013da3 100644 --- a/src/python/OBis/obis/dm/config.py +++ b/src/python/OBis/obis/dm/config.py @@ -30,7 +30,7 @@ class ConfigLocation(object): class ConfigParam(object): """Class for configuration parameters.""" - def __init__(self, name, private, is_json=False): + def __init__(self, name, private, is_json=False, ignore_global=False): """ :param name: Name of the parameter. :param private: Should the parameter be private to the repo or visible in the data set? @@ -39,6 +39,7 @@ class ConfigParam(object): self.name = name self.private = private self.is_json = is_json + self.ignore_global = ignore_global def location_path(self, loc): if loc == 'global': @@ -88,7 +89,8 @@ class ConfigEnv(object): self.add_param(ConfigParam(name='verify_certificates', private=True, is_json=True)) self.add_param(ConfigParam(name='external_dms_id', private=True)) self.add_param(ConfigParam(name='repository_id', private=True)) - self.add_param(ConfigParam(name='sample_id', private=False)) + self.add_param(ConfigParam(name='sample_id', private=False, ignore_global=True)) + self.add_param(ConfigParam(name='experiment_id', private=False, ignore_global=True)) self.add_param(ConfigParam(name='data_set_id', private=False)) self.add_param(ConfigParam(name='data_set_type', private=False)) self.add_param(ConfigParam(name='data_set_properties', private=False, is_json=True)) @@ -157,7 +159,7 @@ class ConfigResolver(object): for name, param in env.params.items(): result[name] = None for l in self.location_search_order: - if local_only and l == 'global': + if l == 'global' and (local_only or param.ignore_global): continue val = self.value_for_parameter(param, l) if val is not None: @@ -215,4 +217,8 @@ class ConfigResolver(object): # Do not overwrite existing values if local_config.get(k) is not None: continue + # Do not copy params which should not be taken from global + param = self.env.params[k] + if param.ignore_global: + continue self.set_value_for_parameter(k, v, 'local') diff --git a/src/python/OBis/obis/dm/data_mgmt.py b/src/python/OBis/obis/dm/data_mgmt.py index a76f45b396978a52a9e345355a08127e4e419230..2f9c280d1b2f1951e2da507d3df1f20d75015016 100644 --- a/src/python/OBis/obis/dm/data_mgmt.py +++ b/src/python/OBis/obis/dm/data_mgmt.py @@ -417,6 +417,9 @@ class OpenbisSync(object): def sample_id(self): return self.config_dict.get('sample_id') + def experiment_id(self): + return self.config_dict.get('experiment_id') + def check_configuration(self): missing_config_settings = [] if self.openbis is None: @@ -425,8 +428,9 @@ class OpenbisSync(object): missing_config_settings.append('user') if self.data_set_type() is None: missing_config_settings.append('data_set_type') - if self.sample_id() is None: + if self.sample_id() is None and self.experiment_id() is None: missing_config_settings.append('sample_id') + missing_config_settings.append('experiment_id') if len(missing_config_settings) > 0: return CommandResult(returncode=-1, output="Missing configuration settings for {}.".format(missing_config_settings)) @@ -498,10 +502,11 @@ class OpenbisSync(object): return result commit_id = result.output sample_id = self.sample_id() + experiment_id = self.experiment_id() contents = GitRepoFileInfo(self.git_wrapper).contents() try: data_set = self.openbis.new_git_data_set(data_set_type, top_level_path, commit_id, repository_id, external_dms.code, - sample_id, data_set_code=data_set_code, parents=parent_data_set_id, + sample_id, experiment_id, data_set_code=data_set_code, parents=parent_data_set_id, properties=properties, contents=contents) return CommandResult(returncode=0, output=""), data_set except ValueError as e: diff --git a/src/python/OBis/obis/scripts/cli.py b/src/python/OBis/obis/scripts/cli.py index 6f56e10b1aa8d5fd0005e34448a2d66b24a9af42..4b256dee839de29124761f8c44c40d59a4c0df17 100644 --- a/src/python/OBis/obis/scripts/cli.py +++ b/src/python/OBis/obis/scripts/cli.py @@ -142,7 +142,7 @@ def init_data_impl(ctx, sample_id, folder, name): with dm.cd(folder): return check_result("init_data", set_property(data_mgmt, 'sample_id', sample_id, False)) - +# TODO test and add param for experiment @cli.command() @click.pass_context @click.option('-o', '--sample_id', help='Set the id of the owning object.') @@ -153,6 +153,7 @@ def init(ctx, sample_id, folder, name): return init_data_impl(ctx, sample_id, folder, name) +# TODO test and add param for experiment @cli.command() @click.pass_context @click.option('-o', '--sample_id', help='Set the id of the owning object.') diff --git a/src/python/PyBis/pybis/data_set.py b/src/python/PyBis/pybis/data_set.py index 3dc4bfe6b5f8fe167e28da47b7ac3ac2671a013c..d2b52fe8df02c8bb3b8bd2e7d613f840150910a8 100644 --- a/src/python/PyBis/pybis/data_set.py +++ b/src/python/PyBis/pybis/data_set.py @@ -20,8 +20,8 @@ def transfer_to_file_creation(content, file_creation, key, file_creation_key=Non class GitDataSetCreation(object): - def __init__(self, openbis, data_set_type, path, commit_id, repository_id, dms, sample=None, properties={}, - dss_code=None, parents=None, data_set_code=None, contents=[]): + def __init__(self, openbis, data_set_type, path, commit_id, repository_id, dms, sample=None, experiment = None, + properties={}, dss_code=None, parents=None, data_set_code=None, contents=[]): """Initialize the command object with the necessary parameters. :param openbis: The openBIS API object. :param data_set_type: The type of the data set @@ -31,6 +31,7 @@ class GitDataSetCreation(object): :param repository_id: The git repository id - same for copies :param dms: An external data managment system object or external_dms_id :param sample: A sample object or sample id. + :param experiment: An experiment or experiment id. :param properties: Properties for the data set. :param dss_code: Code for the DSS -- defaults to the first dss if none is supplied. :param parents: Parents for the data set. @@ -49,6 +50,7 @@ class GitDataSetCreation(object): self.repository_id = repository_id self.dms = dms self.sample = sample + self.experiment = experiment self.properties = properties self.dss_code = dss_code self.parents = parents @@ -112,9 +114,6 @@ class GitDataSetCreation(object): if dss_code is None: dss_code = self.openbis.get_datastores()['code'][0] - # if a sample identifier was given, use it as a string. - # if a sample object was given, take its identifier - sample_id = self.openbis.sample_to_sample_id(self.sample) dms_id = self.openbis.external_data_managment_system_to_dms_id(self.dms) parents = self.parents parentIds = [] @@ -139,7 +138,6 @@ class GitDataSetCreation(object): "@type": "as.dto.entitytype.id.EntityTypePermId", "permId": self.data_set_type }, - "sampleId": sample_id, "dataStoreId": { "permId": dss_code, "@type": "as.dto.datastore.id.DataStorePermId" @@ -149,6 +147,14 @@ class GitDataSetCreation(object): "properties": self.properties, "@type": "as.dto.dataset.create.DataSetCreation" } + + if self.sample is not None: + sample_id = self.openbis.sample_to_sample_id(self.sample) + data_set_creation['sampleId'] = sample_id + elif self.experiment is not None: + experiment_id = self.openbis.experiment_to_experiment_id(self.experiment) + data_set_creation['experimentId'] = experiment_id + if self.data_set_code is not None: data_set_creation['code'] = self.data_set_code data_set_creation["autoGeneratedCode"] = False diff --git a/src/python/PyBis/pybis/pybis.py b/src/python/PyBis/pybis/pybis.py index 5833dfa3473a16773d4e71be06a82e98eeba456e..ee0f4cf256360ac54c268dd51ed48c033a4cf39e 100644 --- a/src/python/PyBis/pybis/pybis.py +++ b/src/python/PyBis/pybis/pybis.py @@ -1835,7 +1835,7 @@ class Openbis: except: return resp - def new_git_data_set(self, data_set_type, path, commit_id, repository_id, dms, sample=None, properties={}, + def new_git_data_set(self, data_set_type, path, commit_id, repository_id, dms, sample=None, experiment=None, properties={}, dss_code=None, parents=None, data_set_code=None, contents=[]): """ Create a link data set. :param data_set_type: The type of the data set @@ -1856,30 +1856,39 @@ class Openbis: 'path': [the relative path string]} :return: A DataSet object """ - return pbds.GitDataSetCreation(self, data_set_type, path, commit_id, repository_id, dms, sample, + return pbds.GitDataSetCreation(self, data_set_type, path, commit_id, repository_id, dms, sample, experiment, properties, dss_code, parents, data_set_code, contents).new_git_data_set() @staticmethod def sample_to_sample_id(sample): """Take sample which may be a string or object and return an identifier for it.""" - sample_id = None - if isinstance(sample, str): - if (is_identifier(sample)): - sample_id = { - "identifier": sample, - "@type": "as.dto.sample.id.SampleIdentifier" + return Openbis._object_to_object_id(sample, "as.dto.sample.id.SampleIdentifier", "as.dto.sample.id.SamplePermId"); + + @staticmethod + def experiment_to_experiment_id(experiment): + """Take experiment which may be a string or object and return an identifier for it.""" + return Openbis._object_to_object_id(experiment, "as.dto.experiment.id.ExperimentIdentifier", "as.dto.experiment.id.SamplePermId"); + + @staticmethod + def _object_to_object_id(obj, identifierType, permIdType): + object_id = None + if isinstance(obj, str): + if (is_identifier(obj)): + object_id = { + "identifier": obj, + "@type": identifierType } else: - sample_id = { - "permId": sample, - "@type": "as.dto.sample.id.SamplePermId" + object_id = { + "permId": obj, + "@type": permIdType } else: - sample_id = { - "identifier": sample.identifier, - "@type": "as.dto.sample.id.SampleIdentifier" + object_id = { + "identifier": obj.identifier, + "@type": identifierType } - return sample_id + return object_id @staticmethod def data_set_to_data_set_id(data_set): diff --git a/src/vagrant/obis/README.md b/src/vagrant/obis/README.md index 2f23656f60d7d34a08d186e1c75e7ccf84a4ca0c..a51ee548624015ae2dd1a1e5847ac4eec7facff1 100644 --- a/src/vagrant/obis/README.md +++ b/src/vagrant/obis/README.md @@ -64,7 +64,7 @@ Now create a file and put some content into it. E.g., vi info.txt -When finished, we need to set the sample_id this data set should be associated with. Then we can commit it. +When finished, we need to set the sample_id or experiment_id this data set should be associated with. Then we can commit it. obis config sample_id /DEMO/BIGDATA obis commit -m"Initial data commit."