-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #402 from lenatr99/morani_scorer
Spatial Autocorrelation Scorer Implementation
- Loading branch information
Showing
8 changed files
with
393 additions
and
25 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
Spatial Autocorrelation Scorer | ||
============================== | ||
|
||
Calculate Moran's I or Geary's C spatial autocorrelation score based on input gene expression data. | ||
|
||
**Inputs** | ||
|
||
- Data: input dataset with spatial coordinates and gene expression values | ||
|
||
**Outputs** | ||
|
||
- Scorer: an instance of SpatialScorer containing the adjacency matrix and selected method for scoring | ||
|
||
**Spatial Autocorrelation Scorer** calculates the spatial autocorrelation score (Moran's I or Geary's C) for each gene in the dataset. The input dataset must include gene expression values in columns and spatial coordinates (x and y) in selected columns. The adjacency matrix is computed using k-nearest neighbors based on the spatial coordinates. The scores are computed independently for each gene. | ||
|
||
![](images/SpatialAutocorrelation-stamped.png) | ||
|
||
|
||
1. Information about the input data. | ||
2. Select X and Y columns that provide spatial coordinates for each cell. | ||
3. Select the method for calculating spatial autocorrelation (Moran I or Geary C) and specify the number of nearest neighbors (k) for constructing the adjacency matrix. | ||
4. Tick to automatically process input data and send the result to the output. If left unchecked, processing must be triggered manually. | ||
|
||
Example | ||
------- | ||
|
||
We will use [Single Cell Datasets](single_cell_datasets.md) widget to load *Bone marrow mononuclear cells with AML (sample)* data. Then we will pass it through **t-SNE** to get the spatial coordinates of the cells. We will pass the data to the **Spatial Autocorrelation Scorer** widget, select *t-SNE-x* and *t-SNE-y* as spatial coordinates, and calculate Moran's I score with 30 nearest neighbors. | ||
|
||
We pass the scorer and the data to **Rank** widget to get the top 10 genes with the highest Moran's I score and visualize the results in **Scatter Plot**. | ||
|
||
![](images/SpatialAutocorrelation-Example.png) |
50 changes: 50 additions & 0 deletions
50
orangecontrib/single_cell/tests/test_owspatialautocorrelation.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import unittest | ||
from Orange.data import Table | ||
from Orange.widgets.tests.base import WidgetTest | ||
from orangecontrib.single_cell.widgets.owspatialautocorrelation import OWSpatialAutocorrelation | ||
from Orange.widgets.utils.concurrent import TaskState | ||
|
||
|
||
class TestOWSpatialAutocorrelation(WidgetTest): | ||
def setUp(self): | ||
self.widget = self.create_widget(OWSpatialAutocorrelation) | ||
|
||
def test_input_data(self): | ||
data = Table("iris") | ||
self.widget.set_data(data) | ||
self.assertEqual(self.widget.data, data) | ||
|
||
def test_feature_selection(self): | ||
data = Table("iris") | ||
self.widget.set_data(data) | ||
self.widget.feature_x_combo.setCurrentIndex(1) | ||
self.widget.feature_y_combo.setCurrentIndex(2) | ||
self.assertEqual(self.widget.feature_x, "sepal width") | ||
self.assertEqual(self.widget.feature_y, "petal length") | ||
|
||
def test_method_selection(self): | ||
self.widget.method = "Geary C" | ||
self.assertEqual(self.widget.method, "Geary C") | ||
|
||
def test_k_neighbors_input(self): | ||
self.widget.k_input.setText("10") | ||
self.widget._on_k_changed() | ||
self.assertEqual(self.widget.k_neighbors, 10) | ||
|
||
def test_auto_commit(self): | ||
self.widget.auto_commit = False | ||
self.assertFalse(self.widget.auto_commit) | ||
|
||
def test_calculate(self): | ||
data = Table("iris") | ||
self.widget.set_data(data) | ||
self.widget.feature_x_combo.setCurrentIndex(0) | ||
self.widget.feature_y_combo.setCurrentIndex(1) | ||
self.widget.k_input.setText("5") | ||
self.widget._on_k_changed() | ||
self.widget.calculate(TaskState()) | ||
self.assertIsNotNone(self.widget.adjacency_matrix) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
38 changes: 38 additions & 0 deletions
38
orangecontrib/single_cell/widgets/icons/SpatialAutocorrelation.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
This file contains 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
Oops, something went wrong.