scripts.run_prediction#

Functions#

get_model_components(panel)

Helper function to retrieve model, scaler, label encoder, and scaling constant from a panel.

hetero_mini_batch(data[, species, type])

Uses a variant of K-Means clustering that is faster and more memory-efficient asking for a single cluster

hetero_simple(data)

Calculate simple heterogeneity as the sum of mean ranges across all channels.

merge_prediction_results(output_dir, prediction_type)

Merge prediction and uncertainty output files into a single file for each case when multiple coculture files are provided.

predict([PredictionPanel])

Runs

predict_species(data_df, model, scaler, label_encoder, ...)

param data_df:

run_heterogeneity(df, species_list, output_dir, sample)

Calculate, plot and export to files heterogeneity metrics.

save_heterogeneity_plots(hetero1, hetero2, output_dir, ...)

Exports html heterogeneity pie chart and bar plot

save_prediction_results(data_df, species_list, ...[, ...])

Saves prediction file for a coculture CellScanner prediction along with its corresponding species and uncertainty plolts.

Module Contents#

scripts.run_prediction.get_model_components(panel)#

Helper function to retrieve model, scaler, label encoder, and scaling constant from a panel.

scripts.run_prediction.hetero_mini_batch(data, species=None, type='av_diss')#

Uses a variant of K-Means clustering that is faster and more memory-efficient asking for a single cluster similar to computing the mean (or geometric center) of all points. The distance of points to this single centroid (central reference point) can be used to assess variability.

It then used this to compute the distance between each pair data point from it.

Parameters:
  • data

  • species

  • type

Return result:

Maximum distance between the centroid and data points

scripts.run_prediction.hetero_simple(data)#

Calculate simple heterogeneity as the sum of mean ranges across all channels.

scripts.run_prediction.merge_prediction_results(output_dir, prediction_type)#

Merge prediction and uncertainty output files into a single file for each case when multiple coculture files are provided.

Parameters:
  • output_dir – Output directory where CellScanner prediction files were saved

  • prediction_type – TYpe of CellScanner output file; `prediction` (counts) or `uncertainty` (heretogeneity)

scripts.run_prediction.predict(PredictionPanel=None, **kwargs)#

Runs

Parameters:
  • PredictionPanel

  • kwargs

scripts.run_prediction.predict_species(data_df, model, scaler, label_encoder, scaling_constant)#
Parameters:
  • data_df

  • model

  • scaler

  • label_encoder

  • scaling_constant

Return predicted_classes (np.ndarray of ints):

The predicted class indices

Return uncertainties (np.ndarray of floats):

The entropy values for each prediction

Return index_to_species (dict):

A mapping from class index to species name

scripts.run_prediction.run_heterogeneity(df, species_list, output_dir, sample)#

Calculate, plot and export to files heterogeneity metrics.

Parameters:
  • df

  • species_list

  • output_dir

  • sample

scripts.run_prediction.save_heterogeneity_plots(hetero1, hetero2, output_dir, sample, species=None)#

Exports html heterogeneity pie chart and bar plot

scripts.run_prediction.save_prediction_results(data_df: pandas.DataFrame, species_list: List, output_dir: str, x_axis, y_axis, z_axis, sample: str = None, scaling_constant: int = 150, uncertainty_threshold: float = 0.5, filter_out_uncertain: bool = False)#

Saves prediction file for a coculture CellScanner prediction along with its corresponding species and uncertainty plolts.