コード例 #1
0
def _method_get_state(workspace, token, URLS, job_manager, method_spec_json, param_values_json, method_job_id):
    methodSpec = json.loads(method_spec_json)
    methodInputValues = json.loads(correct_method_specs_json(param_values_json))
    njsClient = NarrativeJobService(URLS.job_service, token = token)
    wsClient = workspaceService(URLS.workspace, token = token)
    if method_job_id.startswith("method:"):
        method_job_id = method_job_id[7:]
        is_async = is_async_method(methodSpec)
        appState = None
        if is_async:
            # It's an SDK method, we use narrative proxy user to deal with sharing
            ujs_proxy = job_manager.proxy_client()
            appState = ujs_proxy.check_app_state(method_job_id)
        else:  # If it's NJS script method then we cannot use narrative proxy user
            appState = njsClient.check_app_state(method_job_id)
        for stepId in appState['step_outputs']:
            rpcOut = appState['step_outputs'][stepId]
            appState['widget_outputs'] = app_state_output_into_method_output(workspace, token, wsClient, methodSpec, methodInputValues, rpcOut)
        appState['job_id'] = "method:" + appState['job_id']
        return appState
    else:
        input = {}
        rpcArgs = prepare_generic_method_input(token, workspace, methodSpec, methodInputValues, input);
        output = method_job_id
        methodOut = prepare_generic_method_output(token, workspace, methodSpec, input, output)
        return methodOut
コード例 #2
0
 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('kb_muscle'):
         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_muscle',
                          'method': 'please_never_use_it_in_production',
                          'method_params': []
                          }],
                     'authenticated': 1})
     cls.wsURL = cls.cfg['workspace-url']
     cls.wsClient = workspaceService(cls.wsURL)
     cls.serviceImpl = kb_muscle(cls.cfg)
     cls.scratch = cls.cfg['scratch']
     cls.callback_url = os.environ['SDK_CALLBACK_URL']
コード例 #3
0
def _assemble_contigs(meth, asm_input):
    """Use the AssemblyRAST service to assemble a set of contigs from sequenced reads.
    This starts a job that might run for several hours.
    When it finishes, the assembled ContigSet will be stored in your data space. [1]

    :param asm_input: A list of files with read information [1.1]
    :type asm_input: kbtypes.KBaseAssembly.AssemblyInput
    :ui_name asm_input: Assembly Input file
    :return: An assembly job
    :rtype: kbtypes.Unicode
    :output_widget: AssemblyWidget
    """
    ws = os.environ['KB_WORKSPACE_ID']
    token = os.environ['KB_AUTH_TOKEN']
    arURL = 'http://kbase.us/services/assembly/'
    ar_user = token.split('=')[1].split('|')[0]

    wsClient = workspaceService(service.URLS.workspace, token=token)
    ws_request = {'id': asm_input,
                  'workspace': ws}

    asm_data = wsClient.get_object(ws_request)
    meth.debug(str(asm_data))

    return json.dumps({"ar_url": arURL,
                       "ar_user" : ar_user,
                       "ar_token" : token,
                       "ws_url" : service.URLS.workspace,
                       "ws_name" : os.environ['KB_WORKSPACE_ID'],
                       "kbase_assembly_input": asm_data['data']})
