MultiTACGraphicalAnalysis ==================================================================== .. py: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: :py:obj:`GraphicalAnalysis`, :py:obj:`petpal.utils.time_activity_curve.MultiTACAnalysisMixin` A class that performs graphical analysis on multiple tissue TACs (Time Activity Curves). :ivar input_tac_path: Path to the input TAC file. :vartype input_tac_path: str :ivar roi_tacs_dir: Directory containing region of interest TAC files. :vartype roi_tacs_dir: str :ivar output_directory: Directory for saving analysis results. :vartype output_directory: str :ivar output_filename_prefix: Prefix for output filenames. :vartype output_filename_prefix: str :ivar method: Method used for analysis. :vartype method: str :ivar fit_thresh_in_mins: Threshold in minutes for fit calculation. :vartype fit_thresh_in_mins: Optional[float] Initializes the MultiTACGraphicalAnalysis object with required paths, method, and threshold. :param input_tac_path: Path to the input TAC file. :type input_tac_path: str :param roi_tacs_dir: Directory containing region of interest TAC files. :type roi_tacs_dir: str :param output_directory: Directory for saving analysis results. :type output_directory: str :param output_filename_prefix: Prefix for output filenames. :type output_filename_prefix: str :param method: Method used for analysis. :type method: str :param fit_thresh_in_mins: Threshold in minutes for fit calculation. Defaults to None. :type fit_thresh_in_mins: Optional[float], optional .. py:method:: init_analysis_props() Initializes analysis properties for each tissue TAC. Overrides :meth:`GraphicalAnalysis.init_analysis_props`. :returns: *list[dict]* -- A list of analysis property dictionaries for each TAC. .. py:method:: calculate_fit(**run_kwargs) Calculates the fit for each TAC, updating the analysis properties with slope, intercept, and R-squared values. Overrides :meth:`GraphicalAnalysis.calculate_fit`. :param run_kwargs: Additional keyword arguments passed on to `analysis_func`. .. py:method:: 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 :meth:`GraphicalAnalysis.calculate_fit_properties` :param run_kwargs: Additional keyword arguments used in the analysis. These are saved to the analysis properties as individual properties. .. py:method:: 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. :param output_as_tsv: Set True to write results to TSV table. Default True. :type output_as_tsv: bool :param output_as_json: Set True to write results to a folder with one JSON file per region. Default False. :type output_as_json: bool :raises RuntimeError: If 'run_analysis' method has not been called before save_analysis. .. py:method:: __call__(output_as_tsv: bool = True, output_as_json: bool = False, **run_kwargs) Runs :meth:`run_analysis` and :meth:`save_analysis` to run the analysis and save the analysis properties. :param output_as_tsv: Set True to write results to TSV table. Default True. :type output_as_tsv: bool :param output_as_json: Set True to write results to a folder with one JSON file per region. Default False. :type output_as_json: bool :param run_kwargs: Additional keyword arguments used in the analysis. These are passed on to :meth:`run_analysis`. .. py:method:: 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. :param run_kwargs: Additional keyword arguments used in the analysis. These are passed on to :meth:`calculate_fit` and :meth:`calculate_fit_properties`. :returns: None Side Effects: Computes and updates the analysis-related properties in the object based on the provided method and threshold. .. py:property:: tacs_dir Gets the TAC directory path. .. py:property:: reference_tac_path Gets the reference TAC file path. .. py:method:: is_valid_tacs_dir(tacs_dir: str) Validates the TAC directory by checking for TAC files. :param tacs_dir: Directory to validate. :type tacs_dir: str :returns: *bool* -- True if valid, otherwise False. .. py:method:: get_tacs_list_from_dir(tacs_dir: str) -> list[str] :staticmethod: Retrieves a sorted list of TAC file paths from a directory. :param tacs_dir: Directory from which to retrieve TAC files. :type tacs_dir: str :returns: *list[str]* -- Sorted list of TAC file paths. .. py:method:: get_tacs_objects_dict_from_files_list(tacs_files_list: list[str]) :staticmethod: Creates a dict of TAC objects from a list of file paths. :param tacs_files_list: List of TAC file paths. :type tacs_files_list: list[str] :returns: *dict* -- Dictionary of region name-TAC object pairs. .. py:method:: get_tacs_objects_dict_from_dir(tacs_dir: str) -> dict :staticmethod: Creates a dict of TAC objects from a directory of TAC files. :param tacs_dir: A directory of TAC files. :type tacs_dir: str :returns: *dict* -- Dictionary of region name-TAC object pairs. .. py:method:: get_tacs_objects_list_from_files_list(tacs_files_list: list[str]) :staticmethod: Creates a list of TAC objects from a list of file paths. :param tacs_files_list: List of TAC file paths. :type tacs_files_list: list[str] :returns: *list[TimeActivityCurve]* -- List of TAC objects. .. py:method:: get_tacs_vals_from_objs_list(tacs_objects_list: list[TimeActivityCurve]) :staticmethod: Extracts TAC values from a list of TAC objects. :param tacs_objects_list: List of TAC objects. :type tacs_objects_list: list[TimeActivityCurve] :returns: *list* -- List of TAC values. .. py:method:: get_tacs_vals_from_dir(tacs_dir: str) Retrieves TAC values from files in a specified directory. :param tacs_dir: Directory containing TAC files. :type tacs_dir: str :returns: *list* -- List of TAC values. .. py:method:: capitalize_first_char_of_str(input_str: str) :staticmethod: Capitalize only the first character of a string, leaving the remainder unchanged. :param input_str: The string to capitalize the first character of. :type input_str: str :returns: *output_str (str)* -- The string with only the first character capitalized. .. py:method:: infer_segmentation_label_from_tac_path(tac_path: str, tac_id: int) :staticmethod: 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. :param tac_path: Path of the TAC file. :type tac_path: str :param tac_id: ID of the TAC. :type tac_id: int :returns: *str* -- Inferred segmentation label. .. py:method:: infer_segmentation_labels_for_tacs() Infers segmentation labels for TACs. :returns: *list[str]* -- List of inferred segmentation labels. .. seealso:: :meth:`infer_segmentation_label_from_tac_path`