mantispy.pp.feature_select

Contents

mantispy.pp.feature_select#

mantispy.pp.feature_select(adata, operations=('variance_threshold', 'correlation_threshold', 'drop_na_columns', 'blocklist'), min_variance=1e-06, freq_cut=0.05, unique_cut=0.01, corr_threshold=0.9, corr_method='pearson', na_cutoff=0.05, outlier_cutoff=500.0, blocklist='default', noise_removal_perturb_groups='Metadata_Perturbation', noise_removal_stdev_cutoff=0.8, key_added='selected', copy=False)#

Flag the features worth keeping.

Parameters:
  • adata (AnnData) – Object to select features on. Usually well-level profiles.

  • operations (Sequence[str] (default: ('variance_threshold', 'correlation_threshold', 'drop_na_columns', 'blocklist'))) – Which operations to run, from OPERATIONS. The default omits frequency_threshold, drop_outliers and noise_removal, matching pycytominer’s own default.

  • min_variance (float (default: 1e-06)) – variance_threshold: keep features with variance above this.

  • freq_cut (float (default: 0.05)) – frequency_threshold: drop a feature when the count of its second most common value divided by the count of its most common is below this. Either this rule or unique_cut drops a feature.

  • unique_cut (float (default: 0.01)) – frequency_threshold: drop a feature when its share of distinct values is below this.

  • corr_threshold (float (default: 0.9)) – correlation_threshold: drop one member of every pair correlated above this.

  • corr_method (str (default: 'pearson')) – correlation_threshold: "pearson" or "spearman".

  • na_cutoff (float (default: 0.05)) – drop_na_columns: drop features missing in more than this fraction of rows.

  • outlier_cutoff (float (default: 500.0)) – drop_outliers: drop features whose absolute value exceeds this.

  • blocklist (str | Sequence[str] (default: 'default')) – blocklist: "default" for the bundled list, or explicit names. Matched against the current names and against var["original_name"], so it works either side of standardize_feature_names().

  • noise_removal_perturb_groups (str (default: 'Metadata_Perturbation')) – noise_removal: obs column grouping replicates.

  • noise_removal_stdev_cutoff (float (default: 0.8)) – noise_removal: drop features whose within-group standard deviation, averaged over groups, is above this.

  • key_added (str (default: 'selected')) – Name of the boolean var column to write.

  • copy (bool (default: False)) – Return a modified copy instead of mutating in place.

Return type:

AnnData | None

Returns:

None, or the modified copy. Writes var[key_added] and a per-operation count of removals to uns["mantispy"]["feature_select"], each count being what that operation removes on its own. Nothing is dropped; use subset_features() for that.

Raises:
  • ValueError – If operations names an operation that is not in OPERATIONS.

  • KeyError – If noise_removal is requested but noise_removal_perturb_groups is not an obs column.

Notes

Every operation judges the full feature set, so each count in uns["mantispy"]["feature_select"] says what that operation alone would remove and is the same whatever order operations runs in. The counts therefore overlap: a feature that is both constant and mostly missing is counted by variance_threshold and by drop_na_columns, and the counts sum to more than the number of features actually removed, which is n_vars minus var[key_added].sum().

correlation_threshold is the most expensive operation. pycytominer uses pandas.DataFrame.corr, one Cython pass per column pair. Here the pairs come from chunked matrix products over blocks of columns, so no n_vars ** 2 array is held in memory.