コード例 #4
0
    def setUpClass(cls):
        token = environ.get('KB_AUTH_TOKEN', None)
        cls.ctx = {'token': token, 'provenance': [{'service': 'data_api2',
            '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('data_api2'):
            cls.cfg[nameval[0]] = nameval[1]
        cls.wsURL = cls.cfg['workspace-url']
        cls.wsClient = workspaceService(cls.wsURL, token=token)
        cls.serviceImpl = data_api2(cls.cfg)
        cls.obj_name="ReferenceGenomeAnnotations/kb|g.207118"

        cls.obj_name="ReferenceGenomeAnnotations/kb|g.217864"
        cls.feature='kb|g.207118.CDS.3237'
        cls.feature='kb|g.217864.CDS.11485'
        cls.gene='kb|g.217864.locus.10619'

        cls.obj_name="ReferenceGenomeAnnotations/kb|g.140057"
        cls.feature='kb|g.140057.CDS.2901'
        cls.gene='kb|g.140057.locus.2922'
        cls.mrna='kb|g.140057.mRNA.2840'
        cls.taxon= u'1779/523209/1'
        cls.assembly='1837/56/1'
コード例 #5
0
    def setUpClass(cls):
        token = environ.get('KB_AUTH_TOKEN', None)
        cls.token = token
        config_file = environ.get('KB_DEPLOYMENT_CONFIG', None)
        cls.cfg = {}
        config = ConfigParser()
        config.read(config_file)
        for nameval in config.items('kb_trimmomatic'):
            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(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': token,
                        'user_id': user_id,
                        'provenance': [
                            {'service': 'kb_trimmomatic',
                             'method': 'please_never_use_it_in_production',
                             'method_params': []
                             }],
                        'authenticated': 1})
        cls.wsURL = cls.cfg['workspace-url']
        cls.shockURL = cls.cfg['shock-url']
        cls.handleURL = cls.cfg['handle-service-url']
        cls.serviceWizardURL = cls.cfg['service-wizard-url']

        cls.wsClient = workspaceService(cls.wsURL, token=token)
        cls.serviceImpl = kb_trimmomatic(cls.cfg)
コード例 #6
0
ファイル: jnomics_service.py プロジェクト: cbun/narrative
def prepareInputfiles(token,workspace=None,files=None,wstype=None):
    auth = Authentication(userFromToken(token), "", token)
    json_error = None
    status = None
    job_ids = []
    meta = []
    ret_code = "FAILED"
    ws = workspaceService(OTHERURLS.workspace)
    files = files.split(",")
    for nfile in files:
        filename = os.path.basename(nfile)
        try:
            obj = ws.get_object({'auth': token, 'workspace': workspace, 'id': filename.strip(), 'type': wstype})
        except Exception as err:
            raise FileNotFound("File Not Found: {}".format(err))
        #return {"output" : str(status), "error": json_error}
        if 'data' in obj and 'shock_ref' in obj['data'] and 'shock_id' in  obj['data']['shock_ref']:
            node_id = obj['data']['shock_ref']['shock_id']
        if 'data' in obj and 'metadata' in obj['data']:
            meta.append(obj['data']['metadata'])
        shockfilename = filename.replace("|","_")
        if isFileFound(shockfilename,auth):
            pass
        job_ids.append(readShock(node_id,shockfilename,auth))

    for jid in job_ids:
        status = pollGridJob(jid, auth)
        if status and not status.running_state == 2:
            json_error = status.failure_info
    ret_code = "SUCCESS"
    return {"status" : ret_code ,"job_ids" : [x.job_id for x in job_ids] ,"metadata" : meta, "error": json_error}
    def setUpClass(cls):
        token = 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': 'testGenAnnoAPI',
                             '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('testGenAnnoAPI'):
            cls.cfg[nameval[0]] = nameval[1]
        cls.wsURL = cls.cfg['workspace-url']
        cls.wsClient = workspaceService(cls.wsURL, token=token)
        cls.serviceImpl = testGenAnnoAPI(cls.cfg)

        cls.obj_name="ReferenceGenomeAnnotations/kb|g.207118"

        cls.obj_name="ReferenceGenomeAnnotations/kb|g.217864"
        cls.feature='kb|g.207118.CDS.3237'
        cls.feature='kb|g.217864.CDS.11485'
        cls.gene='kb|g.217864.locus.10619'

        cls.obj_name="ReferenceGenomeAnnotations/kb|g.140057"
        cls.feature='kb|g.140057.CDS.2901'
        cls.gene='kb|g.140057.locus.2922'
        cls.mrna='kb|g.140057.mRNA.2840'
        cls.taxon= u'1779/523209/1'
        cls.assembly='1837/56/2'
コード例 #8
0
def _app_get_state(workspace, token, URLS, job_manager, app_spec_json, method_specs_json, param_values_json, app_job_id):
    appSpec = json.loads(app_spec_json)
    paramValues = json.loads(correct_method_specs_json(param_values_json))
    methIdToSpec = json.loads(correct_method_specs_json(method_specs_json))
    njsClient = NarrativeJobService(URLS.job_service, token = token)
    wsClient = workspaceService(URLS.workspace, token = token)
    if app_job_id.startswith("njs:"):
        app_job_id = app_job_id[4:]
    appState = njsClient.check_app_state(app_job_id)
    appState['widget_outputs'] = {}
    prevStepReady = True
    for stepSpec in appSpec['steps']:
        stepId = stepSpec['step_id']
        methodId = stepSpec['method_id']
        methodSpec = methIdToSpec[methodId]
        if stepId in appState['step_outputs']:
            rpcOut = appState['step_outputs'][stepId]
            prevStepReady = True
        elif 'output_mapping' in methodSpec['behavior'] and prevStepReady:
            rpcOut = None
            prevStepReady = True
        else:
            prevStepReady = False
            continue
        methodInputValues = extract_param_values(paramValues, stepId)
        appState['widget_outputs'][stepId] = app_state_output_into_method_output(workspace, token, wsClient, methodSpec, methodInputValues, rpcOut)
    appState['job_id'] = "njs:" + appState['job_id']
    return appState
コード例 #9
0
 def setUpClass(cls):
     cls.token = environ.get('KB_AUTH_TOKEN')
     cls.callbackURL = environ.get('SDK_CALLBACK_URL')
     print('CB URL: ' + cls.callbackURL)
     # 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,
                     'provenance': [
                         {'service': 'gaprice_SPAdes_test',
                          '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('gaprice_SPAdes_test'):
         cls.cfg[nameval[0]] = nameval[1]
     cls.wsURL = cls.cfg['workspace-url']
     cls.shockURL = cls.cfg['shock-url']
     cls.hs = HandleService(url=cls.cfg['handle-service-url'],
                            token=cls.token)
     cls.wsClient = workspaceService(cls.wsURL, token=cls.token)
     wssuffix = int(time.time() * 1000)
     wsName = "test_gaprice_SPAdes_test_" + str(wssuffix)
     cls.wsinfo = cls.wsClient.create_workspace({'workspace': wsName})
     print('created workspace ' + cls.getWsName())
     cls.serviceImpl = gaprice_SPAdes_test(cls.cfg)
     cls.staged = {}
     cls.nodes_to_delete = []
     cls.handles_to_delete = []
     cls.setupTestData()
     print('\n\n=============== Starting tests ==================')
コード例 #10
0
 def setUpClass(cls):
     cls.token = environ.get('KB_AUTH_TOKEN', None)
     cls.ctx = {'token': cls.token,
                'provenance': [
                     {'service': 'gaprice_SPAdes',
                      '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('gaprice_SPAdes'):
         cls.cfg[nameval[0]] = nameval[1]
     cls.wsURL = cls.cfg['workspace-url']
     cls.shockURL = cls.cfg['shock-url']
     cls.hs = HandleService(url=cls.cfg['handle-service-url'],
                            token=cls.token)
     cls.wsClient = workspaceService(cls.wsURL, token=cls.token)
     wssuffix = int(time.time() * 1000)
     wsName = "test_gaprice_SPAdes_" + str(wssuffix)
     cls.wsinfo = cls.wsClient.create_workspace({'workspace': wsName})
     print('created workspace ' + cls.getWsName())
     cls.serviceImpl = gaprice_SPAdes(cls.cfg)
     cls.staged = {}
     cls.nodes_to_delete = []
     cls.handles_to_delete = []
     cls.setupTestData()
     print('\n\n=============== Starting tests ==================')
コード例 #11
0
    def build_msa(self, ctx, workspace_name, featureset_id, msa_id):
        # ctx is the context object
        # return variables are: returnVal
        #BEGIN build_msa
        returnVal = ''
 
        # create workspace client
        token = ctx['token']
        ws = workspaceService(self.workspaceURL, token=token)
        
        # Export fasta
        self.exportFasta(ws, workspace_name, featureset_id)
        
        # Run muscle
        os.system('/kb/runtime/bin/muscle ' + ' -in ' + self.fileFastaName + ' -out ' + self.fileOutputName)
        
        # Create MSA object
        returnVal = self.createMSA(ws, workspace_name, featureset_id, msa_id)
        

        #END build_msa

        # At some point might do deeper type checking...
        if not isinstance(returnVal, basestring):
            raise ValueError('Method build_msa return value ' +
                             'returnVal is not type basestring as required.')
        # return the results
        return [returnVal]
コード例 #12
0
    def featureset_protein_sequence(self, ctx, workspace_name, featureset_id):
        # ctx is the context object
        # return variables are: returnVal
        #BEGIN featureset_protein_sequence
        
        returnVal = []
        
        # create workspace client
        token = ctx['token']
        ws = workspaceService(self.workspaceURL, token=token)

        # Build genome2Features hash
        genome2Features = self.buildGenome2Features(ws, workspace_name, featureset_id)

        # Process each genome one by one
        for genomeRef in genome2Features:
            genome = ws.get_objects([{'ref':genomeRef}])[0]['data']
            featureIds = genome2Features[genomeRef]
            for feature in genome['features']:
                for fId in featureIds:
                    if fId == feature['id']:
                        returnVal.append({'feature_id' : fId, 'genome_ref' : genomeRef,'sequence': feature['protein_translation']})
    
        #END featureset_protein_sequence

        # At some point might do deeper type checking...
        if not isinstance(returnVal, list):
            raise ValueError('Method featureset_protein_sequence return value ' +
                             'returnVal is not type list as required.')
        # return the results
        return [returnVal]
コード例 #13
0
 def setUpClass(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(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': token,
                     'user_id': user_id,
                     'provenance': [
                         {'service': 'TestServiceCalls',
                          '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('TestServiceCalls'):
         cls.cfg[nameval[0]] = nameval[1]
     cls.wsURL = cls.cfg['workspace-url']
     cls.wsClient = workspaceService(cls.wsURL, token=token)
     cls.serviceImpl = TestServiceCalls(cls.cfg)
コード例 #14
0
ファイル: jnomics_service.py プロジェクト: cbun/narrative
def gene_network(meth,workspace_id=None,hm=None):
    """It takes the filtered expression data table and generates the heatmap 
        
        :param workspace_id: Name of the workspace; default is current
        :type workspace_id: kbtypes.Unicode
        :ui_name workspace_id : Workspace
        :param hm: Filtered Datatable
        :type hm: kbtypes.Unicode
        :ui_name hm : Filtered Datatable
        :return: Rows for display
        :rtype: kbtypes.Unicode
        :output_widget: kbaseHeatmap
        """

    if not workspace_id:
        workspace_id = meth.workspace_id

    meth.stages = 1
    # if not workspace_id:
    #     meth.debug("Workspace ID is empty, setting to current ({})".format(meth.workspace_id))
    #     workspace_id = meth.workspace_id
    meth.advance("Retrieve network table from workspace")
    if hm:
        auth = Authentication(userFromToken(meth.token), "", meth.token)
        ws = workspaceService(OTHERURLS.workspace)
        dt_type = WSTYPES.datatabletype

        raw_data = ws.get_object({'auth': meth.token, 'workspace': workspace_id, 'id': hm.strip(), 'type': dt_type})
    else:
        raw_data = {}
    data = {'dataset': raw_data, 'height' : str(len(raw_data["data"]["row_labels"]) * 18) + "px"}

    return json.dumps(data)
コード例 #15
0
 def __init__(self, scratch, workspaceURL, params, token, provenance):
     self.scratch = scratch
     self.workspaceURL = workspaceURL
     self.params = params
     self.token = token
     self.provenance = provenance
     self.plbin = "/kb/deployment/plbin"
     self.log = ""
     self.ws = workspaceService(self.workspaceURL, token=self.token)
コード例 #16
0
def _method_call(meth, method_spec_json, param_values_json):
    """Generic service method calls

    :param method_spec_json: Method descriptor JSON string
    :type method_spec_json: kbtypes.Unicode
    :ui_name method_spec_json: Method descriptor JSON string
    :param param_values_json: Parameter values JSON string
    :type param_values_json: kbtypes.Unicode
    :ui_name param_values_json: Parameter values JSON string
    :return: Service method response
    :rtype: kbtypes.Unicode
    """
    token = os.environ['KB_AUTH_TOKEN']
    workspace = os.environ['KB_WORKSPACE_ID']
    methodSpec = json.loads(correct_method_specs_json(method_spec_json))
    paramValues = json.loads(correct_method_specs_json(param_values_json))
    methodOut = None
    behavior = methodSpec['behavior']
    scriptStep = is_script_method(methodSpec)
    async = is_async_method(methodSpec)
    if scriptStep or async:
        wsClient = workspaceService(service.URLS.workspace, token = token)
        steps = []
        methodId = methodSpec['info']['id']
        app = { 'name' : 'App wrapper for method ' + methodId,'steps' : steps }
        steps.append(create_app_step(workspace, token, wsClient, methodSpec, paramValues, methodId, scriptStep))
        meth.debug(json.dumps(app))
        njsClient = NarrativeJobService(service.URLS.job_service, token = token)
        appState = njsClient.run_app(app)
        jobId = "method:" + appState["job_id"]
        meth.register_app(jobId)
        methodOut = {'job_id': jobId}
    else:
        input = {}
        output = None
        if 'kb_service_input_mapping' in behavior:
            rpcArgs = prepare_generic_method_input(token, workspace, methodSpec, paramValues, input);
            url = behavior['kb_service_url']
            serviceName = behavior['kb_service_name']
            methodName = behavior['kb_service_method']
            if serviceName:
                methodName = serviceName + '.' + methodName
            genericClient = GenericService(url = url, token = token)
            output = genericClient.call_method(methodName, rpcArgs)
        else:
            parameters = methodSpec['parameters']
            for paramPos in range(0, len(parameters)):
                param = parameters[paramPos]
                paramId = param['id']
                paramValue = paramValues[paramPos]
                input[paramId] = paramValue
        methodOut = prepare_generic_method_output(token, workspace, methodSpec, input, output)
        if 'job_id_output_field' in methodSpec:
            jobIdField = methodSpec['job_id_output_field']
            if jobIdField in methodOut:
                meth.register_job(methodOut[jobIdField])
    return json.dumps(methodOut)
コード例 #17
0
    def convert_read_library_to_file(self, ctx, params):
        # ctx is the context object
        # return variables are: output
        #BEGIN convert_read_library_to_file
        ''' potential improvements:
            Add continue_on_failure mode that reports errors for each failed
                conversion rather than failing completely. This would need
                a similar boolean to ignore failures in the workspace
                get_objects method, or it'd require getting the reads objects
                one by one. Yuck.
                Alternatively - call get_object_info_new and then only process
                the reads files that return. Race conditions possible though.
                Probably better to add flag to get_objects.
            Parallelize - probably not worth it, this is all IO bound. Try if
                there's nothing better to do. If so, each process/thread needs
                its own shock_tmp folder.
            Add user specified failure conditions - e.g. fail if is/is not
                metagenome, outwards reads, etc.
        '''

        self.log('Running convert_read_library_to_file with params:\n' +
                 pformat(params))

        token = ctx['token']

        self.process_params(params)
#         self.log('\n' + pformat(params))

        # Get the reads library
        ws = workspaceService(self.workspaceURL, token=token)
        ws_reads_ids = []
        for read_name in params[self.PARAM_IN_LIB]:
            ws_reads_ids.append({'ref': params[self.PARAM_IN_WS] + '/' +
                                 read_name})
        try:
            reads = ws.get_objects(ws_reads_ids)
        except WorkspaceException as e:
            self.log('Logging stacktrace from workspace exception:\n' + e.data)
            raise

        output = {}
        for read_name, read in zip(params[self.PARAM_IN_LIB], reads):
            self.log('=== processing read library ' + read_name + '===\n',
                     prefix_newline=True)
            output[read_name] = self.process_reads(
                read, params[self.PARAM_IN_GZIP],
                params[self.PARAM_IN_INTERLEAVED], token)
        output = {'files': output}
        #END convert_read_library_to_file

        # At some point might do deeper type checking...
        if not isinstance(output, dict):
            raise ValueError('Method convert_read_library_to_file return value ' +
                             'output is not type dict as required.')
        # return the results
        return [output]
コード例 #18
0
    def featureset_nucleotide_sequence(self, ctx, workspace_name, featureset_id):
        # ctx is the context object
        # return variables are: returnVal
        #BEGIN featureset_nucleotide_sequence
        
        returnVal = []
        
        # create workspace client
        token = ctx['token']
        ws = workspaceService(self.workspaceURL, token=token)
        
        # Build genome2Features hash
        genome2Features = self.buildGenome2Features(ws, workspace_name, featureset_id)
        
        
        for genomeRef in genome2Features:
            genome = ws.get_objects([{'ref':genomeRef}])[0]['data']
            contigSet = ws.get_objects([{'ref': genome['contigset_ref']}])[0]['data']
            
            # build a hash by contig name
            contigs = {}
            for contig in contigSet['contigs']:
                contigs[contig['name']] = contig
            
            # proces features
            featureIds = genome2Features[genomeRef]
            for feature in genome['features']:
                for fId in featureIds:
                    if fId == feature['id']:
                        sequence = ''
                        fStrand = ''
                        for location in feature['location']:
                            (contigId, fStart, fStrand, fLen) = location
                            contig = contigs[contigId]
                            if fStrand == '+':
                                start = int(fStart) - 1
                                end = start + int(fLen)
                            else:
                                end = int(fStart)
                                start = end - int(fLen)
                            sequence += contig['sequence'][start:end]
                        if fStrand == '-':
                            sequence = self.reverseComplement( sequence )
                    
                        returnVal.append({'feature_id' : fId, 'genome_ref' : genomeRef,'sequence': sequence})
        
        #END featureset_nucleotide_sequence

        # At some point might do deeper type checking...
        if not isinstance(returnVal, list):
            raise ValueError('Method featureset_nucleotide_sequence return value ' +
                             'returnVal is not type list as required.')
        # return the results
        return [returnVal]
コード例 #19
0
    def run_megahit(self, ctx, params):
        # ctx is the context object
        # return variables are: output
        #BEGIN run_megahit


        ws = workspaceService(self.workspaceURL, token=ctx['token'])
        objects = ws.get_objects([{'ref': params['workspace_name']+'/'+params['read_library_name']}])

        data = objects[0]['data']
        info = objects[0]['info']
        type_name = info[2].split('.')[1].split('-')[0]

        report = 'report will go here'
        report += 'input data type: '+type_name
        reportObj = {
            # 'objects_created':[{'ref':params['workspace_name']+'/'+params['output_contigset_name'], 'description':'Assembled contigs'}],
            'objects_created':[],
            'text_message':report
        }

        provenance = [{}]
        if 'provenance' in ctx:
            provenance = ctx['provenance']
        # add additional info to provenance here, in this case the input data object reference
        provenance[0]['input_ws_objects']=[params['workspace_name']+'/'+params['read_library_name']]

        reportName = 'megahit_report_'+str(hex(uuid.getnode()))
        report_obj_info = ws.save_objects({
                'id':info[6],
                'objects':[
                    {
                        'type':'KBaseReport.Report',
                        'data':reportObj,
                        'name':reportName,
                        'meta':{},
                        'hidden':1,
                        'provenance':provenance
                    }
                ]
            })[0]

        output = { 'report_name': reportName, 'report_ref': str(report_obj_info[6]) + '/' + str(report_obj_info[0]) + '/' + str(report_obj_info[4]) }

        #END run_megahit

        # At some point might do deeper type checking...
        if not isinstance(output, dict):
            raise ValueError('Method run_megahit return value ' +
                             'output is not type dict as required.')


        # return the results
        return [output]
コード例 #20
0
ファイル: microbes_annotation.py プロジェクト: cbun/narrative
def _prepare_genome(meth, contig_set, scientific_name, genetic_code, out_genome):
    """Build a Genome object from a ContigSet, creating structural and functional annotations.
    The annotation job may run for an hour or longer. When the annotation job finishes,
    the annotated Genome object will be stored in your workspace. [3]

    :param contig_set: An object with contig data [3.1]
    :type contig_set: kbtypes.KBaseGenomes.ContigSet
    :ui_name contig_set: Contig Set Object
    :param scientific_name: enter the scientific name to assign to your new genome [3.2]
    :type scientific_name: kbtypes.Unicode
    :ui_name scientific_name: Scientific Name
    :param genetic_code: enter the genetic code for your new genome (default is 11) [3.2]
    :type genetic_code: kbtypes.Unicode
    :ui_name genetic_code: Genetic Code
    :param out_genome: Annotated output genome ID. If empty, an ID will be chosen randomly. [3.3]
    :type out_genome: kbtypes.KBaseGenomes.Genome
    :ui_name out_genome: Output Genome ID
    :return: Preparation message
    :rtype: kbtypes.Unicode
    :output_widget: GenomeAnnotation
    """
    if not scientific_name:
        return json.dump({'error': 'output genome name should be defined'})
    if not genetic_code:
        genetic_code = 11
    if not out_genome:
        out_genome = "genome_" + ''.join([chr(random.randrange(0, 26) + ord('A')) for _ in xrange(8)])
    meth.stages = 2
    meth.advance("Annotating the contigs (3-4 minutes)...")
    token = os.environ['KB_AUTH_TOKEN']
    workspace = os.environ['KB_WORKSPACE_ID']
    fbaClient = fbaModelServices(url = service.URLS.fba, token = token)
        # create the model object
    contigset_to_genome_params = {
        'auth': token,
        'ContigSet_ws': workspace,
        'ContigSet_uid': contig_set,
        'workspace': workspace,
        'uid': out_genome,
        'scientific_name': scientific_name,
        'domain': 'Bacteria',
        'genetic_code': genetic_code,
    }
    fbaClient.ContigSet_to_Genome(contigset_to_genome_params)
    wsClient = workspaceService(service.URLS.workspace, token=token)
    genomeData = wsClient.get_objects([{'ref': workspace+'/'+out_genome}])[0]
    genome = genomeData['data']
    meta = genomeData['info'][10]
    if not meta:
        meta = {}
    meta['Scientific name'] = scientific_name
    wsClient.save_objects({'workspace': workspace, 'objects': [{'type': 'KBaseGenomes.Genome', 'name': out_genome, 'data': genome, 'meta': meta}]})
    return json.dumps({'ws_name': workspace, 'ws_id': out_genome})
コード例 #21
0
 def setUpClass(cls):
     token = environ.get('KB_AUTH_TOKEN', None)
     cls.ctx = {'token': token}
     config_file = environ.get('KB_DEPLOYMENT_CONFIG', None)
     cls.cfg = {}
     config = ConfigParser()
     config.read(config_file)
     for nameval in config.items('arkincount'):
         cls.cfg[nameval[0]] = nameval[1]
     cls.wsURL = cls.cfg['workspace-url']
     cls.wsClient = workspaceService(cls.wsURL, token=token)
     cls.serviceImpl = arkincount(cls.cfg)
コード例 #22
0
 def setUpClass(cls):
     token = environ.get('KB_AUTH_TOKEN', None)
     cls.ctx = {'token': token, 'provenance': [{'service': 'ContigFilterPython',
         '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('ContigFilterPython'):
         cls.cfg[nameval[0]] = nameval[1]
     cls.wsURL = cls.cfg['workspace-url']
     cls.wsClient = workspaceService(cls.wsURL, token=token)
     cls.serviceImpl = ContigFilterPython(cls.cfg)
コード例 #23
0
 def setUpClass(cls):
     token = environ.get('KB_AUTH_TOKEN', None)
     auth_client = biokbase.nexus.Client(config={'server': 'nexus.api.globusonline.org',
             'verify_ssl': True, 'client': None, 'client_secret': None})
     user, _, _ = auth_client.validate_token(token)
     cls.ctx = {'token': token, 'authenticated': 1, 'user_id': user}
     config_file = environ.get('KB_DEPLOYMENT_CONFIG', None)
     cls.cfg = {}
     config = ConfigParser()
     config.read(config_file)
     for nameval in config.items('onerepotest'):
         cls.cfg[nameval[0]] = nameval[1]
     cls.wsURL = cls.cfg['workspace-url']
     cls.wsClient = workspaceService(cls.wsURL, token=token)
     cls.serviceImpl = onerepotest(cls.cfg)
コード例 #24
0
    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('kb_tophat2'):
            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_tophat2',
                'method': 'please_never_use_it_in_production',
                'method_params': []
            }],
            'authenticated':
            1
        })
        cls.wsURL = cls.cfg['workspace-url']
        cls.wsClient = workspaceService(cls.wsURL)
        cls.ws = Workspace(cls.wsURL, token=token)
        cls.serviceImpl = kb_tophat2(cls.cfg)
        cls.scratch = cls.cfg['scratch']
        cls.callback_url = os.environ['SDK_CALLBACK_URL']
        cls.srv_wiz_url = cls.cfg['srv-wiz-url']

        suffix = int(time.time() * 1000)
        cls.wsName = "test_kb_tophat2_" + str(suffix)
        cls.wsClient.create_workspace({'workspace': cls.wsName})

        cls.tophat_runner = TopHatUtil(cls.cfg)

        cls.ru = ReadsUtils(cls.callback_url)
        cls.au = AssemblyUtil(cls.callback_url)
        cls.dfu = DataFileUtil(cls.callback_url)
        cls.gfu = GenomeFileUtil(cls.callback_url)

        cls.prepare_data()
コード例 #25
0
    def setUpClass(cls):
        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('kb_ballgown'):
            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': 'kb_ballgown',
                             'method': 'please_never_use_it_in_production',
                             'method_params': []
                             }],
                        'authenticated': 1})
        cls.hs = HandleService(url=cls.cfg['handle-service-url'],
                               token=cls.token)
        cls.shockURL = cls.cfg['shock-url']
        cls.wsURL = cls.cfg['workspace-url']
        cls.wsClient = workspaceService(cls.wsURL, token=cls.token)
        cls.serviceImpl = kb_ballgown(cls.cfg)
        cls.scratch = cls.cfg['scratch']
        cls.callback_url = os.environ['SDK_CALLBACK_URL']

        cls.gfu = GenomeFileUtil(cls.callback_url)
        cls.dfu = DataFileUtil(cls.callback_url)
        cls.ru = ReadsUtils(cls.callback_url)
        cls.rau = ReadsAlignmentUtils(cls.callback_url, service_ver='dev')
        cls.eu = ExpressionUtils(cls.callback_url, service_ver='dev')
        cls.set_api = SetAPI(cls.callback_url)

        suffix = int(time.time() * 1000)
        cls.wsName = "test_kb_ballgown_" + str(suffix)
        #cls.wsName = "test_kb_ballgown_1004"
        cls.wsClient.create_workspace({'workspace': cls.wsName})

        cls.nodes_to_delete = []
        cls.handles_to_delete = []

        cls.prepare_data()
コード例 #26
0
    def setUpClass(cls):
        token = environ.get('KB_AUTH_TOKEN', None)
        cls.ctx = {'token': token}
        config_file = environ.get('KB_DEPLOYMENT_CONFIG', None)
        cls.cfg = {}
        config = ConfigParser()
        config.read(config_file)
        for nameval in config.items('PEReadUploaderTest'):
            print(nameval[0] + '=' + nameval[1])
            cls.cfg[nameval[0]] = nameval[1]
        cls.wsURL = cls.cfg['workspace-url']
        cls.ws = workspaceService(cls.wsURL, token=token)
        cls.serviceImpl = PEReadUploaderTest(cls.cfg)

        cls.shockURL = cls.cfg['shock-url']
        cls.handleURL = cls.cfg['handle-service-url']
コード例 #27
0
    def count_contigs(self, ctx, workspace_name, contigset_id):
        # ctx is the context object
        # return variables are: returnVal
        #BEGIN count_contigs
        token = ctx['token']
        wsClient = workspaceService(self.workspaceURL, token=token)
        contigSet = wsClient.get_objects([{'ref': workspace_name+'/'+contigset_id}])[0]['data']
        returnVal = {'contig_count': len(contigSet['contigs'])}
        #END count_contigs

        # At some point might do deeper type checking...
        if not isinstance(returnVal, dict):
            raise ValueError('Method count_contigs return value ' +
                             'returnVal is not type dict as required.')
        # return the results
        return [returnVal]
コード例 #28
0
    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('kb_ea_utils'):
            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': 'kb_ea_utils',
                '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('kb_ea_utils'):
            cls.cfg[nameval[0]] = nameval[1]
        cls.wsURL = cls.cfg['workspace-url']
        cls.shockURL = cls.cfg['shock-url']
        cls.handleURL = cls.cfg['handle-service-url']
        cls.serviceWizardURL = cls.cfg['service-wizard-url']

        cls.wsClient = workspaceService(cls.wsURL, token=token)
        cls.serviceImpl = kb_ea_utils(cls.cfg)

        cls.scratch = cls.cfg['scratch']
        cls.callback_url = os.environ['SDK_CALLBACK_URL']
        cls.dfu = DataFileUtil(cls.callback_url)
コード例 #29
0
def _assemble_genome(meth, contig_file, out_genome):
    """This assembles a ContigSet into a Genome object in your workspace.
    This should be run before trying to annotate a Genome. [2]

    :param contig_file: A FASTA file with contig data [2.1]
    :type contig_file: kbtypes.Unicode
    :ui_name contig_file: Contig File ID
    :param out_genome: Annotated output genome ID. If empty, an ID will be chosen randomly. [2.2]
    :type out_genome: kbtypes.KBaseGenomes.Genome
    :ui_name out_genome: Output Genome ID
    :return: Assembled output genome ID
    :rtype: kbtypes.KBaseGenomes.Genome
    """
    # Regarding annotation, here's the latest. You want to take the fasta file that the above command
    # created ("contigs.fasta"), and load it to the workspace as a contig set:
    # "ga-loadfasta contigs.fasta -u MyContigs"
    #
    # -- this is already in the workspace by this point.
    meth.stages = 4

    token = os.environ['KB_AUTH_TOKEN']
    workspace = os.environ['KB_WORKSPACE_ID']

    # Setup invocation and double-check workspace
    meth.advance("Initialize Annotation Service")
    inv = InvocationService(service.URLS.invocation)
    inv.run_pipeline("", "kbws-workspace " + workspace, [], 100, '/')

    # Run sequence to genome.
    meth.advance("Build Contig Set into a Genome")
    inv.run_pipeline("", "ga-seq-to-genome " + contig_file + " --genomeid " + out_genome, [], 100, '/')

    # 4. Fetch genome.
    meth.advance("Fetching Genome for Display")
    wsClient = workspaceService(service.URLS.workspace)

    get_genome_params = {
        'id': out_genome,
        'type': 'Genome',
        'workspace': workspace,
        'auth': token,
    }
    genome_meta = wsClient.get_objectmeta(get_genome_params)

    # 5. Pass it forward to the client.
    meth.advance("Rendering Genome Information")
    return json.dumps(genome_meta)
コード例 #30
0
def _method_call(meth, method_spec_json, param_values_json):
    """Generic service method calls

    :param method_spec_json: Method descriptor JSON string
    :type method_spec_json: kbtypes.Unicode
    :ui_name method_spec_json: Method descriptor JSON string
    :param param_values_json: Parameter values JSON string
    :type param_values_json: kbtypes.Unicode
    :ui_name param_values_json: Parameter values JSON string
    :return: Service method response
    :rtype: kbtypes.Unicode
    """
    token = os.environ['KB_AUTH_TOKEN']
    workspace = os.environ['KB_WORKSPACE_ID']
    methodSpec = json.loads(method_spec_json)
    paramValues = json.loads(param_values_json)
    methodOut = None

    if is_script_method(methodSpec):
        wsClient = workspaceService(service.URLS.workspace, token = token)
        steps = []
        methodId = methodSpec['info']['id']
        app = { 'name' : 'App wrapper for method ' + methodId,'steps' : steps }
        steps.append(create_app_step(workspace, token, wsClient, methodSpec, paramValues, methodId, True))
        njsClient = NarrativeJobService(service.URLS.job_service, token = token)
        appState = njsClient.run_app(app)
        jobId = "method:" + appState["job_id"]
        meth.register_app(jobId)
        methodOut = {'job_id': jobId}
    else:
        input = {}
        rpcArgs = prepare_generic_method_input(token, workspace, methodSpec, paramValues, input);
        behavior = methodSpec['behavior']
        url = behavior['kb_service_url']
        serviceName = behavior['kb_service_name']
        methodName = behavior['kb_service_method']
        if serviceName:
            methodName = serviceName + '.' + methodName
        genericClient = GenericService(url = url, token = token)
        output = genericClient.call_method(methodName, rpcArgs)
        methodOut = prepare_generic_method_output(token, workspace, methodSpec, input, output)
        if 'job_id_output_field' in methodSpec:
            jobIdField = methodSpec['job_id_output_field']
            if jobIdField in methodOut:
                meth.register_job(methodOut[jobIdField])
    return json.dumps(methodOut)
コード例 #31
0
 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': 'kb_PRINSEQ',
             '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('kb_PRINSEQ'):
         cls.cfg[nameval[0]] = nameval[1]
     cls.shockURL = cls.cfg['shock-url']
     cls.wsURL = cls.cfg['workspace-url']
     cls.wsClient = workspaceService(cls.wsURL, token=cls.token)
     cls.serviceImpl = kb_PRINSEQ(cls.cfg)
     # cls.ws = workspaceService(cls.wsURL, token=token)
     # cls.ws = Workspace(cls.cfg['workspace-url'], token=cls.token)
     # cls.hs = HandleService(url=cls.cfg['handle-service-url'],
     #                        token=cls.token)
     cls.scratch = cls.cfg['scratch']
     shutil.rmtree(cls.scratch)
     os.mkdir(cls.scratch)
     suffix = int(time.time() * 1000)
     wsName = "test_kb_PRINSEQ_" + str(suffix)
     cls.ws_info = cls.wsClient.create_workspace({'workspace': wsName})
     cls.dfu = DataFileUtil(os.environ['SDK_CALLBACK_URL'], token=cls.token)
     cls.nodes_to_delete = []
     cls.nodes_to_delete.extend(cls.upload_test_reads())
     print "NODES TO DELETE: {}".format(str(cls.nodes_to_delete))
     print('\n\n=============== Starting tests ==================')
コード例 #32
0
    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('kb_fastqc'):
            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': 'kb_fastqc',
                'method': 'please_never_use_it_in_production',
                'method_params': []
            }],
            'authenticated':
            1
        })
        cls.wsURL = cls.cfg['workspace-url']
        cls.wsClient = workspaceService(cls.wsURL, token=token)
        cls.serviceImpl = kb_fastqc(cls.cfg)

        #retrieve and setup test files
        test_fq_filename = "test_1.fastq.gz"
        output = subprocess.check_output([
            "curl", "-o", test_fq_filename,
            "http://bioseed.mcs.anl.gov/~seaver/Files/Sample_Reads/WT1_S1_L001_R2_001.fastq.gz"
        ])
        cls.large_fq_test_file1 = os.path.join(cls.cfg['scratch'],
                                               test_fq_filename)
        shutil.copy(test_fq_filename, cls.large_fq_test_file1)

        fq_filename = "interleaved.fq"
        cls.small_fq_test_file2 = os.path.join(cls.cfg['scratch'], fq_filename)
        shutil.copy(os.path.join("data", fq_filename), cls.small_fq_test_file2)
コード例 #33
0
 def check_feature_cache(self, ref, token):
     ws_client = workspaceService(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()
         genome = ws_client.get_objects2({"objects": [{"ref": ref, "included": [
                 "/features/[*]/id", "/features/[*]/type", "/features/[*]/function", 
                 "/features/[*]/aliases", "/features/[*]/location",
                 "/features/[*]/ontology_terms/*/*/term_name"]}]})["data"][0]["data"]
         self.save_feature_tsv(genome["features"], inner_chsum)
         if self.debug:
             print("    (time=" + str(time.time() - t1) + ")")
     return inner_chsum
コード例 #34
0
    def setUpClass(cls):
        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('kb_uploadmethods'):
            cls.cfg[nameval[0]] = nameval[1]
        authServiceUrl = cls.cfg.get(
            'auth-service-url',
            "https://kbase.us/services/authorization/Sessions/Login")
        auth_client = _KBaseAuth(authServiceUrl)
        cls.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':
            cls.user_id,
            'provenance': [{
                'service': 'kb_uploadmethods',
                'method': 'please_never_use_it_in_production',
                'method_params': []
            }],
            'authenticated':
            1
        })
        cls.wsURL = cls.cfg['workspace-url']
        cls.wsClient = workspaceService(cls.wsURL, token=cls.token)
        cls.serviceImpl = kb_uploadmethods(cls.cfg)
        cls.dfu = DataFileUtil(os.environ['SDK_CALLBACK_URL'], token=cls.token)
        cls.gfu = GenomeFileUtil(os.environ['SDK_CALLBACK_URL'],
                                 token=cls.token)
        cls.fba_tools = fba_tools(os.environ['SDK_CALLBACK_URL'],
                                  token=cls.token)
        cls.scratch = cls.cfg['scratch']
        cls.shockURL = cls.cfg['shock-url']

        suffix = int(time.time() * 1000)
        cls.wsName = "test_kb_uploadmethods_phenotype_set" + str(suffix)
        cls.wsClient.create_workspace({'workspace': cls.wsName})

        cls.prepare_data()
コード例 #35
0
    def setUpClass(cls):
        cls.__LOGGER = logging.getLogger('ExpressionUtils_test')
        cls.__LOGGER.setLevel(logging.INFO)
        streamHandler = logging.StreamHandler(sys.stdout)
        formatter = logging.Formatter(
            "%(asctime)s - %(filename)s - %(lineno)d - %(levelname)s - %(message)s"
        )
        formatter.converter = time.gmtime
        streamHandler.setFormatter(formatter)
        cls.__LOGGER.addHandler(streamHandler)
        cls.__LOGGER.info("Logger was set")

        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('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(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': 'ExpressionUtils',
                'method': 'please_never_use_it_in_production',
                'method_params': []
            }],
            'authenticated':
            1
        })
        cls.wsURL = cls.cfg['workspace-url']
        cls.callback_url = os.environ['SDK_CALLBACK_URL']
        cls.cfg['SDK_CALLBACK_URL'] = cls.callback_url
        cls.wsClient = workspaceService(cls.wsURL)
        cls.serviceImpl = ExpressionUtils(cls.cfg)
        cls.scratch = cls.cfg['scratch']
