Skip to content

Commit 6d46efb

Browse files
committed
Updating infrastructure. Decided on docstring format (numpy) and experimenting with type hinting (mypy checked). Switching to pyproject.toml instead of setup.py
1 parent 1e5d132 commit 6d46efb

8 files changed

Lines changed: 98 additions & 115 deletions

File tree

.flake8

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
[flake8]
2-
max_line_length = 120
32
ignore =
4-
# allow empty line at end of file
3+
# Allow block comments to start without a space after #
4+
E265,
5+
# Allow empty line at end of file
56
W391,
6-
# break before binary operator - allow either style
7-
W503,
8-
# break after binary operator - allow either style
9-
W504,
10-
# missing whitespace around arithmetic operator
11-
E226,
7+
# Allow breaks before and after binary operators
8+
W503, W504,
9+
# Allow assigning a lambda expression instead of using a def
10+
E731,
1211
# Allow I, l and O as variable names
1312
E741,
14-
15-
1613
exclude=
1714
.git,
1815
venv,
1916
test_data,
20-
test_output,
17+
pcp1,

.github/workflows/tests.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ jobs:
1414
if: github.event.pull_request.draft == false
1515

1616
env:
17-
python-latest: 3.14
17+
python-latest: '3.14'
1818
strategy:
1919
matrix:
20-
python-version: ['3.10', 3.11, 3.12, 3.13, 3.14]
20+
python-version: ['3.10', '3.11', '3.12', '3.13', '3.14']
2121

2222
steps:
2323
- name: Checkout repository
@@ -31,12 +31,17 @@ jobs:
3131
- name: Install dependencies
3232
run: |
3333
python -m pip install --upgrade pip
34-
python -m pip install -e .[test]
34+
python -m pip install -e .[dev]
3535
3636
- name: Check code style with flake8
3737
if: ${{ matrix.python-version == env.python-latest }}
3838
run: |
39-
python -m flake8 pcpostprocess
39+
python -m flake8 -j4
40+
41+
- name: Check typing with mypy
42+
if: ${{ matrix.python-version == env.python-latest }}
43+
run: |
44+
python -m mypy
4045
4146
- name: Extract test data
4247
run: |

.gitignore

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
# Autogenerated by setuptools-wcm
1+
# Autogenerated by setuptools-wcm during (developer) install
22
pcpostprocess/_version.py
33

44
# Tests and test data
55
.coverage
66
/test_data
7-
/test_output
8-
/output
97

108
# Compiled python
11-
*.pyc
129
__pycache__
1310

1411
# Installation files
@@ -19,10 +16,7 @@ __pycache__
1916

2017
# Virtual environments
2118
venv
22-
env
2319

24-
# DS Store
20+
# Annoyances
2521
.DS_Store
26-
27-
# VS code config
2822
.vscode

