Application API

The EMERGEN-DB API is built from the Django REST framework whose official website is available here.

How to add an API?

  1. Step 1 - Create a serializer in the serializers.py

  2. Step 2 - Create a view in view.py

  3. Step 3 - Create a url to access the API in the ulrs.py ;

  4. Step 4 - Test the API in the test.py file. Many examples are already available in the file.

A complete example is available on the official documentation and APIs are already available in the application. They can help you in the structure to follow.

Key files of the « API » application

view.py

apps.api.views.api_detail(request, operationId)

SUMMARY LINE

Detail for a APIs

Renvoie

Return a YAML file in OAS3 format

apps.api.views.api_faq(request)

SUMMARY LINE

Recovery of the user’s token and display FAQ page

Renvoie

Return a HttpResponse

apps.api.views.api_import_procedure(request)

SUMMARY LINE Display page with API procedure to import data in EMERGEN-DB

apps.api.views.api_list(request, type=None, filter=None)

SUMMARY LINE

List of all APIs

Renvoie

Display list of APIs

apps.api.views.api_only(request, operationId)

SUMMARY LINE

Return YAM file for a specific API

Renvoie

Return a YAML file in OAS3 format

apps.api.views.api_token(request)

SUMMARY LINE

Recovery of the user’s token and display TOKEN page

Renvoie

Return a HttpResponse

apps.api.views.swagger_doc(request)

SUMMARY LINE

Recovery of the user’s token, filtering of the results by group and rendering of the api in the Open API form

Renvoie

Return a HttpResponse

serializers.py

The EMERGEN-DB API is built from the Django REST framework. To format the results returned by the API, serializers are created whose official documentation is here :

class apps.api.serializers.CountByTechSerializer(*args, **kwargs)

Count by technology serializer

class Meta

Fields return by serializer

model

alias de apps.collector.models.result

get_Count(res)

SUMMARY LINE

Count by technology.

Note

For a special user (superuser, data analyst, manager) all available results will be used, otherwise only those of the user’s group.

Paramètres
  • self

  • res (queryset) – A queryset element

Renvoie

Query element with technology name and the number of variants detected with it.

class apps.api.serializers.CountByVarSerializer(*args, **kwargs)

Count by variants serializer

class Meta

Fields return by serializer

model

alias de apps.collector.models.result

get_Count(res)

SUMMARY LINE

Count by variant. The result depends on the user’s group.

Note

For a special user (superuser, data analyst, manager) all available results will be used, otherwise only those of the user’s group.

Paramètres
  • self

  • res (queryset) – A queryset element

Renvoie

Query element with variant name and the number of times it was detected

get_Resultat(res)

SUMMARY LINE

Get variant name. The result depends on the user’s group.

Note

For a special user (superuser, data analyst, manager) all available results will be used, otherwise onlythose of the user’s group.

Paramètres
  • self

  • res (queryset) – A queryset element

Renvoie

Variant name

class apps.api.serializers.departementSerializer(*args, **kwargs)

Departement serializer

class Meta

Fields return by serializer

model

alias de apps.stats.models.departement

get_count_var(departement)

SUMMARY LINE

Count by departement.

Note

For a special user (superuser, data analyst, manager) all available results will be used, otherwise only those of the user’s group.

Paramètres
  • self

  • res (queryset) – A queriset element

Renvoie

Query element with depatement name and the number of times a variant was detected

class apps.api.serializers.experimentSerializer(*args, **kwargs)
class Meta

Fields return by serializer

model

alias de apps.home.models.experiment

get_Team(experiment)

SUMMARY LINE

Get the team’s name

Paramètres
  • self

  • experiment (queryset) – A queryset element

Renvoie

Query element with a team name

class apps.api.serializers.regionSerializer(*args, **kwargs)

Region serializer

class Meta

Fields return by serializer

model

alias de apps.stats.models.region

get_count_var(region)

SUMMARY LINE

Count by region.

Note

The result depends on the user’s group. For a special user (superuser, data analyst, manager) all available results will be used, otherwise only those of the user’s group.

Paramètres
  • self

  • res (queryset) – A queriset element

Renvoie

Query element with region name and the number of times a variant was detected

class apps.api.serializers.resultsSerializer(*args, **kwargs)

Result serializer

class Meta

Fields return by serializer

model

alias de apps.collector.models.result

get_Labo_sequenceur(result)

SUMMARY LINE

Get the Laboratoire sequenceur name

Paramètres
  • self

  • result (queryset) – A queryset element

Renvoie

Query element with a Laboratoire sequenceur name

get_Resultat(result)

SUMMARY LINE

Get the variant name from auto_result

Paramètres
  • self

  • result (queryset) – A queryset element

