def inv_session(self, line=None): """Return the current invocation session id, create one if necessary. Parameters are ignored """ global user_id, token, user_profile, inv_client, inv_session, endpoint if inv_client is None: if token is None: user_msg("You are not currently logged in. Using anonymous," " unauthenticated access") try: inv_client = InvocationClient( url = endpoint['invocation'], token = token) sess_id = "nrtv_" + str(int(time.time())) + "_" + ''.join(random.choice(string.hexdigits) for x in range(6)) inv_session = inv_client.start_session(sess_id) if inv_session == sess_id: user_msg("New anonymous session created : %s" % inv_session) else: user_msg("New authenticated session created " "for user %s" % user_id) except Exception, e: user_msg("Error initializing a new invocation service " "client: %s" % e)
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)
def _rm_file(f): token = os.environ["KB_AUTH_TOKEN"] invo = InvocationService(url=URLS.invocation, token=token) invo.remove_files("", "/", f) return
def _mv_file(old, new): token = os.environ["KB_AUTH_TOKEN"] invo = InvocationService(url=URLS.invocation, token=token) invo.rename_file("", "/", old, new) return
def _list_files(d): token = os.environ["KB_AUTH_TOKEN"] invo = InvocationService(url=URLS.invocation, token=token) _, files = invo.list_files("", "/", d) return files
def _run_invo(cmd): token = os.environ["KB_AUTH_TOKEN"] invo = InvocationService(url=URLS.invocation, token=token) stdout, stderr = invo.run_pipeline("", cmd, [], 0, "/") return "".join(stdout), "".join(stderr)
def _list_cmds(): token = os.environ["KB_AUTH_TOKEN"] invo = InvocationService(url=URLS.invocation, token=token) return invo.valid_commands()
def _rm_file(f): token = os.environ['KB_AUTH_TOKEN'] invo = InvocationService(url=URLS.invocation, token=token) invo.remove_files("", '/', f) return
def _mv_file(old, new): token = os.environ['KB_AUTH_TOKEN'] invo = InvocationService(url=URLS.invocation, token=token) invo.rename_file("", '/', old, new) return
def _list_files(d): token = os.environ['KB_AUTH_TOKEN'] invo = InvocationService(url=URLS.invocation, token=token) _, files = invo.list_files("", '/', d) return files
def _run_invo(cmd): token = os.environ['KB_AUTH_TOKEN'] invo = InvocationService(url=URLS.invocation, token=token) stdout, stderr = invo.run_pipeline("", cmd, [], 0, '/') return "".join(stdout), "".join(stderr)
def _list_cmds(): token = os.environ['KB_AUTH_TOKEN'] invo = InvocationService(url=URLS.invocation, token=token) return invo.valid_commands()