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


Python Workspace.save_objects方法代码示例

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


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

示例1: test_loadGenome

# 需要导入模块: from biokbase.workspace.client import Workspace [as 别名]
# 或者: from biokbase.workspace.client.Workspace import save_objects [as 别名]
    def test_loadGenome(self):
        ''' Load a test Genome object into the test workspace. '''
        
        # Create the test workspace.
        wsClient = Workspace(self._config["workspace_url"], token=self._token)
        try:
            # See if the workspace exists.
            wsInfo = wsClient.get_workspace_info( { "workspace": self._config["test_ws"] } )
        except WorkspaceServerError as e:
            # Hopefully this means the workspace does not exist. (It could also mean someone messed up setting up the URLs)
            traceback.print_exc(file=sys.stderr)
            wsInfo = wsClient.create_workspace( { "workspace": self._config["test_ws"] } )

        # We also need to put in a mapping and a biochemistry object somewhere.
        # To do this, I just create a "dependency workspace" and pull them from there.
        try:
            # See if the workspace exists.
            wsInfo = wsClient.get_workspace_info( { "workspace": self._config["dependency_ws"] } )
        except WorkspaceServerError as e:
            # Hopefully this means the workspace does not exist. (It could also mean someone messed up setting up the URLs)
#            traceback.print_exc(file=sys.stderr)
            depWsInfo = wsClient.create_workspace( { "workspace": self._config["dependency_ws"] } )

        # Load the mapping and biochemistry objects
        testContigSet = json.load(open(self._config['contigset_file'], 'r'))
        contigSetSaveData = dict()
        contigSetSaveData['type'] = 'KBaseGenomes.ContigSet'
        contigSetSaveData['name'] = self._config['contigsetid']
        contigSetSaveData['data'] = testContigSet        
        testGenome = json.load(open(self._config["genome_file"], "r"))
        genomeSaveData = dict()
        genomeSaveData['type'] = 'KBaseGenomes.Genome'
        genomeSaveData['name'] = self._config['genomeid']
        genomeSaveData['data'] = testGenome
        wsClient.save_objects( { 'workspace': self._config['test_ws'], 'objects': [ genomeSaveData, contigSetSaveData ] } )
开发者ID:kbase,项目名称:probabilistic_annotation,代码行数:37,代码来源:test-python-client.py

示例2: handler

# 需要导入模块: from biokbase.workspace.client import Workspace [as 别名]
# 或者: from biokbase.workspace.client.Workspace import save_objects [as 别名]
def handler (args) :
    ###
    # download ws object and convert them to csv
    wsd = Workspace(url=args.ws_url, token=os.environ.get('KB_AUTH_TOKEN'))
    indata = wsd.get_object({'id' : args.inobj_id,
                  #'type' : 'KBaseExpression.ExpressionSeries', 
                  'workspace' : args.ws_id})['data']

    if indata is None:
        raise Exception("Object {} not found in workspace {}".format(args.inobj_id, args.ws_id))


    ###
    # execute filtering
    flt_cmd_lst = ['mys_example', "-i", "{}-{}".format(os.getpid(),args.exp_fn) ]
    if (args.method     is not None): 
        flt_cmd_lst.append('-m')
        flt_cmd_lst.append(args.method)
    if (args.p_value    is not None): 
        flt_cmd_lst.append('-p')
        flt_cmd_lst.append(args.p_value)
    if (args.num_genes  is not None): 
        flt_cmd_lst.append('-n')
        flt_cmd_lst.append(args.num_genes)
    if (args.flt_out_fn is not None): 
        flt_cmd_lst.append('-o')
        flt_cmd_lst.append("{}-{}".format(os.getpid(),args.flt_out_fn))

    p1 = Popen(flt_cmd_lst, stdout=PIPE)
    out_str = p1.communicate()
    # print output message for error tracking
    if out_str[0] is not None : print out_str[0]
    if out_str[1] is not None : print >> sys.stderr, out_str[1]
    flt_cmd = " ".join(flt_cmd_lst)
   
    ###
    # put it back to workspace
    #fif = open("{}-{}".format(os.getpid(),args.flt_out_fn), 'r')
    #fif.readline(); # skip header
    
    # assume only one genome id
    outdata = {}
    outdata['key'] = indata['key']
    outdata['value'] = "{}{}".format(indata['value'], indata['value'])
    data_list = []
    data_list.append({'type' : 'MyService.PairString', 'data' : outdata, 'name' : args.outobj_id, 'meta' : {'org.series' : args.inobj_id}})
    wsd.save_objects({'workspace' : args.ws_id, 'objects' : data_list})

    if(args.del_tmps is "true") :
        os.remove("{}-{}".format(os.getpid(), args.exp_fn))
        os.remove("{}-{}".format(os.getpid(), args.flt_out_fn))
