Skip to content

Commit

Permalink
Merge pull request #392 from biolab/reusable-workflows
Browse files Browse the repository at this point in the history
CI - Reusable workflows
  • Loading branch information
markotoplak authored Feb 24, 2023
2 parents 45fb6db + 0d3db91 commit 1083204
Show file tree
Hide file tree
Showing 23 changed files with 192 additions and 207 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/rebase.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: Automatic Rebase
on:
issue_comment:
types: [created]
jobs:
rebase:
uses: biolab/orange-ci-cd/.github/workflows/rebase-addons.yml@master
secrets: inherit
85 changes: 2 additions & 83 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,86 +9,5 @@ on:
- master

jobs:
build:
runs-on: ${{ matrix.os }}
continue-on-error: ${{ matrix.experimental }}
timeout-minutes: 15
name: ${{ matrix.name }} (${{ matrix.os }}, ${{ matrix.python-version }})
strategy:
fail-fast: false
matrix:
os: [ubuntu-18.04, macos-10.15, windows-2016]
python-version: [3.7, 3.8]
tox_env: [py-orange-released]
experimental: [false]
name: [Released]
include:
- os: windows-2019
python-version: 3.8
tox_env: py-orange-released
experimental: true
name: Windows10
- os: macos-11.0
python-version: 3.8
tox_env: py-orange-released
experimental: true
name: Big Sur

- os: windows-2016
python-version: 3.7
tox_env: py-orange-oldest
experimental: false
name: Oldest
- os: macos-10.15
python-version: 3.7
tox_env: py-orange-oldest
name: Oldest
experimental: false
- os: ubuntu-18.04
python-version: 3.7
tox_env: py-orange-oldest
name: Oldest
experimental: false

- os: windows-2016
python-version: 3.8
tox_env: py-orange-latest
experimental: false
name: Latest
- os: macos-10.15
python-version: 3.8
tox_env: py-orange-latest
experimental: false
name: Latest
- os: ubuntu-18.04
python-version: 3.8
tox_env: py-orange-latest
experimental: false
name: Latest

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade tox tox-pip-version
- name: Test with Tox
run: |
tox -e ${{ matrix.tox_env }}
env:
QT_QPA_PLATFORM: offscreen

- name: Upload code coverage
if: |
matrix.python-version == '3.8' &&
matrix.os == 'ubuntu-18.04' &&
matrix.tox_env == 'py-orange-released'
run: |
pip install codecov
codecov
test:
uses: biolab/orange-ci-cd/.github/workflows/test-addons.yml@master
9 changes: 5 additions & 4 deletions orangecontrib/single_cell/preprocess/scbnorm.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def score_data(self, data, feature):
if not all((isinstance(att, ContinuousVariable) for att in data.domain.attributes)):
raise ValueError("All variables in the data must be Continuous!")

a = data.get_column_view(feature.name)[0].reshape((len(data), 1))
a = data.get_column(feature.name).reshape((len(data), 1))
if isinstance(feature, ContinuousVariable):
_, p = self.correlations(a, data.X)
w = (p < self.alpha).mean()
Expand All @@ -91,7 +91,7 @@ class ScBatchShared(SharedComputeValue):
"""Places the values of shared data within the corresponding variable column."""
def compute(self, data, shared_data):
assert self.variable is not None
return shared_data.get_column_view(self.variable)[0] if self.variable in shared_data.domain else np.nan
return shared_data.get_column(self.variable) if self.variable in shared_data.domain else np.nan


class SCBatchNormalizer(Preprocess):
Expand Down Expand Up @@ -186,7 +186,7 @@ def transform(self, data):
assert all((a.name in self.models for a in atts))
assert all(b in data.domain for b in self.batch_vars)
Z = self._design_matrix(data)
W = np.hstack((self.models[a.name].reshape((Z.shape[1], 1)) for a in atts))
W = np.hstack([self.models[a.name].reshape((Z.shape[1], 1)) for a in atts])
Xc = data.X.copy()
if self.nonzero_only:
nz = np.where(Xc)
Expand All @@ -198,7 +198,8 @@ def transform(self, data):
else:
Xc = INV_LINKS[self.link](LINKS[self.link](Xc) - Z.dot(W))
new_data = data.copy()
new_data.X = Xc
with new_data.unlocked_reference(new_data.X):
new_data.X = Xc
return new_data

