Project Class¶
Documentation of the Project class.
- class qmenta.client.Project(account, project_id, max_upload_retries=5)¶
This class is used to work with QMENTA projects. The class is instantiated passing as argument a Connection object and the id
- Parameters
account (qmenta.client.Account) – A QMENTA Account instance
project_id (Int or string) – The ID (or name) of the project you want to work with
- add_metadata_parameter(title, param_id=None, param_type='string', visible=False)¶
Add a metadata parameer to the project.
- Parameters
title (str) – Identificator of this new parameter
param_id (str) – Title of this new parameter
param_type (str) – Type of the parameter. One of: “integer”, “date”, “string”, “list”, “decimal”
visible (bool) – whether the parameter will be visible in the table of patients
- Returns
True if parameter was correctly added, False otherwise.
- Return type
bool
- add_subject(subject)¶
Add a subject to the project.
- Parameters
subject (Subject) – Instance of Subject representing the subject to add.
- Returns
True if correctly added, False otherwise
- Return type
bool
- change_file_metadata(container_id, filename, modality, tags)¶
Change modality and tags of filename in container_id
- Parameters
container_id (int) – Container identifier.
filename (str) – Name of the file to be edited.
modality (str or None) – Modality identifier, or None if the file shouldn’t have any modality
tags (list[str] or None) – List of tags, or None if the filename shouldn’t have any tags
- check_subject_name(subject_name)¶
Check if a given subject name exists in the selected project.
- Parameters
subject_name (str) – name of the subject to check
- Returns
True if subject name exists in project, False otherwise
- Return type
bool
- copy_container_to_project(container_id, project_id)¶
Copy a container to another project.
- Parameters
container_id (int) – ID of the container to copy.
project_id (int or str) – ID of the project to retireve, either the numeric ID or the name
- Returns
True on success, False on fail
- Return type
bool
- delete_analysis(analysis_id)¶
Delete an analysis
- Parameters
analysis_id (Int) – id of the analysis to be deleted
- delete_session(subject_name, session_id, cache=False)¶
Delete a session from a subject within a project.
- Parameters
subject_name (str) – Name of the subject
session_id (int) – The SSID of the session that will be deleted
cache (bool) – Whether to use the cached metadata or not
- Returns
True if correctly deleted, False otherwise.
- Return type
bool
- delete_subject(subject_name)¶
Delete a subject from the project.
- Parameters
name (str) – Name of the subject to be deleted.
- Returns
True if correctly deleted, False otherwise.
- Return type
bool
- download_file(container_id, file_name, local_filename=False, overwrite=False)¶
Download a single file from a specific container.
- Parameters
container_id (int) – ID of the container inside which the file is.
file_name (str) – Name of the file in the container.
local_filename (str) – Name of the file to be created. By default, the same as file_name.
overwrite (bool) – Whether or not to overwrite the file if existing.
- download_files(container_id, filenames, zip_name='files.zip', overwrite=False)¶
Download a set of files from a given container.
- Parameters
container_id (int) – ID of the container inside which the file is.
filenames (list[str]) – List of files to download.
overwrite (bool) – Whether or not to overwrite the file if existing.
zip_name (str) – Name of the zip where the downloaded files are stored.
- get_analysis(analysis_name_or_id)¶
- get_container(subject_name)¶
- get_file_metadata(container_id, filename)¶
Retrieve the metadata from a particular file in a particular container.
- Parameters
container_id (str) – Container identifier.
filename (str) – Name of the file.
- Returns
Dictionary with the metadata.
- Return type
dict
- get_subject(subject_name, cache=True)¶
Return a subject object, representing a subject from the project.
- Parameters
subject_name (str) – Name of the subject.
- Returns
A Subject instance representing the desired subject, or False if the subject was not found.
- Return type
Subject or bool
- get_subject_id(subject_name, cache=False)¶
Given a subject name, return its ID in the project.
- Parameters
subject_name (str) – Name of the subject in the project.
cache (bool) – Whether to use the cached metadata or not
- Returns
The ID of the subject in the project, or False if the subject is not found.
- Return type
int or bool
- get_subjects_metadata(cache=True)¶
List all subject data from the selected project.
- Returns
A list of dictionary of {“metadata_name”: “metadata_value”}
- Return type
dict
- list_analysis(limit=10000000)¶
List the analysis available to the user.
- Parameters
limit (int) – Max number of results
- Returns
List of analysis, each a dictionary
- Return type
dict
- list_container_files(container_id)¶
List the name of the files available inside a given container.
- Parameters
container_id (str) – Container identifier.
- Returns
List of file names (strings)
- Return type
list[str]
- list_container_files_metadata(container_id)¶
List all the metadata of the files available inside a given container.
- Parameters
container_id (str) – Container identifier.
- Returns
Dictionary of {“metadata_name”: “metadata_value”}
- Return type
dict
- list_input_containers(search_condition=None, limit=1000)¶
List the containers available to the user.
- Parameters
search_condition (dict) – d_n: container_name s_n: subject_id from_d: from date to_d: to date sets: data sets (modalities)
limit (int) – Max number of results
- Returns
List of containers, each a dictionary {“name”: “container-name”, “id”: “container_id”}
- Return type
dict
- list_result_containers(limit=1000)¶
List the result containers available to the user.
- Parameters
limit (int) – Max number of results
- Returns
List of containers, each a dictionary {“name”: “container-name”, “id”: “container_id”}
- Return type
dict
- property metadata_parameters¶
List all the parameters in the subject metadata.
Each project has a set of parameters that define the subjects metadata. This function returns all this parameters and its properties.
- Returns
- dictionary {“param_name”:
{ “order”: Int, “tags”: [tag1, tag2, …, ], “title: “Title”, “type”: “integer|string|date|list|decimal”, “visible”: 0|1 }}
- Return type
dict[str] -> dict[str] -> x
- set_qc_status(analysis_id, status=QCStatus.PASS, comments='')¶
Changes the analysis QC status.
- Parameters
analysis_id (int) – Analysis ID number
status (QCStatus) – QCStatus.PASS or QCStatus.FAIL
comments (str, optional) – Additional comments explaining why the QC status has been set to pass or fail.
- start_analysis(script_name, version, in_container_id=None, analysis_name=None, analysis_description=None, ignore_warnings=False, settings=None, tags=None, preferred_destination=None)¶
Starts an analysis on a subject.
- Parameters
script_name (str) – Name of the script to be run. One of: “volumetry”, “diffusion_connectome”, “morphology”
in_container_id (int or dict) – The ID of the container to get the data from, or a dictionary with one or more container names as keys, and IDs as values. Input container names are generally prefixed with “input_”. If not, the prefix will be automatically added.
analysis_name (str) – Name of the analysis (optional)
analysis_description (str) – Description of the analysis (optional)
ignore_warnings (bool) – If False, warnings by server cause failure.
settings (dict) – The input settings used to run the analysis. Use either settings or in_container_id. Input specification in the settings dict can be done by using the key “input”.
tags (list[str]) – The tags of the analysis.
destination (preferred) – The machine on which to run the analysis
- Returns
The analysis ID if correctly started, None otherwise.
- Return type
int
- property subjects¶
Return the list of subject names from the selected projet.
- Returns
a list of subject names
- Return type
List(Strings)
- property subjects_metadata¶
List all subject data from the selected project.
- Returns
A list of dictionary of {“metadata_name”: “metadata_value”}
- Return type
dict
- upload_file(file_path, subject_name, ssid='', date_of_scan='', description='', result=False, name='', input_data_type='qmenta_mri_brain_data:1.0', add_to_container_id=0, chunk_size=512, split_data=False)¶
Upload a file to the platform, associated with the current user.
- Parameters
file_path (str) – Path to the file to upload.
subject_name (str) – Subject to which this file will belong
ssid (str) – The ID of the timepoint
data_of_scan (str) – Date of scan/creation of the file
description (str) – Description of the file
result (bool) – If result=True then the upload will be taken as an offline analysis
name (str) – Name of the file in the platform
input_data_type (str) – mri_brain_data:1.0 or gametection:1.0
add_to_container_id (int) – ID of the container to which this file should be added (if id > 0)
chunk_size (int) – Size in kB of each chunk. Should be expressed as a power of 2: 2**x. Default value of x is 9 (chunk_size = 512 kB)
split_data (bool) – If True, the platform will try to split the uploaded file into different sessions. It will be ignored when the ssid is given.
- Returns
True if correctly uploaded, False otherwise.
- Return type
bool
- upload_gametection(file_path, subject_name)¶
Upload new Gametection data to the subject.
- Parameters
file_path (str) – Path to the file to upload
- Returns
True if upload was correctly done, False otherwise.
- Return type
bool
- upload_mri(file_path, subject_name)¶
Upload new MRI data to the subject.
- Parameters
file_path (str) – Path to the file to upload
- Returns
True if upload was correctly done, False otherwise.
- Return type
bool
- upload_result(file_path, subject_name)¶
Upload new result data to the subject.
- Parameters
file_path (str) – Path to the file to upload
- Returns
True if upload was correctly done, False otherwise.
- Return type
bool