Renvoie

Query element with a Variant name

get_dep_prelev(result)

SUMMARY LINE

Get the code department of the sampling laboratory

Paramètres
  • self

  • result (queryset) – A queryset element

Renvoie

Query element with a code departement

ulrs.py

The urls.py file contains :

  • The addresses of the various GET APIs that begin with api/ ;

  • A special address for the API POST (sending Excel files via the API) ;

  • An address for the OPEN API page ;

  • An address to display the APIs by SWAGGER

test.py

class apps.api.tests.api_test_case(methodName='runTest')

API tests

setUp()

Hook method for setting up the test fixture before exercising it.

tearDown()

Hook method for deconstructing the test fixture after testing it.

test_api_flash()

Test APIs pages

test_api_post_duplicated()

Test post data in same file

test_apis_page()

Test APIs pages

test_count_by_api_no_group()

Test get count results (technology and variant) by user in no group

test_count_by_api_same_group()

Test get count results (technology and variant) by user in same group that the user who submitted the data

test_count_by_api_staff()

Test get count results (technology and variant) by staff member

test_dep_api_bad()

Test get count results by specific departement with bad code

test_dep_api_good()

Test get count results by specific departement with good code

test_dep_api_good_no_log()

Test get count all results by departement but not log

test_deps_api_no_group()

Test get count all results by departement (no group)

test_deps_api_same_group()

Test get count all results by department (same group as the submitter )

test_deps_api_staff()

Test get count all results by departement (STAFF status)

test_experiment_api_no_group()

Test get experiment configuration (no group)

test_experiment_api_same_group()

Test experiment configuration (same group as the submitter )

test_experiment_api_staff()

Test get experiment configuration (STAFF status)

test_get_tar_gz()

Test the APIs for the get tar.gz

test_nextclade_pango_api()

Test get test_nextclade_pango_api

test_one_sequence_request()

Test task : one_sequence_request

test_post_data()

Test post data

test_post_data_bad_file_excel()

Test post by format excel file

test_post_data_bad_file_fasta()

Test post by format file

test_post_data_empty_file_excel()

Test post empty excel file

test_post_data_empty_file_fasta()

Test post empty fasta file

test_post_data_good_api()

Test post with wrong column names

test_post_data_two_submits()

Test post data - Two submissions to test if file is correctly renammed

test_post_data_with_prefix()

Test post data with error prefix

test_post_data_wrong_column()

Test post with wrong column names

test_post_data_wrong_data()

Test post with wrong data

test_reg_api_bad()

Test get count all results by specific region with bad code

test_reg_api_good()

Test get count all results by specific region with good code

test_reg_api_good_no_log()

Test get count all results by region but not log

test_regs_api_no_group()

Test get count all results by regions (no group)

test_regs_api_same_group()

Test get count all results by region (same group as the submitter )

test_regs_api_staff()

Test get count all results by regions (STAFF status)

test_request_TSV_all_results_api_staff()

Test get request_TSV_all_results (Staff)

test_request_all_results_filtred_sequencing_indication_admin()

Test admin action : export results

test_request_sequences_by_mutation_clade_lineage()

Test the APIs for the get tar.gz

test_result_sequence_request()

Test task : result_sequence_request

test_results_api_No_group()

Test get results with no group (All, from year, from year and month and from year, month & day)

test_results_api_Same_group()

Test get results by a user with same group (All, from year, from year and month and from year, month & day)

test_results_api_staff()

Test get results with staff status (All, from year, from year and month and from year, month & day)

test_sequence_request_api_NoStaff()

Test get sequence_request status (no log and no staff)

test_sequence_request_api_staff()

Test get sequence_request status (Staff)

test_sequence_request_task()

Test task : sequence_request_task

test_sequence_requestt_api_NoStaff()

Test get sequence_request status (no log and no staff)

test_task_api_NoStaff()

Test get task status (no log and no staff)

test_task_api_staff()

Test get task status (Staff)

test_token_status()

Test the token status

test_update_auto_result_api_NoStaff()

Test get auto_result(no log and no staff)

test_update_auto_result_api_staff()

Test get auto_result (Staff)

test_update_nexclade_task()

Test task : update_nexclade_task

test_update_nextclade_api_NoStaff()

Test get auto_result(no log and no staff)

test_update_nextclade_api_staff()

Test get update_nextclade (Staff)

test_update_pango_api_NoStaff()

Test get update_pango (no log and no staff)

test_update_pango_api_staff()

Test get update_pango (Staff)

test_update_pango_task()

Test task : update_pango_task

test_upload_data_task()

Test task : upload_data_task

test_upload_data_task_wrong_file_except()

Test task : upload_data_task. Test post file and create exception