<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Example
of building a notebook-friendly object into the output of the data API
Author
Step1:  Authorization
In the vanilla notebook, you need to manually set an auth. token. You'll need your own value for this, of course.
Get this from the running narrative, e.g. write a narrative code cell that has
Step2:  Find and load an object
Open the workspace (1019) and get a Rhodobacter assembly from it
Step3:  Get the contigs for the assembly
This takes a while because the current implementation loads the whole assembly, not just the 300 or so strings with the contig values.
Step4:  View the contigs
The Contigs object wraps the list of contigs as a Pandas DataFrame (with the qgrid output enabled), so as you can see the plot() function is immediately available. The list of strings in the raw contig IDs is parsed to a set of columns and values for the DataFrame.
The default display is the nice sortable, scrollable, etc. table from the qgrid package.
<ASSISTANT_TASK:>
Python Code:
%matplotlib inline
import matplotlib.pyplot as plt
import qgrid
qgrid.nbinstall()
from biokbase import data_api
from biokbase.data_api import display
display.nbviewer_mode(True)
Explanation: Example
of building a notebook-friendly object into the output of the data API
Author: Dan Gunter
Initialization
Imports
Set up matplotlib, the qgrid (nice table), and import biokbase
End of explanation
import os
os.environ['KB_AUTH_TOKEN'] = open('/tmp/kb_auth_token.txt').read().strip()
Explanation: Authorization
In the vanilla notebook, you need to manually set an auth. token. You'll need your own value for this, of course.
Get this from the running narrative, e.g. write a narrative code cell that has:
import os; print(os.environ('KB_AUTH_TOKEN'))
End of explanation
b = data_api.browse(1019)
x = b[0].object # Assembly object
Explanation: Find and load an object
Open the workspace (1019) and get a Rhodobacter assembly from it
End of explanation
cid_strings = x.get_contig_ids() # 1 min
cids = display.Contigs(cid_strings)
Explanation: Get the contigs for the assembly
This takes a while because the current implementation loads the whole assembly, not just the 300 or so strings with the contig values.
End of explanation
from biokbase import data_api
from biokbase.data_api import display
list(b)
rg = b[0]
rgo = rg.object
type(rgo)
Explanation: View the contigs
The Contigs object wraps the list of contigs as a Pandas DataFrame (with the qgrid output enabled), so as you can see the plot() function is immediately available. The list of strings in the raw contig IDs is parsed to a set of columns and values for the DataFrame.
The default display is the nice sortable, scrollable, etc. table from the qgrid package.
End of explanation
<END_TASK>