.var_consistency
- proteopy.pp.var_consistency(adata, batch_key, group_by, min_groups=4, layer=None, key_added=None, inplace=True, verbose=False)[source]
Compute the consistency of each variable’s profile across batches.
Batches (e.g. replicates) are expected to reproduce the same profile across groups (e.g. conditions and fractions). For every variable:
construct its profile across the
group_bygroups for each batchcompute the Pearson correlation between the profiles of every batch pair
summarize the pairwise correlations by their median, minimum and mean
The resulting scores can be used to remove variables with poorly reproducible profiles via
filter_by_var_consistency().- Parameters:
adata (AnnData) –
AnnDataobject in proteodata format.batch_key (str) – Column in
adata.obsidentifying the batches whose profiles are compared, e.g. replicates.group_by (str | list[str]) – Column(s) in
adata.obsdefining the groups that make up a profile. With several columns, each combination of their values is one group, e.g.["condition", "fraction"].min_groups (int) – Minimum number of groups with a value in both batches required to compute a correlation. Must be at least 2.
layer (str | None) – Layer to use for the computation. If None, uses
adata.X.key_added (str | None) – Prefix of the keys under which results are stored. Defaults to
'<batch_key>_corr'. Stored are, inadata.var,'<key_added>_median','<key_added>_min','<key_added>_mean'and'<key_added>_n_valid'(the number of batch pairs with a defined correlation), and, inadata.varm,'<key_added>_pairs': a DataFrame with the correlation ('corr_<batch1>_vs_<batch2>') and the number of shared groups ('n_<batch1>_vs_<batch2>') of every batch pair.inplace (bool) – If True, modify
adatain place. If False, return a copy ofadatawith the added keys.verbose (bool) – If True, print the matrix used and where results are stored.
- Returns:
The annotated copy of
adataifinplace=False, otherwise None.- Return type:
AnnData | None
- Raises:
KeyError – If
batch_keyor agroup_bycolumn is not inadata.obs, orlayeris not inadata.layers.ValueError – If
group_byis empty, has duplicates or containsbatch_key, thebatch_key/group_bycolumns contain missing values,min_groupsis smaller than 2, or fewer than two batches are present.TypeError – If an argument has the wrong type.
- Warns:
UserWarning – If the selected matrix is sparse and is densified, or if an output key already exists and is overwritten.
Notes
If a batch holds more than one sample for the same group, their values are averaged. A correlation is undefined (NaN) when the two batches share fewer than
min_groupsnon-missing groups or either profile is constant. Zeros are used as values, not treated as missing; convert them to NaN beforehand if they denote missing measurements.Examples
>>> import proteopy as pr >>> pr.pp.var_consistency( ... adata, ... batch_key="replicate", ... group_by=["condition", "fraction"], ... ) >>> adata.var["replicate_corr_min"].describe()