def __call__(self, data):
Expand Down
23 changes: 14 additions & 9 deletions orangecontrib/single_cell/preprocess/scpreprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@ def __init__(self, condition=GreaterOrEqual, threshold=1):

def __call__(self, data: Table) -> Table:
new_data = data.copy()
if self.condition == Binarize.GreaterOrEqual:
new_data.X = new_data.X >= self.threshold
elif self.condition == Binarize.Greater:
new_data.X = new_data.X > self.threshold
with new_data.unlocked_reference(new_data.X):
if self.condition == Binarize.GreaterOrEqual:
new_data.X = new_data.X >= self.threshold
elif self.condition == Binarize.Greater:
new_data.X = new_data.X > self.threshold
return new_data


Expand All @@ -78,7 +79,8 @@ def normalize(self, *args):
class NormalizeSamples(Normalize):
def __call__(self, data: Table) -> Table:
new_data = data.copy()
new_data.X = self.normalize(data.X)
with new_data.unlocked_reference(new_data.X):
new_data.X = self.normalize(data.X)
return new_data

def normalize(self, table: AnyArray) -> AnyArray:
Expand Down Expand Up @@ -106,10 +108,11 @@ def __init__(self, group_var, method=Normalize.CPM):
self.group_var = group_var

def __call__(self, data: Table) -> Table:
group_col = data.get_column_view(self.group_var)[0]
group_col = data.get_column(self.group_var)
group_col = group_col.astype("int64")
new_data = data.copy()
new_data.X = self.normalize(data.X, group_col)
with new_data.unlocked_reference(new_data.X):
new_data.X = self.normalize(data.X, group_col)
return new_data

def normalize(self, table: AnyArray, group_col: np.ndarray) -> AnyArray:
Expand Down Expand Up @@ -147,9 +150,11 @@ def __init__(self, lower_bound=None, upper_bound=None):
def __call__(self, data):
new_data = data.copy()
with np.errstate(invalid="ignore"):
new_data.X = np.nan_to_num(zscore(data.X))
with new_data.unlocked_reference(new_data.X):
new_data.X = np.nan_to_num(zscore(data.X))
if self.lower_bound is not None or self.upper_bound is not None:
np.clip(new_data.X, self.lower_bound, self.upper_bound, new_data.X)
with new_data.unlocked(new_data.X):
np.clip(new_data.X, self.lower_bound, self.upper_bound, new_data.X)
return new_data


Expand Down
24 changes: 13 additions & 11 deletions orangecontrib/single_cell/tests/preprocess/test_scbnorm.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import numpy as np
import unittest
from itertools import product
from scipy.stats import pearsonr
from Orange.data import Table, ContinuousVariable, DiscreteVariable, Domain
from orangecontrib.single_cell.preprocess.scbnorm import *


Expand Down Expand Up @@ -61,8 +59,8 @@ def test_multivariate_lin(self):
model = ScBatchNormalizeModel(batch_vars=["Z0", "Z1"], link=LINK_IDENTITY)
model.fit(self.data_lin)
data1 = model(self.data_lin)
assert pearsonr(data1.get_column_view("Z0")[0], data1.X[:, 0].ravel())[1] > alpha
assert pearsonr(data1.get_column_view("Z1")[0], data1.X[:, 0].ravel())[1] > alpha
assert pearsonr(data1.get_column("Z0"), data1.X[:, 0].ravel())[1] > alpha
assert pearsonr(data1.get_column("Z1"), data1.X[:, 0].ravel())[1] > alpha
assert pearsonr(self.noise.ravel(), data1.X[:, 0].ravel())[1] < alpha
assert np.linalg.norm(data1.X[self.zeros]) == 0

Expand All @@ -72,8 +70,8 @@ def test_multivariate_log(self):
model = ScBatchNormalizeModel(batch_vars=["Z0", "Z1"], link=LINK_LOG)
model.fit(self.data_log)
data1 = model(self.data_log)
assert pearsonr(data1.get_column_view("Z0")[0], data1.X[:, 0].ravel())[1] > alpha
assert pearsonr(data1.get_column_view("Z1")[0], data1.X[:, 0].ravel())[1] > alpha
assert pearsonr(data1.get_column("Z0"), data1.X[:, 0].ravel())[1] > alpha
assert pearsonr(data1.get_column("Z1"), data1.X[:, 0].ravel())[1] > alpha
assert pearsonr(self.noise.ravel(), data1.X[:, 0].ravel())[1] < alpha
assert np.linalg.norm(data1.X[self.zeros]) == 0

Expand Down Expand Up @@ -119,8 +117,8 @@ def test_nonzero_lin(self):
link=LINK_IDENTITY)
model.fit(self.data_lin)
data1 = model(self.data_lin)
assert pearsonr(data1.get_column_view("Z0")[0], data1.X[:, 0].ravel())[1] > alpha
assert pearsonr(data1.get_column_view("Z1")[0], data1.X[:, 0].ravel())[1] > alpha
assert pearsonr(data1.get_column("Z0"), data1.X[:, 0].ravel())[1] > alpha
assert pearsonr(data1.get_column("Z1"), data1.X[:, 0].ravel())[1] > alpha
assert pearsonr(self.noise.ravel(), data1.X[:, 0].ravel())[1] < alpha
assert np.linalg.norm(data1.X[self.zeros]) > 0

Expand All @@ -137,8 +135,8 @@ def test_batch_class(self):
alpha = 0.05
pp = SCBatchNormalizer(batch_vars=("class", "Z0"))
data1 = pp(self.data_lin)
assert pearsonr(data1.get_column_view("class")[0], data1.X[:, 0].ravel())[1] > alpha
assert pearsonr(data1.get_column_view("Z0")[0], data1.X[:, 0].ravel())[1] > alpha
assert pearsonr(data1.get_column("class"), data1.X[:, 0].ravel())[1] > alpha
assert pearsonr(data1.get_column("Z0"), data1.X[:, 0].ravel())[1] > alpha

def test_no_vars(self):
""" Test with no batch variables. """
Expand All @@ -163,4 +161,8 @@ def dummy_call():
nonzero_only=True,
link=LINK_IDENTITY)
model.fit(self.data_lin_neg)
self.assertRaises(ValueError, dummy_call)
self.assertRaises(ValueError, dummy_call)


if __name__ == "__main__":
unittest.main()
Original file line number Diff line number Diff line change
Expand Up @@ -273,3 +273,7 @@ def test_preserves_density(self, prepare_table):
is_sparse = table.is_sparse()
filtered_table = DropoutGeneSelection(3)(table)
self.assertEqual(is_sparse, filtered_table.is_sparse())


if __name__ == "__main__":
unittest.main()
6 changes: 6 additions & 0 deletions orangecontrib/single_cell/tests/test_owaligndatasets.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import unittest

from sklearn import datasets
from Orange.data import ContinuousVariable, DiscreteVariable
import numpy as np
Expand Down Expand Up @@ -96,3 +98,7 @@ def test_source_id_defult(self):

self.send_signal(w.Inputs.data, data)
self.assertEqual("class", str(w.source_id))


if __name__ == "__main__":
unittest.main()
15 changes: 12 additions & 3 deletions orangecontrib/single_cell/tests/test_owbatchnorm.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import unittest

import numpy as np

from AnyQt.QtCore import Qt
Expand Down Expand Up @@ -38,7 +40,8 @@ def test_discrete_attributes_input(self):
def test_missing_values_input(self):
"""Check batch normalization for data set with unknown values """
data = Table("iris")
data[0, 3] = np.nan
with data.unlocked(data.X):
data[0, 3] = np.nan
self.send_signal(self.widget.Inputs.data, data)
self.assertIsInstance(self.get_output(self.widget.Outputs.data), Table)
self.assertTrue(self.widget.Warning.missing_values.is_shown())
Expand All @@ -49,7 +52,8 @@ def test_missing_values_input(self):
def test_negative_values_input_log_link(self):
"""Check batch normalization for data set with negative values"""
data = Table("iris")
data[0, 3] = -1
with data.unlocked(data.X):
data[0, 3] = -1
self.send_signal(self.widget.Inputs.data, data)
self.widget.model.item(0).setCheckState(Qt.Checked)
link_method = self.widget.controls.link_method
Expand All @@ -65,7 +69,8 @@ def test_negative_values_input_log_link(self):
def test_negative_values_input_id_link(self):
"""Check batch normalization for data set with negative values"""
data = Table("iris")
data[0, 3] = -1
with data.unlocked(data.X):
data[0, 3] = -1
self.send_signal(self.widget.Inputs.data, data)
self.widget.model.item(0).setCheckState(Qt.Checked)
link_method = self.widget.controls.link_method
Expand All @@ -80,3 +85,7 @@ def test_negative_values_input_id_link(self):
self.assertFalse(self.widget.Warning.negative_values.is_shown())
output = self.get_output(self.widget.Outputs.data)
self.assertFalse((output.X == data.X).any())


