Util¶
Miscellaneous utility functions
- pycytominer.cyto_utils.util.check_aggregate_operation(operation: str) str¶
Confirm that the input operation for aggregation is currently supported.
- Parameters:
operation (str) – Aggregation operation to provide.
- Returns:
Correctly formatted operation method.
- Return type:
str
- pycytominer.cyto_utils.util.check_compartments(compartments: str | list[str])¶
Checks if the input compartments are noncanonical compartments.
- Parameters:
compartments (list of str) – Input compartments.
- Returns:
Nothing is returned.
- Return type:
None
- pycytominer.cyto_utils.util.check_consensus_operation(operation: str) str¶
Confirm that the input operation for consensus is currently supported.
- Parameters:
operation (str) – Consensus operation to provide.
- Returns:
Correctly formatted operation method.
- Return type:
str
- pycytominer.cyto_utils.util.check_correlation_method(method: str) Literal['pearson', 'kendall', 'spearman']¶
Confirm that the input method is currently supported.
- Parameters:
method (str) – The correlation metric to use.
- Returns:
Correctly formatted correlation method.
- Return type:
str
- pycytominer.cyto_utils.util.check_fields_of_view(data_fields_of_view: list[int], input_fields_of_view: list[int])¶
Confirm that the input list of fields of view is a subset of the list of fields of view in the image table.
- Parameters:
data_fields_of_view (list of int) – Fields of view in the image table.
input_fields_of_view (list of int) – Input fields of view.
- Returns:
Nothing is returned.
- Return type:
None
- pycytominer.cyto_utils.util.check_fields_of_view_format(fields_of_view: str | list[int]) str | list[int]¶
Confirm that the input fields of view is valid.
- Parameters:
fields_of_view (list of int) – List of integer fields of view.
- Returns:
Correctly formatted fields_of_view variable.
- Return type:
str or list of int
- pycytominer.cyto_utils.util.check_image_features(image_features: list[str], image_columns: list[str])¶
Confirm that the input list of image features are present in the image table
- Parameters:
image_features (list of str) – Input image features to extract from the image table.
image_columns (list of str) – Columns in the image table
- Returns:
Nothing is returned.
- Return type:
None
- pycytominer.cyto_utils.util.extract_image_features(image_feature_categories: list[str], image_df: DataFrame, image_cols: list[str], strata: list[str]) DataFrame¶
Confirm that the input list of image features categories are present in the image table and then extract those features.
- Parameters:
image_feature_categories (list of str) – Input image feature groups to extract from the image table.
image_df (pd.DataFrame) – Image dataframe.
image_cols (list of str) – Columns to select from the image table.
strata (list of str) – The columns to groupby and aggregate single cells.
- Returns:
image_features_df – Dataframe with extracted image features.
- Return type:
pd.DataFrame
- pycytominer.cyto_utils.util.get_default_compartments() list[str]¶
Returns default compartments.
- Returns:
Default compartments.
- Return type:
list of str
- pycytominer.cyto_utils.util.get_pairwise_correlation(population_df: DataFrame, method: str = 'pearson') tuple[DataFrame, DataFrame]¶
Given a population dataframe, calculate all pairwise correlations.
- Parameters:
population_df (pd.DataFrame) – Includes metadata and observation features.
method (str, default "pearson") – Which correlation matrix to use to test cutoff.
- Returns:
A tuple of two DataFrames. The first is a symmetrical correlation matrix. The second is a long format DataFrame of pairwise correlations.
- Return type:
tuple of (pd.DataFrame, pd.DataFrame)
- pycytominer.cyto_utils.util.load_known_metadata_dictionary(metadata_file: str = '/home/docs/checkouts/readthedocs.org/user_builds/pycytominer/checkouts/stable/pycytominer/cyto_utils/../data/metadata_feature_dictionary.txt') dict[str, list[str]]¶
From a tab separated text file (two columns: [“compartment”, “feature”]), load previously known metadata columns per compartment.
- Parameters:
metadata_file (str) – File location of the metadata text file. Uses a default dictionary if you do not specify.
- Returns:
Compartment (keys) mappings to previously known metadata (values).
- Return type:
dict
- pycytominer.cyto_utils.util.write_to_file_if_user_specifies_output_details(func: Callable[[...], DataFrame | str]) Callable[[...], DataFrame | str]¶
Decorate a function to optionally write its output to disk.
The decorator intercepts common output-related keyword arguments (
output_file,output_type,compression_options,float_format) from the decorated function call. The wrapped function should return apandas.DataFramewhenoutput_fileis provided; the DataFrame is written usingpycytominer.cyto_utils.output()and the resulting path is returned instead.