Skip to content
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
24 changes: 11 additions & 13 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.8'
- name:
Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest
- name: Test with pytest
run: |
pip install -e .
pytest
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.8"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
- name: Test with pytest
run: |
python -m pip install -e ".[test]"
python -m pytest -s -W ignore
71 changes: 44 additions & 27 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,28 +1,45 @@
ci:
autoupdate_commit_msg: "chore: update pre-commit hooks"
autofix_commit_msg: "style: pre-commit fixes"

repos:
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.2.0
hooks:
- id: check-docstring-first
- id: check-executables-have-shebangs
- id: check-merge-conflict
- id: check-toml
- id: end-of-file-fixer
- id: mixed-line-ending
args: [--fix=lf]
- id: requirements-txt-fixer
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md]
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
hooks:
- id: flake8
# this seems to need to be here in addition to setup.cfg
exclude: __init__.py|examples
- repo: https://github.com/psf/black
rev: 22.3.0
hooks:
- id: black
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
args: ["--profile", "black", "--filter-files"]

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: "v4.4.0"
hooks:
- id: check-docstring-first
- id: check-executables-have-shebangs
- id: check-merge-conflict
- id: check-toml
- id: end-of-file-fixer
- id: mixed-line-ending
args: [--fix=lf]
- id: requirements-txt-fixer
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md]
- id: check-added-large-files
- id: check-case-conflict
- id: check-merge-conflict
- id: check-symlinks
- id: check-yaml
- id: debug-statements
- id: end-of-file-fixer
- id: name-tests-test
args: ["--pytest-test-first"]
- id: requirements-txt-fixer

- repo: https://github.com/psf/black
rev: 22.3.0
hooks:
- id: black
- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v3.0.3"
hooks:
- id: prettier
types_or: [yaml, markdown, html, css, scss, javascript, json]
args: [--prose-wrap=always]
33 changes: 16 additions & 17 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
BSD 3-Clause License

