The api
Module
The api
module is essentially a python wrapper for the IRIDA REST API.
It is used in the IRIDA uploader to handle interaction between the uploader logic and IRIDA, but the module can be used on it's own to interact with IRIDA.
Setup
The module can be used as follows:
# import the module
import api
# Create an api instance by initializing an ApiCalls object
api_instance = api.ApiCalls(client_id, client_secret, base_url, username, password)
For more information on the arguments passed to ApiCalls
, please see the configuration documentation
Use
Getting Data from IRIDA
get_projects(self)
API call to api/projects to get list of projects
returns:
List containing projects. each project is Project object.
get_samples(self, project_id)
API call to api/projects/project_id/samples
arguments:
project_id -- project identifier from irida
returns:
list of samples for the given project. Each sample is a Sample object.
get_sequence_files(self, project_id, sample_name)
API call to api/projects/project_id/sample_id/sequenceFiles We fetch the sample file through the project id on this route
arguments:
sample_name -- the sample id to get from irida, relative to a project project_id -- the id of the project the sample is on
returns:
list of sequencefile dictionary for given sample_id
Sending Data to IRIDA
send_project(self, project, clear_cache=True)
post request to send a project to IRIDA via API the project being sent requires a name that is at least 5 characters long
arguments:
project -- a Project object to be sent.
returns:
A dictionary containing the result of post request. when post is successful the dictionary it returns will contain the same name and projectDescription that was originally sent as well as additional keys like createdDate and identifier. when post fails then an error will be raised so return statement is not even reached.
send_sample(self, sample, project_id)
Post request to send a sample to a project
arguments:
sample -- Sample object to send project_id -- id of project to send sample too
returns:
Unmodified json response from server
send_sequence_files(self, sequence_file, sample_name, project_id, upload_id)
Post request to send sequence files found in given sample argument raises error if either project ID or sample ID found in Sample object doesn't exist in irida
arguments:
sample -- Sample object upload_id -- the run to upload the files to
returns:
unmodified json response from server.
Getting / Creating / Modifying Sequencing Runs
get_seq_runs(self)
Get list of all SequencingRun objects
returns:
list of SequencingRuns
create_seq_run(self, metadata)
Create a sequencing run.
uploadStatus "UPLOADING"
There are some parsed metadata keys from the SampleSheet.csv that are currently not accepted/used by the API so they are discarded. Everything not in the acceptable_properties list below is discarded.
arguments:
metadata -- SequencingRun's metadata
returns:
the sequencing run identifier for the sequencing run that was created
set_seq_run_complete(self, identifier)
Update a sequencing run's upload status to "COMPLETE"
arguments:
identifier -- the id of the sequencing run to be updated
returns:
unmodified json response from server
set_seq_run_uploading(self, identifier)
Update a sequencing run's upload status to "UPLOADING"
arguments:
identifier -- the id of the sequencing run to be updated
returns:
unmodified json response from server
set_seq_run_error(self, identifier)
Update a sequencing run's upload status to "ERROR"
arguments:
identifier -- the id of the sequencing run to be updated
returns:
unmodified json response from server
Querying IRIDA
project_exists(self, project_id)
Check if a sample exists on a project
arguments:
project_id -- project that we are checking for existence returns:
True or False
sample_exists(self, sample_name, project_id)
Check if a sample exists on a project
arguments:
sample_name -- sample to confirm existence of project_id -- project that we think the sample is on
returns:
True or False