def check_binnedcontigs_cache(self, ref, token): ws = Workspace(self.ws_url, token=token) info = ws.get_object_info3({"objects": [{"ref": ref}]})['infos'][0] inner_chsum = info[8] index_file = os.path.join(self.metagenome_index_dir, inner_chsum + self.BIN_SUFFIX + ".tsv.gz") if not os.path.isfile(index_file): if self.debug: print(" Loading WS object...") t1 = time.time() included = [ "/bins/[*]/bid", "/bins/[*]/gc", "/bins/[*]/n_contigs", "/bins/[*]/sum_contig_len", "/bins/[*]/cov" ] binnedcontigs = ws.get_objects2( {'objects': [{ 'ref': ref, 'included': included }]})['data'][0]['data'] self.save_binnedcontigs_tsv(binnedcontigs["bins"], inner_chsum) if self.debug: print(" (time=" + str(time.time() - t1) + ")") return inner_chsum
def __init__(self, config): """ :param config: :param logger: :param directory: Working directory :param urls: Service urls """ # BEGIN_CONSTRUCTOR self.ws_url = config["workspace-url"] self.ws_url = config["workspace-url"] self.callback_url = config['SDK_CALLBACK_URL'] self.srv_wiz_url = config['srv-wiz-url'] self.token = config['KB_AUTH_TOKEN'] self.shock_url = config['shock-url'] self.dfu = DataFileUtil(self.callback_url) self.gfu = GenomeFileUtil(self.callback_url) self.au = AssemblyUtil(self.callback_url) self.rau = ReadsAlignmentUtils(self.callback_url) self.set_api = SetAPI(self.srv_wiz_url, service_ver='dev') self.eu = ExpressionUtils(self.callback_url) self.ws = Workspace(self.ws_url, token=self.token) self.scratch = os.path.join(config['scratch'], str(uuid.uuid4())) self._mkdir_p(self.scratch) self.tool_used = "Cufflinks" self.tool_version = os.environ['VERSION'] # END_CONSTRUCTOR pass
def test_build_hisat2_index_from_assembly_ok(self): manager = Hisat2IndexManager(self.wsURL, self.callback_url, self.scratch) ws = Workspace(self.wsURL) genome_obj_info = ws.get_objects2({ 'objects': [{ 'ref': self.genome_ref }], 'no_data': 1 }) # get the list of genome refs from the returned info. # if there are no refs (or something funky with the return), this will be an empty list. # this WILL fail if data is an empty list. But it shouldn't be, and we know because # we have a real genome reference, or get_objects2 would fail. genome_obj_refs = genome_obj_info.get('data', [{}])[0].get('refs', []) # see which of those are of an appropriate type (ContigSet or Assembly), if any. assembly_ref = list() ref_params = [{'ref': x} for x in genome_obj_refs] ref_info = ws.get_object_info3({'objects': ref_params}) for idx, info in enumerate(ref_info.get('infos')): if "KBaseGenomeAnnotations.Assembly" in info[ 2] or "KBaseGenomes.ContigSet" in info[2]: assembly_ref.append(";".join(ref_info.get('paths')[idx])) assembly_ref = assembly_ref[0] idx_prefix = manager.get_hisat2_index(assembly_ref) self.assertIn("kb_hisat2_idx", idx_prefix)
def setUpClass(cls): cls.token = environ.get('KB_AUTH_TOKEN', None) user_id = requests.post( 'https://kbase.us/services/authorization/Sessions/Login', data='token={}&fields=user_id'.format(cls.token)).json()['user_id'] # 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': cls.token, 'user_id': user_id, 'provenance': [{ 'service': 'HTMLFileSetUtils', 'method': 'please_never_use_it_in_production', 'method_params': [] }], 'authenticated': 1 }) config_file = environ.get('KB_DEPLOYMENT_CONFIG', None) cls.cfg = {} config = ConfigParser() config.read(config_file) for nameval in config.items('HTMLFileSetUtils'): cls.cfg[nameval[0]] = nameval[1] cls.ws = Workspace(cls.cfg['workspace-url'], token=cls.token) cls.impl = HTMLFileSetUtils(cls.cfg) suffix = int(time.time() * 1000) shutil.rmtree(cls.cfg['scratch']) os.mkdir(cls.cfg['scratch']) wsName = 'test_HTMLFileSetUtils_' + str(suffix) cls.ws_info = cls.ws.create_workspace({'workspace': wsName})
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 init_clients(self, token): ''' #for prod environment self.ws_client = Workspace(self.workspace_url, token=token) self.cat_client = Catalog('https://kbase.us/services/catalog', auth_svc='https://appdev.kbase.us/services/auth/', token=token) self.njs_client = NarrativeJobService('https://kbase.us/services/njs_wrapper', auth_svc='https://appdev.kbase.us/services/auth/', token=token) self.ujs_client = UserAndJobState('https://kbase.us/services/userandjobstate', auth_svc='https://appdev.kbase.us/services/auth/', token=token) self.uprf_client = UserProfile('https://kbase.us/services/user_profile/rpc', auth_svc='https://appdev.kbase.us/services/auth/', token=token) ''' #for CI environment self.ws_client = Workspace(self.workspace_url, token=token) self.cat_client = Catalog( 'https://ci.kbase.us/services/catalog', auth_svc='https://ci.kbase.us/services/auth/', token=token) self.njs_client = NarrativeJobService( 'https://ci.kbase.us/services/njs_wrapper', auth_svc='https://ci.kbase.us/services/auth/', token=token) self.ujs_client = UserAndJobState( 'https://ci.kbase.us/services/userandjobstate', auth_svc='https://ci.kbase.us/services/auth/', token=token) self.uprf_client = UserProfile( 'https://ci.kbase.us/services/user_profile/rpc', auth_svc='https://ci.kbase.us/services/auth/', token=token)
def get_fasta_file(self, genome_ref): ws = Workspace(self.ws_url) # test if genome references an assembly type # do get_objects2 without data. get list of refs genome_obj_info = ws.get_objects2({ 'objects': [{ 'ref': genome_ref }], 'no_data': 1 }) # get the list of genome refs from the returned info. # if there are no refs (or something funky with the return), this will be an empty list. # this WILL fail if data is an empty list. But it shouldn't be, and we know because # we have a real genome reference, or get_objects2 would fail. genome_obj_refs = genome_obj_info.get('data', [{}])[0].get('refs', []) # see which of those are of an appropriate type (ContigSet or Assembly), if any. assembly_ref = list() ref_params = [{'ref': x} for x in genome_obj_refs] ref_info = ws.get_object_info3({'objects': ref_params}) for idx, info in enumerate(ref_info.get('infos')): if "KBaseGenomeAnnotations.Assembly" in info[ 2] or "KBaseGenomes.ContigSet" in info[2]: assembly_ref.append(";".join(ref_info.get('paths')[idx])) # now just get the file. au = AssemblyUtil(self.callback_url) fasta_file = au.get_assembly_as_fasta({'ref': assembly_ref[0]}) return fasta_file["path"]
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 :returns: instance of type "getAnnotatedMetagenomeAssemblyOutput" -> structure: parameter "genomes" of list of unspecified object """ # 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 fetch_fasta_from_genome(genome_ref, ws_url, callback_url): """ Returns an assembly or contigset as FASTA. """ if not check_ref_type(genome_ref, ['KBaseGenomes.Genome'], ws_url): raise ValueError("The given genome_ref {} is not a KBaseGenomes.Genome type!") # test if genome references an assembly type # do get_objects2 without data. get list of refs ws = Workspace(ws_url) genome_obj_info = ws.get_objects2({ 'objects': [{'ref': genome_ref}], 'no_data': 1 }) # get the list of genome refs from the returned info. # if there are no refs (or something funky with the return), this will be an empty list. # this WILL fail if data is an empty list. But it shouldn't be, and we know because # we have a real genome reference, or get_objects2 would fail. genome_obj_refs = genome_obj_info.get('data', [{}])[0].get('refs', []) # see which of those are of an appropriate type (ContigSet or Assembly), if any. assembly_ref = list() ref_params = [{'ref': genome_ref + ";" + x} for x in genome_obj_refs] ref_info = ws.get_object_info3({'objects': ref_params}) for idx, info in enumerate(ref_info.get('infos')): if "KBaseGenomeAnnotations.Assembly" in info[2] or "KBaseGenomes.ContigSet" in info[2]: assembly_ref.append(";".join(ref_info.get('paths')[idx])) if len(assembly_ref) == 1: return fetch_fasta_from_assembly(assembly_ref[0], ws_url, callback_url) else: raise ValueError("Multiple assemblies found associated with the given genome ref {}! " "Unable to continue.")
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 set_narratorial(self, ctx, params): """ Allows a user to create a Narratorial given a WS they own. Right now anyone can do this, but we may restrict in the future to users that have a particular role. Run simply as: ns.set_narratorial({'ws':'MyWsName'}) or, ns.set_narratorial({'ws':'4231'}) :param params: instance of type "SetNarratorialParams" (ws field is a string, but properly interpreted whether it is a workspace name or ID) -> structure: parameter "ws" of String, parameter "description" of String :returns: instance of type "SetNarratorialResult" -> structure: """ # ctx is the context object # return variables are: returnVal #BEGIN set_narratorial if 'ws' not in params: raise ValueError( '"ws" field indicating WS name or id is required.') if 'description' not in params: raise ValueError( '"description" field indicating WS name or id is required.') ws = Workspace(self.workspaceURL, token=ctx["token"]) nu = NarratorialUtils() nu.set_narratorial(params['ws'], params['description'], ws) returnVal = {} #END set_narratorial # At some point might do deeper type checking... if not isinstance(returnVal, dict): raise ValueError('Method set_narratorial return value ' + 'returnVal is not type dict as required.') # return the results return [returnVal]
def list_narratorials(self, ctx, params): """ :param params: instance of type "ListNarratorialParams" (Listing Narratives / Naratorials (plus Narratorial Management)) -> structure: :returns: instance of type "NarratorialList" -> structure: parameter "narratorials" of list of type "Narratorial" (info for a narratorial) -> structure: parameter "ws" of type "workspace_info" (Information about a workspace. ws_id id - the numerical ID of the workspace. ws_name workspace - name of the workspace. username owner - name of the user who owns (e.g. created) this workspace. timestamp moddate - date when the workspace was last modified. int max_objid - the maximum object ID appearing in this workspace. Since cloning a workspace preserves object IDs, this number may be greater than the number of objects in a newly cloned workspace. permission user_permission - permissions for the authenticated user of this workspace. permission globalread - whether this workspace is globally readable. lock_status lockstat - the status of the workspace lock. usermeta metadata - arbitrary user-supplied metadata about the workspace.) -> tuple of size 9: parameter "id" of Long, parameter "workspace" of String, parameter "owner" of String, parameter "moddate" of String, parameter "max_objid" of Long, parameter "user_permission" of String, parameter "globalread" of String, parameter "lockstat" of String, parameter "metadata" of mapping from String to String, parameter "nar" of type "object_info" (Information about an object, including user provided metadata. obj_id objid - the numerical id of the object. obj_name name - the name of the object. type_string type - the type of the object. timestamp save_date - the save date of the object. obj_ver ver - the version of the object. username saved_by - the user that saved or copied the object. ws_id wsid - the workspace containing the object. ws_name workspace - the workspace containing the object. string chsum - the md5 checksum of the object. int size - the size of the object in bytes. usermeta meta - arbitrary user-supplied metadata about the object.) -> tuple of size 11: parameter "objid" of Long, parameter "name" of String, parameter "type" of String, parameter "save_date" of type "timestamp" (A time in the format YYYY-MM-DDThh:mm:ssZ, where Z is either the character Z (representing the UTC timezone) or the difference in time to UTC in the format +/-HHMM, eg: 2012-12-17T23:24:06-0500 (EST time) 2013-04-03T08:56:32+0000 (UTC time) 2013-04-03T08:56:32Z (UTC time)), parameter "version" of Long, parameter "saved_by" of String, parameter "wsid" of Long, parameter "workspace" of String, parameter "chsum" of String, parameter "size" of Long, parameter "meta" of mapping from String to String """ # ctx is the context object # return variables are: returnVal #BEGIN list_narratorials ws = Workspace(self.workspaceURL, token=ctx["token"]) returnVal = {'narratorials': self.narListUtils.list_narratorials(ws)} #END list_narratorials # At some point might do deeper type checking... if not isinstance(returnVal, dict): raise ValueError('Method list_narratorials return value ' + 'returnVal is not type dict as required.') # return the results return [returnVal]
def __init__(self, workspace_url, job_service_url, srv_wiz_url, njsw_url, auth_service_url, kbase_endpoint, provenance, token): self.workspace_url = workspace_url self.job_service_url = job_service_url self.njsw_url = njsw_url self.auth_service_url = auth_service_url self.srv_wiz_url = srv_wiz_url self.catalog_url = kbase_endpoint + '/catalog' self.user_profile_url = kbase_endpoint + '/user_profile/rpc' self.provenance = provenance # initialize service clients self.ws_client = Workspace(self.workspace_url) self.cat_client = Catalog(self.catalog_url, auth_svc=self.auth_service_url) self.njs_client = NarrativeJobService(self.njsw_url, auth_svc=self.auth_service_url) self.ujs_client = UserAndJobState(self.job_service_url, auth_svc=self.auth_service_url) self.uprf_client = UserProfile(self.user_profile_url, auth_svc=self.auth_service_url) self.met_client = kb_Metrics(self.srv_wiz_url, token=token, auth_svc=self.auth_service_url, service_ver='dev')
def check_feature_cache(self, ref, token): ws_client = Workspace(self.ws_url, token=token) info = ws_client.get_object_info_new({"objects": [{"ref": ref}]})[0] inner_chsum = info[8] index_file = os.path.join(self.genome_index_dir, inner_chsum + "_ftr.tsv.gz") if not os.path.isfile(index_file): if self.debug: print(" Loading WS object...") t1 = time.time() incl = [ x + y for x, y in product([ 'features/[*]/', 'cdss/[*]/', 'mrnas/[*]/', 'non_coding_features/[*]/' ], [ "id", "type", "function", "functions", "aliases", "location", "ontology_terms" ]) ] + ['ontologies_present'] genome = self.get_one_genome( {"objects": [{ "ref": ref, "included": incl }]}, token) self.save_feature_tsv(genome, inner_chsum) if self.debug: print((" (time=" + str(time.time() - t1) + ")")) return inner_chsum
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.bowtie2 = Bowtie2Runner(self.scratch_dir) self.provenance = provenance
def __init__(self, config): wsurl = config.get('workspace-url') self.atoken = config.get('ws-admin-token') self.noadmin = False if self.atoken is None or self.atoken == '': self.noadmin = True self.atoken = config['token'] self.ws = Workspace(wsurl, token=self.atoken)
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.set_api = SetAPI(srv_wiz_url) self.ws = Workspace(workspace_url) self.valid_commands = ['bamqc', 'multi-bamqc']
def __init__(self, config): self.scratch = os.path.abspath(config['scratch']) self.callback_url = os.environ['SDK_CALLBACK_URL'] self.token = os.environ['KB_AUTH_TOKEN'] self.scratch = os.path.abspath(config['scratch']) self.ws = Workspace(config['workspace-url'], token=self.token) self.genome_api = GenomeAnnotationAPI(self.callback_url) self.au = AssemblyUtil(self.callback_url)
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.dfu = DataFileUtil(self.callback_url) self.ws = Workspace(self.ws_url, token=self.token) self.scratch = config['scratch']
def __init__(self, callback_url, workspace_url, scratch_dir): self.callback_url = callback_url self.scratch_dir = scratch_dir self.workspace_url = workspace_url self.ws = Workspace(self.workspace_url) self.jbrowse_dir = os.path.abspath( os.path.join(os.sep, 'kb', 'module', 'jbrowse')) self.jbrowse_bin = os.path.join(self.jbrowse_dir, 'bin') self.out_dir = os.path.join(self.scratch_dir, 'browser_data')
def __init__(self, config, logger=None): self.config = config self.logger = logger self.callback_url = os.environ['SDK_CALLBACK_URL'] self.scratch = os.path.join(config['scratch'], 'EM_' + str(uuid.uuid4())) self.ws_url = config['workspace-url'] self.ws_client = Workspace(self.ws_url) self.dfu = DataFileUtil(self.callback_url) pass
def __init__(self, config): #BEGIN_CONSTRUCTOR self.utils = Utils(config) self.scratch = config['scratch'] self.dfu = DataFileUtil(os.environ['SDK_CALLBACK_URL']) self.ws = Workspace(config['workspace-url']) logging.basicConfig(level=logging.INFO) #END_CONSTRUCTOR pass
def get_contig_info(self, ctx, params): """ :param params: instance of type "GetContigInfoParams" -> structure: parameter "ref" of String, parameter "contig_id" of String :returns: instance of type "GetContigInfoResult" -> structure: parameter "contig" of type "contig" (contig_id - identifier of contig feature_count - number of features associated with contig length - the dna sequence length of the contig) -> structure: parameter "contig_id" of String, parameter "feature_count" of Long, parameter "length" of Long """ # ctx is the context object # return variables are: result #BEGIN get_contig_info if 'ref' not in params: raise RuntimeError(f"'ref' argument required for get_contig_info") if 'contig_id' not in params: raise RuntimeError( f"'contig_id' argument required for get_contig_info") contig_id = params['contig_id'] ws = Workspace(self.config['workspace-url'], token=ctx['token']) ama_utils = AMAUtils(ws) params['included_fields'] = ['contig_ids', 'contig_lengths'] data = ama_utils.get_annotated_metagenome_assembly( params)['genomes'][0]['data'] contig_ids = data['contig_ids'] contig_lengths = data['contig_lengths'] for i, c in enumerate(contig_ids): if c == contig_id: length = contig_lengths[i] break if self.msu.status_good: feature_count = self.msu.search_contig_feature_count( ctx["token"], params.get("ref"), contig_id) result = { 'contig': { "contig_id": contig_id, "length": length, "feature_count": feature_count } } else: result = { 'contig': { "contig_id": contig_id, "length": length, "feature_count": 0 } } #END get_contig_info # At some point might do deeper type checking... if not isinstance(result, dict): raise ValueError('Method get_contig_info return value ' + 'result is not type dict as required.') # return the results return [result]
def get_diffexpr_matrixset(self, params, token): self.ws_client = Workspace(self.ws_url, token=token) col_names = { 'gene_id': 'gene', 'log2_fold_change': 'log2fc_f', 'p_value': 'p_value_f', 'q_value': 'q_value' } json_fields = ['log2fc_f', 'p_value_f', 'q_value'] self.process_params(params) diffexprmatset_list = list() diffexprmatset_ref = params.get(self.PARAM_IN_DIFFEXPMATSET_REF) diffexprmatset_obj = self.ws_client.get_objects2( {'objects': [{ 'ref': diffexprmatset_ref }]})['data'][0] items = diffexprmatset_obj.get('data').get('items') diffexprmat_refs = list() for item in items: diffexprmat_refs.append(item['ref']) self.logger.info('DiffExprMatrix ref: ' + item['ref']) for diffexprmat_ref in diffexprmat_refs: diffexprmat_dict = dict() diffexprmat_obj = self.ws_client.get_objects2( {'objects': [{ 'ref': diffexprmat_ref }]})['data'][0] diffexprmat = diffexprmat_obj.get('data') diffexprmat_dict['condition_1'] = diffexprmat.get( 'condition_mapping').keys()[0] diffexprmat_dict['condition_2'] = diffexprmat.get( 'condition_mapping').values()[0] voldata = list() data = diffexprmat.get('data') for row_index, row_id in enumerate(data.get('row_ids')): row_data = dict() row_data['gene'] = row_id values = data.get('values')[row_index] for col_index in range(len(values)): row_data[json_fields[col_index]] = values[col_index] voldata.append(row_data) diffexprmat_dict['voldata'] = voldata diffexprmatset_list.append(diffexprmat_dict) return diffexprmatset_list
def check_contigs_in_bin_cache(self, binnedcontigs_ref, bin_id, token): ws = Workspace(self.ws_url, token=token) info = ws.get_object_info3({"objects": [{ "ref": binnedcontigs_ref }]})['infos'][0] # base64 encode the string so it is safe for filenames and still unique per contig id b64key = base64.urlsafe_b64encode( bin_id.encode("utf-8")).decode('utf-8') inner_chsum = info[8] + '_' + b64key index_file = os.path.join( self.metagenome_index_dir, inner_chsum + self.CONTIGS_SUFFIX + ".tsv.gz") if not os.path.isfile(index_file): if self.debug: t1 = time.time() # get the position in the array of the bin binnedcontigs = ws.get_objects2({ 'objects': [{ 'ref': binnedcontigs_ref, 'included': ["/bins/[*]/bid"] }] })['data'][0]['data'] pos = 0 found = False for b in binnedcontigs['bins']: if b['bid'] == bin_id: found = True break pos += 1 if not found: raise ValueError('No Bin with ID: "' + bin_id + '" found.') # get the contigs map selection = ws.get_objects2({ 'objects': [{ 'ref': binnedcontigs_ref, 'included': [ '/bins/' + str(pos) + '/contigs', '/bins/' + str(pos) + '/bid' ] }] })['data'][0]['data'] if selection['bins'][0]['bid'] != bin_id: raise ValueError( 'Something went wrong- bin ids do not match on second ws get_objects2 call' ) contigs = selection['bins'][0]['contigs'] self.save_contigs_in_bin_tsv(contigs, inner_chsum) if self.debug: print(" (time=" + str(time.time() - t1) + ")") return inner_chsum
def setUpClass(cls): cls.token = environ.get('KB_AUTH_TOKEN', None) cls.callbackURL = environ.get('SDK_CALLBACK_URL') config_file = environ.get('KB_DEPLOYMENT_CONFIG', None) cls.cfg = {} config = ConfigParser() config.read(config_file) for nameval in config.items('ExpressionUtils'): 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(cls.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': cls.token, 'user_id': user_id, 'provenance': [{ 'service': 'ExpressionUtils', 'method': 'please_never_use_it_in_production', 'method_params': [] }], 'authenticated': 1 }) cls.shockURL = cls.cfg['shock-url'] cls.wsURL = cls.cfg['workspace-url'] cls.service_wizard_url = cls.cfg['srv-wiz-url'] cls.wsClient = workspaceService(cls.wsURL) cls.ws = Workspace(cls.wsURL, token=cls.token) cls.hs = HandleService(url=cls.cfg['handle-service-url'], token=cls.token) # create workspace wssuffix = int(time.time() * 1000) wsname = "test_expression_" + str(wssuffix) cls.wsinfo = cls.wsClient.create_workspace({'workspace': wsname}) print('created workspace ' + cls.getWsName()) cls.serviceImpl = ExpressionUtils(cls.cfg) cls.readUtils = ReadsUtils(cls.callbackURL) cls.dfu = DataFileUtil(cls.callbackURL, service_ver='dev') cls.dfu.ws_name_to_id(wsname) cls.assemblyUtil = AssemblyUtil(cls.callbackURL) cls.gfu = GenomeFileUtil(cls.callbackURL) cls.gaAPI = GenomeAnnotationAPI(cls.service_wizard_url) cls.rau = ReadsAlignmentUtils(cls.callbackURL) cls.scratch = cls.cfg['scratch'] cls.staged = {} cls.nodes_to_delete = [] cls.handles_to_delete = [] cls.setupTestData()
def _get_ws_info(self, obj_ref): ws = Workspace(self.ws_url) try: info = ws.get_object_info_new({'objects': [{'ref': obj_ref}]})[0] except WorkspaceError as wse: self.__LOGGER.error('Logging workspace exception') self.__LOGGER.error(str(wse)) raise return info
def get_object_name(ref, ws_url): """ From an object reference, get the object's name. """ if not check_reference(ref): raise ValueError( "This must be a valid object reference to find the object's name.") ws = Workspace(ws_url) info = ws.get_object_info3({"objects": [{"ref": ref}]}).get("infos")[0] return info[1]
def __init__(self, config, logger=None): self.config = config self.logger = logger self.callback_url = os.environ['SDK_CALLBACK_URL'] self.scratch = os.path.join(config['scratch'], 'DEM_' + str(uuid.uuid4())) self.ws_url = config['workspace-url'] self.ws_client = Workspace(self.ws_url) self.fv = KBaseFeatureValues(self.callback_url) self._mkdir_p(self.scratch)
def __init__(self, config): #BEGIN_CONSTRUCTOR self.config = config self.scratch = config['scratch'] self.callback_url = os.environ['SDK_CALLBACK_URL'] self.ws_url = config['workspace-url'] self.ws_client = Workspace(self.ws_url) self.dfu = DataFileUtil(self.callback_url) #END_CONSTRUCTOR pass