def get_data_obj_type_by_name(self, input_ref, remove_module=False): # 0 obj_id objid - the numerical id of the object. # 1 obj_name name - the name of the object. # 2 type_string type - the type of the object. # 3 timestamp save_date - the save date of the object. # 4 obj_ver ver - the version of the object. # 5 username saved_by - the user that saved or copied the object. # 6 ws_id wsid - the workspace containing the object. # 7 ws_name workspace - the workspace containing the object. # 8 string chsum - the md5 checksum of the object. # 9 int size - the size of the object in bytes. # 10 usermeta meta - arbitrary user-supplied metadata about # the object. [ OBJID_I, NAME_I, TYPE_I, SAVE_DATE_I, VERSION_I, SAVED_BY_I, WSID_I, WORKSPACE_I, CHSUM_I, SIZE_I, META_I ] = range(11) # object_info tuple ws = Workspace(self.ws_url) input_info = ws.get_object_info3({'objects': [{ 'ref': input_ref }]})['infos'][0] obj_name = input_info[NAME_I] type_name = input_info[TYPE_I].split('-')[0] if remove_module: type_name = type_name.split('.')[1] return {obj_name: type_name}
def build_bin_summary_file_from_binnedcontigs_obj(self, input_ref, bin_dir, bin_basename, fasta_extension): # read bin info from obj ws = Workspace(self.ws_url) try: binned_contig_obj = ws.get_objects2( {'objects': [{ 'ref': input_ref }]})['data'][0]['data'] except Exception as e: raise ValueError('Unable to fetch ' + str(input_ref) + ' object from workspace: ' + str(e)) #to get the full stack trace: traceback.format_exc() bin_summary_info = dict() # bid in object is full name of contig fasta file. want just the number for bin_item in binned_contig_obj['bins']: #print ("BIN_ITEM[bid]: "+bin_item['bid']) # DEBUG bin_ID = re.sub('^[^\.]+\.', '', bin_item['bid'].replace('.' + fasta_extension, '')) #print ("BIN_ID: "+bin_ID) # DEBUG bin_summary_info[bin_ID] = { 'n_contigs': bin_item['n_contigs'], 'gc': round(100.0 * float(bin_item['gc']), 1), 'sum_contig_len': bin_item['sum_contig_len'], 'cov': round(100.0 * float(bin_item['cov']), 1) } # write summary file for just those bins present in bin_dir header_line = ['Bin name', 'Completeness', 'Genome size', 'GC content'] bin_fasta_files_by_bin_ID = self.get_bin_fasta_files( bin_dir, fasta_extension) bin_IDs = [] for bin_ID in sorted(bin_fasta_files_by_bin_ID.keys()): bin_ID = re.sub('^[^\.]+\.', '', bin_ID.replace('.' + fasta_extension, '')) bin_IDs.append(bin_ID) summary_file_path = os.path.join(bin_dir, bin_basename + '.' + 'summary') print("writing filtered binned contigs summary file " + summary_file_path) with open(summary_file_path, 'w') as summary_file_handle: print("\t".join(header_line)) summary_file_handle.write("\t".join(header_line) + "\n") for bin_ID in bin_IDs: #print ("EXAMINING BIN SUMMARY INFO FOR BIN_ID: "+bin_ID) # DEBUG bin_summary_info_line = [ bin_basename + '.' + str(bin_ID) + '.' + fasta_extension, str(bin_summary_info[bin_ID]['cov']) + '%', str(bin_summary_info[bin_ID]['sum_contig_len']), str(bin_summary_info[bin_ID]['gc']) ] print("\t".join(bin_summary_info_line)) summary_file_handle.write("\t".join(bin_summary_info_line) + "\n") return summary_file_path
def setUpClass(cls): token = os.environ.get('KB_AUTH_TOKEN', None) config_file = os.environ.get('KB_DEPLOYMENT_CONFIG', None) cls.cfg = {} config = ConfigParser() config.read(config_file) for nameval in config.items('VariationUtil'): cls.cfg[nameval[0]] = nameval[1] # Getting username from Auth profile for token authServiceUrl = cls.cfg['auth-service-url'] auth_client = _KBaseAuth(authServiceUrl) user_id = auth_client.get_user(token) # WARNING: don't call any logging methods on the context object, # it'll result in a NoneType error cls.ctx = MethodContext(None) cls.ctx.update({'token': token, 'user_id': user_id, 'provenance': [ {'service': 'VariationUtil', 'method': 'please_never_use_it_in_production', 'method_params': [] }], 'authenticated': 1, 'test_env': 1}) cls.wsURL = cls.cfg['workspace-url'] cls.wsClient = Workspace(cls.wsURL) cls.serviceImpl = VariationUtil(cls.cfg) cls.scratch = cls.cfg['scratch'] cls.callback_url = os.environ['SDK_CALLBACK_URL'] # cls.VCFtoVar = VCFToVariation(cls.cfg, "/kb/module/work/tmp", cls.callback_url) cls.vcf_test_dir = '/kb/module/test/sample_data/vcf'
def setUpClass(cls): token = os.environ.get('KB_AUTH_TOKEN', None) config_file = os.environ.get('KB_DEPLOYMENT_CONFIG', None) if not config_file: raise RuntimeError("Could not load config file") config = ConfigParser() config.read(config_file) for nameval in config.items('refseq_importer'): cls.cfg[nameval[0]] = nameval[1] # Getting username from Auth profile for token authServiceUrl = cls.cfg['auth-service-url'] auth_client = _KBaseAuth(authServiceUrl) user_id = auth_client.get_user(token) # WARNING: don't call any logging methods on the context object, # it'll result in a NoneType error cls.ctx = MethodContext(None) cls.ctx.update({ 'token': token, 'user_id': user_id, 'provenance': [{ 'service': 'refseq_importer', 'method': 'please_never_use_it_in_production', 'method_params': [] }], 'authenticated': 1 }) cls.wsURL = cls.cfg['workspace-url'] cls.wsClient = Workspace(cls.wsURL) cls.serviceImpl = refseq_importer(cls.cfg) cls.scratch = cls.cfg['scratch']
def load_fastas(config, scratch: str, upa: str): ''' Returns list of (fasta_path, upa) ''' dfu = DataFileUtil(config['callback_url']) au = AssemblyUtil(config['callback_url']) mgu = MetagenomeUtils(config['callback_url']) ws = Workspace(config['workspace-url']) obj_data = dfu.get_objects({"object_refs": [upa]})['data'][0] obj_type = obj_data['info'][2] if 'KBaseSets.GenomeSet' in obj_type: upas = [gsi['ref'] for gsi in obj_data['data']['items']] elif 'KBaseSearch.GenomeSet' in obj_type: upas = [gse['ref'] for gse in obj_data['data']['elements'].values()] elif "KBaseGenomes.Genome" in obj_type: upas = [upa] elif "KBaseGenomes.ContigSet" in obj_type or "KBaseGenomeAnnotations.Assembly" in obj_type: # in this case we use the assembly file util to get the fasta file # file_output = os.path.join(scratch, "input_fasta.fa") faf = au.get_assembly_as_fasta({"ref": upa}) return [(faf['path'], upa)] elif "KBaseSets.AssemblySet" in obj_type: fasta_paths = [] for item_upa in obj_data['data']['items']: faf = au.get_assembly_as_fasta({"ref": item_upa['ref']}) fasta_paths.append((faf['path'], item_upa['ref'])) return fasta_paths elif 'KBaseMetagenomes.BinnedContigs' in obj_type: fasta_paths = [] bin_file_dir = mgu.binned_contigs_to_file({ 'input_ref': upa, 'save_to_shock': 0 })['bin_file_directory'] for (dirpath, dirnames, filenames) in os.walk(bin_file_dir): for fasta_file in filenames: fasta_path = os.path.join(scratch, fasta_file) fasta_path = os.path.splitext(fasta_path)[0] + ".fa" copyfile(os.path.join(bin_file_dir, fasta_file), fasta_path) # Should I verify that the bins have contigs? # is it possible to have empty bins? fasta_paths.append((fasta_path, upa)) break return fasta_paths else: raise Error('Input genome/metagenome reference has unhandled type') fasta_paths = [] for genome_upa in upas: genome_data = ws.get_objects2({'objects': [{ "ref": genome_upa }]})['data'][0]['data'] assembly_upa = genome_upa + ';' + str( genome_data.get('contigset_ref') or genome_data.get('assembly_ref')) faf = au.get_assembly_as_fasta({'ref': assembly_upa}) fasta_paths.append((faf['path'], assembly_upa)) return fasta_paths
def load_fastas(config, scratch, upa): ''' ''' dfu = DataFileUtil(config['callback_url']) au = AssemblyUtil(config['callback_url']) ws = Workspace(config['workspace-url']) obj_data = dfu.get_objects({"object_refs":[upa]})['data'][0] obj_type = obj_data['info'][2] if 'KBaseSets.GenomeSet' in obj_type: upas = [gsi['ref'] for gsi in obj_data['data']['items']] elif 'KBaseSearch.GenomeSet' in obj_type: upas = [gse['ref'] for gse in obj_data['data']['elements'].values()] elif "KBaseGenomes.Genome" in obj_type: upas = [upa] elif "KBaseGenomes.ContigSet" in obj_type or "KBaseGenomeAnnotations.Assembly" in obj_type: # in this case we use the assembly file util to get the fasta file file_output = os.path.join(scratch, "input_fasta.fa") faf = au.get_assembly_as_fasta({"ref": upa}) return [(faf['path'], upa)] fasta_paths = [] for genome_upa in upas: if upa != genome_upa: genome_upa = upa + ';' + genome_upa genome_data = ws.get_objects2( {'objects':[{"ref":genome_upa}]})['data'][0]['data'] target_upa = genome_data.get('contigset_ref') or genome_data.get('assembly_ref') assembly_upa = genome_upa + ';' + target_upa faf = au.get_assembly_as_fasta({"ref":assembly_upa}) fasta_paths.append((faf['path'], assembly_upa)) return fasta_paths
def setUpClass(cls): token = os.environ.get('KB_AUTH_TOKEN', None) config_file = os.environ.get('KB_DEPLOYMENT_CONFIG', None) cls.cfg = {} config = ConfigParser() config.read(config_file) for nameval in config.items('AssemblyUtil'): cls.cfg[nameval[0]] = nameval[1] # Getting username from Auth profile for token authServiceUrl = cls.cfg['auth-service-url'] auth_client = _KBaseAuth(authServiceUrl) user_id = auth_client.get_user(token) # WARNING: don't call any logging methods on the context object, # it'll result in a NoneType error cls.ctx = MethodContext(None) cls.ctx.update({ 'token': token, 'user_id': user_id, 'provenance': [{ 'service': 'AssemblyUtil', 'method': 'please_never_use_it_in_production', 'method_params': [] }], 'authenticated': 1 }) cls.wsURL = cls.cfg['workspace-url'] cls.wsClient = Workspace(cls.wsURL) cls.serviceImpl = AssemblyUtil(cls.cfg) cls.scratch = cls.cfg['scratch'] cls.callback_url = os.environ['SDK_CALLBACK_URL'] shutil.copy2('data/NC_021490.fasta', cls.scratch)
def setUpClass(cls): token = os.environ.get('KB_AUTH_TOKEN', None) config_file = os.environ.get('KB_DEPLOYMENT_CONFIG', None) cls.cfg = {} config = ConfigParser() config.read(config_file) for nameval in config.items('OTUSampleMetadataCorrelation'): cls.cfg[nameval[0]] = nameval[1] # Getting username from Auth profile for token authServiceUrl = cls.cfg['auth-service-url'] auth_client = _KBaseAuth(authServiceUrl) user_id = auth_client.get_user(token) # WARNING: don't call any logging methods on the context object, # it'll result in a NoneType error cls.ctx = MethodContext(None) cls.ctx.update({'token': token, 'user_id': user_id, 'provenance': [ {'service': 'OTUSampleMetadataCorrelation', 'method': 'please_never_use_it_in_production', 'method_params': [] }], 'authenticated': 1}) cls.wsURL = cls.cfg['workspace-url'] cls.wsClient = Workspace(cls.wsURL) cls.wsName = 'OTUSampleMetadataCorrelation_' + str(uuid.uuid4()) cls.wsId = cls.wsClient.create_workspace({'workspace': cls.wsName})[0] cls.params_ws = { 'workspace_id': cls.wsId, 'workspace_name': cls.wsName, } cls.serviceImpl = OTUSampleMetadataCorrelation(cls.cfg) cls.shared_folder = cls.cfg['scratch'] cls.callback_url = os.environ['SDK_CALLBACK_URL']
def get_annotated_metagenome_assembly(self, ctx, params): """ :param params: instance of type "getAnnotatedMetagenomeAssemblyParams" (ref - workspace reference to AnnotatedMetagenomeAssembly Object included_fields - The fields to include from the Object included_feature_fields -) -> structure: parameter "ref" of String, parameter "included_fields" of list of String, parameter "included_feature_fields" of list of String :returns: instance of type "getAnnotatedMetagenomeAssemblyOutput" -> structure: """ # ctx is the context object # return variables are: output #BEGIN get_annotated_metagenome_assembly ws = Workspace(self.config['workspace-url'], token=ctx['token']) ama_utils = AMAUtils(ws) output = ama_utils.get_annotated_metagenome_assembly(params) #END get_annotated_metagenome_assembly # At some point might do deeper type checking... if not isinstance(output, dict): raise ValueError( 'Method get_annotated_metagenome_assembly return value ' + 'output is not type dict as required.') # return the results return [output]
def load_sample_set(workspace_url, ws_name, reads_refs, conditions, library_type, target_name): """ Upload a set of files as a sample set. library_type = "SingleEnd" or "PairedEnd" """ sample_set = { "Library_type": library_type, "domain": "Prokaryotes", "num_samples": len(reads_refs), "platform": None, "publication_id": None, "sample_ids": reads_refs, "sampleset_desc": None, "sampleset_id": target_name, "condition": conditions, "source": None } ws_client = Workspace(workspace_url) ss_obj = ws_client.save_objects({ "workspace": ws_name, "objects": [{ "type": "KBaseRNASeq.RNASeqSampleSet", "data": sample_set, "name": target_name, "provenance": [{ "input_ws_objects": reads_refs }] }] }) ss_ref = "{}/{}/{}".format(ss_obj[0][6], ss_obj[0][0], ss_obj[0][4]) return ss_ref
def setUpClass(cls): token = os.environ.get('KB_AUTH_TOKEN', None) config_file = os.environ.get('KB_DEPLOYMENT_CONFIG', None) cls.cfg = {} config = ConfigParser() config.read(config_file) for nameval in config.items('kb_irep'): cls.cfg[nameval[0]] = nameval[1] # Getting username from Auth profile for token authServiceUrl = cls.cfg['auth-service-url'] auth_client = _KBaseAuth(authServiceUrl) user_id = auth_client.get_user(token) # WARNING: don't call any logging methods on the context object, # it'll result in a NoneType error cls.ctx = MethodContext(None) cls.ctx.update({'token': token, 'user_id': user_id, 'provenance': [ {'service': 'kb_irep', 'method': 'please_never_use_it_in_production', 'method_params': [] }], 'authenticated': 1}) cls.wsURL = cls.cfg['workspace-url'] cls.wsClient = Workspace(cls.wsURL) cls.serviceImpl = kb_irep(cls.cfg) cls.scratch = cls.cfg['scratch'] cls.callback_url = os.environ['SDK_CALLBACK_URL'] suffix = int(time.time() * 1000) cls.wsName = "test_ContigFilter_" + str(suffix) ret = cls.wsClient.create_workspace({'workspace': cls.wsName}) # noqa
def get_workspace_user_perms(workspace_url, workspace_id, token, owner, acls): """ """ ws_client = Workspace(workspace_url, token=token) results = ws_client.get_permissions_mass( {'workspaces': [{ 'id': workspace_id }]}) for user in results['perms'][0]: # skip owner of the samples. if user == owner: continue if user == "*": # set public read to true (>0). acls['public_read'] = 1 continue if results['perms'][0][user] == 'a': acls['admin'].append(user) if results['perms'][0][user] == 'r': acls['read'].append(user) if results['perms'][0][user] == 'w': acls['write'].append(user) if results['perms'][0][user] == 'n': continue return acls
def get_data_obj_name(self, input_ref): [OBJID_I, NAME_I, TYPE_I, SAVE_DATE_I, VERSION_I, SAVED_BY_I, WSID_I, WORKSPACE_I, CHSUM_I, SIZE_I, META_I] = range(11) # object_info tuple ws = Workspace(self.ws_url) input_info = ws.get_object_info3({'objects': [{'ref': input_ref}]})['infos'][0] obj_name = input_info[NAME_I] #type_name = input_info[TYPE_I].split('-')[0] return obj_name
def setUpClass(cls): token = os.environ.get('KB_AUTH_TOKEN', None) # WARNING: don't call any logging methods on the context object, # it'll result in a NoneType error cls.ctx = MethodContext(None) cls.ctx.update({'token': token, 'provenance': [ {'service': 'GenomeFileUtil', 'method': 'please_never_use_it_in_production', 'method_params': [] }], 'authenticated': 1}) config_file = os.environ.get('KB_DEPLOYMENT_CONFIG', None) cls.cfg = {} config = ConfigParser() config.read(config_file) # type: ignore for nameval in config.items('GenomeFileUtil'): cls.cfg[nameval[0]] = nameval[1] cls.wsURL = cls.cfg['workspace-url'] cls.ws = Workspace(cls.wsURL, token=token) cls.gfu = GenomeFileUtil(cls.cfg) # create one WS for all tests suffix = int(time.time() * 1000) cls.ws_name = "test_GenomeAnnotationAPI_" + str(suffix) ws_info = cls.ws.create_workspace({'workspace': cls.ws_name}) cls.ws_id = ws_info[0]
def get_authors(config, wsid): ws = Workspace(url=config.narrative_session.ws_url, token=config.narrative_session.token) ws_info = ws.get_workspace_info({"id": wsid}) author_id_list = [ws_info[2]] other_authors = ws.get_permissions({"id": wsid}) for author in sorted(other_authors.keys()): if author != "*" and other_authors[author] in [ "w", "a" ] and author not in author_id_list: author_id_list.append(author) auth = _KBaseAuth(config.narrative_session.auth_url) disp_names = auth.get_display_names(config.narrative_session.token, author_id_list) author_list = [] for author in author_id_list: author_list.append({ "id": author, "name": html.escape(disp_names.get(author, author)), "path": config.narrative_session.profile_page_url + author }) return author_list
def __init__(self, config, varfiles): self.dfu = DataFileUtil(config['SDK_CALLBACK_URL']) # TODO: input variable for workspace url self.wsc = Workspace("https://appdev.kbase.us/services/ws") self.scratch = config["scratch"] self._process_varfiles(varfiles)
def setUpClass(cls): token = environ.get('KB_AUTH_TOKEN', None) config_file = environ.get('KB_DEPLOYMENT_CONFIG', None) cls.cfg = {} config = ConfigParser() config.read(config_file) for nameval in config.items('NarrativeService'): cls.cfg[nameval[0]] = nameval[1] authServiceUrl = cls.cfg.get('auth-service-url', "https://kbase.us/services/authorization/Sessions/Login") auth_client = _KBaseAuth(authServiceUrl) user_id = auth_client.get_user(token) # WARNING: don't call any logging methods on the context object, # it'll result in a NoneType error cls.ctx = MethodContext(None) cls.ctx.update({'token': token, 'user_id': user_id, 'provenance': [ {'service': 'NarrativeService', 'method': 'please_never_use_it_in_production', 'method_params': [] }], 'authenticated': 1}) cls.wsURL = cls.cfg['workspace-url'] cls.wsClient = Workspace(cls.wsURL, token=token) cls.serviceImpl = NarrativeService(cls.cfg)
def setUpClass(cls): token = os.environ.get('KB_AUTH_TOKEN', None) config_file = os.environ.get('KB_DEPLOYMENT_CONFIG', None) cls.cfg = {} config = ConfigParser() config.read(config_file) for nameval in config.items('TaxonomyTools'): cls.cfg[nameval[0]] = nameval[1] # Getting username from Auth profile for token authServiceUrl = cls.cfg['auth-service-url'] auth_client = _KBaseAuth(authServiceUrl) user_id = auth_client.get_user(token) # WARNING: don't call any logging methods on the context object, # it'll result in a NoneType error cls.ctx = MethodContext(None) cls.ctx.update({ 'token': token, 'user_id': user_id, 'provenance': [{ 'service': 'TaxonomyTools', 'method': 'please_never_use_it_in_production', 'method_params': [] }], 'authenticated': 1 }) cls.wsURL = cls.cfg['workspace-url'] cls.wsClient = Workspace(cls.wsURL) cls.serviceImpl = TaxonomyTools(cls.cfg) cls.scratch = cls.cfg['scratch'] cls.callback_url = os.environ['SDK_CALLBACK_URL'] suffix = int(time.time() * 1000) cls.wsName = "test_ContigFilter_" + str(suffix) ret = cls.wsClient.create_workspace({'workspace': cls.wsName}) # noqa cls.app_impl = AppImpl(cls.cfg, cls.ctx) matrix_data = json.load(open('data/test_amplicon_matrix.json')) info = cls.wsClient.save_objects({ 'workspace': cls.wsName, 'objects': [{ 'name': 'test_amplicon_matrix', 'type': 'KBaseMatrices.AmpliconMatrix', 'data': matrix_data }] })[0] set_data = json.load(open('data/test_amplicon_set.json')) set_data['amplicon_matrix_ref'] = f"{info[6]}/{info[0]}/{info[4]}" info = cls.wsClient.save_objects({ 'workspace': cls.wsName, 'objects': [{ 'name': 'test_amplicon_set', 'type': 'KBaseExperiments.AmpliconSet', 'data': set_data }] })[0] cls.amplicon_set_ref = f"{info[6]}/{info[0]}/{info[4]}"
def __init__(self, Config): self.scratch = Config['scratch'] ws_url = Config['ws_url'] callback_url = os.environ['SDK_CALLBACK_URL'] self.dfu = DataFileUtil(callback_url) self.wsc = Workspace(ws_url) self.au = AssemblyUtil(callback_url) self.vcf_info = dict()
def __init__(self, callback_url, scratch, ws_url): self.scratch = scratch self.dfu = DataFileUtil(callback_url) self.ws = Workspace(ws_url) # Note added X due to kb|g.1886.fasta self.valid_chars = "-ACGTUWSMKRYBDHVNX" self.amino_acid_specific_characters = "PLIFQE"
def __init__(self, config): wsurl = config.get('workspace-url') self.atoken = config.get('workspace-admin-token') self.noadmin = False if self.atoken is None or self.atoken == '': self.noadmin = True self.atoken = os.environ.get('KB_AUTH_TOKEN', None) self.ws = Workspace(wsurl, token=self.atoken)
def __init__(self, config): self.ws_url = config["workspace-url"] self.callback_url = config['SDK_CALLBACK_URL'] self.token = config['KB_AUTH_TOKEN'] self.shock_url = config['shock-url'] self.ws = Workspace(self.ws_url, token=self.token) self.dfu = DataFileUtil(self.callback_url) self.scratch = config['scratch']
def __init__(self, scratch_dir, ws_url, callback_url, service_wizard_url, provenance): self.scratch_dir = scratch_dir self.ws_url = ws_url self.ws = Workspace(self.ws_url) self.callback_url = callback_url self.service_wizard_url = service_wizard_url self.bwa = BwaRunner(self.scratch_dir) self.provenance = provenance
def __init__(self, config): self.cfg = config self.gi = GenomeInterface(config) self.dfu = DataFileUtil(config.callbackURL) self.aUtil = AssemblyUtil(config.callbackURL) self.ws = Workspace(config.workspaceURL) self._messages = [] self.time_string = str( datetime.datetime.fromtimestamp( time.time()).strftime('%Y_%m_%d_%H_%M_%S')) yml_text = open('/kb/module/kbase.yml').read() self.version = re.search("module-version:\n\W+(.+)\n", yml_text).group(1) self.generate_parents = False self.generate_ids = False self.genes = OrderedDict() self.mrnas = OrderedDict() self.cdss = OrderedDict() self.noncoding = [] self.ontologies_present = defaultdict(dict) self.ontology_events = list() self.skiped_features = Counter() self.feature_counts = Counter() self.orphan_types = Counter() self.contig_seq = {} self.circ_contigs = set() self.features_spaning_zero = set() self.genome_warnings = [] self.genome_suspect = False self.defects = Counter() self.spoofed_genes = 0 self.excluded_features = ('source', 'exon', 'fasta_record') self.ont_mappings = load_ontology_mappings('/kb/module/data') self.code_table = 11 self.re_api_url = config.re_api_url # dict with feature 'id's that have been used more than once. self.used_twice_identifiers = {} self.default_params = { 'source': 'Genbank', 'taxon_wsname': self.cfg.raw['taxon-workspace-name'], 'taxon_lookup_obj_name': self.cfg.raw['taxon-lookup-object-name'], 'ontology_wsname': self.cfg.raw['ontology-workspace-name'], 'ontology_GO_obj_name': self.cfg.raw['ontology-gene-ontology-obj-name'], 'ontology_PO_obj_name': self.cfg.raw['ontology-plant-ontology-obj-name'], 'release': None, 'genetic_code': 11, 'generate_ids_if_needed': 0, 'metadata': {} }
def get_data_obj_type(self, input_ref, remove_module=False): [OBJID_I, NAME_I, TYPE_I, SAVE_DATE_I, VERSION_I, SAVED_BY_I, WSID_I, WORKSPACE_I, CHSUM_I, SIZE_I, META_I] = range(11) # object_info tuple ws = Workspace(self.ws_url) input_info = ws.get_object_info3({'objects': [{'ref': input_ref}]})['infos'][0] #obj_name = input_info[NAME_I] type_name = input_info[TYPE_I].split('-')[0] if remove_module: type_name = type_name.split('.')[1] return type_name
def fetch_narrative_data(endpt: str, token: str, ws_id: int, outdir: str) -> int: ws = Workspace(url=endpt + "ws", token=token) ws_info = ws.get_workspace_info({"id": ws_id}) ws_meta = ws_info[8] # Narrative object narr_id = ws_meta["narrative"] narr_obj = ws.get_objects2({"objects": [{ "ref": f"{ws_id}/{narr_id}" }]})["data"][0] narr_ver = narr_obj["info"][4] narr_outpath = os.path.join( outdir, f"narrative-{ws_id}.{narr_id}.{narr_ver}.json") with open(narr_outpath, "w") as fout: json.dump(narr_obj, fout, indent=4) # Report objects for cell in narr_obj["data"]["cells"]: if "kbase" in cell["metadata"]: meta = cell["metadata"]["kbase"] if "appCell" in meta: job_state = meta["appCell"].get("exec", {}).get("jobState") result = list() if "result" in job_state: result = job_state["result"] elif "job_output" in job_state and "result" in job_state[ "job_output"]: result = job_state["job_output"]["result"] if len(result) > 0 and "report_ref" in result[0]: report_data = ws.get_objects2( {"objects": [{ "ref": result[0]["report_ref"] }]})["data"][0] report_info = report_data["info"] ref_dots = f"{report_info[6]}.{report_info[0]}.{report_info[4]}" report_path = os.path.join(outdir, f"report-{ref_dots}.json") with open(report_path, "w") as fout: json.dump(report_data, fout, indent=4) # List objects results service = NarrativeService(url=endpt + "service_wizard", token=token) # service = ServiceClient(url=endpt + "service_wizard", use_url_lookup=True, token=token) ws_data = service.list_objects_with_sets({ "ws_id": ws_id, "includeMetadata": 1 }) # ws_data = service.sync_call( # "NarrativeService.list_objects_with_sets", # [{"ws_id": ws_id, "includeMetadata": 1}] # )[0] data_outpath = os.path.join(outdir, f"objects-{ws_id}.json") with open(data_outpath, "w") as fout: json.dump(ws_data, fout, indent=4) return 0
def __init__(self, scratch_dir, callback_url, workspace_url, srv_wiz_url): self.scratch_dir = scratch_dir self.rau = ReadsAlignmentUtils(callback_url) self.kbr = KBaseReport(callback_url) self.dfu = DataFileUtil(callback_url) self.gfu = GenomeFileUtil(callback_url) self.set_api = SetAPI(srv_wiz_url) self.ws = Workspace(workspace_url) self.valid_commands = ['bamqc', 'multi-bamqc']
def test_read_narrative_bad_client(self, rqm): ws_id = 908 mock_ws_bad(rqm, "Can't fetch object") with self.assertRaises(WorkspaceError) as e: read_narrative( NarrativeRef.parse("908/1/1"), Workspace(url=self.cfg["workspace-url"], token=self.token)) self.assertIn(str(ws_id), str(e.exception)) self.assertIn("Can't fetch object", str(e.exception))
def __init__(self, config): self.callback_url = config['callback_url'] self.shared_folder = config['scratch'] #self.shared_folder = "/kb/module/work" self.ws_url = config['workspace-url'] self.dfu = DataFileUtil(self.callback_url) self.gsu = GenomeSearchUtil(self.callback_url) self.wsc = Workspace(self.ws_url)
def read_assembly_ref_from_binnedcontigs(self, input_ref): ws = Workspace(self.ws_url) try: binned_contig_obj = ws.get_objects2({'objects':[{'ref':input_ref}]})['data'][0]['data'] except Exception as e: raise ValueError('Unable to fetch '+str(input_ref)+' object from workspace: ' + str(e)) #to get the full stack trace: traceback.format_exc() return binned_contig_obj['assembly_ref']