示例#1
0
def get_history(conn, type, id):
    """ Get history information of ReceptorLight object based on the type.
        @param conn OMERO gateway
        @param type ReceptorLight Object Type
        @param id  Unique id of the ReceptorLight Object
    """
    rlService = utilities.get_receptor_light_service(conn)
    metadata_json_data = get_metadata_json(type)
    rl_function_name = get_rl_function_name(type)
    rlobject = getattr(rlService, rl_function_name)(id)
    versions = [rlobject]
    parent_ids_list = get_all_parents_of_rlobject(rlService, rl_function_name,
                                                  rlobject, versions)
    rlobject_versions = []
    if not parent_ids_list:
        parent_ids_list = versions
    for rlobject in parent_ids_list:
        if rlobject:
            history = {}
            history['name'] = rlobject.getName().getValue()
            history['id'] = rlobject.getUId().getValue()
            history['creation_time'] = rlobject.getCreationDateTime().getValue(
            )
            history['ownername'] = utilities.get_experimenter_name(
                conn,
                rlobject.getOwnerId().getValue())
            rlobject_versions.append(history)
    return rlobject_versions
示例#2
0
def get_sections_from_model(conn, type):
    rlService = utilities.get_receptor_light_service(conn)
    model_type = 'Rl' + str(type)
    if type == 'RestrictionEnzyme':
        model_type += 's'
    sections = rlService.uihelpGetSectionsOfType(model_type)
    return sections
示例#3
0
def get_all_exp_materials(conn, type, *args, **kwargs):
    """ Get ReceptorLight object list based on the type.
        @param conn OMERO gateway
        @param type ReceptorLight Object Type
    """
    if 'status' in kwargs:
        status = int(kwargs.get('status', -1))
    rlService = utilities.get_receptor_light_service(conn)
    exp_material_type = type + 's'
    rl_function_name = get_rl_function_name(exp_material_type)
    rlobjects = getattr(rlService, rl_function_name)()
    exp_materials = []
    for rlobject in rlobjects:
        if rlobject.getStatus().getValue() == status:
            exp_material = {}
            exp_material['name'] = rlobject.getName().getValue()
            exp_material['id'] = rlobject.getUId().getValue()
            exp_material['originalid'] = rlobject.getOriginalObjectId(
            ).getValue()
            exp_material['access_right'] = getAccessRights(rlobject, conn)
            exp_material['ownername'] = utilities.get_experimenter_name(
                conn,
                rlobject.getOwnerId().getValue())
            exp_material['status'] = rlobject.getStatus().getValue()
            if type == 'Experiment':
                exp_material['datasetId'] = rlobject.getDatasetId().getValue()
            exp_materials.append(exp_material)
    return exp_materials
示例#4
0
def get_json_from_server(conn, type):
    """ Get ReceptorLight object data in json based on the type.
        @param conn OMERO gateway
        @param type ReceptorLight Object Type
        @param id  Unique id of the ReceptorLight Object
    """
    rlService = utilities.get_receptor_light_service(conn)
    model_type = 'Rl' + str(type)
    if type == 'RestrictionEnzyme':
        model_type += 's'
    experiment_sections = rlService.uihelpGetSectionsOfType(model_type)
    rl_function_name = get_rl_function_name(type)

    experiment_object = {}
    for section in experiment_sections:
        experiment_object[section] = []
        for element in rlService.uihelpGetElementsOfSections(
                model_type, section):
            elem_info = rlService.uihelpGetElementInfo(model_type, element)
            e = {}
            e['key'] = element
            e['name'] = elem_info.getUiName().getValue()
            e['help'] = elem_info.getUiHelp().getValue()
            e['index'] = elem_info.getIndex().getValue()
            e['isVisible'] = elem_info.getIsVisible().getValue()
            experiment_object[section].append(e)
    return experiment_object
