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

Standardise use of atlas vs standard space #137

Merged
merged 3 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 11 additions & 0 deletions brainreg_segment/napari.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: brainreg-segment
schema_version: 0.1.0
contributions:
commands:
- id: brainreg-segment.SegmentationWidget
title: Open segmentation widget
python_name: brainreg_segment.segment:SegmentationWidget

widgets:
- command: brainreg-segment.SegmentationWidget
display_name: Region/track segmentation
13 changes: 2 additions & 11 deletions brainreg_segment/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,14 @@ class Paths:
A single class to hold all file paths that may be used.
"""

def __init__(
self, brainreg_directory, standard_space=True, atlas_space=False
):
def __init__(self, brainreg_directory, atlas_space=False):
self.brainreg_directory = brainreg_directory
self.main_directory = self.brainreg_directory / "manual_segmentation"

if atlas_space:
self.segmentation_directory = self.main_directory / "atlas_space"
else:
if standard_space:
self.segmentation_directory = (
self.main_directory / "standard_space"
)
else:
self.segmentation_directory = (
self.main_directory / "sample_space"
)
self.segmentation_directory = self.main_directory / "sample_space"

self.regions_directory = self.join_seg_files("regions")
self.region_summary_csv = self.regions_directory / "summary.csv"
Expand Down
10 changes: 0 additions & 10 deletions brainreg_segment/plugins.py

This file was deleted.

36 changes: 17 additions & 19 deletions brainreg_segment/segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def add_loading_panel(self, row, column=0):
self.load_button = add_button(
"Load project (sample space)",
self.load_data_layout,
self.load_brainreg_directory_sample,
self.load_brainreg_directory_sample_space,
row=0,
column=0,
visibility=False,
Expand All @@ -205,10 +205,10 @@ def add_loading_panel(self, row, column=0):
"the orientation of your chosen atlas.",
)

self.load_button_standard = add_button(
self.load_button_atlas_space = add_button(
"Load project (atlas space)",
self.load_data_layout,
self.load_brainreg_directory_standard,
self.load_brainreg_directory_atlas_space,
row=1,
column=0,
visibility=False,
Expand All @@ -229,7 +229,7 @@ def add_loading_panel(self, row, column=0):
# buttons made visible after adding to main widget, preventing them
# from briefly appearing in a separate window
self.load_button.setVisible(True)
self.load_button_standard.setVisible(True)
self.load_button_atlas_space.setVisible(True)

def add_saving_panel(self, row):
"""
Expand Down Expand Up @@ -349,7 +349,7 @@ def load_atlas(self):
opacity=0.3,
visible=False,
)
self.standard_space = True
self.atlas_space = True
self.prevent_layer_edit()

def reset_atlas_menu(self):
Expand All @@ -360,25 +360,23 @@ def reset_atlas_menu(self):

# BRAINREG INTERACTION #################################################

def load_brainreg_directory_sample(self):
self.get_brainreg_directory(standard_space=False)
def load_brainreg_directory_sample_space(self):
self.get_brainreg_directory(atlas_space=False)

def load_brainreg_directory_standard(self):
self.get_brainreg_directory(standard_space=True)
def load_brainreg_directory_atlas_space(self):
self.get_brainreg_directory(atlas_space=True)

def get_brainreg_directory(self, standard_space):
def get_brainreg_directory(self, atlas_space):
"""
Shows file dialog to choose output directory
and sets global directory info
"""
if standard_space:
self.plugin = (
"brainglobe-napari-io.brainreg_read_dir_standard_space"
)
self.standard_space = True
if atlas_space:
self.plugin = "brainglobe-napari-io.brainreg_read_dir_atlas_space"
self.atlas_space = True
else:
self.plugin = "brainglobe-napari-io.brainreg_read_dir"
self.standard_space = False
self.atlas_space = False