CONTRIBUTING.md

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ When making changes, we try to follow the procedure below.
4242
**TODO: Once there is a "user" way to install, move the git clone etc. information here [#105](https://github.com/CardiacModelling/pcpostprocess/issues/105).**
4343

4444
```
45-
pip install -e .[test]
45+
pip install -e .[dev]
4646
```
4747

4848
## Style guidelines
@@ -62,6 +62,17 @@ In addition to the rules checked by flake8, we try to use single quotes (`'`) fo
6262

6363
Class, method, and argument names are in UK english.
6464

65+
### Type hints
66+
67+
We'll try to use [type hints](https://docs.python.org/3/library/typing.html), checked with [mypy](https://www.mypy-lang.org/).
68+
69+
To run locally, use
70+
```
71+
$ mypy
72+
```
73+
74+
Mypy is configured in `pyproject.toml`.
75+
6576
## Documentation
6677

6778
Every method and every class should have a [docstring](https://www.python.org/dev/peps/pep-0257/) that describes in plain terms what it does, and what the expected input and output is.
@@ -70,6 +81,48 @@ The only exception are unit test methods starting with `test_` - unit test class
7081
Each docstring should start with a one-line explanation.
7182
If more explanation is needed, this one-liner is followed by a blank line and more information in the following paragraphs.
7283

84+
Pcpostprocess uses the [Numpy docstring syntax](https://numpydoc.readthedocs.io/en/latest/format.html) for parameters and return values.
85+
For example:
86+
87+
```
88+
Single line explanation.
89+
90+
Detailed, multi-line explanation.
91+
Possibly with ``code`` examples or even latex :math:`\sqrt{x}`.
92+
93+
Parameters
94+
----------
95+
x : int
96+
Description of parameter ``x``.
97+
y : float, default=1
98+
Description of the optional parameter ``y``. If not set, the default value
99+
1 will be used
100+
z : str, optional
101+
Description of the optional parameter ``z``. If not given, ``z`` won't be
102+
used.
103+
104+
Returns
105+
-------
106+
float
107+
Description of the returnved value
108+
```
109+
110+
Return values can also be named, which is especially useful when there are multiple
111+
112+
```
113+
Returns
114+
-------
115+
g: float
116+
The estimated conductance, in nS.
117+
E : float
118+
The estimated reversal potential, in mV.
119+
```
120+
121+
(Note that the numpy documentation currently suggests using single backticks ``` `x` ``` when describing parameters, but Sphinx doesn't fully support this yet.
122+
Until this is fully supported, we will use double backticks as in the example above).
123+
124+
125+
73126
**TODO: READTHEDOCS [#60](https://github.com/CardiacModelling/pcpostprocess/issues/60)**
74127

75128
**TODO: SYNTAX, RUNNING LOCALLY, ETC**

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
BSD 3-Clause License
22

3-
Copyright (c) 2024-2025, University of Nottingham
3+
Copyright (c) 2024-2026, University of Nottingham
44

55
Redistribution and use in source and binary forms, with or without
66
modification, are permitted provided that the following conditions are met:

README.md

Lines changed: 2 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ This repository contains a python package and scripts for handling time-series d
55
The package has been tested with data from a SyncroPatch 384, but may be adapted to work with data in other formats.
66
It can also be used to perform quality control (QC) as described in [Lei et al. (2019)](https://doi.org/10.1016%2Fj.bpj.2019.07.029).
77

8-
This package is tested on Ubuntu with Python 3.10, 3.11, 3.12, 3.13 and 3.14.
8+
This package is tested on Ubuntu with Python 3.10 to 3.14.
99

1010
## Getting Started
1111

@@ -27,7 +27,7 @@ Then install the package with `pip`.
2727

2828
```sh
2929
python3 -m pip install --upgrade pip
30-
python3 -m pip install -e .'[test]'
30+
python3 -m pip install -e .'[dev]'
3131
```
3232

3333
To run the tests you must first download some test data.
@@ -79,72 +79,6 @@ First, all four staircase protocols are checked in all wells using the Lei et al
7979
Any wells not rejected are then tested using a smaller set of (less protocol specific) criteria detailed in Shuttleworth et al.
8080
Only wells passing all tests on all protocols are retained.
8181

82-
### Writing an export_config.py
83-
84-
Prior to performing QC and exporting, an `export_config.py` file should be added to the root of the data directory.
85-
An example file is available [here](./example_config.py).
86-
This should contain three entries:
87-
88-
1. A `saveID` variable, providing a name to use in exported data.
89-
2. A dictionary variable `Q2S_DC` indicating the name of the staircase protocol, and mapping it onto an more user-friendly name used in export.
90-
3. A dictionary variable `D2S` indicating names of other protocols to export, again mapping onto names for export.
91-
92-
For example, in the test data (see "Getting Started") above, we have six subdirectories:
93-
- `staircaseramp (2)_2kHz_15.01.07`, staircase run as first protocol before E-4031
94-
- `StaircaseInStaircaseramp (2)_2kHz_15.01.51`, non-QC protocol
95-
- `staircaseramp (2)_2kHz_15.06.53`, staircase run as last protocol before E-4031
96-
- `staircaseramp (2)_2kHz_15.11.33`, staircase run as first protocol after E-4031 addition
97-
- `StaircaseInStaircaseramp (2)_2kHz_15.12.17`, non-QC protocol
98-
- `staircaseramp (2)_2kHz_15.17.19`, staircase run as final protocol
99-
100-
Here each directory name is a protocol name followed by a timestamp.
101-
Corresponding dictionaries could be `Q2S_DC = {'staircaseramp (2)_2kHz': 'staircase'}` (indicating the staircase protocol) and `D2S = {'StaircaseInStaircaseramp (2)_2kHz': 'sis'}`.
102-
The saveID could be any string, but in our example we use `saveID = '13112023_MW2'`
103-
104-
### Running
105-
106-
To run, we call `run_herg_qc` with:
107-
```sh
108-
pcpostprocess run_herg_qc test_data/13112023_MW2_FF -o output --output_traces -w A01 A02 A03
109-
```
110-
Here:
111-
- `test_data/13112023_MW2_FF` is the path to the test data,
112-
- `-o output` tells the script to store all results in the folder `output`
113-
- `--output_traces` tells the script to export the data (instead of running QC only), and
114-
115-
The last part, `-w A01 A02 A03`, tells the script to only check the first three wells.
116-
This speeds things up for testing, but would be omitted in normal use.
117-
118-
To see the full set of options, use
119-
120-
```sh
121-
$ pcpostprocess run_herg_qc --help
122-
```
123-
124-
### Interpreting the output
125-
126-
After running the command above on the test data provided, the directory `output` will contain the subdirectories:
127-
128-
- `-120mV time constant` Plots illustrating the fits performed when estimating time constants. These are output but not used in QC.
129-
- `leak_correction` Plots illustrating the _linear_ leak correction process in all wells passing staircase QC.
130-
- `qc3-bookend` Plots illustrating the "QC3 bookend" criterion used in Shuttleworth et al.
131-
- `reversal_plots` Plots illustrating the reversal potential estimation
132-
- `subtraction_plots` Plots illustrating the drug subtracted trace leak removal.
133-
- `traces` The exported traces (times, voltages, currents)
134-
135-
and the files:
136-
137-
- `chrono.txt` Lists the order in which protocols were run. For the staircase, the repeat at the end of the sequence is indicated by an added `_2`.
138-
- `passed_wells.txt` Lists the wells that **passed all QC**.
139-
- `pcpostprocess_info.txt` Information on the run that generated this output (date, time, command used etc.)
140-
- `QC-13112023_MW2.csv` A CSV representation of the pass/fail results for each individual criterion
141-
- `QC-13112023_MW2.json` A JSON representation of the same
142-
- `qc_table.tex` A table in Tex format with the above.
143-
- `qc_vals_df.csv` Numerical values used in the final QC.
144-
- `selected-13112023_MW2.txt` **Preliminary QC selection** based on staircase protocol 1 (before other protocols) and 2 (after other protocols)
145-
- `selected-13112023_MW2-staircaseramp.txt` Preliminary selection based on staircase 1
146-
- `selected-13112023_MW2-staircaseramp_2.txt` Preliminary selection based on staircase 2
147-
- `subtraction_qc.csv` Numerical values used in the final QC and leak subtraction.
14882

14983
## Contributing
15084

pyproject.toml

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
[build-system]
2+
build-backend = 'setuptools.build_meta'
23
requires = [
3-
'setuptools>=61',
4-
'wheel',
5-
'setuptools_scm[toml]>=8.0',
4+
'setuptools>=80',
5+
'setuptools_scm>=8.0',
6+
#'wheel',
67
]
78

8-
build-backend = 'setuptools.build_meta'
9-
109
[tool.setuptools_scm]
1110
local_scheme = 'dirty-tag'
1211
write_to = 'pcpostprocess/_version.py'
@@ -17,12 +16,12 @@ dynamic = ['version']
1716
readme = { file = 'README.md', content-type = 'text/markdown' }
1817

1918
name = 'pcpostprocess'
20-
description = 'Post-process patch clamp recordings with the staircase protocol'
19+
description = 'Post-process patch clamp recordings'
2120
authors = [
21+
{name='Joseph Shuttleworth'},
2222
{name='Frankie Patten-Elliot'},
23-
{name='Joseph Shuttleworth', email='joey.shuttleworth@nottingham.ac.uk'},
2423
{name='Chon Lok Lei'},
25-
{name='Michael Clerx'}
24+
{name='Michael Clerx', email='michael.clerx@nottingham.ac.uk'}
2625
]
2726

2827
classifiers = [
@@ -35,34 +34,40 @@ dependencies = [
3534
'scipy>=1.7',
3635
'numpy>=1.21',
3736
'matplotlib>=3.4',
38-
'pandas>=1.3',
39-
'seaborn>=0.12.2',
40-
'jinja2>=3.1.0',
37+
#'pandas>=1.3',
38+
#'seaborn>=0.12.2',
39+
#'jinja2>=3.1.0',
4140
'syncropatch_export @ git+https://github.com/CardiacModelling/syncropatch_export.git'
4241
]
4342

4443
[project.optional-dependencies]
45-
test = [
44+
dev = [
4645
'coverage', # For coverage testing
4746
'codecov>=2.1.3', # To upload coverage reports
4847
'flake8>=3', # For code style checking
48+
'mypy>=1', #
4949
]
5050

51-
[tools.setuptools.package-data]
52-
include_package_data = true
53-
5451
[project.urls]
5552
Homepage = 'https://github.com/CardiacModelling/pcpostprocess'
5653
Source = 'https://github.com/CardiacModelling/pcpostprocess'
5754

58-
[project.scripts]
59-
pcpostprocess = 'pcpostprocess.scripts.__main__:main'
55+
#[project.scripts]
56+
#pcpostprocess = 'pcpostprocess.scripts.__main__:main'
57+
58+
[tools.setuptools.package-data]
59+
include_package_data = true
6060

6161
[tool.setuptools.packages.find]
6262
include = [
6363
'pcpostprocess',
6464
]
6565

66+
[tool.mypy]
67+
modules = [
68+
'pcpostprocess',
69+
]
70+
6671
[tool.coverage.run]
6772
source = [
6873
'pcpostprocess',

setup.py

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)