コード例 #36
0
    def setUpClass(cls):
        token = environ.get('KB_AUTH_TOKEN', None)
        cls.ctx = {'token': token, 'provenance': [{'service': 'AssemblyRAST',
            '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('AssemblyRAST'):
            cls.cfg[nameval[0]] = nameval[1]
        cls.wsURL = cls.cfg['workspace-url']
        cls.ws = workspaceService(cls.wsURL, token=token)
        cls.serviceImpl = AssemblyRAST(cls.cfg)

        cls.shockURL = cls.cfg['shock-url']
        cls.handleURL = cls.cfg['handle-service-url']
        logger.info('shockURL='+cls.shockURL)
コード例 #37
0
    def setUpClass(cls):
        token = environ.get('KB_AUTH_TOKEN', None)
        cls.ctx = {'token': token, 'provenance': [{'service': 'AssemblyRAST',
            '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('AssemblyRAST'):
            cls.cfg[nameval[0]] = nameval[1]
        cls.wsURL = cls.cfg['workspace-url']
        cls.ws = workspaceService(cls.wsURL, token=token)
        cls.serviceImpl = AssemblyRAST(cls.cfg)

        cls.shockURL = cls.cfg['shock-url']
        cls.handleURL = cls.cfg['handle-service-url']
        logger.info('shockURL='+cls.shockURL)
コード例 #38
0
ファイル: jnomics_service.py プロジェクト: cbun/narrative
def _get_ws(wsname, name, wtype,auth):
    #token = os.environ['KB_AUTH_TOKEN']
    ws = workspaceService(OTHERURLS.workspace)
    obj = ws.get_object({'auth': auth, 'workspace': wsname, 'id': name, 'type': wtype})
    data = None
    # Data format
    if 'data' in obj['data']:
        data = obj['data']['data']
    # Handle format
    elif 'shock_ref' in obj['data']:
        data = obj['data']['shock_ref']
    # Collection format
    elif 'members' in obj['data']:
        data = [m['ID'] for m in obj['data']['members']]
    # just return the whole thing
    else:
        data = obj['data']
    return data
コード例 #39
0
 def setUpClass(cls):
     token = environ.get("KB_AUTH_TOKEN", None)
     cls.ctx = {
         "token": token,
         "provenance": [
             {"service": "ContigCount_mshukla", "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("ContigCount_mshukla"):
         cls.cfg[nameval[0]] = nameval[1]
     cls.wsURL = cls.cfg["workspace-url"]
     cls.wsClient = workspaceService(cls.wsURL, token=token)
     cls.serviceImpl = ContigCount_mshukla(cls.cfg)
コード例 #40
0
 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('kb_cufflinks'):
         cls.cfg[nameval[0]] = nameval[1]
     # Getting username from Auth profile for token
     authServiceUrl = cls.cfg['auth-service-url']
     # authServiceUrlAllowInsecure = cls.cfg['auth_service_url_allow_insecure']
     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_cufflinks',
             'method': 'please_never_use_it_in_production',
             'method_params': []
         }],
         'authenticated':
         1
     })
     cls.wsURL = cls.cfg['workspace-url']
     cls.wsClient = workspaceService(cls.wsURL)
     cls.serviceImpl = kb_cufflinks(cls.cfg)
     cls.scratch = cls.cfg['scratch']
     cls.callback_url = os.environ['SDK_CALLBACK_URL']
     cls.gfu = GenomeFileUtil(cls.callback_url)
     cls.dfu = DataFileUtil(cls.callback_url)
     cls.ru = ReadsUtils(cls.callback_url)
     cls.rau = ReadsAlignmentUtils(cls.callback_url)
     cls.deu = DifferentialExpressionUtils(cls.callback_url,
                                           service_ver='beta')
     suffix = int(time.time() * 1000)
     cls.wsName = "test_cuffdiff_" + str(suffix)
     cls.wsClient.create_workspace({'workspace': cls.wsName})
     cls.upload_genome()
コード例 #41
0
def _compute_pan_genome(meth, genome_set,pangenome_id):
    """ Rapidly compute gene families for a set of phylogenetically close genomes

    :param genome_set: a Genome Set to compute pangenome for
    :type genome_set: kbtypes.KBaseSearch.GenomeSet
    :ui_name genome_set: Genome Set ID
    
    :param pangenome_id: ID for output pangenome
    :type pangenome_id: kbtypes.KBaseGenomes.Pangenome
    :ui_name pangenome_id: Pangenome ID
    
    :return: Generated Pangenome Object
    :rtype: kbtypes.KBaseGenomes.Pangenome
    :output_widget: kbasePanGenome
    """
    meth.stages = 2
    meth.advance("Computing pangenome (20 sec per genome)...")
    usertoken, workspace_id = meth.token, meth.workspace_id

    ws = workspaceService(service.URLS.workspace, token=usertoken)
    data = ws.get_objects([{'ref': workspace_id+'/'+genome_set}])[0]
    genome_set_elements = data['data']['elements']
    genomes = []
    gwss = []
    for key in genome_set_elements:
        array = genome_set_elements[key]['ref'].split('/')
        gwss.append(array[0])
        genomes.append(array[1])

    pangenome_parameters = {
        'genomes':genomes,
        'genome_workspaces':gwss,
        'workspace':workspace_id,
        'auth':usertoken,
        'wsurl':service.URLS.workspace}
    
    if pangenome_id:
        pangenome_parameters['output_id']=pangenome_id
    
    fbaclient = fbaModelServices(url = service.URLS.fba, token=usertoken)
    meta = fbaclient.build_pangenome(pangenome_parameters)
    
    return json.dumps({'ws': workspace_id, 'name':meta[1]})
コード例 #42
0
    def count_contigs(self, ctx, workspace_name, contigset_id):
        # ctx is the context object
        # return variables are: returnVal
        #BEGIN count_contigs
        token = ctx['token']
        wsClient = workspaceService(self.workspaceURL, token=token)
        contigSet = wsClient.get_objects([{
            'ref':
            workspace_name + '/' + contigset_id
        }])[0]['data']
        returnVal = {'contig_count': len(contigSet['contigs'])}
        #END count_contigs

        # At some point might do deeper type checking...
        if not isinstance(returnVal, dict):
            raise ValueError('Method count_contigs return value ' +
                             'returnVal is not type dict as required.')
        # return the results
        return [returnVal]
コード例 #43
0
 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('ExpressionAPI'):
         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': 'ExpressionAPI',
             'method': 'please_never_use_it_in_production',
             'method_params': []
         }],
         'authenticated':
         1
     })
     cls.wsURL = cls.cfg['workspace-url']
     cls.wsClient = workspaceService(cls.wsURL)
     suffix = int(time.time() * 1000)
     cls.wsName = "test_exprAPI_FEM_test_ws_" + str(suffix)
     cls.wsClient.create_workspace({'workspace': cls.wsName})
     cls.serviceImpl = ExpressionAPI(cls.cfg)
     cls.scratch = cls.cfg['scratch']
     cls.callback_url = os.environ['SDK_CALLBACK_URL']
     cls.dfu = DataFileUtil(cls.callback_url)
     cls.ws_id = cls.dfu.ws_name_to_id(cls.wsName)
     cls.serviceWizardURL = cls.cfg['srv-wiz-url']
     print "### serviceWizardURL = {0}".format(cls.serviceWizardURL)
     cls.gaa = GenomeAnnotationAPI(cls.serviceWizardURL)
     cls.setupdata()
コード例 #44
0
    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('PanGenomeAPI'):
            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': 'PanGenomeAPI',
                'method': 'please_never_use_it_in_production',
                'method_params': []
            }],
            'authenticated':
            1
        })
        cls.wsURL = cls.cfg['workspace-url']
        cls.wsClient = workspaceService(cls.wsURL)
        cls.serviceImpl = PanGenomeAPI(cls.cfg)
        cls.scratch = cls.cfg['scratch']
        shutil.rmtree(cls.scratch)
        os.mkdir(cls.scratch)
        cls.callback_url = os.environ['SDK_CALLBACK_URL']

        suffix = int(time.time() * 1000)
        wsName = "test_pangenome_api_" + str(suffix)
        cls.ws_info = cls.wsClient.create_workspace({'workspace': wsName})
        cls.gcs = GenomeComparisonSDK(cls.callback_url)
        cls.gaa = GenomeAnnotationAPI(cls.callback_url)
        cls.prepare_data()