self.status_label.setText("Loading...")
options = QFileDialog.Options()
Expand Down Expand Up @@ -415,7 +413,7 @@ def load_brainreg_directory(self):
self.viewer.open(str(self.directory), plugin=self.plugin)
self.paths = Paths(
self.directory,
standard_space=self.standard_space,
atlas_space=self.atlas_space,
)
self.initialise_loaded_data()
except ValueError:
Expand Down Expand Up @@ -443,7 +441,7 @@ def initialise_loaded_data(self):
self.metadata = self.base_layer.metadata
self.atlas = self.metadata["atlas_class"]
self.annotations_layer = self.viewer.layers[self.metadata["atlas"]]
if self.standard_space:
if self.atlas_space:
self.hemispheres_data = self.atlas.hemispheres
else:
self.hemispheres_layer = self.viewer.layers[
Expand Down Expand Up @@ -497,7 +495,7 @@ def initialise_segmentation_interface(self):
self.initialise_image_view()
self.save_data_panel.setVisible(True)
self.save_button.setVisible(True)
self.export_button.setVisible(self.standard_space)
self.export_button.setVisible(self.atlas_space)
self.show_regionseg_button.setEnabled(True)
self.show_trackseg_button.setEnabled(True)
self.status_label.setText("Ready")
Expand Down
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ classifiers = [
]
requires-python = ">=3.7"
dependencies = [
"brainglobe-napari-io",
"brainglobe-napari-io >= 0.3.0",
"dask >= 2.15.0",
"imio",
"brainglobe-utils",
Expand Down Expand Up @@ -52,6 +52,8 @@ dev = [
"napari-time-slicer" # to test non ndarray-types
]

[project.entry-points."napari.manifest"]
cellfinder-napari = "brainreg_segment:napari.yaml"

[project.scripts]
brainreg-segment = "brainreg_segment.segment:main"
Expand Down
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ def segmentation_widget_with_data_atlas_space(tmp_path, segmentation_widget):
"""
tmp_input_dir = tmp_path / "brainreg_output"
shutil.copytree(brainreg_dir, tmp_input_dir)
segmentation_widget.standard_space = True
segmentation_widget.atlas_space = True
segmentation_widget.plugin = (
"brainglobe-napari-io.brainreg_read_dir_standard_space"
"brainglobe-napari-io.brainreg_read_dir_atlas_space"
)
segmentation_widget.directory = Path(tmp_input_dir)
segmentation_widget.load_brainreg_directory()
Expand Down
30 changes: 15 additions & 15 deletions tests/tests/test_integration/test_gui/test_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@


def test_load_sample_space(segmentation_widget):
segmentation_widget.standard_space = False
segmentation_widget.atlas_space = False
segmentation_widget.plugin = "brainglobe-napari-io.brainreg_read_dir"
segmentation_widget.directory = brainreg_dir
segmentation_widget.load_brainreg_directory()
check_loaded_layers(segmentation_widget, 7)
check_not_editable(segmentation_widget, standard_space=False)
check_not_editable(segmentation_widget, atlas_space=False)


def test_load_standard_space(segmentation_widget):
segmentation_widget.standard_space = True
def test_load_atlas_space(segmentation_widget):
segmentation_widget.atlas_space = True
segmentation_widget.plugin = (
"brainglobe-napari-io.brainreg_read_dir_standard_space"
"brainglobe-napari-io.brainreg_read_dir_atlas_space"
)
segmentation_widget.directory = brainreg_dir
segmentation_widget.load_brainreg_directory()
check_loaded_layers(segmentation_widget, 4)
check_not_editable(segmentation_widget, standard_space=True)
check_not_editable(segmentation_widget, atlas_space=True)


def test_layer_deletion(segmentation_widget):
Expand All @@ -35,7 +35,7 @@ def test_layer_deletion(segmentation_widget):
assert len(segmentation_widget.viewer.layers) == 0
segmentation_widget.viewer.add_points(np.array([[1, 1], [2, 2]]))
assert len(segmentation_widget.viewer.layers) == 1
segmentation_widget.standard_space = False
segmentation_widget.atlas_space = False
segmentation_widget.plugin = "brainglobe-napari-io.brainreg_read_dir"
segmentation_widget.directory = brainreg_dir
segmentation_widget.load_brainreg_directory()
Expand All @@ -51,10 +51,10 @@ def check_loaded_layers(widget, num_layers):
assert widget.annotations_layer.name == widget.atlas.atlas_name


def check_not_editable(widget, standard_space=False):
def check_not_editable(widget, atlas_space=False):
assert widget.base_layer.editable is False
assert widget.annotations_layer.editable is False
if not standard_space:
if not atlas_space:
assert widget.viewer.layers["Hemispheres"].editable is False


Expand All @@ -72,9 +72,9 @@ def test_load_atlas(segmentation_widget, tmp_path):


def test_general(segmentation_widget):
segmentation_widget.standard_space = True
segmentation_widget.atlas_space = True
segmentation_widget.plugin = (
"brainglobe-napari-io.brainreg_read_dir_standard_space"
"brainglobe-napari-io.brainreg_read_dir_atlas_space"
)
segmentation_widget.directory = brainreg_dir
segmentation_widget.load_brainreg_directory()
Expand Down Expand Up @@ -104,23 +104,23 @@ def check_paths(widget):

assert (
widget.paths.segmentation_directory
== brainreg_dir / "manual_segmentation" / "standard_space"
== brainreg_dir / "manual_segmentation" / "atlas_space"
)

assert (
widget.paths.regions_directory
== brainreg_dir / "manual_segmentation" / "standard_space" / "regions"
== brainreg_dir / "manual_segmentation" / "atlas_space" / "regions"
)

assert (
widget.paths.region_summary_csv
== brainreg_dir
/ "manual_segmentation"
/ "standard_space"
/ "atlas_space"
/ "regions"
/ "summary.csv"
)
assert (
widget.paths.tracks_directory
== brainreg_dir / "manual_segmentation" / "standard_space" / "tracks"
== brainreg_dir / "manual_segmentation" / "atlas_space" / "tracks"
)
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@

brainreg_dir = Path.cwd() / "tests" / "data" / "brainreg_output"
validate_regions_dir = (
brainreg_dir / "manual_segmentation" / "standard_space" / "regions"
brainreg_dir / "manual_segmentation" / "atlas_space" / "regions"
)


@pytest.fixture
def test_regions_dir(tmp_path):
tmp_input_dir = tmp_path / "brainreg_output"
test_regions_dir = (
tmp_input_dir / "manual_segmentation" / "standard_space" / "regions"
tmp_input_dir / "manual_segmentation" / "atlas_space" / "regions"
)
return test_regions_dir

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@

brainreg_dir = Path.cwd() / "tests" / "data" / "brainreg_output"
validate_tracks_dir = (
brainreg_dir / "manual_segmentation" / "standard_space" / "tracks"
brainreg_dir / "manual_segmentation" / "atlas_space" / "tracks"
)


@pytest.fixture
def test_tracks_dir(tmp_path):
tmp_input_dir = tmp_path / "brainreg_output"
test_tracks_dir = (
tmp_input_dir / "manual_segmentation" / "standard_space" / "tracks"
tmp_input_dir / "manual_segmentation" / "atlas_space" / "tracks"
)
return test_tracks_dir

Expand Down
Loading