Skip to content

Commit

Permalink
Merge pull request #60 from brainglobe/run-pre-commit
Browse files Browse the repository at this point in the history
Run `pre-commit` and fix besides `mypy`
  • Loading branch information
paddyroddy authored Feb 18, 2022
2 parents 169d6cc + b3587c8 commit b998960
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 62 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test_and_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ jobs:

deploy:
# this will run when you have tagged a commit, starting with "v*"
# and requires that you have put your twine API key in your
# and requires that you have put your twine API key in your
# github secrets (see readme for details)
needs: [test]
runs-on: ubuntu-latest
Expand Down
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

### Efficient cell detection in large images (e.g. whole mouse brain images)

`cellfinder-napari` is a front-end to [cellfinder-core](https://github.com/brainglobe/cellfinder-core) to allow ease of use within the [napari](https://napari.org/index.html) multidimensional image viewer. For more details on this approach, please see [Tyson, Rousseau & Niedworok et al. (2021)](https://doi.org/10.1371/journal.pcbi.1009074). This algorithm can also be used within the original
[cellfinder](https://github.com/brainglobe/cellfinder) software for
`cellfinder-napari` is a front-end to [cellfinder-core](https://github.com/brainglobe/cellfinder-core) to allow ease of use within the [napari](https://napari.org/index.html) multidimensional image viewer. For more details on this approach, please see [Tyson, Rousseau & Niedworok et al. (2021)](https://doi.org/10.1371/journal.pcbi.1009074). This algorithm can also be used within the original
[cellfinder](https://github.com/brainglobe/cellfinder) software for
whole-brain microscopy analysis.

`cellfinder-napari`, `cellfinder` and `cellfinder-core` were developed by [Charly Rousseau](https://github.com/crousseau) and [Adam Tyson](https://github.com/adamltyson) in the [Margrie Lab](https://www.sainsburywellcome.org/web/groups/margrie-lab), based on previous work by [Christian Niedworok](https://github.com/cniedwor), generously supported by the [Sainsbury Wellcome Centre](https://www.sainsburywellcome.org/web/).
Expand All @@ -32,46 +32,46 @@ whole-brain microscopy analysis.
## Instructions

### Installation
Once you have [installed napari](https://napari.org/index.html#installation).
You can install napari either through the napari plugin installation tool, or
Once you have [installed napari](https://napari.org/index.html#installation).
You can install napari either through the napari plugin installation tool, or
directly from PyPI with:
```bash
pip install cellfinder-napari
```

### Usage
Full documentation can be
found [here](https://docs.brainglobe.info/cellfinder-napari).
This software is at a very early stage, and was written with our data in mind.
Over time we hope to support other data types/formats. If you have any
questions or issues, please get in touch [on the forum](https://forum.image.sc/tag/brainglobe) or by
Full documentation can be
found [here](https://docs.brainglobe.info/cellfinder-napari).

This software is at a very early stage, and was written with our data in mind.
Over time we hope to support other data types/formats. If you have any
questions or issues, please get in touch [on the forum](https://forum.image.sc/tag/brainglobe) or by
[raising an issue](https://github.com/brainglobe/cellfinder-napari/issues).


---
## Illustration

### Introduction
cellfinder takes a stitched, but otherwise raw dataset with at least
cellfinder takes a stitched, but otherwise raw dataset with at least
two channels:
* Background channel (i.e. autofluorescence)
* Signal channel, the one with the cells to be detected:

![raw](https://raw.githubusercontent.com/brainglobe/cellfinder/master/resources/raw.png)
**Raw coronal serial two-photon mouse brain image showing labelled cells**


### Cell candidate detection
Classical image analysis (e.g. filters, thresholding) is used to find
Classical image analysis (e.g. filters, thresholding) is used to find
cell-like objects (with false positives):

![raw](https://raw.githubusercontent.com/brainglobe/cellfinder/master/resources/detect.png)
**Candidate cells (including many artefacts)**


### Cell candidate classification
A deep-learning network (ResNet) is used to classify cell candidates as true
A deep-learning network (ResNet) is used to classify cell candidates as true
cells or artefacts:

![raw](https://raw.githubusercontent.com/brainglobe/cellfinder/master/resources/classify.png)
Expand All @@ -85,7 +85,7 @@ If you find this plugin useful, and use it in your research, please cite the pre


**If you use this, or any other tools in the brainglobe suite, please
[let us know](mailto:[email protected]?subject=cellfinder-napari), and
[let us know](mailto:[email protected]?subject=cellfinder-napari), and
we'd be happy to promote your paper/talk etc.**

---
Expand Down
24 changes: 8 additions & 16 deletions cellfinder_napari/curation.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
import tifffile
from pathlib import Path

import napari
import numpy as np
from qtpy import QtCore
from pathlib import Path
from napari.qt.threading import thread_worker
from qtpy.QtWidgets import (
QLabel,
QWidget,
QFileDialog,
QGridLayout,
QGroupBox,
)
import tifffile
from brainglobe_napari_io.cellfinder.utils import convert_layer_to_cells
from imlib.cells.cells import Cell
from imlib.general.system import ensure_directory_exists
from imlib.IO.yaml import save_yaml
from napari.qt.threading import thread_worker
from qtpy import QtCore
from qtpy.QtWidgets import QFileDialog, QGridLayout, QGroupBox, QLabel, QWidget

from .utils import add_combobox, add_button, display_question, display_info

from .utils import add_button, add_combobox, display_info, display_question

# Constants used throughout
WINDOW_HEIGHT = 750
Expand Down Expand Up @@ -501,9 +495,7 @@ def extract_cubes(
cube_height,
cube_depth,
):
from cellfinder_core.classify.cube_generator import (
CubeGeneratorFromFile,
)
from cellfinder_core.classify.cube_generator import CubeGeneratorFromFile

to_extract = {
"cells": cells_to_extract,
Expand Down
13 changes: 8 additions & 5 deletions cellfinder_napari/detect.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import napari
from pathlib import Path
from magicgui import magicgui
from typing import List

import napari
from magicgui import magicgui

from cellfinder_napari.utils import brainglobe_logo

# TODO:
Expand All @@ -21,12 +22,14 @@
def detect():
from math import ceil

from cellfinder_core.classify.cube_generator import get_cube_depth_min_max
from cellfinder_core.main import main as cellfinder_run
from imlib.cells.cells import Cell

# from fancylog import fancylog
# import cellfinder_napari as program_for_log
from napari.qt.threading import thread_worker
from cellfinder_core.main import main as cellfinder_run
from cellfinder_core.classify.cube_generator import get_cube_depth_min_max
from imlib.cells.cells import Cell

from .utils import cells_to_array

DEFAULT_PARAMETERS = dict(
Expand Down
4 changes: 2 additions & 2 deletions cellfinder_napari/plugins.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from cellfinder_napari.train import train
from cellfinder_napari.detect import detect
from cellfinder_napari.curation import CurationWidget
from cellfinder_napari.detect import detect
from cellfinder_napari.train import train


def napari_experimental_provide_dock_widget():
Expand Down
2 changes: 2 additions & 0 deletions cellfinder_napari/train.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from pathlib import Path

from magicgui import magicgui
from napari.qt.threading import thread_worker

from cellfinder_napari.utils import brainglobe_logo


Expand Down
12 changes: 2 additions & 10 deletions cellfinder_napari/utils.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
import pandas as pd
from pkg_resources import resource_filename

from qtpy.QtWidgets import (
QPushButton,
QLabel,
QComboBox,
QMessageBox,
)

from imlib.cells.cells import Cell

from pkg_resources import resource_filename
from qtpy.QtWidgets import QComboBox, QLabel, QMessageBox, QPushButton

brainglobe_logo = resource_filename(
"cellfinder_napari", "images/brainglobe.png"
Expand Down
6 changes: 3 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ commit = True
tag = True
tag_name = {new_version}
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\-(?P<release>[a-z]+)(?P<rc>\d+))?
serialize =
serialize =
{major}.{minor}.{patch}-{release}{rc}
{major}.{minor}.{patch}

[bumpversion:part:release]
optional_value = prod
first_value = rc
values =
values =
rc
prod

Expand All @@ -31,7 +31,7 @@ max-line-length = 79
exclude = __init__.py,build,.eggs

[check-manifest]
ignore =
ignore =
resources/*
.pre-commit-config.yaml
tox.ini
13 changes: 7 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from setuptools import setup, find_packages
from os import path

from setuptools import find_packages, setup

this_directory = path.abspath(path.dirname(__file__))
with open(path.join(this_directory, "README.md"), encoding="utf-8") as f:
long_description = f.read()
Expand Down Expand Up @@ -60,9 +61,9 @@
"Operating System :: OS Independent",
],
entry_points={
"napari.manifest": [
"cellfinder-napari = cellfinder_napari:napari.yaml",
],
},
package_data={"cellfinder_napari": ["napari.yaml"]},
"napari.manifest": [
"cellfinder-napari = cellfinder_napari:napari.yaml",
],
},
package_data={"cellfinder_napari": ["napari.yaml"]},
)
8 changes: 4 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,25 @@ python =
3.7: py37
3.8: py38
3.9: py39

[gh-actions:env]
PLATFORM =
ubuntu-latest: linux
macos-latest: macos
windows-latest: windows

[testenv]
platform =
platform =
macos: darwin
linux: linux
windows: win32
passenv =
passenv =
CI
GITHUB_ACTIONS
DISPLAY XAUTHORITY
NUMPY_EXPERIMENTAL_ARRAY_FUNCTION
PYVISTA_OFF_SCREEN
deps =
deps =
pytest # https://docs.pytest.org/en/latest/contents.html
pytest-cov # https://pytest-cov.readthedocs.io/en/latest/
pytest-xvfb ; sys_platform == 'linux'
Expand Down

0 comments on commit b998960

Please sign in to comment.