Any operation from the Emedgene's graphical user interface (GUI) can also be performed by using the Emedgene's API.
Following are some basic examples of how to use Emedgene's API with Python.
For instructions on using the API with other programming languages, please refer to their respective documentation.
An installed copy of Python (https://www.python.org/)
The Python package installer, pip (https://pip.pypa.io/)
The requests library installed (run pip install requests
)
In order to perform a secure session with Emedgene's API servers you should first accomplish the authentication phase and retrieve the bearer token. The bearer token is further required to perform API requests on associated resources without extra identification. The token is valid for a predefined time. Once the bearer token is not valid, you will need to revalidate the token and accomplish the authentication phase again.
There are two ways to get your authentication token for your user before executing API calls:
To generate the authorization token, use your username and password as follows:
This is your Bearer token that will be used for the following API requests.
For Illumina domain users there are two options to authenticate your user and retrieve the Bearer token.
Illumina credentials - use your username and password
Using your API Key to generate the authentication token. To generate an API Key take a look API Key Generating. Copy your API Key to the code below instead of 'my-api-key'.
Either of these options will produce your Bearer token that will be used for the following API requests.
The different API commands can be found at https://<hostname>.emedgene.com/api/apidoc/swagger or https://<hostname>.emg.illumina.com/api/apidoc/swagger
It is useful to explore possible APIs and get an overview of the available parameters.
The examples in the API Reference page use curl (Client URL), while Python uses requests.
In order to get the curl command:
Find the endpoint you want to use on the API Reference page.
Select Try it out
.
Enter the necessary parameters.
Select Execute
.
Copy the resulting curl command.
Let's break down the parts of a curl command:
-X
specifies the request method to use when communicating with the HTTP server. By default, curl
performs a GET
request, but you can use the -X
option to set a different method, such as POST
, PUT
, DELETE
, etc.
-H
allows you to pass custom headers to the server.
-d
is used to send data in a POST
request to the server. This option implies using the POST
method.
To translate a POST
command to a Python request:
Translating a GET
command would be similar:
In the examples below, <hostname>.emedgene.com and <hostname>.emg.illumina.com are used indifferently.
The following examples will build the requests step-by-step, allowing you to execute them individually to understand their functionality, using the output of one request as the input for the next.
You can also use the GUI to obtain all the parameters or record them after executing the individual API calls in this section. Then, use these values to construct your final API call.
This example can be used as a simple way to verify your connection.
To validate the API request was completed successfully, check the HTTP response code.
HTTP 200 means the API call was successful. Learn more about HTTP response code here.
In order to pretty-print the JSON response and view it in a formatted way:
Tip: when returning lists (like lists of cases) Emedgene API uses pagination. It is possible to get the next items from the list using from and size, shown below.
Now that we are able to retrieve information with the API, let's continue by using it for a more practical request like retrieving the list of storage providers your user can access files from.
Your storage provider holds the sample files accessible for creating samples in a case.
To create a new case, multiple parameters need to be defined such as samples, the relationship between samples, phenotypes, genes and more. All the required details can be found in the API Reference page under /api/cases/v2/cases
.
Once the complete JSON defining the case details is complete, the case can be created as follows:
Once the case was created successfully, the response code expected is HTTP 201.
Use the case name to retrieve information about the case.
In order to know if the case has completed successfully, check the status as follows:
To get more information about a case, use the same API call as above without any test_fields
The response can be used to find which test fields are of interest and use them in the next API calls:
To retrieve the candidate variants of the completed case:
To retrieve candidate variants of the completed case with details such as transcript data, pathogenicity, ACMG tags and more: