Skip to content

Commit

Permalink
Merge pull request #38 from vinferrer/integration
Browse files Browse the repository at this point in the history
add Integration tests to the toolbox
  • Loading branch information
vinferrer authored Nov 28, 2021
2 parents 4582a09 + 3912d65 commit ba83d11
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 12 deletions.
24 changes: 24 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,27 @@ jobs:
- codecov/upload:
file: /tmp/src/connPFM/coverage.xml

py39_integration_and_coverage:
working_directory: /tmp/src/connPFM
docker:
- image: connpfm/afni_miniconda
steps:
- attach_workspace: # get connPFM
at: /tmp
- restore_cache: # load environment
key: deps1-{{ checksum "connPFM/info.py" }}-{{ checksum "setup.py" }}
- run:
name: Run tests and compile coverage
command: |
apt-get update
apt-get install -yqq make
apt-get install -yqq curl
cp -r /opt/conda/envs/py39_env /opt/miniconda-latest/envs/py39_env
source activate py39_env
make integration
- codecov/upload:
file: /tmp/src/connPFM/coverage.xml

build_docs:
working_directory: /tmp/src/connPFM
docker:
Expand Down Expand Up @@ -283,6 +304,9 @@ workflows:
- py39_unittest_and_coverage:
requires:
- py39_env
- py39_integration_and_coverage:
requires:
- py39_env
- build_slim_latest:
requires:
- py39_unittest_and_coverage
Expand Down
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ lint:
@flake8 connPFM

unittest:
@py.test -m "not integration" --cov-append --cov-report xml --cov-report term-missing --cov=connPFM connPFM
@py.test --skipintegration --cov-append --cov-report xml --cov-report term-missing --cov=connPFM connPFM

performancetest:
@py.test -m "integration" --cov-append --cov-report xml --cov-report term-missing --cov=connPFM connPFM
integration:
@pip install -e ".[test]"
@py.test --cov-append --cov-report xml --cov-report term-missing --cov=connPFM connPFM/tests/test_integration.py
4 changes: 4 additions & 0 deletions connPFM/deconvolution/stability_lars.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os

import numpy as np
from sklearn.linear_model import lars_path

Expand All @@ -11,6 +13,8 @@ def __init__(self, nsurrogates=100, mode=1, nTE=1, key=1, maxiterfactor=0.5):
self.maxiterfactor = maxiterfactor

def _subsampling(self):
if "mode" in os.environ.keys(): # only for testing
np.random.seed(200)
# Subsampling for Stability Selection
if self.mode == 1: # different time points are selected across echoes
subsample_idx = np.sort(
Expand Down
19 changes: 10 additions & 9 deletions connPFM/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,17 @@ def bold_file(testpath):

@pytest.fixture
def AUC_file(testpath):
return fetch_file("h6uv3", testpath, "sub-pixar123_task-pixar_AUC_100.nii.gz")
return fetch_file("nh6y9", testpath, "sub-pixar123_task-pixar_AUC_100_200_seed.nii.gz")


@pytest.fixture
def ets_auc_original_file(testpath):
return fetch_file("bnp4z", testpath, "ets_AUC_original.txt")
return fetch_file("56apy", testpath, "ets_AUC_original_200_seed.txt")


@pytest.fixture
def ets_auc_denoised_file(testpath):
return fetch_file("jvuwn", testpath, "ets_AUC_denoised.txt")
return fetch_file("57fcw", testpath, "ets_AUC_denoised_200_seed.txt")


@pytest.fixture
Expand All @@ -97,6 +97,11 @@ def atlas_file(testpath):
)


@pytest.fixture
def atlas_1roi(testpath):
return fetch_file("ankvr", testpath, "Schaefer_1Parcel_4mm.nii.gz")


@pytest.fixture
def rssr_auc_file(testpath):
return fetch_file("7pnj2", testpath, "rssr_AUC.txt")
Expand All @@ -119,16 +124,12 @@ def hrf_linear_file(testpath):

@pytest.fixture
def beta_file(testpath):
return fetch_file(
"apuv9", testpath, "sub-pixar123_task-pixar_space-MNI152-preproc_bold_beta_ETS.nii.gz"
)
return fetch_file("2pmju", testpath, "sub-pixar123_task-pixar_beta_ETS.nii.gz")


@pytest.fixture
def fitt_file(testpath):
return fetch_file(
"c7g69", testpath, "sub-pixar123_task-pixar_space-MNI152-preproc_bold_fitt_ETS.nii.gz"
)
return fetch_file("ud369", testpath, "sub-pixar123_task-pixar_fitt_ETS.nii.gz")


@pytest.fixture
Expand Down
81 changes: 81 additions & 0 deletions connPFM/tests/test_integration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import subprocess
from os.path import basename, join

import numpy as np
import pytest
from nilearn.input_data import NiftiLabelsMasker


def test_integration_pfm(testpath, bold_file, atlas_1roi, AUC_file, skip_integration):
if skip_integration:
pytest.skip("Skipping integration test")
auc_output = join(testpath, "auc_local.nii.gz")
subprocess.call(
"export mode=integration_pfm && "
"connPFM -i {} -a {} --AUC {} -tr 1 -u vferrer -job 0 -nsur 1 -w pfm".format(
bold_file, atlas_1roi, auc_output
),
shell=True,
)
masker = NiftiLabelsMasker(
labels_img=atlas_1roi,
standardize=False,
strategy="mean",
resampling_target=None,
)
# compare the AUC values
auc_osf = masker.fit_transform(AUC_file)
auc_local = masker.fit_transform(auc_output)
np.allclose(auc_osf, auc_local)


def test_integration_ev(
testpath, bold_file, atlas_file, AUC_file, ets_auc_denoised_file, surr_dir, skip_integration
):
if skip_integration:
pytest.skip("Skipping integration test")
subprocess.call(
"connPFM -i {} -a {} --AUC {} -d {} -m {} -tr 1 -u vferrer -nsur 50 -w ev".format(
bold_file, atlas_file, AUC_file, surr_dir, join(testpath, "ets_AUC_denoised.txt")
),
shell=True,
)
ets_auc_denoised_local = np.loadtxt(join(testpath, "ets_AUC_denoised.txt"))
ets_auc_osf = np.loadtxt(join(ets_auc_denoised_file))
np.allclose(ets_auc_denoised_local, ets_auc_osf)


def test_integration_debias(
testpath,
bold_file,
atlas_file,
AUC_file,
ets_auc_denoised_file,
surr_dir,
beta_file,
fitt_file,
skip_integration,
):
if skip_integration:
pytest.skip("Skipping integration test")
subprocess.call(
"connPFM -i {} -a {} --AUC {} -d {} -m {} -tr 1 -u vferrer -nsur 50 -w debias".format(
bold_file, atlas_file, AUC_file, surr_dir, ets_auc_denoised_file
),
shell=True,
)
masker = NiftiLabelsMasker(
labels_img=atlas_file,
standardize=False,
strategy="mean",
)
beta_osf = masker.fit_transform(beta_file)
fitt_osf = masker.fit_transform(fitt_file)
beta_local = masker.fit_transform(
join(testpath, f"{basename(bold_file[:-7])}_beta_ETS.nii.gz")
)
fitt_local = masker.fit_transform(
join(testpath, f"{basename(bold_file[:-7])}_fitt_ETS.nii.gz")
)
np.allclose(beta_osf, beta_local)
np.allclose(fitt_osf, fitt_local)

0 comments on commit ba83d11

Please sign in to comment.