HomeGuidesRecipesAPI EndpointsRelease NotesCommunity
Log In

Uploading CSV Ontologies

Creating a CSV or another table-based ontology requires an extra step. First, you'll upload your ontology as a table and then create an ontology from the table. We'll start, as before, by instantiating our API class and data provider.

Instantiating The SourceDocumentApi

Everything we'll be covering in this tutorial uses the SourceDocumentApi, so we will only need to instantiate that one. Similarly to Uploading OBO and OWL ontologies we want to make sure we are only providing our Layar instance as a data provider to avoid any permission errors.

documents = layar_api.SourceDocumentApi(client)
providers = 'my_instance.vyasa.com'

Uploading Your Table

Before we can convert our table to an ontology, we need to upload it to Layar with the create_document method. This method will return a Layar Source Document object which we will store the ID of to use when converting it to an ontology.

table = documents.create_document(x-vyasa-data-providers=providers, file='./my_table.csv', name='My Ontology Table', cortex_document_type: 'TABLE')
table_id = table.id

Create an Ontology From Your Table

Now that you have your table uploaded we can use the document ID from the response to create an ontology from it. First, let's define some variables to organize our ontology structure.

  • name - The name for your new ontology (required)
  • id - Select the column from your table that you would like to use to assign the term IDs (required)
  • label - Select the column from your table that you would like to use to assign the term labels (required)
  • synonyms - Select the column(s), as a list, that you would like to use to assign your term synonyms
  • properties - Select the column(s), as a list, that you would like to use to assign your term properties
  • delimiter - Finally, if any of the columns selected for the above properties uses delimiters to define a list in a cell, define that delimiter here. We typically suggest not using a comma (,) or hyphen (-) delimiter in your ontologies, as those are regularly used in nomenclature as part of your term (e.g., caffeine is also known as "1,3,7-Trimethylpurine-2,6-dione". If you assigned a comma delimiter, you'd get synonyms "1", "3", 7-Trimethylpurine-2", etc.

🚧

Check Your Column Names

Remember columns are zero-indexed. This means the first column will be column_0_string followed by column_1_string and so forth. Make sure when you are selecting the columns from your table that you are following this convention and not using the column headers in the document.

name = 'My New Ontology'
term_id = 'column_0_string'
label = 'column_1_string'
synonyms = ['column_2_string']
properties = ['column_3_string', 'column_4_string']
delimiter = ' | '

Now we are ready to create our ontology! When assigning your parameters, make sure to enter your table ID first and without a key, followed by the rest of your parameters with keys.

ontology = documents.create_table_ontology(table_id, name=name, id=term_id, label=label, synonyms=synonyms, properties=properties, delimiter=delimiter)
# Print returned Layar object (optional)
pprint(ontology)