当前位置: 首页>>代码示例>>Python>>正文


Python Workspace.get_objects方法代码示例

本文整理汇总了Python中biokbase.workspace.client.Workspace.get_objects方法的典型用法代码示例。如果您正苦于以下问题:Python Workspace.get_objects方法的具体用法?Python Workspace.get_objects怎么用?Python Workspace.get_objects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在biokbase.workspace.client.Workspace的用法示例。


在下文中一共展示了Workspace.get_objects方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: associateReads

# 需要导入模块: from biokbase.workspace.client import Workspace [as 别名]
# 或者: from biokbase.workspace.client.Workspace import get_objects [as 别名]
 def associateReads(self, ctx, params):
     # ctx is the context object
     # return variables are: returnVal
     # BEGIN associateReads
     user_token = ctx["token"]
     ws_client = Workspace(url=self.__WS_URL, token=user_token)
     out = dict()
     out["metadata"] = {
         k: v
         for k, v in params.iteritems()
         if not k in ("ws_id", "analysis_id", "genome_id", "singleend_sample", "pairedend_sample") and v is not None
     }
     self.__LOGGER.info("Uploading RNASeqSample {0}".format(out["metadata"]["sample_id"]))
     if "genome_id" in params and params["genome_id"] is not None:
         out["metadata"]["genome_id"] = script_util.get_obj_info(
             self.__LOGGER, self.__WS_URL, [params["genome_id"]], params["ws_id"], user_token
         )[0]
     if "analysis_id" in params and params["analysis_id"] is not None:
         g_ref = script_util.get_obj_info(
             self.__LOGGER, self.__WS_URL, [params["analysis_id"]], params["ws_id"], user_token
         )[0]
         out["analysis_id"] = g_ref
     if "singleend_sample" in params and params["singleend_sample"] is not None:
         try:
             s_res = ws_client.get_objects([{"name": params["singleend_sample"], "workspace": params["ws_id"]}])
             out["singleend_sample"] = s_res[0]["data"]
             print out["singleend_sample"]
         except Exception, e:
             raise KBaseRNASeqException(
                 "Error Downloading SingleEndlibrary object from the workspace {0},{1}".format(
                     params["singleend_sample"], e
                 )
             )
开发者ID:r2sunita,项目名称:KBaseRNASeq,代码行数:35,代码来源:KBaseRNASeqImpl.py

示例2: get_object_uid

# 需要导入模块: from biokbase.workspace.client import Workspace [as 别名]
# 或者: from biokbase.workspace.client.Workspace import get_objects [as 别名]
def get_object_uid(name):
    WS_URL = "https://ci.kbase.us/services/ws/"
    from biokbase.workspace.client import Workspace

    ws = Workspace(WS_URL)
    info = ws.get_objects([dict(workspace=os.environ["KB_WORKSPACE_ID"], name=name)])[0]["info"]
    return "%s/%s/%s" % (info[6], info[0], info[4])
开发者ID:aitatanit,项目名称:metatlas,代码行数:9,代码来源:kbase_utils.py

示例3: TophatCall

# 需要导入模块: from biokbase.workspace.client import Workspace [as 别名]
# 或者: from biokbase.workspace.client.Workspace import get_objects [as 别名]
    def TophatCall(self, ctx, params):
        # ctx is the context object
        # return variables are: returnVal
        # BEGIN TophatCall
        ws_client = Workspace(url=self.__WS_URL, token=user_token)
        hs = HandleService(url=self.__HS_URL, token=user_token)
        try:
            ### Make a function to download the workspace object  and prepare dict of genome ,lib_type

            self.__LOGGER.info("Downloading RNASeq Sample file")
            try:
                ret = ws_client.get_objects(
                    [
                        {"name": params["sample_id"], "workspace": params["ws_id"]},
                        {"name": params["reference"], "workspace": params["ws_id"]},
                        {"name": params["bowtie_index"], "workspace": params["ws_id"]},
                        {"name": params["annotation_gtf"], "workspace": params["ws_id"]},
                    ]
                )
            except Exception, e:
                raise KBaseRNASeqException("Error Downloading objects from the workspace ")

                # Download reads from the JSON object
            genome = params["reference"]
            if "data" in reads:
                # if 'metadata' in reads['data']:
                # genome = reads['data']['metadata']['ref_genome']
                if "singleend_sample" in reads["data"]:
                    lib_type = "SingleEnd"
                    # cmdstring =
                elif "pairedend_sample" in reads["data"]:
                    lib_type = "PairedEnd"
开发者ID:r2sunita,项目名称:KBaseRNASeq,代码行数:34,代码来源:KBaseRNASeqImpl.py

