diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 575061d..f1e8d3a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -23,9 +23,9 @@ jobs: with: environment-file: environment.yaml - # - name: Install package - # shell: bash -l {0} - # run: pip install -e . + - name: Install package + shell: bash -l {0} + run: pip install -e . - name: Run tests shell: bash -l {0} diff --git a/README.md b/README.md index a483c30..4ef08f8 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ Data processing for light-sheet microscopy, specifically for data from [Flamingo The `flamingo_tools` library implements functionality for: - converting the lightsheet data into a format compatible with [BigDataViewer](https://imagej.net/plugins/bdv/) and [BigStitcher](https://imagej.net/plugins/bigstitcher/). +- Cell / nucleus segmentation via a 3D U-net. - ... and more functionality is planned! This is work in progress! @@ -12,25 +13,38 @@ This is work in progress! ## Requirements & Installation You need a python environment with the following dependencies: [pybdv](https://github.com/constantinpape/pybdv) and [z5py](https://github.com/constantinpape/z5). -You can for example install these dependencies with [mamba](https://github.com/mamba-org/mamba) (a faster implementation of [conda](https://docs.conda.io/en/latest/)) via: +You install these dependencies with [mamba](https://github.com/mamba-org/mamba) or [conda](https://docs.conda.io/en/latest/) via: ```bash -$ mamba install -c conda-forge z5py pybdv +conda install -c conda-forge z5py pybdv ``` -You can also set up a new environment with these dependencies using the file `environment.yaml`: +(for an existing conda environment). You can also set up a new environment with all required dependencies using the file `environment.yaml`: ```bash -$ mamba env create -f environment.yaml +conda env create -f environment.yaml +``` +This will create the environment `flamingo`, which you can then activate via `conda activate flamingo`. +Finally, to install `flamingo_tools` into the environment run +```bash +pip install -e . ``` ## Usage -We provide the follwoing scripts: +We provide a command line tool, `convert_flamingo`, for converting data from the flamingo microscope to a data format compatible with BigDataViewer / BigStitcher: +```bash +convert_flamingo -i /path/to/data -o /path/to/output.n5 --file_ext .tif +``` +Here, `/path/to/data` is the filepath to the folder with the flamingo data to be converted, `/path/to/output.n5` is the filepath where the converted data will be stored, and `--file_ext .tif` declares that the files are stored as tif stacks. +Use `--file_ext .raw` isntead if the data is stored in raw files. + +The data will be converted to the [bdv.n5 format](https://github.com/bigdataviewer/bigdataviewer-core/blob/master/BDV%20N5%20format.md). +It can be opened with BigDataViewer via `Plugins->BigDataViewer->Open XML/HDF5`. +Or with BigStitcher as described [here](https://imagej.net/plugins/bigstitcher/open-existing). + +You can also check out the following example scripts: - `create_synthetic_data.py`: create small synthetic test data to check that the scripts work. -- `convert_flamingo_data.py`: convert flamingo data to a file format comatible with BigDataViewer / BigStitcher via command line interface. Run `python convert_flamingo_data.py -h` for details. - `convert_flamingo_data_examples.py`: convert flamingo data to a file format comatible with BigDataViewer / BigStitcher with parameters defined in the python script. Contains two example functions: - `convert_synthetic_data` to convert the synthetic data created via `create_synthetic_data.py`. - `convert_flamingo_data_moser` to convert sampled flamingo data from the Moser group. - `load_data.py`: Example script for how to load sub-regions from the converted data into python. -The data will be converted to the [bdv.n5 format](https://github.com/bigdataviewer/bigdataviewer-core/blob/master/BDV%20N5%20format.md). -It can be opened with BigDataViewer via `Plugins->BigDataViewer->Open XML/HDF5`. -Or with BigStitcher as described [here](https://imagej.net/plugins/bigstitcher/open-existing). +For advanced examples to segment data with a U-Net, check out the `scripts` folder. diff --git a/convert_flamingo_data.py b/convert_flamingo_data.py deleted file mode 100644 index 4d42e60..0000000 --- a/convert_flamingo_data.py +++ /dev/null @@ -1,3 +0,0 @@ -from flamingo_tools import convert_lightsheet_to_bdv_cli - -convert_lightsheet_to_bdv_cli() diff --git a/environment.yaml b/environment.yaml index b342e5e..d29e3f8 100644 --- a/environment.yaml +++ b/environment.yaml @@ -1,4 +1,4 @@ -name: lightsheet +name: flamingo channels: - pytorch diff --git a/flamingo_tools/data_conversion.py b/flamingo_tools/data_conversion.py index c7479e7..36ad876 100644 --- a/flamingo_tools/data_conversion.py +++ b/flamingo_tools/data_conversion.py @@ -409,9 +409,14 @@ def convert_lightsheet_to_bdv_cli(): ) args = parser.parse_args() + if args.metadata_pattern == "": + metadata_pattern = None + else: + metadata_pattern = args.metadata_pattern + convert_lightsheet_to_bdv( root=args.input_root, out_path=args.out_path, file_ext=args.file_ext, - metadata_file_name_pattern=args.metadata_pattern + metadata_file_name_pattern=metadata_pattern ) diff --git a/setup.py b/setup.py index fc9a720..0b7c4c8 100644 --- a/setup.py +++ b/setup.py @@ -1,9 +1,16 @@ import runpy from setuptools import setup, find_packages -version = runpy.run_path('flamingo_tools/version.py')['__version__'] -setup(name='flamingo_tools', - packages=find_packages(exclude=['test']), - version=version, - author='Constantin Pape', - license='MIT') +version = runpy.run_path("flamingo_tools/version.py")["__version__"] +setup( + name="flamingo_tools", + packages=find_packages(exclude=["test"]), + version=version, + author="Constantin Pape", + license="MIT", + entry_points={ + "console_scripts": [ + "convert_flamingo = flamingo_tools.data_conversion:convert_lightsheet_to_bdv_cli" + ] + } +) diff --git a/test/test_cli.py b/test/test_cli.py new file mode 100644 index 0000000..445a064 --- /dev/null +++ b/test/test_cli.py @@ -0,0 +1,35 @@ +import os +import unittest +from shutil import rmtree + +import z5py + +from subprocess import run + + +class TestCLI(unittest.TestCase): + folder = "./tmp" + + def setUp(self): + from flamingo_tools import create_test_data + + # TODO Create flamingo metadata. + create_test_data(self.folder) + + def tearDown(self): + rmtree(self.folder) + + def test_convert_flamingo(self): + out_path = os.path.join(self.folder, "converted_data.n5") + cmd = ["convert_flamingo", "-i", self.folder, "-o", out_path, "--metadata_pattern", ""] + run(cmd) + + self.assertTrue(os.path.exists(out_path)) + xml_path = out_path.replace(".n5", ".xml") + self.assertTrue(os.path.exists(xml_path)) + with z5py.File(out_path, "r") as f: + self.assertTrue("setup0" in f) + + +if __name__ == "__main__": + unittest.main() diff --git a/test/test_data_conversion.py b/test/test_data_conversion.py index 1ee7400..75afec0 100644 --- a/test/test_data_conversion.py +++ b/test/test_data_conversion.py @@ -1,10 +1,7 @@ import os -import sys import unittest from shutil import rmtree -sys.path.append("..") - class TestDataConversion(unittest.TestCase): folder = "./tmp" @@ -12,7 +9,7 @@ class TestDataConversion(unittest.TestCase): def setUp(self): from flamingo_tools import create_test_data - # TODO metadata + # TODO Create flamingo metadata. create_test_data(self.folder) def tearDown(self):