def _populate_set_item_ref_path(self, set_list): for s in set_list: obj_spec = util.build_ws_obj_selector(s['ref'], s.get('ref_path_to_set', [])) util.populate_item_object_ref_paths(s['items'], obj_spec) return set_list
def get_set(self, ref, include_item_info=False, ref_path_to_set=[], include_set_item_ref_paths=False): """ Get a set object from the Workspace using the set_type provided (e.g. set_type=KBaseSets.ReadsSet) """ obj_selector = util.build_ws_obj_selector(ref, ref_path_to_set) ws_data = self._get_set_from_ws(obj_selector) if include_item_info: self._populate_item_object_info(ws_data, ref_path_to_set) if include_set_item_ref_paths: set_items = ws_data['data']['items'] util.populate_item_object_ref_paths(set_items, obj_selector) return ws_data
def get_reads_alignment_set(self, ctx, params): """ If the set is a KBaseSets.ReadsAlignmentSet, it gets returned as-is. If it's a KBaseRNASeq.RNASeqAlignmentSet, a few things get juggled. 1. We try to figure out the object references for the alignments (which are optional) 2. From each ref, we try to figure out the condition, and apply those as labels (also might be optional) """ set_type, obj_spec = self._check_get_reads_alignment_set_params(params) include_item_info = False if 'include_item_info' in params: if params['include_item_info'] == 1: include_item_info = True include_set_item_ref_paths = False if 'include_set_item_ref_paths' in params: if params['include_set_item_ref_paths'] == 1: include_set_item_ref_paths = True ref_path_to_set = [] if 'ref_path_to_set' in params and len(params['ref_path_to_set']) > 0: ref_path_to_set = params['ref_path_to_set'] if "KBaseSets" in set_type: # If it's a KBaseSets type, then we know the usual interface will work... return self.set_interface.get_set(params['ref'], include_item_info, ref_path_to_set, include_set_item_ref_paths) else: # ...otherwise, we need to fetch it directly from the workspace and tweak it into the # expected return object obj_data = self.workspace_client.get_objects2( {"objects": [obj_spec]})["data"][0] obj = obj_data["data"] obj_info = obj_data["info"] alignment_ref_list = list() if "sample_alignments" in obj: alignment_ref_list = obj["sample_alignments"] else: # this is a list of dicts of random strings -> alignment refs # need them all as a set, then emit as a list. reads_to_alignments = obj["mapped_alignments_ids"] refs = set() for mapping in reads_to_alignments: refs.update(mapping.values()) alignment_ref_list = list(refs) alignment_items = [{"ref": i} for i in alignment_ref_list] item_infos = self.workspace_client.get_object_info3({ "objects": alignment_items, "includeMetadata": 1 })["infos"] for idx, ref in enumerate(alignment_items): alignment_items[idx]["label"] = item_infos[idx][10].get( "condition", None) if include_item_info: alignment_items[idx]["info"] = item_infos[idx] """ If include_set_item_ref_paths is set, then add a field ref_path in alignment items """ if include_set_item_ref_paths: util.populate_item_object_ref_paths(alignment_items, obj_spec) return { "data": { "items": alignment_items, "description": "" }, "info": obj_info }
def get_reads_set(self, ctx, params): set_type, obj_spec = self._check_get_reads_set_params(params) include_item_info = False if params.get("include_item_info", 0) == 1: include_item_info = True include_set_item_ref_paths = False if 'include_set_item_ref_paths' in params: if params['include_set_item_ref_paths'] == 1: include_set_item_ref_paths = True ref_path_to_set = [] if 'ref_path_to_set' in params and len(params['ref_path_to_set']) > 0: ref_path_to_set = params['ref_path_to_set'] # If this is a KBaseSets.ReadsSet, do as normal. if "KBaseSets" in set_type: set_data = self.setInterface.get_set(params['ref'], include_item_info, ref_path_to_set, include_set_item_ref_paths) return self._normalize_read_set_data(set_data) # Otherwise, fetch the SampleSet info from the workspace and go on from there. elif "KBaseRNASeq.RNASeqSampleSet" in set_type: obj_data = self.ws.get_objects2({"objects": [obj_spec]})["data"][0] obj = obj_data["data"] obj_info = obj_data["info"] desc = obj.get("sampleset_desc", "") obj_info[10]["description"] = desc obj_info[10]["item_count"] = len(obj.get('sample_ids', [])) set_data = { "data": { "items": [], "description": desc }, "info": obj_info } reads_items = list() if len(obj.get('sample_ids')) != len(obj.get('condition')): raise RuntimeError( "Invalid RNASeqSampleSet! The number of conditions \ doesn't match the number of reads objects." ) if len(obj.get('sample_ids', [])) == 0: return set_data for idx, ref in enumerate(obj['sample_ids']): reads_items.append({ "ref": obj['sample_ids'][idx], "label": obj['condition'][idx] }) if include_item_info: reads_obj_specs = [{"ref": i["ref"]} for i in reads_items] infos = self.ws.get_object_info3({ "objects": reads_obj_specs, "includeMetadata": 1 })["infos"] for idx, info in enumerate(infos): reads_items[idx]["info"] = info """ If include_set_item_ref_paths is set, then add a field ref_path in alignment items """ if include_set_item_ref_paths: util.populate_item_object_ref_paths(reads_items, obj_spec) set_data["data"]["items"] = reads_items return set_data # Otherwise-otherwise, it's not the right type for this getter. else: raise ValueError( "The object type {} is invalid for get_reads_set_v1".format( set_type))
def get_expression_set(self, ctx, params): set_type, obj_spec = self._check_get_expression_set_params(params) include_item_info = False if 'include_item_info' in params: if params['include_item_info'] == 1: include_item_info = True include_set_item_ref_paths = False if 'include_set_item_ref_paths' in params: if params['include_set_item_ref_paths'] == 1: include_set_item_ref_paths = True ref_path_to_set = [] if 'ref_path_to_set' in params: ref_path_to_set = params['ref_path_to_set'] if "KBaseSets" in set_type: # If it's a KBaseSets type, then we know the usual interface will work... return self.set_interface.get_set( params['ref'], include_item_info, ref_path_to_set, include_set_item_ref_paths ) else: # ...otherwise, we need to fetch it directly from the workspace and tweak it into the # expected return object obj_data = self.workspace_client.get_objects2({"objects": [obj_spec]})["data"][0] obj = obj_data["data"] obj_info = obj_data["info"] if "sample_expression_ids" in obj: expression_ref_list = obj["sample_expression_ids"] else: alignments_to_expressions = obj.get('mapped_expression_ids') refs = set() for mapping in alignments_to_expressions: refs.update(list(mapping.values())) expression_ref_list = list(refs) expression_items = [{"ref": i} for i in expression_ref_list] item_infos = self.workspace_client.get_object_info3( {"objects": expression_items, "includeMetadata": 1})["infos"] for idx, ref in enumerate(expression_items): expression_items[idx]["label"] = item_infos[idx][10].get("condition", None) if include_item_info: expression_items[idx]["info"] = item_infos[idx] """ If include_set_item_ref_paths is set, then add a field ref_path in alignment items """ if include_set_item_ref_paths: util.populate_item_object_ref_paths(expression_items, obj_spec) return { "data": { "items": expression_items, "description": "" }, "info": obj_info }