示例4: get_object_from_ref

# 需要导入模块: from biokbase.workspace.client import Workspace [as 别名]
# 或者: from biokbase.workspace.client.Workspace import get_objects [as 别名]
def get_object_from_ref(ref):
    objid = int(ref.split("/")[1])
    WS_URL = "https://ci.kbase.us/services/ws/"
    from biokbase.workspace.client import Workspace

    ws = Workspace(WS_URL)
    return ws.get_objects([dict(workspace=os.environ["KB_WORKSPACE_ID"], objid=objid)])[0]["data"]
开发者ID:aitatanit,项目名称:metatlas,代码行数:9,代码来源:kbase_utils.py

示例5: get_probanno

# 需要导入模块: from biokbase.workspace.client import Workspace [as 别名]
# 或者: from biokbase.workspace.client.Workspace import get_objects [as 别名]
    def get_probanno(self, ctx, input):
        # ctx is the context object
        # return variables are: output
        #BEGIN get_probanno
        ''' Convert a probabilistic annotation object into a human-readbable table.

            @param ctx Current context object
            @param input Dictionary with input parameters for function
            @return Dictionary keyed by gene to a list of tuples with roleset and likelihood
            @raise WrongVersionError when ProbAnno object version number is invalid
        '''

        input = self._checkInputArguments(ctx, input,
                                          ['probanno', 'probanno_workspace'],
                                          { 'probanno_version': None }
                                          )

        wsClient = Workspace(self.config["workspace_url"], token=ctx['token'])
        probAnnoObjectId = make_object_identity(input["probanno_workspace"], input["probanno"], input['probanno_version'])
        objectList = wsClient.get_objects( [ probAnnoObjectId ] )
        probAnnoObject = objectList[0]
        if probAnnoObject['info'][2] != ProbAnnoType:
            message = 'ProbAnno object type %s is not %s for object %s' %(probAnnoObject['info'][2], ProbAnnoType, probAnnoObject['info'][1])
            ctx.log_err(message)
            raise WrongVersionError(message)
        output = probAnnoObject["data"]["roleset_probabilities"]

        #END get_probanno

        # At some point might do deeper type checking...
        if not isinstance(output, dict):
            raise ValueError('Method get_probanno return value ' +
                             'output is not type dict as required.')
        # return the results
        return [output]
开发者ID:kbase,项目名称:probabilistic_annotation,代码行数:37,代码来源:Impl.py

示例6: download_workspace_data

# 需要导入模块: from biokbase.workspace.client import Workspace [as 别名]
# 或者: from biokbase.workspace.client.Workspace import get_objects [as 别名]
def download_workspace_data(ws_url, source_ws, source_obj, working_dir,
                            logger):
    ws = Workspace(ws_url, token=TOKEN)
    objdata = ws.get_objects([{'ref': source_ws + '/' + source_obj}])[0]
    info = objdata['info']
    if info[2].split('-')[0] != 'KBaseFile.AssemblyFile':
        raise ValueError(
            'This method only works on the KBaseFile.AssemblyFile type')
    shock_url = objdata['data']['assembly_file']['file']['url']
    shock_id = objdata['data']['assembly_file']['file']['id']
    ref = str(info[6]) + '/' + str(info[0]) + '/' + str(info[4])
    source = objdata['data'].get('source')

    outfile = os.path.join(working_dir, source_obj)
    shock_node = shock_url + '/node/' + shock_id + '/?download'
    headers = {'Authorization': 'OAuth ' + TOKEN}
    with open(outfile, 'w') as f:
        response = requests.get(shock_node, stream=True, headers=headers)
        if not response.ok:
            try:
                err = json.loads(response.content)['error'][0]
            except:
                logger.error("Couldn't parse response error content: " +
                             response.content)
                response.raise_for_status()
            raise Exception(str(err))
        for block in response.iter_content(1024):
            if not block:
                break
            f.write(block)

    return shock_url, shock_id, ref, source
开发者ID:brettin,项目名称:transform,代码行数:34,代码来源:trns_transform_KBaseFile_AssemblyFile_to_KBaseGenomes_ContigSet.py

示例7: fetch_narrative

# 需要导入模块: from biokbase.workspace.client import Workspace [as 别名]
# 或者: from biokbase.workspace.client.Workspace import get_objects [as 别名]
def fetch_narrative(nar_id, auth_token, url=ci_ws, file_name=None):
    """
    Fetches a Narrative object with the given reference id (of the form ##/##).
    If a file_name is given, then it is printed to that file.
    If the narrative is found, the jsonized string of it is returned.

    If nothing is found, an empty Dict is returned.
    """
    ws_client = Workspace(url=url, token=auth_token)
    nar_data = ws_client.get_objects([{'ref':nar_id}])
    if len(nar_data) > 0:
        nar_json = json.dumps(nar_data[0])
        if file_name is not None:
            f = open(file_name, 'w')
            f.write(nar_json)
            f.close()
        return nar_json
    return {}
