Programming Interface Application

Version 6.1 by maaike on 2022/06/23 16:33

Programmatic access (API)

The EBRAINS Knowledge Graph provides convenient tools and APIs for the implementation of queries into your scripts. 

Request permission

To be able to access the Knowledge Graph (KG) programmatically, you require:

  1. An EBRAINS account. Register for an account here: https://ebrains.eu/register/
  2. Register and request credentials for your KG client by emailing support@ebrains.eu

Query Builder

The query builder allows you to make, save, and reuse complex queries without any knowledge of graph query languages.

Go to the Query Builder: https://query.kg.ebrains.eu

Select a category

A query for the Knowledge Graph is always executed against a specific data structure (e.g. a "Dataset version"). First select the data structure for your query.

Step 1: Select a category

Select an experimental approach

Similar to the facetted filters in the Knowledge Graph Search UI, we can refine our query by defining the experimental approach of our interest, for example electrophysiology.

To ensure that all dataset versions with electrophysiology are queried, and none of the dataset versions without electrophysiology, we make this property required and we apply a filter to the label we are searching for (i.e. electrophysiology).

Step 2: Select modality

Select species

Similarly, we can refine our query for mice only.

Step 3: Select species

Access detailed metadata

Following 

Step 4: Access detailed metadata

The above query in the Query Builder is written below:

{
 "@context": {
   "@vocab": "https://core.kg.ebrains.eu/vocab/query/",
   "query": "https://schema.hbp.eu/myQuery/",
   "propertyName": {
     "@id": "propertyName",
     "@type": "@id"
    },
   "path": {
     "@id": "path",
     "@type": "@id"
    }
  },
 "meta": {
   "type": "https://openminds.ebrains.eu/core/DatasetVersion",
   "responseVocab": "https://schema.hbp.eu/myQuery/"
  },
 "structure": [
    {
     "propertyName": "query:experimentalApproach",
     "path": "https://openminds.ebrains.eu/vocab/experimentalApproach",
     "required": true,
     "structure": {
       "propertyName": "query:name",
       "path": "https://openminds.ebrains.eu/vocab/name",
       "required": true,
       "filter": {
         "op": "CONTAINS",
         "value": "electrophysiology"
        }
      }
    },
    {
     "propertyName": "query:studiedSpecimen",
     "path": "https://openminds.ebrains.eu/vocab/studiedSpecimen",
     "structure": [
        {
         "propertyName": "query:species",
         "path": "https://openminds.ebrains.eu/vocab/species",
         "required": true,
         "structure": [
            {
             "propertyName": "query:name",
             "path": "https://openminds.ebrains.eu/vocab/name"
            },
            {
             "propertyName": "query:species",
             "path": "https://openminds.ebrains.eu/vocab/species",
             "required": true,
             "structure": {
               "propertyName": "query:name",
               "path": "https://openminds.ebrains.eu/vocab/name",
               "required": true,
               "filter": {
                 "op": "CONTAINS",
                 "value": "mus musculus"
                }
              }
            }
          ]
        },
        {
         "propertyName": "query:lookupLabel",
         "path": "https://openminds.ebrains.eu/vocab/lookupLabel"
        },
        {
         "propertyName": "query:biologicalSex",
         "path": "https://openminds.ebrains.eu/vocab/biologicalSex",
         "structure": {
           "propertyName": "query:name",
           "path": "https://openminds.ebrains.eu/vocab/name",
           "required": true,
           "filter": {
             "op": "CONTAINS",
             "value": "male"
            }
          }
        },
        {
         "propertyName": "query:studiedState",
         "path": "https://openminds.ebrains.eu/vocab/studiedState",
         "structure": [
            {
             "propertyName": "query:lookupLabel",
             "path": "https://openminds.ebrains.eu/vocab/lookupLabel"
            },
            {
             "propertyName": "query:age",
             "path": "https://openminds.ebrains.eu/vocab/age",
             "structure": [
                {
                 "propertyName": "query:value",
                 "path": "https://openminds.ebrains.eu/vocab/value"
                },
                {
                 "propertyName": "query:unit",
                 "path": "https://openminds.ebrains.eu/vocab/unit",
                 "structure": {
                   "propertyName": "query:name",
                   "path": "https://openminds.ebrains.eu/vocab/name"
                  }
                }
              ]
            },
            {
             "propertyName": "query:ageCategory",
             "path": "https://openminds.ebrains.eu/vocab/ageCategory",
             "structure": {
               "propertyName": "query:name",
               "path": "https://openminds.ebrains.eu/vocab/name"
              }
            },
            {
             "propertyName": "query:attribute",
             "path": "https://openminds.ebrains.eu/vocab/attribute",
             "structure": {
               "propertyName": "query:name",
               "path": "https://openminds.ebrains.eu/vocab/name"
              }
            }
          ]
        }
      ]
    }
  ]
}