# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

#
# ## Overview:   
# This notebook demonstrates how to leverage different data formats for OMXWare results for downstream analysis.
#

# +
# %matplotlib inline

import json
from IPython.display import display

import omxware


# --- Authentication options --- #
# generate token with OMXWare user name and password (likely done once and then stored in file, see usage below)
# token = omxware.get_token('harsha', '<pwd>') # fill in password to initiate token

# or

# use previously generated token loaded from file
token_path = "./omxware_collaborative_work/super_awesome_token"  # update for your path to the token file you create
f = open(token_path)
token = f.readline()

# provide your token to authenticate with OMXWare
omx = omxware.omxware(token)
# -

# ### Retrieve gene data from OMXWare as a Pandas Dataframe

# +
search_string = 'sporulation'
response = omx.genes(gene_name=search_string, page_size=25)

#total_results = response.total_results()
#print(total_results)

results_df = response.results(type='df')
results_df.head()
# -

# ### Distribution of Genes by Genera

response.show_facets(name='genera', topN=7)

# ### Retrieve gene data from OMXWare as JSON

results_json = response.results(type='json')
print(json.dumps(results_json[:3], indent=4, sort_keys=True))

# ### Retrieve gene data from OMXWare as an Object

# +
results_list = response.results(type='list')

# By default, the API returns a `list`
print("Returns: List of {} objects \nResults: {}\n".format(response.type(), response.total_results()) )
    
gene = results_list[0]
print("Id  \t\t=> " + gene.id())
print("Name   \t\t=> " + gene.name())
print("Sequence   \t=> " + gene.sequence()[:100] + "...")
print("Sequence length => " + str(gene.sequence_length()))

print("\n\n JSON:")
print(gene.json())
# -

# ### Retrieve gene data from OMXWare as FASTA

new_gene_object = omx.genes(ids='00054a98f8ddd95e3f46d9d757137284').results(type='fasta')
print(new_gene_object)

# ### Retrieve Gene query results as fasta

results_fasta = response.results(type='fasta')
print(results_fasta)



StarcoderdataJupyterScriptsDedupFiltered