开发者ID:danielolson5,项目名称:narrative,代码行数:20,代码来源:narrative_test_helper.py

示例8: test_annotate

# 需要导入模块: from biokbase.workspace.client import Workspace [as 别名]
# 或者: from biokbase.workspace.client.Workspace import get_objects [as 别名]
    def test_annotate(self):
        ''' Run pa-annotate on a valid Genome object and verify that the job runs and returns a valid ProbAnno object in the expected time.'''

        # Run the annotate() function to generate a ProbAnno object.
        paClient = ProbabilisticAnnotation(self._config["probanno_url"], token=self._token)
        jobid = paClient.annotate( {
            "genome": self._config["genomeid"],
            "genome_workspace": self._config["test_ws"],
            "probanno": self._config["probannoid"],
            "probanno_workspace": self._config["test_ws"] } )
        
        # Allow time for the command to run.
        time.sleep(float(self._config["runtime"]))
        
        # Make sure the job has completed.
        ujsClient = UserAndJobState(self._config['ujs_url'], token=self._token)
        jobList = ujsClient.list_jobs([ self._config['test_user'] ], 'CE')
        jobCompleted = False
        for job in jobList:
            if jobid == job[0]:
                jobCompleted = True
                jobInfo = job
        self.assertTrue(jobCompleted, 'Job did not complete before timeout of %s seconds' %(self._config['runtime']))
        
        # See if the job ended in error.
        details = ''
        if jobInfo[11] == 1:
            details = ujsClient.get_detailed_error(jobInfo[0])
        self.assertEqual(jobInfo[11], 0, 'Job ended in error: %s' %(details))

        # Look for the ProbAnno object in the test workspace.
        wsClient = Workspace(self._config["workspace_url"], token=self._token)
        try:
            probannoObjectId = { 'workspace': self._config['test_ws'], 'name': self._config['probannoid'] }
            objectList = wsClient.get_objects( [ probannoObjectId ] )
            probannoObject = objectList[0]
            self.assertEqual(probannoObject['info'][1], self._config['probannoid'], 'ProbAnno object id %s is not %s' %(probannoObject['info'][1], self._config['probannoid']))
        except WorkspaceServerError as e:
            traceback.print_exc(file=sys.stderr)
            self.fail(msg = "The expected object %s did not get created in the workspace %s!\n" %(self._config["probannoid"], self._config["test_ws"]))
开发者ID:kbase,项目名称:probabilistic_annotation,代码行数:42,代码来源:test-python-client.py

示例9: test_calculate

# 需要导入模块: from biokbase.workspace.client import Workspace [as 别名]
# 或者: from biokbase.workspace.client.Workspace import get_objects [as 别名]
 def test_calculate(self):
     ''' Run pa-calculate on a valid ProbAnno object and verify that the job runs and returns a valid RxnProbs object.'''
     
     # Run the calculate() function to generate a RxnProbs object.
     paClient = ProbabilisticAnnotation(self._config["probanno_url"], token=self._token)
     rxnprobsMetadata = paClient.calculate( {
         "probanno":           self._config["probannoid"],
         "probanno_workspace": self._config["test_ws"],
         "rxnprobs":           self._config["rxnprobsid"],
         "rxnprobs_workspace": self._config["test_ws"] 
         } )
      
     # Look for the RxnProbs object in the test workspace.
     wsClient = Workspace(self._config["workspace_url"], token=self._token)
     try:
         rxnprobsObjectId = { 'workspace': self._config['test_ws'], 'name': self._config['rxnprobsid'] }
         objectList = wsClient.get_objects( [ rxnprobsObjectId ] )
         rxnprobsObject = objectList[0]
         self.assertEqual(rxnprobsObject['info'][1], self._config['rxnprobsid'], 'RxnProbs object id %s is not %s' %(rxnprobsObject['info'][1], self._config['rxnprobsid']))
     except WorkspaceServerError as e:
         traceback.print_exc(file=sys.stderr)
         self.fail(msg = "The expected object %s did not get created in the workspace %s!\n" %(self._config["rxnprobsid"], self._config["test_ws"]))
开发者ID:kbase,项目名称:probabilistic_annotation,代码行数:24,代码来源:test-python-client.py

示例10: get_rxnprobs

