MultiTACGraphicalAnalysis#
- class petpal.kinetic_modeling.graphical_analysis.MultiTACGraphicalAnalysis(input_tac_path: str, roi_tacs_dir: str, output_directory: str, output_filename_prefix: str, method: str, fit_thresh_in_mins=None)#
Bases:
GraphicalAnalysis,petpal.utils.time_activity_curve.MultiTACAnalysisMixinA class that performs graphical analysis on multiple tissue TACs (Time Activity Curves).
- Variables:
input_tac_path (str) – Path to the input TAC file.
roi_tacs_dir (str) – Directory containing region of interest TAC files.
output_directory (str) – Directory for saving analysis results.
output_filename_prefix (str) – Prefix for output filenames.
method (str) – Method used for analysis.
fit_thresh_in_mins (Optional[float]) – Threshold in minutes for fit calculation.
Initializes the MultiTACGraphicalAnalysis object with required paths, method, and threshold.
- Parameters:
input_tac_path (str) – Path to the input TAC file.
roi_tacs_dir (str) – Directory containing region of interest TAC files.
output_directory (str) – Directory for saving analysis results.
output_filename_prefix (str) – Prefix for output filenames.
method (str) – Method used for analysis.
fit_thresh_in_mins (Optional[float], optional) – Threshold in minutes for fit calculation. Defaults to None.
- init_analysis_props()#
Initializes analysis properties for each tissue TAC. Overrides
GraphicalAnalysis.init_analysis_props().- Returns:
list[dict] – A list of analysis property dictionaries for each TAC.
- calculate_fit(**run_kwargs)#
Calculates the fit for each TAC, updating the analysis properties with slope, intercept, and R-squared values. Overrides
GraphicalAnalysis.calculate_fit().- Parameters:
run_kwargs – Additional keyword arguments passed on to analysis_func.
- calculate_fit_properties(**run_kwargs)#
Calculates additional properties of the fit, such as threshold, method name, start and end times, and number of points. Iterates over all the TACs.
Overrides
GraphicalAnalysis.calculate_fit_properties()- Parameters:
run_kwargs – Additional keyword arguments used in the analysis. These are saved to the analysis properties as individual properties.
- save_analysis(output_as_tsv: bool = True, output_as_json: bool = False)#
Saves the analysis results to a TSV file as a table with fit parameters for each ROI.
- Parameters:
output_as_tsv (bool) – Set True to write results to TSV table. Default True.
output_as_json (bool) – Set True to write results to a folder with one JSON file per region. Default False.
- Raises:
RuntimeError – If ‘run_analysis’ method has not been called before save_analysis.
- __call__(output_as_tsv: bool = True, output_as_json: bool = False, **run_kwargs)#
Runs
run_analysis()andsave_analysis()to run the analysis and save the analysis properties.- Parameters:
output_as_tsv (bool) – Set True to write results to TSV table. Default True.
output_as_json (bool) – Set True to write results to a folder with one JSON file per region. Default False.
run_kwargs – Additional keyword arguments used in the analysis. These are passed on to
run_analysis().
- run_analysis(**run_kwargs)#
Runs the graphical analysis on the data using the specified method.
This method is the main entry point to carry out the analysis. It executes the steps in order, first calculating the fit, then calculating the properties of the fit.
- Parameters:
run_kwargs – Additional keyword arguments used in the analysis. These are passed on to
calculate_fit()andcalculate_fit_properties().- Returns:
None
- Side Effects:
- Computes and updates the analysis-related properties in the object based on the
provided method and threshold.
- property tacs_dir#
Gets the TAC directory path.
- property reference_tac_path#
Gets the reference TAC file path.
- is_valid_tacs_dir(tacs_dir: str)#
Validates the TAC directory by checking for TAC files.
- Parameters:
tacs_dir (str) – Directory to validate.
- Returns:
bool – True if valid, otherwise False.
- static get_tacs_list_from_dir(tacs_dir: str) list[str]#
Retrieves a sorted list of TAC file paths from a directory.
- Parameters:
tacs_dir (str) – Directory from which to retrieve TAC files.
- Returns:
list[str] – Sorted list of TAC file paths.
- static get_tacs_objects_dict_from_files_list(tacs_files_list: list[str])#
Creates a dict of TAC objects from a list of file paths.
- Parameters:
tacs_files_list (list[str]) – List of TAC file paths.
- Returns:
dict – Dictionary of region name-TAC object pairs.
- static get_tacs_objects_dict_from_dir(tacs_dir: str) dict#
Creates a dict of TAC objects from a directory of TAC files.
- Parameters:
tacs_dir (str) – A directory of TAC files.
- Returns:
dict – Dictionary of region name-TAC object pairs.
- static get_tacs_objects_list_from_files_list(tacs_files_list: list[str])#
Creates a list of TAC objects from a list of file paths.
- Parameters:
tacs_files_list (list[str]) – List of TAC file paths.
- Returns:
list[TimeActivityCurve] – List of TAC objects.
- static get_tacs_vals_from_objs_list(tacs_objects_list: list[TimeActivityCurve])#
Extracts TAC values from a list of TAC objects.
- Parameters:
tacs_objects_list (list[TimeActivityCurve]) – List of TAC objects.
- Returns:
list – List of TAC values.
- get_tacs_vals_from_dir(tacs_dir: str)#
Retrieves TAC values from files in a specified directory.
- Parameters:
tacs_dir (str) – Directory containing TAC files.
- Returns:
list – List of TAC values.
- static capitalize_first_char_of_str(input_str: str)#
Capitalize only the first character of a string, leaving the remainder unchanged.
- Parameters:
input_str (str) – The string to capitalize the first character of.
- Returns:
output_str (str) – The string with only the first character capitalized.
- static infer_segmentation_label_from_tac_path(tac_path: str, tac_id: int)#
Infers a segmentation label from a TAC file path by analyzing the filename.
This method extracts a segment label from the filename of a TAC file. It checks the presence of a seg- marker in the filename, which is followed by the segment name. This segment name is then formatted with each part capitalized. If no segment label is found, a default unknown label is generated using the TAC’s ID.
- Parameters:
tac_path (str) – Path of the TAC file.
tac_id (int) – ID of the TAC.
- Returns:
str – Inferred segmentation label.
- infer_segmentation_labels_for_tacs()#
Infers segmentation labels for TACs.
- Returns:
list[str] – List of inferred segmentation labels.