コード例 #45
0
def _align_protein_sequences(meth, feature_set, alignment_method, out_msa):
    """Construct multiple sequence alignment object based on set of proteins. [27]

    :param feature_set: An object with protein features [27.1]
    :type feature_set: kbtypes.KBaseSearch.FeatureSet
    :ui_name feature_set: Feture Set Object
    :param alignment_method: name of alignment method (one of Muscle, Clustal, ProbCons, T-Coffee, Mafft), leave it blank for default Clustal method [27.2]
    :type alignment_method: kbtypes.Unicode
    :ui_name alignment_method: Multiple Alignment Method
    :param out_msa: Multiple sequence alignment object ID. If empty, an ID will be chosen randomly. [27.3]
    :type out_msa: kbtypes.KBaseTrees.MSA
    :ui_name out_msa: Output MSA ID
    :return: Preparation message
    :rtype: kbtypes.Unicode
    :output_widget: kbaseMSA
    """
    if not alignment_method:
        alignment_method = 'Clustal'
    if not out_msa:
        out_msa = "msa_" + ''.join([chr(random.randrange(0, 26) + ord('A')) for _ in xrange(8)])
    meth.stages = 1
    token, workspace = meth.token, meth.workspace_id
    ws = workspaceService(service.URLS.workspace, token=token)
    elements = ws.get_objects([{'ref': workspace+'/'+feature_set}])[0]['data']['elements']
    gene_sequences = {}
    for key in elements:
        elem = elements[key]['data']
        id = elem['id']
        if 'genome_ref' in elem:
            genome_obj_name = ws.get_object_info([{'ref' : elem['genome_ref']}],0)[0][1]
            id = genome_obj_name + '/' + id
        seq = elements[key]['data']['protein_translation']
        gene_sequences[id] = seq
    treeClient = KBaseTrees(url = service.URLS.trees, token = token)
    construct_multiple_alignment_params = {
        'gene_sequences': gene_sequences,                                  
        'alignment_method': alignment_method, 
        'out_workspace': workspace, 
        'out_msa_id': out_msa 
    }
    job_id = treeClient.construct_multiple_alignment(construct_multiple_alignment_params)
    return json.dumps({'workspaceID': workspace, 'msaID': out_msa, 'jobID' : job_id})
