diff --git a/CHANGELOG.md b/CHANGELOG.md index 33c66d8d..e2ec54e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,12 @@ Bug fixes: mismatched spots. - `generate_sim_spatialcluster`: check that the simulated dataset still lines up with the real one, through a new `check_alignment()` helper. + - `downstream`: reuse the `spatial_cluster` that + `process_datasets/generate_sim_spatialcluster` already computed, instead of + running `BayesSpace::spatialCluster()` a second time. Saves an MCMC run per + method per dataset and makes the metric report the clustering the pipeline + stored. This does not make `clustering_ari` reproducible: both before and + after, a fixed reference is compared against one unseeded run. - `generate_cosine()`: filter the Moran's I values rather than the objects holding them, so that a single NaN no longer takes the whole metric with it. `crosscor_cosine` was NA for 32 of 99 runs. diff --git a/src/metrics/downstream/script.R b/src/metrics/downstream/script.R index f03009c8..0f0dcb6e 100644 --- a/src/metrics/downstream/script.R +++ b/src/metrics/downstream/script.R @@ -43,13 +43,20 @@ crosscor_cosine <- generate_cosine(real_moransI, sim_moransI) crosscor_mantel <- generate_mantel(real_moransI, sim_moransI) cat("spatial clustering evaluation\n") -# reclassify the clustering result -real_cluster <- input_real_sp$obs[, c("spatial_cluster")] -sim_cluster <- generate_sim_spatialCluster(input_real_sp, input_simulated_sp) -location <- rownames(input_simulated_sp) -sim_new_cluster <- reclassify_simsce(location, real_cluster, sim_cluster) +# the simulated clustering was already computed by +# process_datasets/generate_sim_spatialcluster; recomputing it here would give a +# different answer every time, since BayesSpace is stochastic and unseeded +real_cluster <- input_real_sp$obs[["spatial_cluster"]] +sim_cluster <- input_simulated_sp$obs[["spatial_cluster"]] -# ART and NMI +if (is.null(sim_cluster)) { + stop( + "The simulated dataset has no 'spatial_cluster' column. ", + "Did it pass through process_datasets/generate_sim_spatialcluster?" + ) +} + +# ARI and NMI clustering_ari <- aricode::ARI(real_cluster, sim_cluster) clustering_nmi <- aricode::NMI(real_cluster, sim_cluster)