forked from biolab/orange3-single-cell
-
Notifications
You must be signed in to change notification settings - Fork 0
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 biolab#82 from pavlin-policar/louvain-sorted-clusters
OWLouvain: Sort cluster names by number of instances
- Loading branch information
Showing
2 changed files
with
49 additions
and
2 deletions.
There are no files selected for viewing
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,41 @@ | ||
import numpy as np | ||
|
||
from Orange.data import Table, Domain | ||
from Orange.widgets.tests.base import WidgetTest | ||
from orangecontrib.single_cell.widgets.owlouvainclustering import \ | ||
OWLouvainClustering | ||
|
||
|
||
# Deterministic tests | ||
np.random.seed(42) | ||
|
||
|
||
class TestOWLouvain(WidgetTest): | ||
def setUp(self): | ||
self.widget = self.create_widget( | ||
OWLouvainClustering, stored_settings={'auto_commit': False} | ||
) | ||
|
||
def tearDown(self): | ||
self.widget.onDeleteWidget() | ||
super().tearDown() | ||
|
||
def test_clusters_ordered_by_size(self): | ||
"""Cluster names should be sorted based on the number of instances.""" | ||
x1 = np.array([[0, 0]] * 20) | ||
x2 = np.array([[1, 0]] * 15) | ||
x3 = np.array([[0, 1]] * 10) | ||
x4 = np.array([[1, 1]] * 5) | ||
data = np.vstack((x1, x2, x3, x4)) | ||
# Remove any order depencence in data, not that this should affect it | ||
np.random.shuffle(data) | ||
|
||
table = Table.from_numpy(domain=Domain.from_numpy(X=data), X=data) | ||
self.send_signal(self.widget.Inputs.data, table) | ||
self.widget.k_neighbours = 4 | ||
self.widget.commit(force=True) | ||
output = self.get_output(self.widget.Outputs.annotated_data, wait=1000) | ||
|
||
clustering = output.get_column_view('Cluster')[0].astype(int) | ||
counts = np.bincount(clustering) | ||
np.testing.assert_equal(counts, sorted(counts, reverse=True)) |
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