Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DatasetSearcher class with search methods from Dataset #677

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update get_studies_by_mask.
tsalo committed Apr 25, 2022
commit a4646854a1ab495f254a0d06300cf8c609b62390
5 changes: 3 additions & 2 deletions examples/02_meta-analyses/07_macm.py
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@
from nilearn import datasets, image, plotting

from nimare.correct import FWECorrector
from nimare.dataset import Dataset
from nimare.dataset import Dataset, DatasetSearcher
from nimare.meta.cbma.ale import SCALE
from nimare.meta.cbma.mkda import MKDAChi2

@@ -44,7 +44,8 @@
###############################################################################
# Select studies with a reported coordinate in the ROI
# -----------------------------------------------------------------------------
roi_ids = dset.get_studies_by_mask(roi_img)
searcher = DatasetSearcher()
roi_ids = searcher.get_studies_by_mask(dset, roi_img)
dset_sel = dset.slice(roi_ids)
print(f"{len(roi_ids)}/{len(dset.ids)} studies report at least one coordinate in the ROI")

5 changes: 3 additions & 2 deletions examples/04_decoding/01_plot_discrete_decoders.py
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@
import numpy as np
from nilearn.plotting import plot_roi

from nimare.dataset import Dataset
from nimare.dataset import Dataset, DatasetSearcher
from nimare.decode import discrete
from nimare.utils import get_resource_path

@@ -40,7 +40,8 @@
plot_roi(mask_img, draw_cross=False)

# Get studies with voxels in the mask
ids = dset.get_studies_by_mask(mask_img)
searcher = DatasetSearcher()
ids = searcher.get_studies_by_mask(dset, mask_img)

###############################################################################
#
26 changes: 15 additions & 11 deletions nimare/decode/continuous.py
Original file line number Diff line number Diff line change
@@ -8,14 +8,15 @@
from nilearn.masking import apply_mask
from tqdm.auto import tqdm

from .. import references
from ..base import Decoder
from ..due import due
from ..meta.cbma.base import CBMAEstimator
from ..meta.cbma.mkda import MKDAChi2
from ..stats import pearson
from ..utils import _check_type, _safe_transform
from .utils import weight_priors
from nimare import references
from nimare.base import Decoder
from nimare.dataset import DatasetSearcher
from nimare.decode.utils import weight_priors
from nimare.due import due
from nimare.meta.cbma.base import CBMAEstimator
from nimare.meta.cbma.mkda import MKDAChi2
from nimare.stats import pearson
from nimare.utils import _check_type, _safe_transform

LGR = logging.getLogger(__name__)

@@ -182,10 +183,12 @@ def _fit(self, dataset):
Masked meta-analytic maps
"""
self.masker = dataset.masker
searcher = DatasetSearcher()

n_features = len(self.features_)
for i_feature, feature in enumerate(tqdm(self.features_, total=n_features)):
feature_ids = dataset.get_studies_by_label(
feature_ids = searcher.get_studies_by_label(
dataset,
labels=[feature],
label_threshold=self.frequency_threshold,
)
@@ -292,11 +295,12 @@ def _fit(self, dataset):
Masked meta-analytic maps
"""
self.masker = dataset.masker
searcher = DatasetSearcher()

images_ = {}
for feature in self.features_:
feature_ids = dataset.get_studies_by_label(
labels=[feature], label_threshold=self.frequency_threshold
feature_ids = searcher.get_studies_by_label(
dataset, labels=[feature], label_threshold=self.frequency_threshold
)
selected_ids = sorted(list(set(feature_ids).intersection(self.inputs_["id"])))
selected_id_idx = [
5 changes: 3 additions & 2 deletions nimare/workflows/macm.py
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
from shutil import copyfile

from ..correct import FWECorrector
from ..dataset import Dataset
from ..dataset import Dataset, DatasetSearcher
from ..meta import ALE

LGR = logging.getLogger(__name__)
@@ -17,7 +17,8 @@ def macm_workflow(
"""Perform MACM with ALE algorithm."""
LGR.info("Loading coordinates...")
dset = Dataset(dataset_file)
sel_ids = dset.get_studies_by_mask(mask_file)
searcher = DatasetSearcher()
sel_ids = searcher.get_studies_by_mask(dset, mask_file)
sel_dset = dset.slice(sel_ids)

# override sample size