# 需要导入模块: from biokbase.workspace.client import Workspace [as 别名]
# 或者: from biokbase.workspace.client.Workspace import get_objects [as 别名]
    def get_rxnprobs(self, ctx, input):
        # ctx is the context object
        # return variables are: output
        #BEGIN get_rxnprobs
        ''' Convert a reaction probability object into a human-readable table.

            @param ctx Current context object
            @param input Dictionary with input parameters for function
            @return List of reaction_probability tuples
            @raise WrongVersionError when RxnProbs object version number is invalid
        '''

        # Sanity check on input arguments
        input = self._checkInputArguments(ctx, input, 
                                          [ "rxnprobs", "rxnprobs_workspace" ], 
                                          { 'rxnprobs_version': None, 'sort_field': 'rxnid' }
                                          )

        wsClient = Workspace(self.config["workspace_url"], token=ctx['token'])
        rxnProbsObjectId = make_object_identity(input["rxnprobs_workspace"], input["rxnprobs"], input['rxnprobs_version'])
        objectList = wsClient.get_objects( [ rxnProbsObjectId ] )
        rxnProbsObject = objectList[0]
        if rxnProbsObject['info'][2] != RxnProbsType:
            message = 'RxnProbs object type %s is not %s for object %s' %(rxnProbsObject['info'][2], RxnProbsType, rxnProbsObject['info'][1])
            ctx.log_err(message)
            raise WrongVersionError(message)
        output = rxnProbsObject["data"]["reaction_probabilities"]
        if input['sort_field'] == 'rxnid':
            output.sort(key=lambda tup: tup[0])
        elif input['sort_field'] == 'probability':
            output.sort(key=lambda tup: tup[1], reverse=True)
        #END get_rxnprobs

        # At some point might do deeper type checking...
        if not isinstance(output, list):
            raise ValueError('Method get_rxnprobs return value ' +
                             'output is not type list as required.')
        # return the results
        return [output]
开发者ID:kbase,项目名称:probabilistic_annotation,代码行数:41,代码来源:Impl.py

示例11: generate_cummerbund_plots

# 需要导入模块: from biokbase.workspace.client import Workspace [as 别名]
# 或者: from biokbase.workspace.client.Workspace import get_objects [as 别名]
    def generate_cummerbund_plots(self, ctx, cummerbundParams):
        # ctx is the context object
        # return variables are: returnVal
        #BEGIN generate_cummerbund_plots

        params    = cummerbundParams
        returnVal = params['ws_cummerbund_output']

        #Set up workspace client
        user_token = ctx['token']
        ws_client  = Workspace(url=self.__WS_URL, token=user_token)

        #Read the input cuffdiff workspace object json file and get filehandle for cuffdiff tar file
        s_res = ws_client.get_objects([{
            'name' : params['ws_cuffdiff_id'],
            'workspace' : params['workspace_name']
            }])

        # Check if workspace has data
        if len(s_res) == 0:
            self.__LOGGER.info("Workspace did not return any objects")
            return returnVal

        cuffdiff_dir = script_util2.extract_cuffdiff_data (self.__LOGGER, self.__SHOCK_URL, self.__SCRATCH, s_res, user_token)
        self.__LOGGER.info("Cuffdiff folder = " + cuffdiff_dir)

        if (cuffdiff_dir is False):
            return returnVal

        # Run R script to run cummerbund json and update the cummerbund output json file
        # Prepare output object.
        outputobject=dict()

        # Prepare output plot list
        cummerbundplotset=[]

        # List of plots to generate
        plotlist = [
                { 'file': "dispersionplot.R",
                  'title': "Dispersion plot",
                  'description': "Dispersion plot is the quality measure of the data. It estimates deviation from threshold against counts in FPKM." },


                { 'file': "fpkmscvplot.R",
                  'title': "Genes CV plot",
                  'description': "The squared coefficient of variation plot is a normalized measure of cross-replicate variability that can be useful for evaluating the quality of RNA-seq data." },

                { 'file': "isoformscvplot.R",
                  'title': "Isoform CV plot",
                  'description': "The squared coefficient of variation plot is a normalized measure of cross-replicate variability that can be useful for evaluating the quality of RNA-seq data.Differences in CV2 can result in lower numbers of differentially expressed isoforms due to a higher degree of variability between replicate fpkm estimates." },

                { 'file': "densityplot.R",
                  'title': "Density plot",
                  'description': "The density plot shows the distribution of FPKM scores across samples" },

                { 'file': "csdensityrepplot.R",
                  'title': "Replicates density plot",
                  'description': "The replicates density plot shows the distribution of FPKM scores across sample replicates" },

                { 'file': "boxplot.R",
                  'title': "Box plots",
                  'description': "The box plots show the FPKM distribution across samples." },

                { 'file': "boxrepplot.R",
                  'title': "Box plots of replicates",
                  'description': "The box plots of replicates show the FPKM distribution across sample replicates." },

                { 'file': "pairwisescatterplots.R",
                  'title': "Pairwise scatter plots",
                  'description': "The scatterplots show differences in gene expression between two samples. If two samples are identical, all genes will fall on the mid-line." },

                 { 'file': "volcanomatrixplot.R",
                  'title': "Volcano matrix plots",
                  'description': "Volcano matrix plot is a scatter plot that also identifies differentially expressed genes (by color) between samples based on log2 fold change cut off." },

                { 'file': "pcaplot.R",
                  'title': "PCA plot",
                  'description': "Principal Component Analysis (PCA) is an informative approach for dimensionality reduction for exploring teh relationship between sample conditions." },

                { 'file': "pcarepplot.R",
                  'title': "PCA plot including replicates",
                  'description': "Principal Component Analysis (PCA) is an informative approach for dimensionality reduction for exploring teh relationship between sample conditions including replicates." },

                { 'file': "mdsplot.R",
                  'title': "Multi-dimensional scaling plot",
                  'description': "Multi-dimensional scaling plots are similar to PCA plots and useful for determining the major sources of variation in the dataset. " },

                { 'file': "mdsrepplot.R",
                  'title': "Multi-dimensional scaling plot including replicates",
                  'description': "Multi-dimensional scaling plot including replicates are  similar to PCA plots and useful for determining the major sources of variation in the dataset with replicates. These can be useful to determine any systematic bias that may be present between conditions." }
            ]

