metamorph-mda-parser 0.0.1__tar.gz → 0.0.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,75 @@
1
+ name: Publish to PyPI
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - 'metamorph-mda-parser-*'
7
+ branches:
8
+ - main
9
+
10
+ permissions:
11
+ contents: read
12
+
13
+ jobs:
14
+ build:
15
+ name: Build wheel and source distribution
16
+ if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
17
+ runs-on: ubuntu-latest
18
+
19
+ environment: release
20
+ permissions:
21
+ id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
22
+
23
+ steps:
24
+ - name: Checkout code
25
+ uses: actions/checkout@v4
26
+ with:
27
+ fetch-depth: 0
28
+
29
+ - name: Set up Python
30
+ uses: actions/setup-python@v5
31
+ with:
32
+ python-version: '3.11'
33
+ cache: 'pip'
34
+
35
+ - name: Install dependencies
36
+ run: |
37
+ python -m pip install --upgrade pip
38
+ pip install hatch
39
+
40
+ - name: Build package
41
+ run: hatch build
42
+
43
+ - name: Test package
44
+ run: hatch run test
45
+
46
+ - name: Upload artifacts
47
+ uses: actions/upload-artifact@v4
48
+ with:
49
+ name: python-artifacts
50
+ path: dist/*
51
+ if-no-files-found: error
52
+
53
+ publish:
54
+ name: Publish to PyPI
55
+ if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
56
+ needs:
57
+ - build
58
+ runs-on: ubuntu-latest
59
+
60
+ permissions:
61
+ contents: write
62
+ id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
63
+
64
+ steps:
65
+ - name: Download Python artifacts
66
+ uses: actions/download-artifact@v4
67
+ with:
68
+ name: python-artifacts
69
+ path: dist
70
+ - name: Add assets to release
71
+ uses: softprops/action-gh-release@v2
72
+ with:
73
+ files: dist/*
74
+ - name: Publish package distributions to PyPI
75
+ uses: pypa/gh-action-pypi-publish@v1.9.0
@@ -1,42 +1,42 @@
1
- name: test
2
-
3
- on:
4
- push:
5
- branches: [main, master]
6
- pull_request:
7
- branches: [main, master]
8
-
9
- concurrency:
10
- group: test-${{ github.head_ref }}
11
- cancel-in-progress: true
12
-
13
- env:
14
- PYTHONUNBUFFERED: "1"
15
- FORCE_COLOR: "1"
16
-
17
- jobs:
18
- run:
19
- name: Python ${{ matrix.python-version }} on ${{ startsWith(matrix.os, 'macos-') && 'macOS' || startsWith(matrix.os, 'windows-') && 'Windows' || 'Linux' }}
20
- runs-on: ${{ matrix.os }}
21
- strategy:
22
- fail-fast: false
23
- matrix:
24
- os: [ubuntu-latest, windows-latest, macos-latest]
25
- python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
26
-
27
- steps:
28
- - uses: actions/checkout@v3
29
-
30
- - name: Set up Python ${{ matrix.python-version }}
31
- uses: actions/setup-python@v4
32
- with:
33
- python-version: ${{ matrix.python-version }}
34
-
35
- - name: Install Hatch
36
- run: pip install --upgrade hatch
37
-
38
- - name: Run static analysis
39
- run: hatch fmt --check
40
-
41
- - name: Run tests
42
- run: hatch run cov
1
+ name: test
2
+
3
+ on:
4
+ push:
5
+ branches: [main, master]
6
+ pull_request:
7
+ branches: [main, master]
8
+
9
+ concurrency:
10
+ group: test-${{ github.head_ref }}
11
+ cancel-in-progress: true
12
+
13
+ env:
14
+ PYTHONUNBUFFERED: "1"
15
+ FORCE_COLOR: "1"
16
+
17
+ jobs:
18
+ run:
19
+ name: Python ${{ matrix.python-version }} on ${{ startsWith(matrix.os, 'macos-') && 'macOS' || startsWith(matrix.os, 'windows-') && 'Windows' || 'Linux' }}
20
+ runs-on: ${{ matrix.os }}
21
+ strategy:
22
+ fail-fast: false
23
+ matrix:
24
+ os: [ubuntu-latest, windows-latest, macos-latest]
25
+ python-version: ['3.10', '3.11', '3.12']
26
+
27
+ steps:
28
+ - uses: actions/checkout@v3
29
+
30
+ - name: Set up Python ${{ matrix.python-version }}
31
+ uses: actions/setup-python@v4
32
+ with:
33
+ python-version: ${{ matrix.python-version }}
34
+
35
+ - name: Install Hatch
36
+ run: pip install --upgrade hatch
37
+
38
+ - name: Run static analysis
39
+ run: hatch fmt --check
40
+
41
+ - name: Run tests
42
+ run: hatch run cov
@@ -1,11 +1,11 @@
1
- Copyright (c) 2024-present Jan Eglinger <jan.eglinger@fmi.ch>.
2
-
3
- Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4
-
5
- 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6
-
7
- 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8
-
9
- 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10
-
11
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1
+ Copyright (c) 2024-present Jan Eglinger <jan.eglinger@fmi.ch>.
2
+
3
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4
+
5
+ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6
+
7
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8
+
9
+ 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10
+
11
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.3
2
2
  Name: metamorph-mda-parser
3
- Version: 0.0.1
3
+ Version: 0.0.2
4
4
  Summary: Light-weight parsing of Metamorph/VisiView .nd files.
5
5
  Project-URL: Documentation, https://github.com/fmi-faim/metamorph-mda-parser#readme
6
6
  Project-URL: Issues, https://github.com/fmi-faim/metamorph-mda-parser/issues
@@ -10,15 +10,15 @@ License-Expression: BSD-3-Clause
10
10
  License-File: LICENSE.txt
11
11
  Classifier: Development Status :: 4 - Beta
12
12
  Classifier: Programming Language :: Python
13
- Classifier: Programming Language :: Python :: 3.8
14
- Classifier: Programming Language :: Python :: 3.9
15
13
  Classifier: Programming Language :: Python :: 3.10
16
14
  Classifier: Programming Language :: Python :: 3.11
17
15
  Classifier: Programming Language :: Python :: 3.12
18
16
  Classifier: Programming Language :: Python :: Implementation :: CPython
19
17
  Classifier: Programming Language :: Python :: Implementation :: PyPy
20
- Requires-Python: >=3.8
18
+ Requires-Python: >=3.10
19
+ Requires-Dist: lark
21
20
  Requires-Dist: pandas
21
+ Requires-Dist: pydantic
22
22
  Description-Content-Type: text/markdown
23
23
 
24
24
  # metamorph-mda-parser
@@ -1,25 +1,25 @@
1
- # metamorph-mda-parser
2
-
3
- [![PyPI - Version](https://img.shields.io/pypi/v/metamorph-mda-parser.svg)](https://pypi.org/project/metamorph-mda-parser)
4
- [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/metamorph-mda-parser.svg)](https://pypi.org/project/metamorph-mda-parser)
5
-
6
- -----
7
-
8
- Light-weight parsing of Metamorph/VisiView Multi Dimensional Acquisition .nd files.
9
-
10
- For the file format description, see: https://support.moleculardevices.com/s/article/MDA-file-formats
11
-
12
- **Table of Contents**
13
-
14
- - [Installation](#installation)
15
- - [License](#license)
16
-
17
- ## Installation
18
-
19
- ```console
20
- pip install metamorph-mda-parser
21
- ```
22
-
23
- ## License
24
-
25
- `metamorph-mda-parser` is distributed under the terms of the [BSD-3-Clause](https://spdx.org/licenses/BSD-3-Clause.html) license.
1
+ # metamorph-mda-parser
2
+
3
+ [![PyPI - Version](https://img.shields.io/pypi/v/metamorph-mda-parser.svg)](https://pypi.org/project/metamorph-mda-parser)
4
+ [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/metamorph-mda-parser.svg)](https://pypi.org/project/metamorph-mda-parser)
5
+
6
+ -----
7
+
8
+ Light-weight parsing of Metamorph/VisiView Multi Dimensional Acquisition .nd files.
9
+
10
+ For the file format description, see: https://support.moleculardevices.com/s/article/MDA-file-formats
11
+
12
+ **Table of Contents**
13
+
14
+ - [Installation](#installation)
15
+ - [License](#license)
16
+
17
+ ## Installation
18
+
19
+ ```console
20
+ pip install metamorph-mda-parser
21
+ ```
22
+
23
+ ## License
24
+
25
+ `metamorph-mda-parser` is distributed under the terms of the [BSD-3-Clause](https://spdx.org/licenses/BSD-3-Clause.html) license.
@@ -1,83 +1,87 @@
1
- [build-system]
2
- requires = ["hatchling", "hatch-vcs"]
3
- build-backend = "hatchling.build"
4
-
5
- [project]
6
- name = "metamorph-mda-parser"
7
- dynamic = ["version"]
8
- description = 'Light-weight parsing of Metamorph/VisiView .nd files.'
9
- readme = "README.md"
10
- requires-python = ">=3.8"
11
- license = "BSD-3-Clause"
12
- keywords = []
13
- authors = [
14
- { name = "Jan Eglinger", email = "jan.eglinger@fmi.ch" },
15
- ]
16
- classifiers = [
17
- "Development Status :: 4 - Beta",
18
- "Programming Language :: Python",
19
- "Programming Language :: Python :: 3.8",
20
- "Programming Language :: Python :: 3.9",
21
- "Programming Language :: Python :: 3.10",
22
- "Programming Language :: Python :: 3.11",
23
- "Programming Language :: Python :: 3.12",
24
- "Programming Language :: Python :: Implementation :: CPython",
25
- "Programming Language :: Python :: Implementation :: PyPy",
26
- ]
27
- dependencies = [
28
- "pandas",
29
- ]
30
-
31
- [project.urls]
32
- Documentation = "https://github.com/fmi-faim/metamorph-mda-parser#readme"
33
- Issues = "https://github.com/fmi-faim/metamorph-mda-parser/issues"
34
- Source = "https://github.com/fmi-faim/metamorph-mda-parser"
35
-
36
- [tool.hatch.version]
37
- source = "vcs"
38
-
39
- [tool.hatch.envs.default]
40
- dependencies = [
41
- "coverage[toml]>=6.5",
42
- "pytest",
43
- ]
44
- [tool.hatch.envs.default.scripts]
45
- test = "pytest {args:tests}"
46
- test-cov = "coverage run -m pytest {args:tests}"
47
- cov-report = [
48
- "- coverage combine",
49
- "coverage report",
50
- ]
51
- cov = [
52
- "test-cov",
53
- "cov-report",
54
- ]
55
-
56
- [[tool.hatch.envs.all.matrix]]
57
- python = ["3.8", "3.9", "3.10", "3.11", "3.12"]
58
-
59
- [tool.hatch.envs.types]
60
- dependencies = [
61
- "mypy>=1.0.0",
62
- ]
63
- [tool.hatch.envs.types.scripts]
64
- check = "mypy --install-types --non-interactive {args:src/metamorph_mda_parser tests}"
65
-
66
- [tool.coverage.run]
67
- source_pkgs = ["metamorph_mda_parser", "tests"]
68
- branch = true
69
- parallel = true
70
- omit = [
71
- "src/metamorph_mda_parser/__about__.py",
72
- ]
73
-
74
- [tool.coverage.paths]
75
- metamorph_mda_parser = ["src/metamorph_mda_parser", "*/metamorph-mda-parser/src/metamorph_mda_parser"]
76
- tests = ["tests", "*/metamorph-mda-parser/tests"]
77
-
78
- [tool.coverage.report]
79
- exclude_lines = [
80
- "no cov",
81
- "if __name__ == .__main__.:",
82
- "if TYPE_CHECKING:",
83
- ]
1
+ [build-system]
2
+ requires = ["hatchling", "hatch-vcs"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "metamorph-mda-parser"
7
+ dynamic = ["version"]
8
+ description = 'Light-weight parsing of Metamorph/VisiView .nd files.'
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = "BSD-3-Clause"
12
+ keywords = []
13
+ authors = [
14
+ { name = "Jan Eglinger", email = "jan.eglinger@fmi.ch" },
15
+ ]
16
+ classifiers = [
17
+ "Development Status :: 4 - Beta",
18
+ "Programming Language :: Python",
19
+ "Programming Language :: Python :: 3.10",
20
+ "Programming Language :: Python :: 3.11",
21
+ "Programming Language :: Python :: 3.12",
22
+ "Programming Language :: Python :: Implementation :: CPython",
23
+ "Programming Language :: Python :: Implementation :: PyPy",
24
+ ]
25
+ dependencies = [
26
+ "lark",
27
+ "pandas",
28
+ "pydantic",
29
+ ]
30
+
31
+ [project.urls]
32
+ Documentation = "https://github.com/fmi-faim/metamorph-mda-parser#readme"
33
+ Issues = "https://github.com/fmi-faim/metamorph-mda-parser/issues"
34
+ Source = "https://github.com/fmi-faim/metamorph-mda-parser"
35
+
36
+ [tool.hatch.version]
37
+ source = "vcs"
38
+
39
+ [tool.hatch.envs.default]
40
+ dependencies = [
41
+ "coverage[toml]>=6.5",
42
+ "pytest",
43
+ ]
44
+ [tool.hatch.envs.default.scripts]
45
+ test = "pytest {args:tests}"
46
+ test-cov = "coverage run -m pytest {args:tests}"
47
+ cov-report = [
48
+ "- coverage combine",
49
+ "coverage report",
50
+ ]
51
+ cov = [
52
+ "test-cov",
53
+ "cov-report",
54
+ ]
55
+
56
+ [[tool.hatch.envs.all.matrix]]
57
+ python = ["3.10", "3.11", "3.12"]
58
+
59
+ [tool.hatch.envs.types]
60
+ dependencies = [
61
+ "mypy>=1.0.0",
62
+ ]
63
+ [tool.hatch.envs.types.scripts]
64
+ check = "mypy --install-types --non-interactive {args:src/metamorph_mda_parser tests}"
65
+
66
+ [tool.coverage.run]
67
+ source_pkgs = ["metamorph_mda_parser", "tests"]
68
+ branch = true
69
+ parallel = true
70
+ omit = [
71
+ "src/metamorph_mda_parser/__about__.py",
72
+ ]
73
+
74
+ [tool.coverage.paths]
75
+ metamorph_mda_parser = ["src/metamorph_mda_parser", "*/metamorph-mda-parser/src/metamorph_mda_parser"]
76
+ tests = ["tests", "*/metamorph-mda-parser/tests"]
77
+
78
+ [tool.coverage.report]
79
+ show_missing = true
80
+ exclude_lines = [
81
+ "no cov",
82
+ "if __name__ == .__main__.:",
83
+ "if TYPE_CHECKING:",
84
+ ]
85
+
86
+ [tool.ruff.lint.flake8-type-checking]
87
+ runtime-evaluated-base-classes = ["pydantic.BaseModel"]
@@ -0,0 +1,36 @@
1
+ from lark import Lark, Transformer
2
+
3
+
4
+ class NDInfoTransformer(Transformer):
5
+ def __init__(self):
6
+ self.wave_names = []
7
+ self.wave_do_z = []
8
+ self.stage_positions = []
9
+
10
+ def start(self, items):
11
+ result = dict(i for i in items if i is not None)
12
+ result["WaveNames"] = self.wave_names
13
+ result["WaveDoZ"] = self.wave_do_z
14
+ result["StagePositions"] = self.stage_positions
15
+ return result
16
+
17
+ def line(self, key_value):
18
+ key, value = key_value
19
+ if key.startswith("WaveName"):
20
+ self.wave_names.append(value)
21
+ return None # We handle WaveName entries separately
22
+ if key.startswith("Stage"):
23
+ self.stage_positions.append(value)
24
+ return None # We handle Stage entries separately
25
+ if key.startswith("WaveDoZ"):
26
+ self.wave_do_z.append(value)
27
+ return None # We handle WaveDoZ entries separately
28
+ return (key, value)
29
+
30
+ def boolean_value(self, b):
31
+ return b[0].value == "TRUE"
32
+
33
+
34
+ def parse(content):
35
+ parser = Lark.open("nd_grammar.lark", rel_to=__file__, parser="lalr", transformer=NDInfoTransformer())
36
+ return parser.parse(content)
@@ -0,0 +1,91 @@
1
+ from __future__ import annotations
2
+
3
+ from pathlib import Path
4
+ from typing import Literal
5
+
6
+ import pandas as pd
7
+ from pydantic import AliasGenerator, BaseModel, ConfigDict
8
+ from pydantic.alias_generators import to_pascal
9
+
10
+ from metamorph_mda_parser.lark import parse
11
+
12
+
13
+ class NdInfo(BaseModel):
14
+ model_config = ConfigDict(
15
+ alias_generator=AliasGenerator(
16
+ validation_alias=to_pascal,
17
+ ),
18
+ )
19
+
20
+ path: Path
21
+ name: str
22
+ version: Literal["1.0", "2.0"]
23
+ description: str
24
+ do_timelapse: bool
25
+ do_stage: bool
26
+ do_wave: bool
27
+ do_z_series: bool
28
+ stage_positions: list[str] = []
29
+ wave_names: list[str] = []
30
+ wave_do_z: list[bool] = []
31
+ n_stage_positions: int = 1
32
+ n_time_points: int = 1
33
+ n_z_steps: int = 1
34
+ z_step_size: float | None = None
35
+ wave_in_file_name: bool
36
+
37
+ @staticmethod
38
+ def from_path(path: Path):
39
+ with open(path) as f:
40
+ content = f.read()
41
+ result = parse(content)
42
+ result["Path"] = path
43
+ result["Name"] = path.stem
44
+ result["Version"] = "1.0" # HACK
45
+ return NdInfo(**result)
46
+
47
+ def _wavelengths(self):
48
+ for i, w in enumerate(self.wave_names):
49
+ if self.do_wave:
50
+ yield (
51
+ i,
52
+ w,
53
+ f"_w{i+1}{w}" if self.wave_in_file_name else "",
54
+ self.wave_do_z[i] if self.wave_do_z else False,
55
+ )
56
+
57
+ def _stage_positions(self):
58
+ for s, s_name in enumerate(self.stage_positions):
59
+ if self.do_stage:
60
+ yield s, s_name, f"_s{s+1}"
61
+
62
+ def _timepoints(self):
63
+ if self.do_timelapse:
64
+ for t in range(self.n_time_points):
65
+ yield t, f"_t{t+1}"
66
+
67
+ def _get_path_channel_position_time(self):
68
+ for w_idx, w_name, w, has_z in list(self._wavelengths()) or [("", self.do_z)]:
69
+ for s_idx, s_name, s in list(self._stage_positions()) or [(0, None, "")]:
70
+ for t_idx, t in list(self._timepoints()) or [(0, "")]:
71
+ yield (
72
+ self.path.parent / (self.name + w + s + t + (".stk" if has_z else ".tif")),
73
+ w_idx,
74
+ w_name,
75
+ s_idx,
76
+ s_name,
77
+ t_idx,
78
+ )
79
+
80
+ def get_files(self) -> pd.DataFrame:
81
+ return pd.DataFrame.from_records(
82
+ self._get_path_channel_position_time(),
83
+ columns=[
84
+ "path",
85
+ "channel",
86
+ "channel_name",
87
+ "position",
88
+ "position_name",
89
+ "time",
90
+ ],
91
+ )
@@ -0,0 +1,40 @@
1
+ start: line+ "\"EndFile\""
2
+ line: _QUOTE _special_key _QUOTE "," _special_value
3
+ | _QUOTE _string_key _QUOTE "," _QUOTE _string_value _QUOTE
4
+ | _QUOTE _boolean_key _QUOTE "," boolean_value
5
+ | _QUOTE _integer_key _QUOTE "," _integer_value
6
+ | _QUOTE _float_key _QUOTE "," _float_value
7
+
8
+ _special_key: /NDInfoFile/
9
+ | /Description/
10
+ | /StartTime[0-9]+/
11
+ _special_value: /.+/
12
+
13
+ _string_key: /WaveName[0-9]+/
14
+ | /Stage[0-9]+/
15
+ _string_value: /[^"]+/
16
+
17
+ _boolean_key: /DoTimelapse/
18
+ | /DoStage/
19
+ | /DoWave/
20
+ | /DoZSeries/
21
+ | /WaveInFileName/
22
+ | /WaveDoZ[0-9]+/
23
+ boolean_value: BOOLEAN
24
+
25
+ _integer_key: /NWavelengths/
26
+ | /NStagePositions/
27
+ | /NTimePoints/
28
+ | /NZSteps/
29
+ _integer_value: INT
30
+
31
+ _float_key: /ZStepSize/
32
+ _float_value: DECIMAL | INT
33
+
34
+ %import common.INT
35
+ %import common.DECIMAL
36
+ %import common.WS
37
+ %ignore WS
38
+
39
+ BOOLEAN: "TRUE" | "FALSE"
40
+ _QUOTE: "\""
@@ -1,93 +1,93 @@
1
- "NDInfoFile", Version 1.0
2
- "Description", File recreated from images.
3
- "StartTime1", 20240209 16:25:29.500
4
- "DoTimelapse", TRUE
5
- "NTimePoints", 361
6
- "DoStage", TRUE
7
- "NStagePositions", 75
8
- "Stage1", "1"
9
- "Stage2", "2"
10
- "Stage3", "3"
11
- "Stage4", "4"
12
- "Stage5", "5"
13
- "Stage6", "6"
14
- "Stage7", "7"
15
- "Stage8", "8"
16
- "Stage9", "9"
17
- "Stage10", "10"
18
- "Stage11", "11"
19
- "Stage12", "12"
20
- "Stage13", "13"
21
- "Stage14", "14"
22
- "Stage15", "15"
23
- "Stage16", "16"
24
- "Stage17", "17"
25
- "Stage18", "18"
26
- "Stage19", "19"
27
- "Stage20", "20"
28
- "Stage21", "21"
29
- "Stage22", "22"
30
- "Stage23", "23"
31
- "Stage24", "24"
32
- "Stage25", "25"
33
- "Stage26", "26"
34
- "Stage27", "27"
35
- "Stage28", "28"
36
- "Stage29", "29"
37
- "Stage30", "30"
38
- "Stage31", "31"
39
- "Stage32", "32"
40
- "Stage33", "33"
41
- "Stage34", "34"
42
- "Stage35", "35"
43
- "Stage36", "36"
44
- "Stage37", "37"
45
- "Stage38", "38"
46
- "Stage39", "39"
47
- "Stage40", "40"
48
- "Stage41", "41"
49
- "Stage42", "42"
50
- "Stage43", "43"
51
- "Stage44", "44"
52
- "Stage45", "45"
53
- "Stage46", "46"
54
- "Stage47", "47"
55
- "Stage48", "48"
56
- "Stage49", "49"
57
- "Stage50", "50"
58
- "Stage51", "51"
59
- "Stage52", "52"
60
- "Stage53", "53"
61
- "Stage54", "54"
62
- "Stage55", "55"
63
- "Stage56", "56"
64
- "Stage57", "57"
65
- "Stage58", "58"
66
- "Stage59", "59"
67
- "Stage60", "60"
68
- "Stage61", "61"
69
- "Stage62", "62"
70
- "Stage63", "63"
71
- "Stage64", "64"
72
- "Stage65", "65"
73
- "Stage66", "66"
74
- "Stage67", "67"
75
- "Stage68", "68"
76
- "Stage69", "69"
77
- "Stage70", "70"
78
- "Stage71", "71"
79
- "Stage72", "72"
80
- "Stage73", "73"
81
- "Stage74", "74"
82
- "Stage75", "75"
83
- "DoWave", TRUE
84
- "NWavelengths", 2
85
- "WaveName1", "BF-488-Cam1"
86
- "WaveDoZ1", TRUE
87
- "WaveName2", "488-BF-Cam0"
88
- "WaveDoZ2", TRUE
89
- "DoZSeries", TRUE
90
- "NZSteps", 25
91
- "ZStepSize", 2.00
92
- "WaveInFileName", TRUE
93
- "EndFile"
1
+ "NDInfoFile", Version 1.0
2
+ "Description", File recreated from images.
3
+ "StartTime1", 20240209 16:25:29.500
4
+ "DoTimelapse", TRUE
5
+ "NTimePoints", 361
6
+ "DoStage", TRUE
7
+ "NStagePositions", 75
8
+ "Stage1", "1"
9
+ "Stage2", "2"
10
+ "Stage3", "3"
11
+ "Stage4", "4"
12
+ "Stage5", "5"
13
+ "Stage6", "6"
14
+ "Stage7", "7"
15
+ "Stage8", "8"
16
+ "Stage9", "9"
17
+ "Stage10", "10"
18
+ "Stage11", "11"
19
+ "Stage12", "12"
20
+ "Stage13", "13"
21
+ "Stage14", "14"
22
+ "Stage15", "15"
23
+ "Stage16", "16"
24
+ "Stage17", "17"
25
+ "Stage18", "18"
26
+ "Stage19", "19"
27
+ "Stage20", "20"
28
+ "Stage21", "21"
29
+ "Stage22", "22"
30
+ "Stage23", "23"
31
+ "Stage24", "24"
32
+ "Stage25", "25"
33
+ "Stage26", "26"
34
+ "Stage27", "27"
35
+ "Stage28", "28"
36
+ "Stage29", "29"
37
+ "Stage30", "30"
38
+ "Stage31", "31"
39
+ "Stage32", "32"
40
+ "Stage33", "33"
41
+ "Stage34", "34"
42
+ "Stage35", "35"
43
+ "Stage36", "36"
44
+ "Stage37", "37"
45
+ "Stage38", "38"
46
+ "Stage39", "39"
47
+ "Stage40", "40"
48
+ "Stage41", "41"
49
+ "Stage42", "42"
50
+ "Stage43", "43"
51
+ "Stage44", "44"
52
+ "Stage45", "45"
53
+ "Stage46", "46"
54
+ "Stage47", "47"
55
+ "Stage48", "48"
56
+ "Stage49", "49"
57
+ "Stage50", "50"
58
+ "Stage51", "51"
59
+ "Stage52", "52"
60
+ "Stage53", "53"
61
+ "Stage54", "54"
62
+ "Stage55", "55"
63
+ "Stage56", "56"
64
+ "Stage57", "57"
65
+ "Stage58", "58"
66
+ "Stage59", "59"
67
+ "Stage60", "60"
68
+ "Stage61", "61"
69
+ "Stage62", "62"
70
+ "Stage63", "63"
71
+ "Stage64", "64"
72
+ "Stage65", "65"
73
+ "Stage66", "66"
74
+ "Stage67", "67"
75
+ "Stage68", "68"
76
+ "Stage69", "69"
77
+ "Stage70", "70"
78
+ "Stage71", "71"
79
+ "Stage72", "72"
80
+ "Stage73", "73"
81
+ "Stage74", "74"
82
+ "Stage75", "75"
83
+ "DoWave", TRUE
84
+ "NWavelengths", 2
85
+ "WaveName1", "BF-488-Cam1"
86
+ "WaveDoZ1", TRUE
87
+ "WaveName2", "488-BF-Cam0"
88
+ "WaveDoZ2", TRUE
89
+ "DoZSeries", TRUE
90
+ "NZSteps", 25
91
+ "ZStepSize", 2.00
92
+ "WaveInFileName", TRUE
93
+ "EndFile"
@@ -0,0 +1,14 @@
1
+ "NDInfoFile", Version 1.0
2
+ "Description", File recreated from images.
3
+ "StartTime1", 20240603 12:25:48.610
4
+ "DoTimelapse", FALSE
5
+ "DoStage", FALSE
6
+ "DoWave", TRUE
7
+ "NWavelengths", 4
8
+ "WaveName1", "confDAPI"
9
+ "WaveName2", "confGFP"
10
+ "WaveName3", "confmCherry"
11
+ "WaveName4", "confCy5"
12
+ "DoZSeries", FALSE
13
+ "WaveInFileName", TRUE
14
+ "EndFile"
@@ -1,25 +1,25 @@
1
- "NDInfoFile", Version 1.0
2
- "Description", File recreated from images.
3
- "StartTime1", 20230922 12:33:22.559
4
- "DoTimelapse", FALSE
5
- "DoStage", TRUE
6
- "NStagePositions", 4
7
- "Stage1", "Position1"
8
- "Stage2", "Position2"
9
- "Stage3", "Position3"
10
- "Stage4", "Position4"
11
- "DoWave", TRUE
12
- "NWavelengths", 4
13
- "WaveName1", "Conf640"
14
- "WaveDoZ1", TRUE
15
- "WaveName2", "Conf561"
16
- "WaveDoZ2", TRUE
17
- "WaveName3", "Conf488"
18
- "WaveDoZ3", TRUE
19
- "WaveName4", "Conf405"
20
- "WaveDoZ4", TRUE
21
- "DoZSeries", TRUE
22
- "NZSteps", 42
23
- "ZStepSize", 3
24
- "WaveInFileName", TRUE
25
- "EndFile"
1
+ "NDInfoFile", Version 1.0
2
+ "Description", File recreated from images.
3
+ "StartTime1", 20230922 12:33:22.559
4
+ "DoTimelapse", FALSE
5
+ "DoStage", TRUE
6
+ "NStagePositions", 4
7
+ "Stage1", "Position1"
8
+ "Stage2", "Position2"
9
+ "Stage3", "Position3"
10
+ "Stage4", "Position4"
11
+ "DoWave", TRUE
12
+ "NWavelengths", 4
13
+ "WaveName1", "Conf640"
14
+ "WaveDoZ1", TRUE
15
+ "WaveName2", "Conf561"
16
+ "WaveDoZ2", TRUE
17
+ "WaveName3", "Conf488"
18
+ "WaveDoZ3", TRUE
19
+ "WaveName4", "Conf405"
20
+ "WaveDoZ4", TRUE
21
+ "DoZSeries", TRUE
22
+ "NZSteps", 42
23
+ "ZStepSize", 3
24
+ "WaveInFileName", TRUE
25
+ "EndFile"
@@ -1,68 +1,96 @@
1
- from pathlib import Path
2
-
3
- import pytest
4
-
5
- from metamorph_mda_parser.nd import NdInfo
6
-
7
-
8
- @pytest.fixture
9
- def sample_4ch_4pos():
10
- return Path("tests/resources/sample_4ch_4pos.nd")
11
-
12
-
13
- @pytest.fixture
14
- def sample_2ch_75pos_361t():
15
- return Path("tests/resources/sample_2ch_75pos_361t.nd")
16
-
17
-
18
- def test_sample_4ch_4pos(sample_4ch_4pos):
19
- nd_info = NdInfo(sample_4ch_4pos)
20
-
21
- assert nd_info.version == "1.0"
22
- assert nd_info.description == "File recreated from images."
23
- assert not nd_info.do_timelapse
24
- assert nd_info.do_stage
25
- assert len(nd_info.stage_positions) == 4
26
- assert nd_info.do_wave
27
- assert len(nd_info.wave_names) == 4
28
- assert nd_info.do_z
29
- assert nd_info.n_z_steps == 42
30
- assert nd_info.z_step_size == 3.0
31
- assert nd_info.wave_in_file_name
32
- assert nd_info.wave_names == ["Conf640", "Conf561", "Conf488", "Conf405"]
33
-
34
- files = nd_info.get_files()
35
-
36
- assert len(files) == 16
37
- assert files["channel"].unique().tolist() == [0, 1, 2, 3]
38
- assert files["channel_name"].unique().tolist() == nd_info.wave_names
39
- assert files["position"].unique().tolist() == [0, 1, 2, 3]
40
- assert files["position_name"].unique().tolist() == [
41
- "Position1",
42
- "Position2",
43
- "Position3",
44
- "Position4",
45
- ]
46
- assert files["time"].unique().tolist() == [0]
47
-
48
-
49
- def test_sample_2ch_75pos_361t(sample_2ch_75pos_361t):
50
- nd_info = NdInfo(sample_2ch_75pos_361t)
51
-
52
- assert nd_info.version == "1.0"
53
- assert nd_info.description == "File recreated from images."
54
- assert nd_info.do_timelapse
55
- assert nd_info.n_timepoints == 361
56
- assert nd_info.do_stage
57
- assert len(nd_info.stage_positions) == 75
58
- assert nd_info.do_wave
59
- assert len(nd_info.wave_names) == 2
60
- assert nd_info.do_z
61
- assert nd_info.n_z_steps == 25
62
- assert nd_info.z_step_size == 2.0
63
- assert nd_info.wave_in_file_name
64
- assert nd_info.wave_names == ["BF-488-Cam1", "488-BF-Cam0"]
65
-
66
- files = nd_info.get_files()
67
-
68
- assert len(files) == 54150
1
+ from pathlib import Path
2
+
3
+ import pytest
4
+
5
+ from metamorph_mda_parser.nd import NdInfo
6
+
7
+
8
+ @pytest.fixture
9
+ def sample_4ch_4pos():
10
+ return Path("tests/resources/sample_4ch_4pos.nd")
11
+
12
+
13
+ @pytest.fixture
14
+ def sample_2ch_75pos_361t():
15
+ return Path("tests/resources/sample_2ch_75pos_361t.nd")
16
+
17
+
18
+ @pytest.fixture
19
+ def sample_4ch_1pos_1z():
20
+ return Path("tests/resources/sample_4ch_1pos_1z.nd")
21
+
22
+
23
+ def test_sample_4ch_4pos(sample_4ch_4pos):
24
+ nd_info = NdInfo.from_path(sample_4ch_4pos)
25
+
26
+ assert nd_info.version == "1.0"
27
+ assert nd_info.description == "File recreated from images."
28
+ assert not nd_info.do_timelapse
29
+ assert nd_info.do_stage
30
+ assert len(nd_info.stage_positions) == 4
31
+ assert nd_info.do_wave
32
+ assert len(nd_info.wave_names) == 4
33
+ assert nd_info.do_z_series
34
+ assert nd_info.n_z_steps == 42
35
+ assert nd_info.z_step_size == 3.0
36
+ assert nd_info.wave_in_file_name
37
+ assert nd_info.wave_names == ["Conf640", "Conf561", "Conf488", "Conf405"]
38
+
39
+ files = nd_info.get_files()
40
+
41
+ assert len(files) == 16
42
+ assert files["channel"].unique().tolist() == [0, 1, 2, 3]
43
+ assert files["channel_name"].unique().tolist() == nd_info.wave_names
44
+ assert files["position"].unique().tolist() == [0, 1, 2, 3]
45
+ assert files["position_name"].unique().tolist() == [
46
+ "Position1",
47
+ "Position2",
48
+ "Position3",
49
+ "Position4",
50
+ ]
51
+ assert files["time"].unique().tolist() == [0]
52
+
53
+
54
+ def test_sample_2ch_75pos_361t(sample_2ch_75pos_361t):
55
+ nd_info = NdInfo.from_path(sample_2ch_75pos_361t)
56
+
57
+ assert nd_info.version == "1.0"
58
+ assert nd_info.description == "File recreated from images."
59
+ assert nd_info.do_timelapse
60
+ assert nd_info.n_time_points == 361
61
+ assert nd_info.do_stage
62
+ assert len(nd_info.stage_positions) == 75
63
+ assert nd_info.do_wave
64
+ assert len(nd_info.wave_names) == 2
65
+ assert nd_info.do_z_series
66
+ assert nd_info.n_z_steps == 25
67
+ assert nd_info.z_step_size == 2.0
68
+ assert nd_info.wave_in_file_name
69
+ assert nd_info.wave_names == ["BF-488-Cam1", "488-BF-Cam0"]
70
+
71
+ files = nd_info.get_files()
72
+
73
+ assert len(files) == 54150
74
+
75
+
76
+ def test_sample_4ch_1pos_1z(sample_4ch_1pos_1z):
77
+ nd_info = NdInfo.from_path(sample_4ch_1pos_1z)
78
+
79
+ assert nd_info.version == "1.0"
80
+ assert nd_info.description == "File recreated from images."
81
+ assert not nd_info.do_timelapse
82
+ assert nd_info.n_time_points == 1
83
+ assert not nd_info.do_stage
84
+ assert len(nd_info.stage_positions) == 0
85
+ assert nd_info.do_wave
86
+ assert len(nd_info.wave_names) == 4
87
+ assert not nd_info.do_z_series
88
+ assert nd_info.n_z_steps == 1
89
+ assert nd_info.z_step_size is None
90
+ assert nd_info.wave_in_file_name
91
+ assert nd_info.wave_names == ["confDAPI", "confGFP", "confmCherry", "confCy5"]
92
+
93
+ files = nd_info.get_files()
94
+
95
+ assert len(files) == 4
96
+ assert all(p.suffix == ".tif" for p in files["path"])
@@ -1,132 +0,0 @@
1
- from __future__ import annotations
2
-
3
- from typing import TYPE_CHECKING, Callable, Literal
4
-
5
- if TYPE_CHECKING:
6
- from pathlib import Path
7
-
8
- import pandas as pd
9
-
10
-
11
- class NdInfo:
12
- path: Path
13
- name: str
14
- version: Literal["1.0", "2.0"]
15
- description: str
16
- do_timelapse: bool
17
- do_stage: bool
18
- do_wave: bool
19
- do_z: bool
20
- stage_positions: list[str]
21
- wave_names: list[str]
22
- wave_do_z: list[bool]
23
- n_timepoints: int
24
- n_z_steps: int
25
- z_step_size: float
26
- wave_in_file_name: bool
27
-
28
- def __init__(self, path: Path):
29
- self.path = path
30
- self.name = path.stem
31
- self._parse_nd()
32
-
33
- def _parse_nd(self) -> None:
34
- with open(self.path) as nd:
35
- # Version
36
- self.version = self._parse_line(nd.readline(), "NDInfoFile", self._extract_version)
37
- self.description = self._parse_line(nd.readline(), "Description", str)
38
- self.start_time = self._parse_line(nd.readline(), "StartTime1", str)
39
- # Time lapse
40
- self.do_timelapse = self._parse_line(nd.readline(), "DoTimelapse", self._parse_bool)
41
- if self.do_timelapse:
42
- self.n_timepoints = self._parse_line(nd.readline(), "NTimePoints", int)
43
-
44
- # Stage positions
45
- self.do_stage = self._parse_line(nd.readline(), "DoStage", self._parse_bool)
46
- if self.do_stage:
47
- n_stage_positions = self._parse_line(nd.readline(), "NStagePositions", int)
48
- self.stage_positions = []
49
- for s in range(n_stage_positions):
50
- self.stage_positions.append(self._parse_line(nd.readline(), f"Stage{s+1}", str))
51
-
52
- # Wavelengths
53
- self.do_wave = self._parse_line(nd.readline(), "DoWave", self._parse_bool)
54
- if self.do_wave:
55
- n_wavelengths = self._parse_line(nd.readline(), "NWavelengths", int)
56
- self.wave_names = []
57
- self.wave_do_z = []
58
- for w in range(n_wavelengths):
59
- self.wave_names.append(self._parse_line(nd.readline(), f"WaveName{w+1}", str))
60
- self.wave_do_z.append(self._parse_line(nd.readline(), f"WaveDoZ{w+1}", self._parse_bool))
61
-
62
- # Z steps
63
- self.do_z = self._parse_line(nd.readline(), "DoZSeries", self._parse_bool)
64
- self.n_z_steps = self._parse_line(nd.readline(), "NZSteps", int)
65
- self.z_step_size = self._parse_line(nd.readline(), "ZStepSize", float)
66
-
67
- self.wave_in_file_name = self._parse_line(nd.readline(), "WaveInFileName", self._parse_bool)
68
-
69
- # End of file
70
- last_line = nd.readline()
71
- if last_line.strip(' "\n') != "EndFile":
72
- message = f"Expected end of file, got: {last_line}"
73
- raise ValueError(message)
74
-
75
- def _parse_line(self, line: str, key: str, value_function: Callable):
76
- tokens = line.split(",")
77
- if tokens[0].strip(' "') != key:
78
- message = f"Invalid nd file contents.\n\texpected: {key}\n\tgot: {line}"
79
- raise ValueError(message)
80
- return value_function(tokens[1].strip(' "\n'))
81
-
82
- def _extract_version(self, value: str) -> str:
83
- return value[8:]
84
-
85
- def _parse_bool(self, value: str) -> bool:
86
- return value.lower() == "true"
87
-
88
- def _wavelengths(self):
89
- for i, w in enumerate(self.wave_names):
90
- if self.do_wave:
91
- yield (
92
- i,
93
- w,
94
- f"_w{i+1}{w}" if self.wave_in_file_name else "",
95
- self.wave_do_z[i],
96
- )
97
-
98
- def _stage_positions(self):
99
- for s, s_name in enumerate(self.stage_positions):
100
- if self.do_stage:
101
- yield s, s_name, f"_s{s+1}"
102
-
103
- def _timepoints(self):
104
- if self.do_timelapse:
105
- for t in range(self.n_timepoints):
106
- yield t, f"_t{t+1}"
107
-
108
- def _get_path_channel_position_time(self):
109
- for w_idx, w_name, w, has_z in list(self._wavelengths()) or [("", self.do_z)]:
110
- for s_idx, s_name, s in list(self._stage_positions()) or [(0, None, "")]:
111
- for t_idx, t in list(self._timepoints()) or [(0, "")]:
112
- yield (
113
- self.path.parent / (self.name + w + s + t + (".stk" if has_z else ".tif")),
114
- w_idx,
115
- w_name,
116
- s_idx,
117
- s_name,
118
- t_idx,
119
- )
120
-
121
- def get_files(self) -> pd.DataFrame:
122
- return pd.DataFrame.from_records(
123
- self._get_path_channel_position_time(),
124
- columns=[
125
- "path",
126
- "channel",
127
- "channel_name",
128
- "position",
129
- "position_name",
130
- "time",
131
- ],
132
- )