示例#5
0
def delete_rl_object(conn, type, id):
    """ Delete ReceptorLight object based on the type.
        @param conn OMERO gateway
        @param type ReceptorLight Object Type
        @param id  Unique id of the ReceptorLight Object
    """
    rlService = utilities.get_receptor_light_service(conn)
    rl_function_name = delete_rl_function_name(type)
    delete_used_materials(conn, id)
    return getattr(rlService, rl_function_name)(id)
示例#6
0
def get_rl_object(conn, type, id):
    """ Get ReceptorLight object based on the type.
        @param conn OMERO gateway
        @param type ReceptorLight Object Type
        @param id  Unique id of the ReceptorLight Object
    """
    rlService = utilities.get_receptor_light_service(conn)
    rl_function_name = get_rl_function_name(type)
    rlobject = getattr(rlService, rl_function_name)(id)
    return rlobject
示例#7
0
def get_all_experimentids_of_login_user(conn, type, *args, **kwargs):
    current_user_id = conn.getUser().getId()
    rlService = utilities.get_receptor_light_service(conn)
    exp_material_type = type + 's'
    rl_function_name = get_rl_function_name(exp_material_type)
    rlobjects = getattr(rlService, rl_function_name)()
    rl_obj_ids = []
    for rlobject in rlobjects:
        if rlobject.getOwnerId().getValue() == current_user_id:
            rl_obj_ids.append(rlobject.getUId().getValue())
    return rl_obj_ids
示例#8
0
def delete_used_materials(conn, source_id):
    rlService = utilities.get_receptor_light_service(conn)
    used_materials = rlService.getUsedMaterialsBySourceId(source_id)
    for used_material in used_materials:
        used_material_id = used_material.getUId().getValue()
        if used_material.getTargetType().getValue() == 'RlFileInformation':
            fileId = used_material.getTargetID().getValue()
            fileService = utilities.get_receptor_light_file_service(conn)
            fileService.deleteFile(int(fileId))

        rlService.deleteUsedMaterial(int(used_material_id))
示例#9
0
def execute_proposal_action(conn, input_type, input_id, action_id):
    rlService = utilities.get_receptor_light_service(conn)
    rlobject = get_rl_object(conn, input_type, input_id)
    if int(action_id) == 1:
        rlobject.setStatus(omero.rtypes.rint(4))
    elif int(action_id) == 2:
        rlobject.setStatus(omero.rtypes.rint(8))
    current_user_id = conn.getUser().getId()
    rlobject.setOwnerId(omero.rtypes.rint(current_user_id))
    current_user_group_id = conn.getGroupFromContext().getId()
    rlobject.setOwnerGroupId(omero.rtypes.rint(current_user_group_id))
    save_rl_fn_name = save_rl_function_name(input_type)
    getattr(rlService, save_rl_fn_name)(rlobject)
示例#10
0
def get_experiment_id_from_dataset(conn, datasetId):
    """ Get experiment id from the dataset with ReceptorLight Service
        @param rlService ReceptorLight Service
        @param datasetId Dataset Id to which the experiment belongs
        @type datasetId Integer
    """
    rlService = utilities.get_receptor_light_service(conn)
    exp = rlService.getExperimentByDatasetId(datasetId)
    if exp:
        if int(exp.getStatus().getValue()) == 1:
            return int(exp.getUId().getValue())
    else:
        return None
示例#11
0
def get_options(conn, type):
    """ Get options of ReceptorLight object
        @param conn OMERO gateway
        @param type ReceptorLight Object Type
    """
    rlService = utilities.get_receptor_light_service(conn)
    exp_material_type = type + 's'
    rl_function_name = get_rl_function_name(exp_material_type)
    rlobjects = getattr(rlService, rl_function_name)()
    exp_materials = {}
    for rlobject in rlobjects:
        exp_materials[
            rlobject.getUId().getValue()] = rlobject.getName().getValue()
    return exp_materials
示例#12
0
def get_fieldsets_of_type(conn, type):
    rlService = utilities.get_receptor_light_service(conn)
    model_type = 'Rl' + str(type)
    if type == 'RestrictionEnzyme':
        model_type += 's'
    experiment_sections = rlService.uihelpGetSectionsOfType(model_type)
    fieldsets = []
    for section in experiment_sections:
        fields = []
        for element in rlService.uihelpGetElementsOfSections(
                model_type, section):
            elem_info = rlService.uihelpGetElementInfo(model_type, element)
            if elem_info.getIsVisible().getValue():
                fields.append(element)
        fieldset_values = {"fields": tuple(fields), "classes": ['collapse']}
        fieldsets.append((section, fieldset_values))
    fieldsets = tuple(fieldsets)
    return fieldsets
示例#13
0
def add_to_used_material(conn, source_id, source_type, target_id, target_type,
                         used_in_step):
    rlService = utilities.get_receptor_light_service(conn)
    used_material = rlService.createUsedMaterial()
    source_type = get_used_material_type(source_type)

    used_material.setSourceID(omero.rtypes.rint(source_id))

    st = used_material.getSourceType()
    st.setValue(omero.rtypes.rstring(source_type))
    used_material.setSourceType(st)

    used_material.setTargetID(omero.rtypes.rint(target_id))
    tt = used_material.getTargetType()
    tt.setValue(omero.rtypes.rstring(target_type))
    used_material.setTargetType(tt)

    used_material.setUsedIn(omero.rtypes.rstring(used_in_step))
    return rlService.saveUsedMaterial(used_material)
示例#14
0
def get_proposals_on_mine(conn, type, *args, **kwargs):
    """ Get ReceptorLight object list based on the type.
        @param conn OMERO gateway
        @param type ReceptorLight Object Type
    """
    if 'status' in kwargs:
        status = int(kwargs.get('status', -1))
    if 'flag' in kwargs:
        flag = int(kwargs.get('flag', -1))
    current_user_id = conn.getUser().getId()
    rlService = utilities.get_receptor_light_service(conn)
    exp_material_type = type + 's'
    rl_function_name = get_rl_function_name(exp_material_type)
    rlobjects = getattr(rlService, rl_function_name)()
    exp_materials = []
    login_user_exp_ids = get_all_experimentids_of_login_user(
        conn, type, *args, **kwargs)
    for rlobject in rlobjects:
        if rlobject.getOriginalObjectId().getValue(
        ) in login_user_exp_ids and rlobject.getStatus().getValue() in (2, 4,
                                                                        8):
            exp_material = {}
            exp_material['name'] = rlobject.getName().getValue()
            exp_material['id'] = rlobject.getUId().getValue()
            exp_material['originalid'] = rlobject.getOriginalObjectId(
            ).getValue()
            exp_material['access_right'] = getAccessRights(rlobject, conn)
            exp_material['ownername'] = utilities.get_experimenter_name(
                conn,
                rlobject.getOwnerId().getValue())
            exp_material['status'] = rlobject.getStatus().getValue()
            if exp_material['status'] == 2:
                exp_material['status_text'] = 'Proposed'
            elif exp_material['status'] == 4:
                exp_material['status_text'] = 'Accepted'
            elif exp_material['status'] == 8:
                exp_material['status_text'] = 'Rejected'
            if type == 'Experiment':
                exp_material['datasetId'] = rlobject.getDatasetId().getValue()
            exp_materials.append(exp_material)
    return exp_materials
示例#15
0
def get_all_exp_materials_choices(conn):
    """ Get options of ReceptorLight object
        @param conn OMERO gateway
    """
    rlService = utilities.get_receptor_light_service(conn)
    exp_material_types = [
        'Proteins', 'Plasmids', 'Vectors', 'Dnas', 'Rnas',
        'ChemicalSubstances', 'Solutions', 'FluorescentProteins',
        'RestrictionEnzymes', 'Oligonucleotides', 'Sops'
    ]
    all_exp_materials_choices = {}
    for exp_material_type in exp_material_types:
        rl_function_name = get_rl_function_name(exp_material_type)
        rlobjects = getattr(rlService, rl_function_name)()
        exp_materials = {}
        for rlobject in rlobjects:
            if rlobject.getStatus().getValue() == 1:
                exp_materials[rlobject.getUId().getValue()] = rlobject.getName(
                ).getValue()
        all_exp_materials_choices[exp_material_type[:-1]] = exp_materials
    return all_exp_materials_choices