#TODO.. Giving Rplot.pdf
#                { 'file': "dendrogramplot.R",
#                  'title': "Dendrogram",
#                  'description': "Dendrogram  based on the JS (Jensen-Shannon divergence) distance" },
#
#                { 'file': "dendrogramrepplot.R",
#                  'title': "Dendrogram including replicates",
#                  'description': "Dendrogram including replicates based on the JS (Jensen-Shannon divergence) distance" },
#.........这里部分代码省略.........
开发者ID:srividya22,项目名称:kb_cummerbund,代码行数:103,代码来源:kb_cummerbundImpl.py

示例12: create_interactive_heatmap_de_genes

# 需要导入模块: from biokbase.workspace.client import Workspace [as 别名]
# 或者: from biokbase.workspace.client.Workspace import get_objects [as 别名]
    def create_interactive_heatmap_de_genes(self, ctx, interactiveHeatmapParams):
        # ctx is the context object
        # return variables are: returnVal
        #BEGIN create_interactive_heatmap_de_genes
        fparams    = interactiveHeatmapParams
        #returnVal = "ttt"
        #Set up workspace client
        user_token = ctx['token']
        workspace = fparams['workspace_name']
        ws_client  = Workspace(url=self.__WS_URL, token=user_token)
        system_params = {}
        system_params['token'] = user_token
        system_params['ws_url'] =  self.__WS_URL
        system_params['logger'] =  self.__LOGGER
        system_params['shock_url'] =  self.__SHOCK_URL
        system_params['hs_url'] =  self.__HS_URL
        system_params['scratch'] =  self.__SCRATCH
        system_params['rscripts'] =  self.__RSCRIPTS
        system_params['workspace'] = workspace






        #Read the input cuffdiff workspace object json file and get filehandle for cuffdiff tar file
        s_res = ws_client.get_objects([{
            'name' : fparams['ws_cuffdiff_id'],
            'workspace' : fparams['workspace_name']
            }])

         #Check if workspace has data
        if len(s_res) == 0:
            self.__LOGGER.info("Workspace did not return any objects")
            return returnVal
        cuffdiff_dir = join (self.__SCRATCH , "cuffdiffData/cuffdiff")
        cuffdiff_dir = script_util2.extract_cuffdiff_data (self.__LOGGER, self.__SHOCK_URL, self.__SCRATCH, s_res, user_token)
        #cuffdiff_dir = "/kb/module/work/nnc/cuffdiff"
        self.__LOGGER.info("Cuffdiff folder = " + cuffdiff_dir)


        #if (cuffdiff_dir is False):
        #    return returnVal
        fparams['cuffdiff_dir'] = cuffdiff_dir
        fparams['infile'] = join (cuffdiff_dir, "gene_exp.diff")
        fparams['outfile'] = join(system_params['scratch'],  "gene_exp.diff.filter")

        filtered_matrix = script_util2.filter_expression_matrix(fparams, system_params)
        self.__LOGGER.info("matrix is " + filtered_matrix)

        fparams['infile'] = join (system_params['scratch'], "gene_exp.diff.filter")
        fparams['outfile'] = join(system_params['scratch'],  "gene_exp.diff.filter.genelist")



        genelist_filtered_matrix_file = script_util2.get_gene_list_from_filter_step(fparams)


        # Prepare output object.
        outjson = False;
 

        rparams = {}
        rparams['genelist'] = filtered_matrix
        rparams['cuffdiff_dir'] = fparams['cuffdiff_dir']
        rparams['outpng'] = join (system_params['scratch'], "heatmap.png")
        rparams['imageheight'] = 1600
        rparams['imagewidth'] = 800
        rparams['plotscript'] = join(system_params['rscripts'], "heatmapplotinteractive.R")
        rparams['include_replicates'] = 1
        rparams['outmatrix'] = join (system_params['scratch'], "outmatrix")

        roptstr_basic_heatmap_rep = script_util2.get_command_line_heatmap_basic (rparams)

        # Run R script to run cummerbund json and update the cummerbund output json file
        # Prepare output object.
        outputobject=dict()




        # Prepare output plot list
        cummerbundplotset=[]

        # List of plots to generate
        plotlist = [
                  
                { 'roptstr': roptstr_basic_heatmap_rep,
                  'title': "Heatmap",
                  'description': "Heatmap", 
                  'exp' : fparams['ws_expression_matrix_id']
                  }

            ]
        fparams['cummerbundplotset'] = cummerbundplotset
        # Iterate through the plotlist and generate the images and json files.
        for plot in plotlist:
            fparams['title'] = plot['title']
            fparams['description'] = plot['description']