开发者ID:sjyoo,项目名称:loader,代码行数:53,代码来源:upload_handler.py

示例3: upload_workspace_data

# 需要导入模块: from biokbase.workspace.client import Workspace [as 别名]
# 或者: from biokbase.workspace.client.Workspace import save_objects [as 别名]
def upload_workspace_data(cs, ws_url, source_ref, target_ws, obj_name):
    ws = Workspace(ws_url, token=TOKEN)
    type_ = ws.translate_from_MD5_types([CS_MD5_TYPE])[CS_MD5_TYPE][0]
    ws.save_objects(
        {'workspace': target_ws,
         'objects': [{'name': obj_name,
                      'type': type_,
                      'data': cs,
                      'provenance': [{'script': SCRIPT_NAME,
                                      'script_ver': __VERSION__,
                                      'input_ws_objects': [source_ref],
                                      }]
                      }
                     ]
         }
    )
开发者ID:brettin,项目名称:transform,代码行数:18,代码来源:trns_transform_KBaseFile_AssemblyFile_to_KBaseGenomes_ContigSet.py

示例4: create

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

        print('Creating KBase Report.')

        # check that the basic parameters are set
        if 'report' not in params:
            raise ValueError('Field "report" must be defined to save a report')
        if 'workspace_name' not in params:
            raise ValueError('Field "workspace_name" must be defined to save a report')

        # setup proper provenance for the report
        provenance = [{}]
        if 'provenance' in ctx:
            provenance = ctx['provenance']

        # generate a random report name
        reportName = 'report_'+str(uuid.uuid4())
        if 'prefix' in params:
            reportName = params['prefix'] + reportName


        print('Report Name' + reportName)

        # let any workspace errors just percolate up for now
        ws = Workspace(self.workspaceURL, token=ctx['token'])
        report_info = ws.save_objects({
                'workspace':params['workspace_name'],
                'objects':[
                    {
                        'type':'KBaseReport.Report',
                        'data':params['report'],
                        'name':reportName,
                        'meta':{},
                        'hidden':1,
                        'provenance':provenance
                    }
                ]
            })[0]

        info = {
            'ref'  : str(report_info[6]) + '/' + str(report_info[0]) + '/' + str(report_info[4]),
            'name' : report_info[1]
        }

        #END create

        # At some point might do deeper type checking...
        if not isinstance(info, dict):
            raise ValueError('Method create return value ' +
                             'info is not type dict as required.')
        # return the results
        return [info]
开发者ID:msneddon,项目名称:KBaseReport,代码行数:57,代码来源:OLD-KBaseReportImpl.py

示例5: upload_narrative

# 需要导入模块: from biokbase.workspace.client import Workspace [as 别名]
# 或者: from biokbase.workspace.client.Workspace import save_objects [as 别名]
def upload_narrative(nar_file, auth_token, user_id, url=ci_ws, set_public=False):
    """
    Uploads a Narrative from a downloaded object file.
    This file needs to be in JSON format, and it expects all
    data and info that is usually returned by the Workspace.get_objects
    method.

    Returns a dict of three elements:
        ws: the id of the workspace that was created
        obj: the id of the narrative object
        ref: the above two joined together into an object ref (for convenience)
    """

    # read the file
    f = open(nar_file, 'r')
    nar = json.loads(f.read())
    f.close()

    # do some setup.
    current_nar_metadata = ws_metadata
    current_nar_metadata['narrative_nice_name'] = nar['data']['metadata']['name']
    ws_client = Workspace(url=url, token=auth_token)

    # create the new workspace for the narrative
    ws_info = ws_client.create_workspace({
        'workspace': '{}:{}'.format(user_id, str(time.time()).replace('.', '')),
        'meta': current_nar_metadata,
        'globalread': 'r' if set_public else 'n'
    })
    ws_id = ws_info[0]

    # setup and save the narrative object
    metadata = nar['info'][10]
    ws_save_obj = {
        'type': 'KBaseNarrative.Narrative',
        'data': nar['data'],
        'name': nar['info'][1],
        'meta': nar['info'][10],
        'provenance': [{
            'script': 'upload_narrative_test.py',
            'description': 'Temporary Narrative uploaded for automated testing'
        }]
    }
    obj_info = ws_client.save_objects({'id': ws_id,
                                       'objects': [ws_save_obj]})

    # tweak the workspace's metadata to properly present its narrative
    ws_client.alter_workspace_metadata({'wsi': {'id': ws_id}, 'new': {'narrative': obj_info[0][0]}})
    return {
        'ws': ws_info[0],
        'obj': obj_info[0][0],
        'refstr': '{}/{}'.format(ws_info[0], obj_info[0][0]),
        'ref': NarrativeRef({'wsid': ws_info[0], 'objid': obj_info[0][0]})
    }