示例#16
0
def create_new_from_parent_rlobject(conn, type, rlobject, *args, **kwargs):
    if 'rl_obj_name' in kwargs:
        rl_obj_name = str(kwargs.get('rl_obj_name', ''))
    if rl_obj_name == '':
        rl_obj_name = rlobject.getName().getValue()
    rlService = utilities.get_receptor_light_service(conn)
    create_rl_object_fn = get_create_rl_object_fn(type)
    new_rlobject = getattr(rlService, create_rl_object_fn)(rl_obj_name)
    new_rlobject_id = new_rlobject.getUId().getValue()
    new_rlobject_creation_time = new_rlobject.getCreationDateTime().getValue()
    new_rlobject_owner_id = new_rlobject.getOwnerId().getValue()
    new_rlobject_owner_group_id = new_rlobject.getOwnerGroupId().getValue()
    rl_object_keys = getattr(rlService, 'getMemberNames')(new_rlobject)

    if rlobject:
        rl_object_id = rlobject.getUId().getValue()
        for rl_obj_key in rl_object_keys:
            set_fn = 'set' + rl_obj_key
            get_fn = 'get' + rl_obj_key
            rlobject_value = getattr(rlobject, get_fn)()
            getattr(new_rlobject, set_fn)(rlobject_value)
        new_rlobject.setUId(omero.rtypes.rint(new_rlobject_id))
        new_rlobject.setCreationDateTime(
            omero.rtypes.rstring(new_rlobject_creation_time))
        new_rlobject.setOwnerId(omero.rtypes.rint(new_rlobject_owner_id))
        new_rlobject.setOwnerGroupId(
            omero.rtypes.rint(new_rlobject_owner_group_id))
        used_materials = rlService.getUsedMaterialsBySourceId(rl_object_id)
        for used_material in used_materials:
            source_id = new_rlobject_id
            source_type = used_material.getSourceType().getValue().getValue()
            target_id = used_material.getTargetID().getValue()
            target_type = used_material.getTargetType().getValue().getValue()
            used_in_step = used_material.getUsedIn().getValue()
            add_to_used_material(conn, source_id, source_type, target_id,
                                 target_type, used_in_step)
    return new_rlobject
示例#17
0
def get_difference_of_rlobjects(conn, type, id1, id2):
    rlService = utilities.get_receptor_light_service(conn)
    model_type = 'Rl' + str(type)
    if type == 'RestrictionEnzyme':
        model_type += 's'
    metadata_json_data = get_metadata_json(type)
    rl_function_name = get_rl_function_name(type)
    rlobject1 = getattr(rlService, rl_function_name)(id1)
    rlobject2 = getattr(rlService, rl_function_name)(id2)

    experiment_object = {}
    for section in metadata_json_data:
        experiment_object[section] = []
        for data in metadata_json_data[section]:
            e = {}
            e['key'] = data['key']
            e['name'] = data['name']
            e['help'] = data['help']
            e['index'] = data['index']
            e['isVisible'] = data['isVisible']
            e['uiType'] = data['uiType']
            if data['uiType'] == 'weblink' and 'linkType' in data:
                e['linkType'] = data['linkType']
            method_name = 'get' + data['key']

            val1 = getattr(rlobject1, method_name)()
            val2 = getattr(rlobject2, method_name)()

            e['value1'] = get_element_value(conn, val1, data)
            e['value2'] = get_element_value(conn, val2, data)
            if hasattr(val1, '__class__'):
                value = val1.__class__
                e['type'] = str(value)

            experiment_object[section].append(e)
    return experiment_object