#.........这里部分代码省略.........
开发者ID:srividya22,项目名称:kb_cummerbund,代码行数:103,代码来源:kb_cummerbundImpl.py

示例13: create_expression_matrix

# 需要导入模块: from biokbase.workspace.client import Workspace [as 别名]
# 或者: from biokbase.workspace.client.Workspace import get_objects [as 别名]
    def create_expression_matrix(self, ctx, expressionMatrixParams):
        # ctx is the context object
        # return variables are: returnVal
        #BEGIN create_expression_matrix


        params    = expressionMatrixParams
        returnVal = params['ws_expression_matrix_id']
        #Set up workspace client
        user_token = ctx['token']
        workspace = params['workspace_name']
        ws_client  = Workspace(url=self.__WS_URL, token=user_token)

        #Read the input cuffdiff workspace object json file and get filehandle for cuffdiff tar file
        s_res = ws_client.get_objects([{
            'name' : params['ws_cuffdiff_id'],
            'workspace' : params['workspace_name']
            }])

        # Check if workspace has data
        if len(s_res) == 0:
            self.__LOGGER.info("Workspace did not return any objects")
            return returnVal

        cuffdiff_dir = join (self.__SCRATCH , "cuffdiffData/cuffdiff")
        cuffdiff_dir = script_util2.extract_cuffdiff_data (self.__LOGGER, self.__SHOCK_URL, self.__SCRATCH, s_res, user_token)
        self.__LOGGER.info("Cuffdiff folder = " + cuffdiff_dir)

        if (cuffdiff_dir is False):
            return returnVal

        # Run R script to get fpkmgenematrix.R

        # Prepare output object.
        outjson = False;
        #outjson = "repfpkmgenematrix.R.matrix.txt.json";

        if params['include_replicates'] ==0:
         scriptfile = "fpkmgenematrix.R"
         outjson = script_util2.generate_and_upload_expression_matrix(self.__LOGGER, self.__SCRATCH,
                    self.__RSCRIPTS, scriptfile, self.__SHOCK_URL, self.__HS_URL, user_token,
                    cuffdiff_dir, self.__WS_URL,workspace)


        else:
         scriptfile = "repfpkmgenematrix.R"
         outjson = script_util2.generate_and_upload_expression_matrix(self.__LOGGER, self.__SCRATCH,
                    self.__RSCRIPTS, scriptfile, self.__SHOCK_URL, self.__HS_URL, user_token,
                    cuffdiff_dir, self.__WS_URL,workspace)

        if outjson is False:
            self.__LOGGER.info("Creation of expression matrix failed")
            return returnVal
        with open("{0}/{1}".format(self.__SCRATCH , outjson),'r') as et:
                  eo = json.load(et)
        eo['type']='untransformed'
        genome_ref = s_res[0]['data']['genome_id']
        #eo['genome_ref'] = genome_ref

        self.__LOGGER.info(workspace + self.__SCRATCH + outjson + params['ws_expression_matrix_id'])
        ws_client.save_objects({'workspace' : workspace,
            'objects' : [{ 'type' : 'KBaseFeatureValues.ExpressionMatrix',
                           'data' : eo,
                           'name' : params['ws_expression_matrix_id']
                        }]})


        #END create_expression_matrix

        # At some point might do deeper type checking...
        if not isinstance(returnVal, basestring):
            raise ValueError('Method create_expression_matrix return value ' +
                             'returnVal is not type basestring as required.')
        # return the results
        return [returnVal]