开发者ID:briehl,项目名称:narrative,代码行数:56,代码来源:util.py

示例6: save_ws_object

# 需要导入模块: from biokbase.workspace.client import Workspace [as 别名]
# 或者: from biokbase.workspace.client.Workspace import save_objects [as 别名]
def save_ws_object(obj):
    """Save an object to the workspace

    Parameters
    ----------
    obj : dict
        Object with the fields: type, data, and name.
        The type must be the full typespec
        (e.g. 'MetaboliteAtlas.Compound-0.3')

    Returns
    -------
    id : str
        Object workspace id
    """
    from biokbase.workspace.client import Workspace

    ws = Workspace(WS_URL)
    obj.setdefault("hidden", 0)
    wks = ws.list_workspaces({"excludeGlobal": 1})
    ws_id = [wk[-1] for wk in wks if wk[0] == os.environ["KB_WORKSPACE_ID"]][0]
    save_objects_params = {"id": ws_id, "objects": [obj]}
    return ws.save_objects(save_objects_params)[0][-2]
开发者ID:aitatanit,项目名称:metatlas,代码行数:25,代码来源:kbase_utils.py

示例7: SetupRNASeqAnalysis

# 需要导入模块: from biokbase.workspace.client import Workspace [as 别名]
# 或者: from biokbase.workspace.client.Workspace import save_objects [as 别名]
    def SetupRNASeqAnalysis(self, ctx, params):
        # ctx is the context object
        # return variables are: returnVal
        # BEGIN SetupRNASeqAnalysis
        user_token = ctx["token"]
        ws_client = Workspace(url=self.__WS_URL, token=user_token)
        out_obj = {k: v for k, v in params.iteritems() if not k in ("ws_id", "genome_id", "annotation_id") and v}
        pprint(out_obj)
        if "num_samples" in out_obj:
            out_obj["num_samples"] = int(out_obj["num_samples"])
        if "num_replicates" in out_obj:
            out_obj["num_replicates"] = int(out_obj["num_replicates"])
        if "genome_id" in params and params["genome_id"] is not None:
            out_obj["genome_id"] = script_util.get_obj_info(
                self.__LOGGER, self.__WS_URL, [params["genome_id"]], params["ws_id"], user_token
            )[0]
        if "annotation_id" in params and params["annotation_id"] is not None:
            g_ref = script_util.get_obj_info(
                self.__LOGGER, self.__WS_URL, [params["annotation_id"]], params["ws_id"], user_token
            )[0]
            out_obj["annotation_id"] = g_ref
        self.__LOGGER.info("Uploading RNASeq Analysis object to workspace {0}".format(out_obj["experiment_id"]))
        try:
            res = ws_client.save_objects(
                {
                    "workspace": params["ws_id"],
                    "objects": [
                        {"type": "KBaseRNASeq.RNASeqAnalysis", "data": out_obj, "name": out_obj["experiment_id"]}
                    ],
                }
            )
            returnVal = {"workspace": params["ws_id"], "output": out_obj["experiment_id"]}

        except Exception, e:
            raise KBaseRNASeqException(
                "Error Saving the object to workspace {0},{1}".format(out_obj["experiment_id"], e)
            )
开发者ID:r2sunita,项目名称:KBaseRNASeq,代码行数:39,代码来源:KBaseRNASeqImpl.py

示例8: run_filter_genes

# 需要导入模块: from biokbase.workspace.client import Workspace [as 别名]
# 或者: from biokbase.workspace.client.Workspace import save_objects [as 别名]

#.........这里部分代码省略.........
      cmd_coex_filter.append(param['num_features'])

    if 'num_features' not in param and 'p_value' in param:
      cmd_coex_filter.append("-p")
      cmd_coex_filter.append(param['p_value'])

    if 'p_value' not in param and 'num_features' not in param:
      logger.error("One of p_value or num_features must be defined");
      sys.exit(2)

    #if 'p_value' in param and 'num_features' in param:
    #  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:
        logger.info(stdout)

    if stderr is not None and len(stderr) > 0:
        logger.info(stderr)

    ## Header correction
    with open("{0}/{1}".format(FLTRD_DIR, FLTRD_FN), 'r') as ff:
        fe = ff.readlines()
    with open("{0}/{1}".format(FLTRD_DIR, FLTRD_FN), 'w') as ff:
        ff.write(fl) # use original first line that has correct header information
        fe.pop(0)
        ff.writelines(fe)
    

    ## Upload FVE
    from biokbase.workspace.client import Workspace
    ws = Workspace(url=workspace_service_url, token=os.environ['KB_AUTH_TOKEN'])
    expr = ws.get_objects([{'workspace': param['workspace_name'], 'name' : param['object_name']}])[0]['data']
    
    # change workspace to be the referenced object's workspace_name because it may not be in the same working ws due to referencing
    cmd_upload_expr = [TSV_2_FVE, '--workspace_service_url', workspace_service_url, 
                                      '--object_name', param['out_expr_object_name'],
                                      '--working_directory', FINAL_DIR,
                                      '--input_directory', FLTRD_DIR,
                                      '--output_file_name', FINAL_FN
                          ]
    tmp_ws = param['workspace_name']
    if 'genome_ref' in expr:
        cmd_upload_expr.append('--genome_object_name')
        obj_infos = ws.get_object_info_new({"objects": [{'ref':expr['genome_ref']}]})[0]

        if len(obj_infos) < 1:
            logger.error("Couldn't find {0} from the workspace".format(expr['genome_ref']))
            raise Exception("Couldn't find {0} from the workspace".format(expr['genome_ref']))

        cmd_upload_expr.append(obj_infos[1])
        tmp_ws = obj_infos[7]
        logger.info("{0} => {1} / {2}".format(expr['genome_ref'], tmp_ws, obj_infos[1]))

    # updated ws name
    cmd_upload_expr.append('--workspace_name')
    cmd_upload_expr.append(tmp_ws)

    tool_process = subprocess.Popen(" ".join(cmd_upload_expr), stderr=subprocess.PIPE, shell=True)
    stdout, stderr = tool_process.communicate()
    
    if stdout is not None and len(stdout) > 0:
        logger.info(stdout)

    if stderr is not None and len(stderr) > 0:
        logger.info(stderr)

    
    with open("{0}/{1}".format(FINAL_DIR,FINAL_FN),'r') as et:
      eo = json.load(et)

    if 'description' in expr: expr['description'] = "{0}, coex_filter by {1}".format(expr['description'], " ".join(cmd_coex_filter))
    if 'feature_mapping' in expr:
        expr['feature_mapping'] = eo['feature_mapping']
    expr['data'] = eo['data']

    ws.save_objects({'workspace' : param['workspace_name'], 'objects' : [{'type' : 'KBaseFeatureValues.ExpressionMatrix',
                                                                          'data' : expr,
                                                                          'name' : (param['out_expr_object_name'])}]})

    ## Upload FeatureSet
    fs ={'description':'Differentially expressed genes generated by {0}'.format(" ".join(cmd_coex_filter)),
         'elements': {}}
    
    with open("{0}/{1}".format(RAWEXPR_DIR, GENELST_FN),'r') as glh:
      gl = glh.readlines()
    gl = [x.strip('\n') for x in gl]

    for g in gl:
      if 'genome_ref' in expr:
        fs['elements'][g] = [expr['genome_ref']]
      else:
        fs['elements'][g] = []

    ws.save_objects({'workspace' : param['workspace_name'], 'objects' : [{'type' : 'KBaseCollections.FeatureSet',
                                                                          'data' : fs,
                                                                          'name' : (param['out_fs_object_name'])}]})