示例#18
0
def get_json(conn, type, id):
    """ Get ReceptorLight object data in json based on the type.
        @param conn OMERO gateway
        @param type ReceptorLight Object Type
        @param id  Unique id of the ReceptorLight Object
    """
    rlService = utilities.get_receptor_light_service(conn)
    model_type = 'Rl' + str(type)
    if type == 'RestrictionEnzyme':
        model_type += 's'
    metadata_json_data = get_metadata_json(type)
    rl_function_name = get_rl_function_name(type)
    rlobject = getattr(rlService, rl_function_name)(id)

    experiment_object = {}
    for section in metadata_json_data:
        experiment_object[section] = []
        for data in metadata_json_data[section]:
            e = {}
            e['key'] = data['key']
            e['name'] = data['name']
            e['help'] = data['help']
            e['index'] = data['index']
            e['isVisible'] = data['isVisible']
            e['uiType'] = data['uiType']
            if 'unit' in data:
                e['unit'] = data['unit']
            if data['uiType'] == 'weblink' and 'linkType' in data:
                e['linkType'] = data['linkType']
            method_name = 'get' + data['key']

            val = getattr(rlobject, method_name)()
            if hasattr(val, 'getValue'):
                value = val.getValue()
                # if data['key'] == 'ContactPerson':
                #     if isinstance(value, int):
                #         e['value'] = utilities.get_experimenter_name(conn, value)
                #     else:
                #         e['value'] = value
                if data['uiType'] == 'file':
                    fileService = utilities.get_receptor_light_file_service(
                        conn)
                    if value:
                        fileInfo = fileService.getFileInformation(int(value))
                        if fileInfo:
                            e['value'] = str(fileInfo.getName().getValue())
                            e['fileId'] = int(value)
                else:
                    e['value'] = value if value else None
            if hasattr(val, 'copyValues'):
                val_list = val.copyValues()
                if data['uiType'] == 'multiplefiles':
                    fileService = utilities.get_receptor_light_file_service(
                        conn)
                    e['value'] = {}
                    for v in val_list:
                        if v:
                            fileInfo = fileService.getFileInformation(
                                int(v.getValue().getValue()))
                            if fileInfo:
                                e['value'][int(
                                    v.getValue().getValue())] = (str(
                                        fileInfo.getName().getValue()))
            if hasattr(val, '__class__'):
                value = val.__class__
                e['type'] = str(value)

            experiment_object[section].append(e)
    return experiment_object
示例#19
0
def save_rl_object(conn, type, changed_dict, form_data, *args, **kwargs):
    """ Save information of ReceptorLight object based on the type.
        @param conn OMERO gateway
        @param type ReceptorLight Object Type
        @param changed_dict  Changed information
        @param form_data the Form data
        @param args Args
        @param kwargs Request Args
    """
    try:
        save_rl_fn_name = save_rl_function_name(type)
        rlService = utilities.get_receptor_light_service(conn)
        parent_rlobject_id = None
        new_rlobject_id = None
        rlobject = None
        action = ''
        root_folder_id = -1
        if 'action' in kwargs:
            action = str(kwargs.get('action', ''))
        if 'input_name' in kwargs:
            rl_obj_name = str(kwargs.get('input_name', ''))
        if 'id' in kwargs:
            input_id = int(kwargs.get('id', -1))
        if input_id != -1:
            rlobject = get_rl_object(conn, type, input_id)
            parent_rlobject_id = rlobject.getUId()
            if type == 'Experiment':
                root_folder_id = rlobject.getRootFolderId().getValue()
                parent_datasetId = rlobject.getDatasetId().getValue()
            if action == '':
                rlobject.setStatus(omero.rtypes.rint(0))
                getattr(rlService, save_rl_fn_name)(rlobject)
        if 'files' in kwargs:
            rl_files = kwargs.get('files', '')
        new_rlobject = create_new_from_parent_rlobject(conn,
                                                       type,
                                                       rlobject,
                                                       rl_obj_name=rl_obj_name)
        new_rlobject_id = new_rlobject.getUId().getValue()
        if type == 'Experiment':
            if input_id == -1:
                root_folder_id = getCreateRootFolder(conn, new_rlobject_id)
            new_rlobject.setRootFolderId(omero.rtypes.rint(root_folder_id))
        getattr(rlService, save_rl_fn_name)(new_rlobject)
        new_rlobject = save_rlobject_types(conn,
                                           new_rlobject_id,
                                           type,
                                           changed_dict,
                                           root_folder_id=root_folder_id,
                                           files=rl_files)

        if input_id != -1 and type == 'Experiment':
            new_rlobject.setDatasetId(omero.rtypes.rint(parent_datasetId))
        if parent_rlobject_id:
            new_rlobject.setOriginalObjectId(parent_rlobject_id)
        if action == 'propose':
            new_rlobject.setStatus(omero.rtypes.rint(2))
        else:
            new_rlobject.setStatus(omero.rtypes.rint(1))
        getattr(rlService, save_rl_fn_name)(new_rlobject)
        return 1
    except Exception as e:
        logging.info("Exception:(%s)", e)
        if new_rlobject_id:
            delete_rl_object(conn, type, new_rlobject_id)
        if rlobject:
            rlobject.setStatus(omero.rtypes.rint(1))
            getattr(rlService, save_rl_fn_name)(rlobject)
        return 0
示例#20
0
def save_rlobject_types(conn, new_rlobject_id, type, changed_dict, *args,
                        **kwargs):
    if 'files' in kwargs:
        rl_files = kwargs.get('files', '')
    if 'root_folder_id' in kwargs:
        root_folder_id = int(kwargs.get('root_folder_id', -1))
    metadata_json_data = get_metadata_json(type)
    rlService = utilities.get_receptor_light_service(conn)
    new_rlobject = get_rl_object(conn, type, new_rlobject_id)
    for key, value in changed_dict.items():
        for categories in metadata_json_data:
            for data in metadata_json_data[categories]:
                if data['key'] == key:
                    if value:
                        if data['uiType'] == 'file':
                            for filename, file in rl_files.iteritems():
                                if filename == data['key'] and rl_files[
                                        filename]:
                                    if type == 'Experiment':
                                        omero_value_object = save_file_information(
                                            conn,
                                            rl_files[filename],
                                            data['key'],
                                            root_folder_id=root_folder_id,
                                            input_id=new_rlobject_id,
                                            input_type=type)
                                    else:
                                        omero_value_object = save_file_information(
                                            conn,
                                            rl_files[filename],
                                            data['key'],
                                            input_id=new_rlobject_id,
                                            input_type=type)
                        elif data['uiType'] == 'multiplefiles':
                            if type == 'Experiment':
                                omero_value_object = save_multiple_files(
                                    conn,
                                    rl_files,
                                    data['key'],
                                    root_folder_id=root_folder_id,
                                    input_id=new_rlobject_id,
                                    input_type=type)
                            else:
                                omero_value_object = save_multiple_files(
                                    conn,
                                    rl_files,
                                    data['key'],
                                    input_id=new_rlobject_id,
                                    input_type=type)
                        elif data['uiType'] == 'richText':
                            if type == 'Experiment':
                                omero_value_object = save_richText(
                                    conn,
                                    rl_files,
                                    value,
                                    data['key'],
                                    root_folder_id=root_folder_id,
                                    input_id=new_rlobject_id,
                                    input_type=type)
                            else:
                                omero_value_object = save_richText(
                                    conn,
                                    rl_files,
                                    value,
                                    data['key'],
                                    input_id=new_rlobject_id,
                                    input_type=type)
                        else:
                            omero_value_object = convert_value_to_omero_value(
                                value, data['type'], data['uiType'],
                                data['key'], conn)
                        function_name = convert_type_to_function(data['type'])
                        try:
                            if data['type'] == 'omero.rtypes.RDoubleI':
                                set_fn = 'set' + data['key']
                                getattr(new_rlobject,
                                        set_fn)(omero_value_object)
                            else:
                                new_rlobject = getattr(rlService,
                                                       function_name)(
                                                           new_rlobject, key,
                                                           omero_value_object)
                        except Exception as e:
                            logging.info("Exception:(%s)", e)
                            return 0
    return new_rlobject