Scores¶
Read runs back and score them against the reference annotation. These calls need only the
kdomainbench package, not the method environments, except kdb.metrics, which runs the
paper's metric code in R and in kdb_py.
read_clusters
¶
Read the domains of one run.
| PARAMETER | DESCRIPTION |
|---|---|
path
|
A run folder, or its
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame
|
Indexed by |
| RAISES | DESCRIPTION |
|---|---|
FileNotFoundError
|
There is no such folder or file, or the run did not finish. |
ValueError
|
The file has no |
Examples:
reference_annotation
¶
Read the reference annotation: the annotated domain of each spot.
| PARAMETER | DESCRIPTION |
|---|---|
h5ad
|
The input file, or the data already in memory.
TYPE:
|
reference_key
|
Column of
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Series
|
Label (as a string) per spot. Spots without a label are dropped. |
| RAISES | DESCRIPTION |
|---|---|
FileNotFoundError
|
|
KeyError
|
|
ValueError
|
|
Examples:
evaluate
¶
Score one run against the reference annotation.
k_estimated counts every label the method returned and k_reference every annotated
domain. ARI and NMI use the spots that have both a label and an annotation. NMI is
normalized by the arithmetic mean of the two entropies (the scikit-learn default).
| PARAMETER | DESCRIPTION |
|---|---|
clusters
|
The run's labels, as returned by run or read_clusters, or its run folder.
TYPE:
|
reference
|
The
TYPE:
|
reference_key
|
Column of
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict
|
|
| RAISES | DESCRIPTION |
|---|---|
FileNotFoundError
|
The run folder or the |
KeyError
|
|
TypeError
|
|
ValueError
|
No spot has both a label and an annotation (the two do not use the same barcodes),
a barcode occurs twice, or the file is not an |
| WARNS | DESCRIPTION |
|---|---|
UserWarning
|
|
Examples:
metrics
¶
Compute the twelve metrics of the paper for one finished run.
Eleven metrics come from metrics.R, run in your R, and SCS from scs.py, run in
kdb_py. The result is saved as metric.csv in the run folder, where
load_results picks it up, and a later call reads it back.
The input file needs pixel coordinates in obs["pixel_row"], obs["pixel_col"] and
obsm["spatial"], and a reference annotation in obs["clusters"] with at least two
domains. Every spot needs both an annotation and a label from the run.
| PARAMETER | DESCRIPTION |
|---|---|
run
|
A run folder with
TYPE:
|
h5ad
|
The input file. Default: the path recorded in the run's
TYPE:
|
recompute
|
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Series
|
|
| RAISES | DESCRIPTION |
|---|---|
MetricsFailed
|
The metric code stopped, for example because a package is missing or a spot has no label. |
FileNotFoundError
|
|
Examples:
MetricsFailed
¶
Bases: RuntimeError
The metric code stopped with an error or returned no value.
The message names the run's metric.log, which holds the output of the metric code.
load_results
¶
Collect every run under a folder into one table.
Reads each run_info.json under root, at any depth. Each successful run is scored
against the reference annotation of its own .h5ad file.
| PARAMETER | DESCRIPTION |
|---|---|
root
|
Folder that holds the run folders.
TYPE:
|
reference_key
|
Column of
TYPE:
|
score
|
TYPE:
|
h5ad
|
Where the input file is now, when the runs were made elsewhere: one file when all
runs are of one dataset, else
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame
|
One row per run, always with |
| RAISES | DESCRIPTION |
|---|---|
FileNotFoundError
|
|
TypeError
|
|
ValueError
|
A file given as |
| WARNS | DESCRIPTION |
|---|---|
UserWarning
|
Successful runs could not be scored, for example because their input file is not found, or labels of a run belong to no spot of its input file. A file without an annotation gives no warning. |
Examples:
k_accuracy
¶
Summarize how well each method estimates k.
Each method is summarized over all its runs in summary. Filter the table first to
compare within one dataset or device. Failed runs and runs without a reference
annotation are left out.
| PARAMETER | DESCRIPTION |
|---|---|
summary
|
The table from load_results.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame
|
One row per method, best first (smallest mean absolute k error, then highest mean ARI):
|
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
|
KeyError
|
|
| WARNS | DESCRIPTION |
|---|---|
UserWarning
|
There are successful runs, but none of them could be scored. The warning quotes
the first |
Examples: