Order scdesign2 input by spatial cluster - #22
Merged
Conversation
`simulate_count_scDesign2()` writes its output one cell type at a time, in contiguous blocks (`new_count[, llim:ulim] <- ...`), but scdesign2 was pulling the coordinates from the input in its original order. The datasets are not sorted by spatial_cluster -- MOBNEW starts 1,2,3,3,4,2,4,1 -- so every spot got the counts of an unrelated spot and the spatial signal was destroyed before the metrics ever saw it. It shows: scdesign2 came last on morans_I (25.7, against 1.8 for scdesign3_nb) and on svg_precision. Every other method already does `input[order(input$obs$spatial_cluster)]` first; this one now does too. Also make cell_type_sel and cell_type_prop agree: they are matched by position, but were built with `unique()` and `table()` respectively, which only coincide when the labels happen to sort the same way. Both now come from `unique()` on the sorted data, which also matches the block order for 10 or more clusters, where numeric and character sorting disagree.
8 tasks
Sorting for the simulation is only half of it: the result has to be sorted back, or scdesign2 joins the group of methods whose output is in a different spot order than the real dataset and whose clustering_ari is therefore scored against mismatched spots. See #31.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
simulate_count_scDesign2()writes its output one cell type at a time, in contiguous blocks (new_count[, llim:ulim] <- ...in the package source), but the script attached coordinates from the input in its original order. The datasets are not sorted byspatial_cluster-- MOBNEW starts1,2,3,3,4,2,4,1-- so every spot received the counts of an unrelated spot, and the spatial signal was destroyed before the metrics saw it.It shows in the results: scdesign2 came last on
ks_statistic_morans_I(25.7, against 1.8 for scdesign3_nb) and last onsvg_precision(0.442). Every other method already doesinput[order(input$obs$spatial_cluster)]first; this one now does too.While in there:
cell_type_selandcell_type_propare matched to each other by position, but were built withunique()andtable()respectively. Those only coincide when the labels happen to sort the same way -- with 10 or more clusterstable()gives1,10,11,12,2,...and the proportions get attached to the wrong clusters. Both now derive fromunique()on the sorted data, which is also exactly the block order:Block sizes come out exact, so coordinates line up spot for spot rather than approximately.
Checklist before requesting a review
I have performed a self-review of my code
Check the correct box. Does this PR contain:
Proposed changes are described in the CHANGELOG.md
CI Tests succeed and look good!