开发者ID:srividya22,项目名称:coexpression,代码行数:104,代码来源:njs-run-coex.py

示例9: filter_BlastOutput

# 需要导入模块: from biokbase.workspace.client import Workspace [as 别名]
# 或者: from biokbase.workspace.client.Workspace import save_objects [as 别名]
    def filter_BlastOutput(self, ctx, params):
        # ctx is the context object
        # return variables are: returnVal
        #BEGIN filter_BlastOutput
        user_token=ctx['token']
        ws_client=Workspace(url=self.__WS_URL, token=user_token)
        blast_outputs=ws_client.get_objects([{'name':params['in_id'], 
                                              'workspace': params['ws_id']}])

            

        fs ={'elements': {}}
        fs['description'] = "FeatureSet from BlastOutput by "
        printedEvalue = False
        printedEntries = False
        if 'evalue' in params and params['evalue'] != "":
            fs['description'] += " E-value:{0}".format(params['evalue'])
            printedEvalue = True
        if 'entries' in params and (params['entries'] != "" or params['entries'] > 0):
            if(printedEvalue): fs['description'] += ","
            fs['description'] += " # of entries :{0}".format(params['entries'])
            printedEntries = True
        if not printedEvalue and not printedEntries:
            fs['description'] += "no filtering"
        
        if len(blast_outputs) != 1:
            fs['description'] = "No such blast output object was found : {0}/{1}".format(param['workspace_name'], param['object_name'])
        else:
            fm = {}
            f2g = {}
            for boid in blast_outputs[0]['data']['BlastOutput_iterations']['Iteration']:
                for hitd in boid['Iteration_hits']['Hit']:
                    print hitd['Hit_def']
                    ali = hitd['Hit_def'].find('#')
                    if(ali < 0): next
                    fid = hitd['Hit_def'][0:ali]
                    gri = hitd['Hit_def'].find('#', ali+1)
                    if fid not in f2g: f2g[fid] = {}
                    if (gri >=  0 and not gri == (ali+1)): 
                        grid = hitd['Hit_def'][(ali+1):gri]
                        f2g[fid][grid] = 1
                    for hspd in hitd['Hit_hsps']['Hsp']:
                        if fid in fm:
                            if float(hspd['Hsp_evalue']) < fm[fid]:
                                fm[fid] = float(hspd['Hsp_evalue'])
                        else: fm[fid] = float(hspd['Hsp_evalue'])
           
            fms = sorted(fm.items(), key=lambda x: x[1], reverse=False)
            bol = len(fms)
            if params['entries'] != "" or int(params['entries']) > 0:
                if(int(params['entries']) < bol):
                    bol = int(params['entries'])
            for i in range(bol):
                if(fms[i][1] > float(params['evalue'])): break
                if fms[i][0] in f2g:
                    fs['elements'][fms[i][0]] = f2g[fms[i][0]].keys()
                else:
                    fs['elements'][fms[i][0]] = []

        ws_client.save_objects(
            {"workspace":params['ws_id'],
            "objects": [{
                "type":"KBaseCollections.FeatureSet",
                "data":fs,
                "name":params['out_id']}
            ]})

        #pprint(fs)
        returnVal = {'obj_name' : params['out_id'], 'ws_id' : params['ws_id']}

        #END filter_BlastOutput

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

示例10: generate_cummerbund_plots

# 需要导入模块: from biokbase.workspace.client import Workspace [as 别名]
# 或者: from biokbase.workspace.client.Workspace import save_objects [as 别名]

#.........这里部分代码省略.........
        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" },


        # 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

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

示例11: Workspace

