mantispy.tl.nn_moa_classify#
- mantispy.tl.nn_moa_classify(adata, moa_key='Metadata_MOA', metric='cosine', scheme='nsc', compound_key='Metadata_Compound', batch_key='Metadata_Batch', use_rep=None, key_added='moa', copy=False)#
Leave-one-out nearest-neighbor mechanism assignment.
- Parameters:
adata (
AnnData) – Profiles to classify, one row per treatment or per well.moa_key (
str(default:'Metadata_MOA')) –obscolumn holding the known mechanism.metric (
str(default:'cosine')) – Similarity between profiles,"cosine"or"pearson".scheme (
str(default:'nsc')) –"nn"allows any neighbor, which is usually optimistic because a compound can match itself at another dose."nsc"(not-same-compound) excludes neighbors of the same compound, as in the published BBBC021 benchmark."nscb"also excludes neighbors from the same batch, so a batch effect cannot produce the match.compound_key (
str(default:'Metadata_Compound')) –obscolumn read for thenscandnscbexclusions.batch_key (
str(default:'Metadata_Batch')) –obscolumn read for thenscbexclusion.use_rep (
str|None(default:None)) – Classifyobsm[use_rep]instead ofX.key_added (
str(default:'moa')) – Name for the outputs.copy (
bool(default:False)) – Return a modified copy instead of mutating in place.
- Return type:
- Returns:
None, or the modified copy. Writesobs[key_added + "_predicted"], a summary atuns["mantispy"][key_added](accuracy,n_classified,n_excluded,scheme) and a tidytrue/predicted/counttable atuns["mantispy"][key_added + "_confusion"].- Raises:
ValueError –
schemeis not one ofSCHEMES.KeyError –
obshas nomoa_key, or no column that the chosen scheme excludes neighbors on.
Notes
A row with no admissible neighbor, for example under
"nscb"on a single batch, is left unclassified and counted inn_excluded. Chance level is1/n_classesonly when the classes are balanced; otherwise compare against the largest class’s share.A profile with no mechanism on file is neither scored nor used as a neighbor, so the accuracy does not depend on the annotated fraction.