コード例 #46
0
 def setUpClass(cls):
     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('kb_uploadmethods'):
         cls.cfg[nameval[0]] = nameval[1]
     authServiceUrl = cls.cfg.get(
         'auth-service-url',
         "https://kbase.us/services/authorization/Sessions/Login")
     auth_client = _KBaseAuth(authServiceUrl)
     cls.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':
         cls.user_id,
         'provenance': [{
             'service': 'kb_uploadmethods',
             'method': 'please_never_use_it_in_production',
             'method_params': []
         }],
         'authenticated':
         1
     })
     cls.wsURL = cls.cfg['workspace-url']
     cls.wsClient = workspaceService(cls.wsURL, token=cls.token)
     cls.serviceImpl = kb_uploadmethods(cls.cfg)
     cls.dfu = DataFileUtil(os.environ['SDK_CALLBACK_URL'], token=cls.token)
     cls.scratch = cls.cfg['scratch']
     cls.shockURL = cls.cfg['shock-url']
     cls.ftp_domain = socket.gethostbyname(socket.gethostname())
     cls.ftp_port = 21
     thread = threading.Thread(target=cls.start_ftp_service,
                               args=(cls.ftp_domain, cls.ftp_port))
     thread.daemon = True
     thread.start()
     time.sleep(5)
コード例 #47
0
 def setUpClass(cls):
     token = environ.get('KB_AUTH_TOKEN', None)
     cls.callback_url = os.environ['SDK_CALLBACK_URL']
     cls.ctx = {'token': token}
     config_file = environ.get('KB_DEPLOYMENT_CONFIG', None)
     cls.cfg = {}
     config = ConfigParser()
     config.read(config_file)
     for nameval in config.items('kb_cummerbund'):
         cls.cfg[nameval[0]] = nameval[1]
     cls.scratch = cls.cfg['scratch']
     cls.wsURL = cls.cfg['ws_url']
     cls.gfu = GenomeFileUtil(cls.callback_url)
     cls.ru = ReadsUtils(cls.callback_url)
     cls.rau = ReadsAlignmentUtils(cls.callback_url, service_ver='dev')
     cls.eu = ExpressionUtils(cls.callback_url, service_ver='dev')
     cls.wsClient = workspaceService(cls.wsURL, token=token)
     cls.dfu = DataFileUtil(cls.callback_url, token=token)
     cls.serviceImpl = kb_cummerbund(cls.cfg)
     cls.prepare_data()
コード例 #48
0
    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('kb_cutadapt'):
            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': 'kb_cutadapt',
                             'method': 'please_never_use_it_in_production',
                             'method_params': []
                             }],
                        'authenticated': 1})
        cls.wsURL = cls.cfg['workspace-url']
        cls.shockURL = cls.cfg['shock-url']
        cls.handleURL = cls.cfg['handle-service-url']
        cls.serviceWizardURL = cls.cfg['service-wizard-url']

        cls.wsClient = workspaceService(cls.wsURL, token=token)
        cls.serviceImpl = kb_cutadapt(cls.cfg)

        # setup data at the class level for now (so that the code is run
        # once for all tests, not before each test case.  Not sure how to
        # do that outside this function..)
        suffix = int(time.time() * 1000)
        wsName = "test_SetAPI_" + str(suffix)
        ret = cls.wsClient.create_workspace({'workspace': wsName})
        cls.wsName = wsName

        # handle files in test
        """
コード例 #49
0
    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('kb_MaSuRCA'):
            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': 'MaSuRCA',
                'method': 'please_never_use_it_in_production',
                'method_params': []
            }],
            'authenticated':
            1
        })
        cls.wsURL = cls.cfg['workspace-url']
        cls.wsClient = workspaceService(cls.wsURL)
        cls.serviceImpl = kb_MaSuRCA(cls.cfg)
        cls.scratch = cls.cfg['scratch']
        cls.callback_url = os.environ['SDK_CALLBACK_URL']

        cls.masurca_PROJECT_DIR = 'masurca_outputs'
        cls.scratch = cls.cfg['scratch']
        if not os.path.exists(cls.scratch):
            os.makedirs(cls.scratch)
        cls.masurca_prjdir = os.path.join(cls.scratch, cls.masurca_PROJECT_DIR)
        cls.masurca_assembler = MaSuRCA_Assembler(cls.cfg, cls.ctx.provenance)
        cls.masurca_utils = masurca_utils(cls.masurca_prjdir, cls.cfg)
コード例 #50
0
    def setUpClass(cls):

        cls.token = environ.get('KB_AUTH_TOKEN')
        cls.callbackURL = environ.get('SDK_CALLBACK_URL')
        print('CB URL: ' + cls.callbackURL)
        # 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,
            'provenance': [{
                'service': 'kb_IDBA',
                '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('kb_IDBA'):
            cls.cfg[nameval[0]] = nameval[1]
        cls.wsURL = cls.cfg['workspace-url']
        cls.shockURL = cls.cfg['shock-url']
        cls.hs = HandleService(url=cls.cfg['handle-service-url'],
                               token=cls.token)
        cls.wsClient = workspaceService(cls.wsURL, token=cls.token)
        wssuffix = int(time.time() * 1000)
        wsName = "test_kb_IDBA" + str(wssuffix)
        cls.wsinfo = cls.wsClient.create_workspace({'workspace': wsName})
        print('created workspace ' + cls.getWsName())
        cls.serviceImpl = kb_IDBA(cls.cfg)
        cls.readUtilsImpl = ReadsUtils(cls.callbackURL, token=cls.token)
        cls.staged = {}
        cls.nodes_to_delete = []
        cls.handles_to_delete = []
        cls.setupTestData()
        print('\n\n=============== Starting tests ==================')
コード例 #51
0
def view_phenotype(meth, phenotype_set_id):
    """Bring up a detailed view of your Phenotype Simulation results within the narrative. 
    
    :param phenotype_set_id: the phenotype results to view
    :type phenotype_set_id: kbtypes.KBasePhenotypes.PhenotypeSimulationSet
    :ui_name phenotype_set_id: Phenotype Simulation Set
    
    :return: Phenotype Simulation Set Data
    :rtype: kbtypes.KBasePhenotypes.PhenotypeSimulationSet
    :output_widget: kbaseSimulationSet
    """
    meth.stages = 2  # for reporting progress
    meth.advance("Starting...")
    
    #grab token and workspace info, setup the client
    userToken, workspaceName = meth.token, meth.workspace_id;
    meth.advance("Loading the phenotype simulation results")
    
    ws = workspaceService(service.URLS.workspace, token=userToken)

    return json.dumps({'ws': meth.workspace_id, 'name' : phenotype_set_id})    
コード例 #52
0
def create_app_for_njs(workspace, token, URLS, appId, stepSpecs, methIdToSpec, paramValues):
    steps = []
    app = { 'name' : appId,'steps' : steps }
    wsClient = workspaceService(URLS.workspace, token=token)
    scriptApp = False
    for stepSpec in stepSpecs:
        methodId = stepSpec['method_id']
        methodSpec = methIdToSpec[methodId]
        if is_script_method(methodSpec):
            scriptApp = True
            break
    for stepSpec in stepSpecs:
        stepId = stepSpec['step_id']
        methodId = stepSpec['method_id']
        methodSpec = methIdToSpec[methodId]
        methodInputValues = extract_param_values(paramValues, stepId)
        step = create_app_step(workspace, token, wsClient, methodSpec, methodInputValues, stepId, scriptApp)
        if step is None:
            continue
        steps.append(step)
    return app
コード例 #53
0
 def setUpClass(cls):
     token = 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 = environ.get('KB_DEPLOYMENT_CONFIG', None)
     cls.cfg = {}
     config = ConfigParser()
     config.read(config_file)
     for nameval in config.items('GenomeFileUtil'):
         cls.cfg[nameval[0]] = nameval[1]
     cls.wsURL = cls.cfg['workspace-url']
     cls.wsClient = workspaceService(cls.wsURL, token=token)
     cls.serviceImpl = GenomeFileUtil(cls.cfg)
コード例 #54
0
    def featureset_protein_sequence(self, ctx, workspace_name, featureset_id):
        # ctx is the context object
        # return variables are: returnVal
        #BEGIN featureset_protein_sequence

        returnVal = []

        # create workspace client
        token = ctx['token']
        ws = workspaceService(self.workspaceURL, token=token)

        # Build genome2Features hash
        genome2Features = self.buildGenome2Features(ws, workspace_name,
                                                    featureset_id)

        # Process each genome one by one
        for genomeRef in genome2Features:
            genome = ws.get_objects([{'ref': genomeRef}])[0]['data']
            featureIds = genome2Features[genomeRef]
            for feature in genome['features']:
                for fId in featureIds:
                    if fId == feature['id']:
                        returnVal.append({
                            'feature_id':
                            fId,
                            'genome_ref':
                            genomeRef,
                            'sequence':
                            feature['protein_translation']
                        })

        #END featureset_protein_sequence

        # At some point might do deeper type checking...
        if not isinstance(returnVal, list):
            raise ValueError(
                'Method featureset_protein_sequence return value ' +
                'returnVal is not type list as required.')
        # return the results
        return [returnVal]
コード例 #55
0
    def get_fastq_ea_utils_stats(self, ctx, input_params):
        """
        This function should be used for getting statistics on read library object types 
        The results are returned as a string.
        :param input_params: instance of type
           "get_fastq_ea_utils_stats_params" (if read_library_ref is set,
           then workspace_name and read_library_name are ignored) ->
           structure: parameter "workspace_name" of String, parameter
           "read_library_name" of String, parameter "read_library_ref" of
           String
        :returns: instance of String
        """
        # ctx is the context object
        # return variables are: ea_utils_stats
        #BEGIN get_fastq_ea_utils_stats
        token = ctx['token']
        wsClient = workspaceService(self.workspaceURL)
        # add additional info to provenance here, in this case the input data object reference
        input_reads_ref = self.get_reads_ref_from_params(input_params)

        info = None
        readLibrary = None
        try:
            readLibrary = wsClient.get_objects2({'objects':[{'ref': input_reads_ref}]})['data'][0]
            info = readLibrary['info']
            readLibrary = readLibrary['data']
        except Exception as e:
            raise ValueError('Unable to get read library object from workspace: (' + input_reads_ref + ')' + str(e))

        ea_utils_stats = ''
        ea_utils_stats = self.get_ea_utils_result(input_reads_ref, input_params)

        #END get_fastq_ea_utils_stats

        # At some point might do deeper type checking...
        if not isinstance(ea_utils_stats, basestring):
            raise ValueError('Method get_fastq_ea_utils_stats return value ' +
                             'ea_utils_stats is not type basestring as required.')
        # return the results
        return [ea_utils_stats]
コード例 #56
0
    def setUpClass(cls):
        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('kb_ke_util'):
            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': 'kb_ke_util',
                             'method': 'please_never_use_it_in_production',
                             'method_params': []
                             }],
                        'authenticated': 1})
        cls.shockURL = cls.cfg['shock-url']
        cls.wsURL = cls.cfg['workspace-url']
        cls.wsClient = workspaceService(cls.wsURL)
        cls.serviceImpl = kb_ke_util(cls.cfg)
        cls.scratch = cls.cfg['scratch']
        cls.callback_url = os.environ['SDK_CALLBACK_URL']

        cls.dfu = DataFileUtil(cls.callback_url)
        cls.cfg['KB_AUTH_TOKEN'] = cls.token
        cls.ke_util = KnowledgeEngineUtil(cls.cfg)

        suffix = int(time.time() * 1000)
        cls.wsName = "test_kb_ke_apps_" + str(suffix)
        cls.wsClient.create_workspace({'workspace': cls.wsName})

        cls.nodes_to_delete = []
        cls.prepare_data()
コード例 #57
0
 def setUpClass(cls):
     token = environ.get('KB_AUTH_TOKEN', None)
     cls.ctx = {
         'token':
         token,
         'provenance': [{
             'service': 'MegaHitTest',
             '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('MegaHitTest'):
         cls.cfg[nameval[0]] = nameval[1]
     cls.wsURL = cls.cfg['workspace-url']
     cls.wsClient = workspaceService(cls.wsURL, token=token)
     cls.serviceImpl = MegaHitTest(cls.cfg)
コード例 #58
0
    def _save_report(self, base_report_name, report_obj, provenance, ws_name, token):
        """
        Raises the usual exceptions if there's a failure while saving.
        """
        wsClient = workspaceService(self.workspaceURL, token=token)

        report_name = '{}_{}'.format(base_report_name, str(hex(uuid.getnode())))
        report_info_list = None
        report_info_list = wsClient.save_objects({
            'workspace': ws_name,
            'objects': [
                {
                    'type': 'KBaseReport.Report',
                    'data': report_obj,
                    'name': report_name,
                    'meta': {},
                    'hidden': 1, # important!  make sure the report is hidden
                    'provenance': provenance
                }
            ]
        })
        return report_info_list[0]