# 需要导入模块: from biokbase.workspace.client import Workspace [as 别名]
# 或者: from biokbase.workspace.client.Workspace import save_objects [as 别名]
    
    kb_token = os.environ.get('KB_AUTH_TOKEN')
    wsd = Workspace(url=args.ws_url, token=kb_token)

    gids = [ re.sub(r"_ContigSet.jsonp$","", f) for f in listdir(".") if f.endswith("_ContigSet.jsonp")]


    ## main loop
    for gid in gids:
      # store contigset first
      jif = open("{}/{}_ContigSet.jsonp".format(".",gid, 'r'))
      data = json.loads(jif.read())
      jif.close()
      
      wsd.save_objects({'workspace':args.ws_id, 'objects' : [ {
        'type' : 'KBaseGenomes.ContigSet', 'data' : data, 'name' : "{}-{}_cs".format(args.outobj_id, gid), 
        'meta' : { 'source_id' : args.inobj_id, 'source_type' : args.etype,
                   'ujs_job_id' : args.jid} } ]})
      
      jif = open("{}/{}.jsonp".format(".",gid, 'r'))
      data = json.loads(jif.read())
      jif.close()
      
      data['contigset_ref'] = "{}/{}-{}_cs".format(args.ws_id,args.outobj_id, gid)


      wsd.save_objects({'workspace':args.ws_id, 'objects' : [ {
        'type' : 'KBaseGenomes.Genome', 'data' : data, 'name' : "{}-{}_gn".format(args.outobj_id, gid), 
        'meta' : { 'source_id' : args.inobj_id, 'source_type' : args.etype,
                   'ujs_job_id' : args.jid} } ]})

    exit(0);
开发者ID:mshatsky,项目名称:transform,代码行数:34,代码来源:trns_upload_KBaseGenomes.Genome.py

示例12: generate_cummerbund_plot2

# 需要导入模块: from biokbase.workspace.client import Workspace [as 别名]
# 或者: from biokbase.workspace.client.Workspace import save_objects [as 别名]

#.........这里部分代码省略.........
                { '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." }
            ]


        # 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'],
            "objects": [{
                "type":"KBaseRNASeq.cummerbund_output",
                "data":outputobject,
                "name":params["ws_cummerbund_output"]}]
            })

        infile =  join(cuffdiff_dir, "gene_exp.diff") 
        outfile = join(cuffdiff_dir, "gene_exp_diff.out") 
        x=v.volcano_plot_data_parse_and_upload(infile,outfile, genome_dict)
        with open(outfile) as f:
            statdata = json.load(f)
        res = ws_client.save_objects({
            "workspace":params['workspace'],
            "objects": [{
                "type":"KBaseRNASeq.DifferentialExpressionStat",
                "data":statdata,
                "name":params["ws_diffstat_output"]}]
            })

        #END generate_cummerbund_plot2

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

示例13: open

# 需要导入模块: from biokbase.workspace.client import Workspace [as 别名]
# 或者: from biokbase.workspace.client.Workspace import save_objects [as 别名]
    parser.add_argument('-o', '--out_id', help='Output workspace object name', action='store', dest='outobj_id', default=None, required=True)

    parser.add_argument('-l', '--support_dir', help='Support directory', action='store', dest='sdir', default='lib', required=True)
    parser.add_argument('-g', '--out_file', help='Output prefix or file name', action='store', dest='otmp', default='outfile', required=True)
    # for meta data
    parser.add_argument('-i', '--in_id', help='Input Shock node id for meta', action='store', dest='inobj_id', default='NotProvided', required=True)
    parser.add_argument('-e', '--ext_type', help='External object type', action='store', dest='etype', default=None, required=True)
    parser.add_argument('-j', '--job_id', help='UJS job id', action='store', dest='jid', default='NoJodID', required=False)

    usage = parser.format_usage()
    parser.description = desc1 + '      ' + usage + desc2
    parser.usage = argparse.SUPPRESS
    args = parser.parse_args()

    
    kb_token = os.environ.get('KB_AUTH_TOKEN')

    ## main loop
    jif = open("{}/{}".format(args.sdir,args.otmp, 'r'))
    data = json.loads(jif.read())
    jif.close()
    
    wsd = Workspace(url=args.ws_url, token=kb_token)
    wsd.save_objects({'workspace':args.ws_id, 'objects' : [ {
      'type' : 'Transform.Pair', 'data' : data, 'name' : args.outobj_id, 
      'meta' : { 'source_id' : args.inobj_id, 'source_type' : args.etype,
                 'ujs_job_id' : args.jid} } ]})
    

    exit(0);
开发者ID:brettin,项目名称:transform,代码行数:32,代码来源:trns_upload_Transform.Pair.py

示例14: Workspace