Copyright (c) 2022, Alan Turing Institute
All rights reserved.
Copyright (c) 2022, Alan Turing Institute All rights reserved.

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

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
Expand All @@ -13,17 +12,17 @@ modification, are permitted provided that the following conditions are met:
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

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.
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.

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.
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.
80 changes: 57 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,50 @@
[![Tests](https://github.com/alan-turing-institute/affinity-vae/actions/workflows/tests.yml/badge.svg)](https://github.com/alan-turing-institute/affinity-vae/actions/workflows/tests.yml)
[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit)

> Note: This a development version of the code. The code in the `main` branch is a more stable version of the code.
> Note: This a development version of the code. The code in the `main` branch is
> a more stable version of the code.

# Affinity-VAE


**Affinity-VAE for disentanglement, clustering and classification of objects in multidimensional image data**
Mirecka J, Famili M, Kotanska A, Jurashcko N, Costa-Gomes B, Palmer CM, Thiyagalingam J, Burnley T, Basham M & Lowe AR
**Affinity-VAE for disentanglement, clustering and classification of objects in
multidimensional image data**
Mirecka J, Famili M, Kotanska A, Jurashcko N, Costa-Gomes B, Palmer CM,
Thiyagalingam J, Burnley T, Basham M & Lowe AR
[![doi:10.48550/arXiv.2209.04517](https://img.shields.io/badge/doi-10.48550/arXiv.2209.04517-blue)](https://doi.org/10.48550/arXiv.2209.04517)

## Installation

### Installing with pip + virtual environments

> Note: This has been tested in the `refactor` branch.
> Note: This has been tested in the `develop` branch.

You can install the libraries needed for this package on a [fresh virtual environment](https://packaging.python.org/en/latest/guides/installing-using-pip-and-virtual-environments/) with the following:
You can install the libraries needed for this package on a
[fresh virtual environment](https://packaging.python.org/en/latest/guides/installing-using-pip-and-virtual-environments/)
with the following:

```
python3 -m venv env
python -m venv env
source env/bin/activate
pip install -e .
python -m pip install --upgrade pip
python -m pip install -e .
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the venv is running from python3 endpoint maybe update this to pyton3 too? or set both to python for consistency.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, good catch!

```

If you are developing code, you should be able to run precommits and tests,
thefore the best installation option after setting up the virtual environment
is:

```
python -m pip install -e ."[test]"
```
> Note: This is the preffered option for running on Turing macOS laptops.

> Warning: M1 macOS can not do [pytorch paralelisation](https://github.com/pytorch/pytorch/issues/70344). A temporary solution for this is to modify the code on the DataLoaders in data.py to `num_workers=0` in order to run the code. Otherwise you will get the error: `AttributeError: Can't pickle local object 'ProteinDataset.__init__.<locals>.<lambda>'`.
> Note: This is the preferred option for running on Turing macOS laptops.

> Warning: M1 macOS can not do
> [pytorch paralelisation](https://github.com/pytorch/pytorch/issues/70344). A
> temporary solution for this is to modify the code on the DataLoaders in
> data.py to `num_workers=0` in order to run the code. Otherwise you will get
> the error:
> `AttributeError: Can't pickle local object 'ProteinDataset.__init__.<locals>.<lambda>'`.

### Installing with conda in Baskerville

Expand All @@ -52,10 +71,12 @@ conda install -c anaconda click
conda install pytorch torchvision pytorch-cuda=11.6 -c pytorch -c nvidia
```

if the follwoing error occurs:
if the follwoing error occurs:

```
:ImportError: libtiff.so.5: cannot open shared object file: No such file or directory
```

you can resolve it via:

```
Expand All @@ -64,7 +85,8 @@ conda install -c anaconda libtiff==4.4.0

### Quick start

Affinity-vae has a running script (`run.py`)that allows you to configure and run the code. You can look at the avaible configuration options by running:
Affinity-vae has a running script (`run.py`)that allows you to configure and run
the code. You can look at the avaible configuration options by running:

```
python run.py --help
Expand Down Expand Up @@ -201,42 +223,54 @@ Options:
--help Show this message and exit.
```

Note that setting ```-g/--gamma``` to ```0``` and ```-pd/--pose_dims``` to ```0``` will run a vanilla beta-VAE.
Note that setting `-g/--gamma` to `0` and `-pd/--pose_dims` to `0` will run a
vanilla beta-VAE.

### Quickstart

#### Configuring from the command line


You can run on example data with the following command:

```
python affinity-vae/run.py -d data/subtomo_files --split 20 --epochs 10 -ba 128 -lr 0.001 -de 4 -ch 64 -ld 8 -pd 3 --beta 1 --gamma 2 --limit 1000 --freq_all 5 --vis_all --dynamic
```
where the **subtomo_files** is a directory with a number of `.mcr` proteine image files named with the protein keyword such as (`1BXN_m0_156_Th0.mrc`,`5MRC_m8_1347_Th0.mrc`, etc). The **subtomo_files** directory should also have be a `classes.csv` file with a list of the protein names and keywords to be considered (`1BXN`, `5MRC`, etc.) and a `affinity_scores.csv` matrix with the initial values for the proteins named in the `classes.csv`.

where the **subtomo_files** is a directory with a number of `.mcr` proteine
image files named with the protein keyword such as
(`1BXN_m0_156_Th0.mrc`,`5MRC_m8_1347_Th0.mrc`, etc). The **subtomo_files**
directory should also have be a `classes.csv` file with a list of the protein
names and keywords to be considered (`1BXN`, `5MRC`, etc.) and a
`affinity_scores.csv` matrix with the initial values for the proteins named in
the `classes.csv`.

#### Using a config submission file

You can also run the code using a submission config file (you can find an example with default values
on `configs/avae-test-config.yml`). For example, you can run the following command:
You can also run the code using a submission config file (you can find an
example with default values on `configs/avae-test-config.yml`). For example, you
can run the following command:

```
python affinity-vae/run.py --config_file affinity-vae/configs/avae-test-config.yml
```

You can also use a mix of config file and command line arguments. For example, you can run the following command:
You can also use a mix of config file and command line arguments. For example,
you can run the following command:

```
python affinity-vae/run.py --config_file affinity-vae/configs/avae-test-config.yml --epochs 10 --affinity /path/to/different_affinity.csv
```

this will rewrite the values for the epochs and affinity path in the config file.

At the end of the run, the code will save the final config file used for the run in the working directory. This will
account for any changes made to the config file from the command line. Running the code again with that config file will reproduce the results.
this will rewrite the values for the epochs and affinity path in the config
file.

At the end of the run, the code will save the final config file used for the run
in the working directory. This will account for any changes made to the config
file from the command line. Running the code again with that config file will
reproduce the results.

In the tools folder you can find notebooks which will assist you in creating the input files for Affinity-VAE or analyse teh output of the model.
In the tools folder you can find notebooks which will assist you in creating the
input files for Affinity-VAE or analyse teh output of the model.

#### Considerations

Expand Down
4 changes: 0 additions & 4 deletions configs/avae-create_subtomo_test_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
# Not implemented yet : can apply crop after rotation
# Not Implemented yet: gaussian blur


#### Data parameters
input_path: /Users/mfamili/work/test_affinity_merge/test_create_subtomo_avae
annot_path: /Users/mfamili/work/test_affinity_merge/test_create_subtomo_avae
Expand All @@ -20,8 +19,6 @@ output_path: /Users/mfamili/work/test_affinity_merge/test_create_subtomo_avae/su
datatype: mrc
vox_size: [32, 32, 32]



### Filters
bandpass: False
low_freq: 0
Expand All @@ -31,7 +28,6 @@ normalise: True
add_noise: True
noise_int: 3


#### augmentation
augment: 3
aug_th_min: -20
Expand Down
Loading