HomeGuidesRecipesAPI EndpointsRelease NotesCommunity
Log In
Guides

Uploading OBO, OWL, or CSV ontologies

The /layar/sourceDocument API endpoints can allow us to upload OBO, OWL, or CSV files. We will then use the /layar/sourceDocument/{documentId}/extractTables to turn the Document into a Table. Once the Table is created, we will use /layar/sourceDocument/{tableId}/createOntology to create the Ontology from the Table.

Pre-Reqs

Before we can fill out the body we need to make sure that our calls to the API are authenticated. Make sure you are using your token variable that was made in Getting Your Authentication Token.

👍

Check Your Imported Modules

Make sure you have imported the requests and json module before proceeding with this guide.

Configuring Your Header

Unlike in previous sections, the header will be slightly different. Specifically, the Content-Type and Accept value needs to be multipart/form-data. As with previous sections, the X-Vyasa-Data-Providers dictates what data provider the ontology

header = {'Accept': 'multipart/form-data',
          'Content-Type': 'multipart/form-data',
          'Authorization': f"Bearer {token}",
          'X-Vyasa-Client': 'layar',
          'X-Vyasa-Data-Providers' : 'sandbox.certara.ai'}

Upload Your Document

A file variable will need to be filled out in order to use requests.post. You will need the path to the file you are uploading.

file = {
  			'file' :'PATH TO FILE HERE',
  			'name' : 'DESIRED NAME OF FILE'
       }

We will need the ID of the Document we uploaded, which will require us to use the JSON module with Requests to pull the id from the response.

uploadDocsUri = f'{envUrl}/layar/sourceDocument'

response = requests.post(uploadDocsUri, 
                         headers = header, 
                         files=files
                        )

documentId = response.json().get('id')
print(documentId) #optional

Turn Your Document into a Table

🚧

Double Check Your Header

Uploading a Document requires you use a Content-Type and Accept value of application/json inside of your header.

Now that we have the documentId we can use this to turn the Document into a Table. We will be using the /layar/sourceDocument/{documentId}/extractTables endpoint to do this. We do not need a body for this since the endpoint dictates all the information we need.

createTableUri = f'{envUrl}/layar/sourceDocument/{documentId}/extractTables'

response = requests.post(createTableUri, 
                         headers = header, 
                        )

tableId = response.json().get('id')
print(documentId) #optional

Turn Your Table into an Ontology

Now that we have the tableId we can utilize it and the /layar/sourceDocument/{tableId}/createOntology endpoint to create our Ontology. There are various values we need in our body variable in order to properly create the Ontology.

  • name - The name for your new ontology (required)
  • label - Select the column from your table that you would like to use to assign the term labels (required)
  • parent - If there is an existing Ontology that you want this Ontology to be under
  • 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.
body = {
 	'name': 'DESIRED TABLE NAME',
  'label': 'DESIRED LABEL NAME',
  'parent': 'DESIRED PARENT NAME', #Optional
  'synonyms': [
       'synonym1','synonym2'
              ],
       'properties': [
           'property1','property2'
                     ],
  'delimiter': 'DESIRED DELIMITER',
  'startRow': 0 #This will most likely be 0 unless there are undesired rows in the table.
       }

Once you have the body you can put together the requests.post to turn the Table into an Ontology.

createOntologyUri = f'{envUrl}/layar/sourceDocument/{tableId}/createOntology'

response = requests.post(createOntologyUri, 
                         headers = header, 
                         json = body
                        )

ontologyId = response.json().get('id')
print(ontologyId) #optional

Up Next

Now that we have an Ontology made, we can perform a search using those terms.