AnalysisContext

class qmenta.sdk.context.AnalysisContext(analysis_id, comm)

Bases: object

get_files(input_id, modality=None, tags=None, reg_expression=None, file_filter_condition_name=None)

Returns the files in the input container specified by input_id that match the modality, tags and regular expression, if any. (X)OR that are selected by the file filter condition defined in the tool settings.

Parameters:
  • input_id (str) – Identifier “id” of the input container in advanced settings.

  • modality (str, optional) – Optional modality, will allow any modalities if None given. Default is None.

  • tags (set, optional) – Optional set of tags, will allow any tags if None given, and will match any set of tags (including the empty set) otherwise. Default is None.

  • reg_expression (str, optional) – Regular expression to match with the file names in the specified container, will allow any file names if None given. Default is None.

  • file_filter_condition_name (str, optional) – File filter specified in the settings of the tool. Default is None.

  • subject_container_id (str, optional) –

Examples

Get all files that passed c_TEST (including any selection the user may have done using the GUI)

>>> context.get_files('input', file_filter_condition_name='c_TEST')

Get all files that passed c_TEST and have no tags

>>> context.get_files('input', file_fitler_condition_name='c_TEST', tags=set()

Get all files that passed c_TEST and have the DTI tag in their list of tags

>>> context.get_files('input', file_fitler_condition_name='c_TEST', tags={'DTI'})

Get all files that passed c_TEST whose name match the given regexp

>>> context.get_files('input', file_filter_condition_name='c_TEST', reg_expression='^some_expression[0-9]')

Alternatively, you can use no file_filter_condition_name to browse through the whole input container

>>> context.get_files('input')
Returns:

List of selected file handlers from the container.

Return type:

list of qmenta.sdk.context.File

upload_file(self, source_file_path, destination_path, modality=None, tags=None, file_info=None, file_format=None)

Upload a file to the platform, to be part of the result files.

Parameters:
  • source_file_path (str) – Path to the file to be uploaded.

  • destination_path (str) – Path in the output container. Will be shown in the platform.

  • modality (str, optional) – Optional modality of the uploaded file. None by default.

  • tags (set, optional) – Set of tags for the uploaded file. None by default.

  • file_info (dict, optional) – File information metadata.

  • file_format (str, optional) – Use “dicom” when .zip file with .dcm slices (uploading a “nifti” file is automatically recognized as such).

  • protocol (str, optional) –

  • container_id (str, optional) –

  • replace (str, optional) –

  • direct (bool) –

class QCEntity(value)

Bases: Enum

Enum with the following options: ANALYSIS, SESSION

ANALYSIS = 'analysis'
SESSION = 'patients'
class QCStatus(value)

Bases: Enum

Enum with the following options: FAIL, PASS

PASS = 'pass'
FAIL = 'fail'
fetch_analysis_data()

Fetch information about current analysis.

Returns:

Dictionary that contains important information about the current analysis, such as:
  • state (str) : State of the analysis

  • name (str) : Name of the analysis

  • script_name (str) : Name of the script

  • analysis_id (str) : A unique identifier for the current analysis

  • user_id (str) : Username of the user that started the analysis

  • patient_secret_name (str) : Name of the subject

  • ssid (str) : Timepoint identifier

  • settings (dict) : Settings dictionary. See documentation in method get_settings

  • tags (list) : List of tags

  • version (str) : Tool version

Return type:

dict

fetch_parent_analysis_data()

Fetch information about the parent analysis of the current analysis.

Returns:

Dictionary that contains important information about the current analysis, such as:
  • state (str) : State of the analysis

  • name (str) : Name of the analysis

  • script_name (str) : Name of the script

  • user_id (str) : Username of the user that started the analysis

  • patient_secret_name (str) : Name of the subject

  • ssid (str) : Timepoint identifier

  • settings (dict) : Settings dictionary. See documentation in method get_settings

  • tags (list) : List of tags

  • version (str) : Tool version

Return type:

dict

get_communication_object()

Return the communication object used for communication with the platform

Returns:

The communication object used to communicate the platform

Return type:

CommunicationObject

set_qc_status(status=QCStatus.PASS, comments='', entity=QCEntity.ANALYSIS, input_id=None)

Changes the analysis or session QC status.

Parameters:
  • status (QCStatus) – QCStatus.PASS or QCStatus.FAIL

  • comments (str, optional) – Additional comments explaining why the QC status has been set to pass or fail.

  • entity (QCEntity, optional) – QCEntity.ANALYSIS or QCEntity.SESSION

  • input_id (str, optional) – The id of the session in the settings definition when entity is QCEntity.SESSION

get_qc_status(analysis=False)

Gets the session QC status.

Parameters:

analysis (bool) – to get analysis QC

set_progress(message=None, value=None)

Sets analysis progress.

Parameters:
  • value (int, optional) – Number between 0 and 100 indicating the current status of the execution

  • message (str, optional) – Progress message.

get_settings()

Analysis settings.

Returns:

Settings for the current analysis. This includes all the parameters defined in the tool specification (checkboxes, input fields, etc.) and can be accessed using their identifier.

Return type:

dict

download_resource(resource_path, destination_path)

Downloads a resource file from the bucket (user/group based resources, or legacy).

Parameters:
  • resource_path (str) – Path to the file in the resources bucket.

  • destination_path (str) – Path where the file will be downloaded.

set_metadata_value(key, value, title=None, readonly=False, patient_secret_name=None, ssid=None)

Sets the value of a metadata parameter.

Parameters:
  • key (str) – The ID of the metadata parameter.

  • value (int, str, float or list) – The new content of the parameter.

  • title (str, optional) – How the metadata field should be presented

  • readonly (bool, optional) – Whether the user should be able to edit the value on the platform or not (only by analyses)

  • patient_secret_name (str, optional) – Manually select the patient_secret_name

  • ssid (str, optional) – Manually select the ssid. This is useful to choose a specific session in a longitudinal analysis.

get_metadata_value(key=None, patient_secret_name=None, ssid=None)

Gets the value of a metadata parameter for the current session

Parameters:
  • key (str, optional) – The ID of the metadata parameter. If not set, it will return all the metadata for the session.

  • patient_secret_name (str, optional) – Manually select the patient_secret_name

  • ssid (str, optional) – Manually select the ssid. This is useful to choose a specific session in a longitudinal analysis.

Return type:

The value of the parameter if it exists, None otherwise

get_parent_files_from_input_id(input_id)
get_session_owner(input_id)
Parameters:

input_id (str) – ID of the container used as input in the analysis