Documentation and Help

Using the API


Search Endpoint
Export Endpoint

Besides our web service for searching, retrieving, and exporting data we also provide an API interface to, for example, automate workflows that require obtaining certain tRNA sequences. In order to keep our service responsive and fair, we limit API requests to 1 request per second per client. Note that repeatedly violating this limit might result in a temporary lock-out from the tRNAdb service. Please ensure your use of the API respects these limits (for example, via waiting/sleep after every request).

Querying the Search Endpoint


The API provides nearly equal search parameters as the Search form and can be reached with POST request at https://www.tdb.bioinf.uni-leipzig.de/api.

A POST request with JSON content-type is expected. The following JSON contains all supported fields, and field types:

{
    'database': <list, string>, 
    'organism': <list, string>,
    'organism_synonym_search': <boolean>
    'clade': <list, string>,
    'ncbi_id': <string, integer, list>'
    'amino_acid': <list, string>,
    'anticodon': <list, string>, 
    'sequence': <dictionary {'0': <string>, '1': <string>, ..., '16': <string>}, string>,
    'structure': <dictionary {'0': <string>, '1': <string>, ... , '16': <string>}, string>, 
    'reference': <string>, 
    'trna_id': <list, string>,
    'id': <list, integer> 
    'sprinzl_id': <list, string>, 
    'page_size': <integer>,
    'page_offset': <integer>
}

In particular, you need to pay attention to the 'page_offset' and 'page_size' parameters. If you do not specify these two, the API will always return the first (at most) 1000 matching entries. These two parameters are explained in more detail below

Search Query Parameters