开发者ID:srividya22,项目名称:kb_cummerbund,代码行数:77,代码来源:kb_cummerbundImpl.py

示例14: generate_cummerbund_plots

# 需要导入模块: from biokbase.workspace.client import Workspace [as 别名]
# 或者: from biokbase.workspace.client.Workspace import get_objects [as 别名]
    def generate_cummerbund_plots(self, ctx, cummerbundParams):
        # ctx is the context object
        # return variables are: returnVal
        #BEGIN generate_cummerbund_plots

        params    = cummerbundParams
        returnVal = params['ws_cummerbund_output']

        #Set up workspace client
        user_token = ctx['token']
        ws_client  = Workspace(url=self.__WS_URL, token=user_token)

        #Read the input cuffdiff workspace object json file and get filehandle for cuffdiff tar file
        s_res = ws_client.get_objects([{
            'name' : params['ws_cuffdiff_id'],
            'workspace' : params['workspace_name']
            }])

        # Check if workspace has data
        if len(s_res) == 0:
            self.__LOGGER.info("Workspace did not return any objects")
            return returnVal

        # Get input data Shock Id and Filename.
        cuffdiff_shock_id = s_res[0]['data']['file']['id']
        cuffdiff_file_name = s_res[0]['data']['file']['file_name']

        #cuffdiff_file_name =None 
        filesize = None

        # Download tar file
        dx = script_util.download_file_from_shock( self.__LOGGER, 
            self.__SHOCK_URL, cuffdiff_shock_id, cuffdiff_file_name,
            self.__SCRATCH, filesize, user_token)
    
        #Decompress tar file and keep it in a directory
        tarfile = join(self.__SCRATCH, cuffdiff_file_name)
        dstnExtractFolder = join(self.__SCRATCH, "cuffdiffData")
        if not os.path.exists(dstnExtractFolder):
            os.makedirs(dstnExtractFolder)

        untarStatus = script_util2.untar_files(self.__LOGGER, tarfile, dstnExtractFolder)
        if untarStatus == False:
            self.__LOGGER.info("Problem extracting the archive")
            return returnVal

        foldersinExtractFolder = os.listdir(dstnExtractFolder)

        if len(foldersinExtractFolder) == 0:
            self.__LOGGER.info("Problem extracting the archive")
            return returnVal

        # Run R script to run cummerbund json and update the cummerbund output json file
        cuffdiff_dir = join(dstnExtractFolder, foldersinExtractFolder[0])
	self.__LOGGER.info("Cuffdiff folder = " + cuffdiff_dir)

        # Prepare output object.
        outputobject=dict()

        # Prepare output plot list
        cummerbundplotset=[]

        # List of plots to generate
        plotlist = [
                { 'file': "dispersionplot.R",
                  'title': "Dispersion plot",
                  'description': "Dispersion plot" },
                { 'file': "pcaplot.R",
                  'title': "PCA plot",
                  'description': "PCA plot" },
                { 'file': "fpkmscvplot.R",
                  'title': "FPKM SCV plot",
                  'description': "FPKM SCV plot" }
            ]

        # Iterate through the plotlist and generate the images and json files.
        for plot in plotlist:
            status = script_util2.rplotandupload(self.__LOGGER, self.__SCRATCH, self.__RSCRIPTS,
                plot['file'], self.__SHOCK_URL, self.__HS_URL, user_token,
                cummerbundplotset, plot['title'], plot['description'], cuffdiff_dir)
            if status == False:
                self.__LOGGER.info("Problem generating image and json file - " + plot["file"])


        # Populate the output object
        outputobject['cummerbundplotSet'] = cummerbundplotset

        #TODO: Need to figure out how to get rnaseq experiment id
        outputobject['rnaseq_experiment_id'] = "rnaseq_experiment_id"
        outputobject['cuffdiff_input_id'] = params['ws_cuffdiff_id']

        res = ws_client.save_objects({
            "workspace":params['workspace_name'],
            "objects": [{
                "type":"KBaseRNASeq.cummerbund_output",
                "data":outputobject,
                "name":params["ws_cummerbund_output"]}]
            })

        #END generate_cummerbund_plots