if __name__ == "__main__":
unittest.main()
7 changes: 6 additions & 1 deletion orangecontrib/single_cell/tests/test_owdotmatrix.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from unittest.mock import patch, Mock
import unittest
from unittest.mock import Mock

import numpy as np

Expand Down Expand Up @@ -212,3 +213,7 @@ def test_output_transpose(self):
self.assertEqual(1, len(cont_data.domain.metas))
self.assertEqual(1, len(cont_data.domain.metas))
self.assertEqual("Gene", str(cont_data.domain.metas[0]))


if __name__ == "__main__":
unittest.main()
2 changes: 1 addition & 1 deletion orangecontrib/single_cell/tests/test_owdropout.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from AnyQt.QtCore import Qt, QPoint
from AnyQt.QtTest import QTest
from PyQt5.QtWidgets import QToolTip
from AnyQt.QtWidgets import QToolTip

from Orange.data import Table, StringVariable, Domain, ContinuousVariable
from Orange.data.filter import Values, FilterString
Expand Down
10 changes: 5 additions & 5 deletions orangecontrib/single_cell/tests/test_owmultisample.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import numpy.testing as npt

from AnyQt.QtCore import Qt, QMimeData, QUrl, QPoint
from AnyQt.QtCore import Qt, QMimeData, QUrl, QPointF
from AnyQt.QtGui import QDropEvent

from Orange.widgets.tests.base import WidgetTest
Expand Down Expand Up @@ -35,9 +35,9 @@ def setUp(self):
self.widget.set_current_path(self.file_name_1)
self.widget.set_current_path(self.file_name_2)
model = self.widget.view.model()
model.item(0).setCheckState(True)
model.item(1).setCheckState(True)
self.widget.commit()
model.item(0).setCheckState(Qt.CheckState.Checked)
model.item(1).setCheckState(Qt.CheckState.Checked)
self.widget.commit.now()

def test_minimum_size(self):
pass
Expand Down Expand Up @@ -80,7 +80,7 @@ def test_drop_sample(self):
data = QMimeData()
data.setUrls([QUrl.fromLocalFile(path)])
event = QDropEvent(
QPoint(10, 10), Qt.MoveAction, data,
QPointF(10, 10), Qt.MoveAction, data,
Qt.NoButton, Qt.NoModifier, QDropEvent.Drop)
self.widget.view.dropEvent(event)
self.assertEqual(self.widget.view.model().rowCount(), 3)
Expand Down
6 changes: 3 additions & 3 deletions orangecontrib/single_cell/tests/test_owscorecells.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def test_score_cells(self):
self.assertIsNotNone(self.widget.marker_genes)

# output data
self.widget.commit()
self.widget.commit.now()
out_data = self.get_output(self.widget.Outputs.data)
self.assertTrue((self.expected_score_values == out_data.metas).all())

Expand All @@ -68,9 +68,9 @@ def test_no_input_genes(self):
self.assertIsNotNone(self.widget.input_data)

# output data
self.widget.commit()
self.widget.commit.now()
out_data = self.get_output(self.widget.Outputs.data)
self.assertTrue(np.all(out_data.get_column_view('Score')[0] == 1.0))
self.assertTrue(np.all(out_data.get_column("Score") == 1.0))


if __name__ == '__main__':
Expand Down
Loading

0 comments on commit 1083204

Please sign in to comment.