Field Usage/Parameters Example
database restricts which datasource the tRNA should be retrieved from, i.e., nuclear tRNAs sequences (trna), nuclear tRNA RNA sequences (trna_rna), mitochondrial tRNA sequences (mttrna), and mitochondrial tRNA RNA sequences (mttrna_rna). Datasources can be supplied as a single string (single datasource) or as a list of strings (multiple datasources). 'database': ['trna', 'mttrna'] matches nuclear tRNA sequences as well as mitochondrial tRNA sequences while no nuclear tRNA RNA sequences/mitochondrial tRNA RNA sequences are returned.
organism matches species names, (and synonyms) for species inluded. Species names can be either single species as a string, or a list of species strings. When a single organism (via string/list) is supplied, partially matching organism names are returned, i.e. "canis" matches "Canis Latrans", "Canis Lupus", etc.. If multiple organism names are supplied, only exact matches are returned. When organism_synonym_search is supplied, partial organism names are always considered as matching. organism: ['Homo Sapiens Nea'] matches tRNA belonging to "Homo Sapiens Neanderthalensis".
organism_synonym_search restricts/enables whether synonym searching for organism should be enabled. When organism_synonym_search is not provided, synonym searching is turned on by default. Value has to be provided as boolean, i.e., true/false. 'organism_synonym_search: true together with organism: ['Mosquito'] returns all tRNA for organisms in tRNAdb which common names include mosquito, e.g., 'Anopheles funestus'.
clade matches species, family, order, ..., kingdom, etc.. Clades can be supplied as a string (matching a single clade) or as a list (matching multiple clades). Partial matches are also allowed. clade: ['Hominidae'] returns tRNA for any species belonging to the family of great apes.
ncbi_id restricts the search to tRNA belonging to the species with the supplied NCBI Taxonomy ID. Individual taxonomy ids (as string or integer) as well as a list of taxonomy IDs (as string or integer) can be queried. clade: [8801, 9838] matches tRNA entries belonging to the african ostrich and the one-humped camel.
amino_acid restricts the search to tRNAs for specific amino acids. You have to use the three-letter codes for amino acids (Ala, Arg, Asn, Asp, Cys, fMet, Gln, Glu, Gly, His, Ile, Ile2, iMet, Ini, Leu, Leu1, Leu2, Lys, Met, Phe, Pro, Pyr, Sec, Ser, Ser1, Ser2, Thr, Trp, Tyr, Val). A single amino acid (string) or multiple amino acids (list of strings) can be matched. 'amino_acid':['Ala', 'Cys', 'His'] matches tRNA for Alanine, Cysteine, or Histidine.
anticodon restricts the search to tRNAs with specific anticodons. When a single string is supplied, wobble bases are supported (in case only two nucleotides are provided). If a list is supplied, only exact matches are considered. 'anticodon': 'AC' returns tRNAs with anticodons starting with "AC", e.g, "ACT, ACG, ACA, ...". 'anticodon': 'ACT' matches only tRNAs with the "ACT" anticodon. 'anticodon': ['ACG', 'ACA'] matches tRNAs with "ACG" or "ACA" as anticodon.
sequence resticts the search to tRNA sequence motifs. If a string is supplied, only tRNAs matching the full motif are returned. If a dictionary is supplied, the corresponding regions of the tRNAs in the database are matched. See the region section below for an explaination of the dictionary region format. 'sequence': {3: 'AGCT', 10: 'AAAT'} matches tRNAs which D-Stems contains motif "AGCT" and which V-Region contains motif "AAAT".
structure restricts the search to certain tRNA structures. If a string is supplied, only tRNAs matching the full structure motif are returned. If a dictionary is supplied, the corresponding structure regions of the tRNAs in the database are matched. See the region section below for an explaination of the dictionary region format. "=" encode standard watson-crick basepairs (e.g., G-C, A-T/A-U), "*" encode wobble basepairs (e.g., G-U), and "." encode unpaired bases 'structure': {3: '***', 5: '***'} matches tRNAs which D-Stem contain three consecutive wobble pairs on each side. 'structure': {3: '**=-'} returns tRNAs which D-stem contains two wobble pairs followed by a single watson-crick basepair and an unpaired nucleotide.
reference restricts the search to tRNA from a certain source. The sources are the Reference/Database fields you can see on the individual results page. This can be genome accessions, data sources like gtRNAdb, or publication references. Note that partial matches are allowed. 'reference': 'gtRNAdb' matches all entries included from gtRNAdb. 'reference': 'GCA_000786425.1' matches all entries that match the GenBank accession "GCA_000786425.1".
trna_id restricts the search to tRNA with a specific ID. Either a single tRNAdb ID (string) or a list of multiple tRNAdb IDs can be supplied. trna_id: ['tdbD00013523', 'tdbD00013524', 'tdbD00013525'] matches tRNA with (one of) the three supplied IDs.
trna_id restricts the search to tRNA with a specific internal ID - this is the ID field on the results pages. Either a single ID (integer), or a list of IDs (list) can be supplied. Note that this ID is only unique in combination with the 'database' field. 'id': [1, 2, 3] matches tRNA with (one of) the three supplied internal IDs.
sprinzl_id restricts the search to tRNA with a specific SprinzlID (sourced originally from the Sprinzl tRNA database in 2009). Either a single SprinzlID (string), or a list of multiple SprinzlIDs can be supplied. trna_id: ['DA3680'] matches the tRNA with SprinzlID 'DA3680'.
page_size How many entries the API should return. This is limited at 1000. 'page_size': 100, 'page_offset:0 returns the first 1-100 results matching the query. 'page_size': 100, 'page_offset:1 returns the 101st-200th entries matching the query.
page_offset Which "offset" of matching entries is returned. Think of it like a book page containing <page_size> entries. The 0th page contains the first 1 to <page_size> entries, the 1st page contains the <page_size>+1 to 2 * <page_size> entries, etc. To retrieve all results matching a query you can repeat the same query with +1 until no more results are contained in the API responses (or as many as the total_results are obtained). See example above.
Regions:

For querying sequence and structure we utilize the conserved structural regions of tRNAs. Simply put, they are numbered by occurencce from 5'->3' end of the tRNA. "Empty Regions" in this context are not necessarily empty, but contain nucleotides that do not strictly belong into any of the other structural regions. Indices in the table below are exactly as one would query the API for the 'sequence' and 'structure' fields.

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
Empty Region Acceptor Stem Empty Region D-Stem D-Loop D-Stem Empty Region Anticodon Stem Anticodon Loop Anticodon Stem Variable Region T-Stem T-Loop T-Stem Acceptor Stem Empty Region CCA

API Response


When you POST a valid JSON to https://www.tdb.bioinf.uni-leipzig.de/api, the server will answer with a JSON in this shape:

{   
        'total_results': <integer>,
        'page_offset': <integer>,
        'page_size': <integer,
        'results': [
                        {<dictionary>},
                        {<dictionary>}, 
                        ... 
                   ]
}
  • total_results is an integer value that describes how many tRNAdb entries match the query in total. Note that only up to 1000 entries can be retrieved with a single query.
  • 'page_offset' is the page number of results that the 'results' field contains. See "Query Parameters" above for more information.
  • 'page_size' is the maximum number of results per page of results retrieved.
  • 'results' is a list that contains dictionaries (JSON) of individual entries that match the query.

In case your request JSON was malformed, the server responds with a JSON that describes the error that occured. This JSON could, for example, look something like this: {'error': 'Some fields not supported: some_field'}. If the 'results' list does not contain any entries (or 'total_results is zero), your request does not match any tRNAs in the database.

Entry Fields


Every entry that is returned by the API in the 'results' field is a JSON that contains the following keys/values:

Key Value Description
'sequence' nucleotide sequence of the tRNA. tRNA RNA sequences contain special characters for modified nucleotides
'structure' dot-bracket structure of the tRNA
'aligned_sequence' sequence aligned to the global alignment (global alignment is region-wise, sequence based)
'aligned_structure' structure aligned to the global alignment (global alignment is region-wise, sequence based)
'amino_acid' three letter code of the amino acid the tRNA is for
'annotated_aligned_sequence' sequence aligned to the global alignment, regions split by @-character
'annotated_aligned_structure' strucutre aligned to the global sequence alignment, regions split by @-character
'annotated_sequence' raw sequence, regions split by @-character
'annotated_structure' dot-bracket structure, regions split by @-character
'anticodon' anticodon nucleotides. Three characters
'database' database origin, i.e. "tRNA DNA", "tRNA RNA", "mt-tRNA DNA", "mt-tRNA RNA"
'id' internal ID, unique together with "database"
'parent_clades taxonomic lineage from NCBI taxonomy. Hierarchical comma separated list of taxonomic lineage from species, ..., domain-of-life
'reference' this can be genome accessions, data sources like gtRNAdb, or publication references, ...
'sprinzl_id' SprinzlID, if available
'tRNAdb_version' version number; version at which the particular tRNA has been added to tRNAdb
'version_details' version description
'taxon_embl_code' EMBL Code of the organism the tRNA is from
'taxon_id' NCBI taxonomy ID of the organism the tRNA is from
'taxon_name' species name of the organism the tRNA is from
'taxon_synonyms' synonyms of taxon_name
'trnadb_id' tRNAdb ID, unique and consistent

Simple Search Python Example


Using python for the sake of an easy and readable example, a simple request querying the tRNAdb API for human nuclear Alanine tRNAs could look like this:

import requests
import json

request_dict = {
    "database": "trna",
    "amino_acid": "Ala",
    "organism": "Human",
    "page_size": 1000,
    "page_offset": 0
}


api_server = "https://tdb.bioinf.uni-leipzig.de/api"

api_response = requests.post(
    api_server,
    json=request_dict,
    timeout=10
)

response_data = json.loads(api_response.text)

print()
print("Total results matching query:", response_data["total_results"])

# get the first entry
entry = response_data["results"][0]

print()
print("The first matching entry:")

# output every field name and field data for the first entry
for k in entry.keys():
    print(k,  ":", entry[k])

Querying the Export Endpoint


For export of larger (more than 1 000) sets of sequences, we also expose an export endpoint which enables direct export of desired sequences and selected fields to .tsv, .csv, .json, and .fasta. The endpoint can be reached at https://www.tdb.bioinf.uni-leipzig.de/export. The request schema, hence which format the request to https://www.tdb.bioinf.uni-leipzig.de/export should have, is precisely the schema outlined above in the Querying the Search Endpoint but supports additional fields for "filetype", "export_fields", "fasta_identifier".

Export Query Parameters

Field Usage/Parameters Example
"filetype" Desired filetype of the exported data. "fasta", "json", "tsv", "csv" are supported, "filetype" needs to be supplied as a string. "file_type": "fasta" exports to .fasta, "file_type":"tsv" exports requested entries to .tsv.
"export_fields" Fields that should be included in the exported file, "export_fields" needs to be supplied as an array. These differ between .fasta and .tsv/.csv/.json.
Supported .fasta fields: "sequence", "structure", "aligned_sequence", "aligned_structure", "annotated_sequence", "annotated_structure", "annotated_aligned_sequence", "annotated_aligned_structure".

Supported .tsv/.csv/.json fields: "id", "trnadb_id", "sprinzl_id", "amino_acid", "anticodon", "ncbi_taxonomy_id", "taxon_name", "parent_clades", "taxon_embl_code", "database", "external_database", "reference", "pubmed", "sequence","structure", "aligned_sequence", "aligned_structure", "annotated_sequence", "annotated_structure", "annotated_aligned_sequence", "annotated_aligned_structure", "version_details", "version"
"export_fields": ["trnadb_id", "amino_acid", "anticodon", "sequence"] would be a valid selection of fields for .tsv export.

"export_fields": ["sequence", "structure"] would be valid export fields for .fasta export
"fasta_identifier" When fasta export is chosen, this request parameter can be used to customize the fasta identifier. "fasta_identifier" should be supplied as a list/array. Supported identifier fields: "id", "trnadb_id", "taxon_name", "amino_acid", "anticodon", "taxon_embl_code", "ncbi_taxonomy_id", "database" "fasta_identifier": ["trnadb_id", "ncbi_taxonomy_id", "database", "amino_acid", "anticodon"] would produce a .fasta where the identifier line looks like >trnadb_id|database|amino_acid|anticodon, for example, >mtdbD00000445|32536|mt-tRNA_DNA|Trp|TCA

Export Job Lifetime


After successfully requesting the export job at https://www.tdb.bioinf.uni-leipzig.de/export, the API server responds with a job description in .json format of the shape

{
  "job_id": <string>,
  "status": <string>,
  "total_rows": <integer>,
  "processed_rows": <integer>
}

"job_id" is a unique identifier for your export job. "status" is a current status of the job. An export job moves from "queued" while waiting for execution to "processing" during execution to "done" when execution is finished. "total_rows" is the total number of tRNAdb entries matching your search request. " processed_rows" are already exported/processed rows. Export jobs might take some time, depending on how busy the server is. Jobs might remain in "queued" state for some time.

Status of export jobs can be queried at the https://www.tdb.bioinf.uni-leipzig.de/export/status/<job_id> endpoint for your "job_id". Once the export job is done, hence "status": "done", the exported file can be downloaded at https://www.tdb.bioinf.uni-leipzig.de/export/download/<job_id>. Please note that exported files for finished jobs are deleted after 24 hours.

Simple Export Python Example

Below, there is a simple example python script that creates an export job, saves the job_id, and then queries the status endpoint https://www.tdb.bioinf.uni-leipzig.de/export/status/job_id until the job is done. Finally, it prints the exported file.

import requests
import json
import time

# Export job for genomic human alanine tRNAs
# Export to .json, including the fields
# "trnadb_id", "amino_acid", "anticodon", "taxon_name", "database", "sequence", "version"
request_dict = {
    "database": "trna",
    "amino_acid": "Ala",
    "organism": "Homo sapiens",
    "filetype": "json", 
    "export_fields": ["trnadb_id", "amino_acid", "anticodon", "taxon_name", "database", "sequence", "version"] 
}

# Endpoint for starting export jobs
export_endpoint = "https://www.tdb.bioinf.uni-leipzig.de/export"

# Request send to export endpoint, with a 10s timeout
api_response = requests.post(
    export_endpoint,
    json=request_dict,
    timeout=10
)

# Read server response. If an error occured, response will contain "error" field with a description.
response_data = json.loads(api_response.text)

# Get the job ID assigned to export job
job_id = response_data["job_id"]
print("Export Job with ID:", job_id)

# Endpoint to query status of export job
status_path = "https://www.tdb.bioinf.uni-leipzig.de/export/status/" + job_id

# While the export job is not "done"
while response_data["status"] != "done":

    # Get updated status of export job
    print()
    api_response = requests.get(
        status_path,
        timeout=10
    )

    # Read status response
    response_data = json.loads(api_response.text)

    # If export job not finished, output progress
    if response_data["status"] != "done":
        print("Job status", response_data["status"])
        print("Job ID", job_id)
        print("Job progress", response_data["progress"], "/", response_data["total_rows"])
        time.sleep(1)

    # If export job is finished, output exported data
    else:
        print("Job finished. Download available at", "https://www.tdb.bioinf.uni-leipzig.de" + response_data["download_url"])
        export_data = requests.get("https://www.tdb.bioinf.uni-leipzig.de" + response_data["download_url"], stream=True)
        print("Export job contents:")
        print(export_data.text)

Downloads

Download Manager