#.........这里部分代码省略.........
开发者ID:r2sunita,项目名称:kb_cummerbund,代码行数:103,代码来源:kb_cummerbundImpl.py

示例15: filter_genes

# 需要导入模块: from biokbase.workspace.client import Workspace [as 别名]
# 或者: from biokbase.workspace.client.Workspace import get_objects [as 别名]
    def filter_genes(self, ctx, args):
        # ctx is the context object
        # return variables are: result
        #BEGIN filter_genes
        try:
            os.makedirs(self.RAWEXPR_DIR)
        except:
            pass
        try:
            os.makedirs(self.FLTRD_DIR)
        except:
            pass
        try:
            os.makedirs(self.FINAL_DIR)
        except:
            pass
 
        if self.logger is None:
            self.logger = script_utils.stderrlogger(__file__)
        
        result = {}
        self.logger.info("Starting conversion of KBaseFeatureValues.ExpressionMatrix to TSV")
        token = ctx['token']
 
        eenv = os.environ.copy()
        eenv['KB_AUTH_TOKEN'] = token

        param = args
 
 
        from biokbase.workspace.client import Workspace
        ws = Workspace(url=self.__WS_URL, token=token)
        expr = ws.get_objects([{'workspace': param['workspace_name'], 'name' : param['object_name']}])[0]['data']
 
 
        cmd_dowload_cvt_tsv = [self.FVE_2_TSV, '--workspace_service_url', self.__WS_URL, 
                                          '--workspace_name', param['workspace_name'],
                                          '--object_name', param['object_name'],
                                          '--working_directory', self.RAWEXPR_DIR,
                                          '--output_file_name', self.EXPRESS_FN
                              ]
 
        # need shell in this case because the java code is depending on finding the KBase token in the environment
        #  -- copied from FVE_2_TSV
        tool_process = subprocess.Popen(" ".join(cmd_dowload_cvt_tsv), stderr=subprocess.PIPE, shell=True, env=eenv)
        stdout, stderr = tool_process.communicate()
        
        if stdout is not None and len(stdout) > 0:
            self.logger.info(stdout)
 
        if stderr is not None and len(stderr) > 0:
            self.logger.info(stderr)
 
        self.logger.info("Identifying differentially expressed genes")
 
        ## Prepare sample file
        # detect num of columns
        with open("{0}/{1}".format(self.RAWEXPR_DIR, self.EXPRESS_FN), 'r') as f:
          fl = f.readline()
        ncol = len(fl.split('\t'))
        
        # force to use ANOVA if the number of sample is two
        if(ncol == 3): param['method'] = 'anova'
 
        with open("{0}/{1}".format(self.RAWEXPR_DIR, self.SAMPLE_FN), 'wt') as s:
          s.write("0")
          for j in range(1,ncol-1):
            s.write("\t{0}".format(j))
          s.write("\n")
 
 
        ## Run coex_filter
        cmd_coex_filter = [self.COEX_FILTER, '-i', "{0}/{1}".format(self.RAWEXPR_DIR, self.EXPRESS_FN), '-o', "{0}/{1}".format(self.FLTRD_DIR, self.FLTRD_FN),
                           '-m', param['method'], '-s', "{0}/{1}".format(self.RAWEXPR_DIR, self.SAMPLE_FN),
                           '-x', "{0}/{1}".format(self.RAWEXPR_DIR, self.GENELST_FN), '-t', 'y']
        if 'num_features' in param:
          cmd_coex_filter.append("-n")
          cmd_coex_filter.append(str(param['num_features']))
 
        if 'p_value' in param:
          cmd_coex_filter.append("-p")
          cmd_coex_filter.append(str(param['p_value']))
 
        if 'p_value' not in param and 'num_features' not in param:
          self.logger.error("One of p_value or num_features must be defined");
          return empty_results("One of p_value or num_features must be defined", expr,self.__WS_URL, param, self.logger, ws)
          #sys.exit(2) #TODO: No error handling in narrative so we do graceful termination
 
        #if 'p_value' in param and 'num_features' in param:
        #  self.logger.error("Both of p_value and num_features cannot be defined together");
        #  sys.exit(3)
 
        tool_process = subprocess.Popen(cmd_coex_filter, stderr=subprocess.PIPE)
        stdout, stderr = tool_process.communicate()
        
        if stdout is not None and len(stdout) > 0:
            self.logger.info(stdout)
 
        if stderr is not None and len(stderr) > 0:
            self.logger.info(stderr)
#.........这里部分代码省略.........
开发者ID:dcchivian,项目名称:coexpression,代码行数:103,代码来源:CoExpressionImpl.py


注:本文中的biokbase.workspace.client.Workspace.get_objects方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。