# 需要导入模块: from biokbase.workspace.client import Workspace [as 别名]
# 或者: from biokbase.workspace.client.Workspace import save_objects [as 别名]
from biokbase.workspace.client import Workspace
ws_client = Workspace()
ws_next_client = Workspace(url='https://next.kbase.us/services/ws')
a, b = ws_next_client.get_objects([{'objid' : '4', 'wsid' : '68'}, {'objid' : '5', 'wsid' : '68'}])[0:2]
a_params = {'type' : a['info'][2], 'data': a['data']}
b_params = {'type' : b['info'][2], 'data': b['data']}
ws_client.save_objects({'id': '9145', 'objects': [a_params, b_params]})

开发者ID:kingb12,项目名称:model-morphing,代码行数:9,代码来源:ws_getter.py

示例15: const_coex_net_clust

# 需要导入模块: from biokbase.workspace.client import Workspace [as 别名]
# 或者: from biokbase.workspace.client.Workspace import save_objects [as 别名]

#.........这里部分代码省略.........
        
        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)
            #raise Exception(stderr)
 
        self.logger.info("Coexpression clustering analysis")
 
        ## 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'))
        
        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_cluster
        cmd_coex_cluster = [self.COEX_CLUSTER, '-t', 'y',
                           '-i', "{0}/{1}".format(self.RAWEXPR_DIR, self.EXPRESS_FN), 
                           '-o', "{0}/{1}".format(self.CLSTR_DIR, self.CLSTR_FN), '-m', "{0}/{1}".format(self.CLSTR_DIR, self.CSTAT_FN) ]
 
        for p in ['net_method', 'minRsq', 'maxmediank', 'maxpower', 'clust_method', 'minModuleSize', 'detectCutHeight']:
           if p in param:
             cmd_coex_cluster.append("--{0}".format(p))
             cmd_coex_cluster.append(str(param[p]))
  
 
        #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_cluster, 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:
            if re.search(r'^There were \d+ warnings \(use warnings\(\) to see them\)', stderr):
              self.logger.info(stderr)
            else:
              self.logger.error(stderr)
              raise Exception(stderr)
 
        
        # build index for gene list
        pos_index ={expr['data']['row_ids'][i]: i for i in range(0, len(expr['data']['row_ids']))}
 
 
        # parse clustering results
        cid2genelist = {}
        cid2stat = {}
        with open("{0}/{1}".format(self.CLSTR_DIR, self.CSTAT_FN),'r') as glh:
            glh.readline() # skip header
            for line in glh:
                cluster, mcor, msec = line.rstrip().replace('"','').split("\t")
                cid2stat[cluster]= [mcor, msec]
        with open("{0}/{1}".format(self.CLSTR_DIR, self.CLSTR_FN),'r') as glh:
            glh.readline() # skip header
            for line in glh:
                gene, cluster = line.rstrip().replace('"','').split("\t")
                if cluster not in cid2genelist:
                    cid2genelist[cluster] = []
                cid2genelist[cluster].append(gene)
 
        if(len(cid2genelist) < 1) :
          self.logger.error("Clustering failed")
          return empty_results("Error: No cluster output", expr,self.__WS_URL, param, self.logger, ws)
          #sys.exit(4)
 
        self.logger.info("Uploading the results onto WS")
        feature_clusters = []
        for cluster in cid2genelist:
            feature_clusters.append( {"meancor": float(cid2stat[cluster][0]), "msec": float(cid2stat[cluster][0]), "id_to_pos" : { gene : pos_index[gene] for gene in cid2genelist[cluster]}})

        ## Upload Clusters
        feature_clusters ={"original_data": "{0}/{1}".format(param['workspace_name'],param['object_name']),
                           "feature_clusters": feature_clusters}
 
        ws.save_objects({'workspace' : param['workspace_name'], 'objects' : [{'type' : 'KBaseFeatureValues.FeatureClusters',
                                                                          'data' : feature_clusters,
                                                                          'name' : (param['out_object_name'])}]})
        result = {'workspace_name' : param['workspace_name'], 'out_object_name' : param['out_object_name']}
        #END const_coex_net_clust

        # At some point might do deeper type checking...
        if not isinstance(result, dict):
            raise ValueError('Method const_coex_net_clust return value ' +
                             'result is not type dict as required.')
        # return the results
        return [result]
开发者ID:dcchivian,项目名称:coexpression,代码行数:104,代码来源:CoExpressionImpl.py


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