Metadata-Version: 2.5
Name: emscan
Version: 1.0.0
Summary: package description.
Project-URL: homepage, https://github.com/brisvag/emscan
Project-URL: repository, https://github.com/brisvag/emscan
Author-email: Lorenzo Gaifas <brisvag@gmail.com>
License: GPLv3
License-File: LICENSE
Classifier: Development Status :: 3 - Alpha
Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
Classifier: Natural Language :: English
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Requires-Python: >=3.11
Requires-Dist: click
Requires-Dist: morphosamplers>=0.0.13
Requires-Dist: mrcfile
Requires-Dist: napari[all]>=0.10.0
Requires-Dist: numpy
Requires-Dist: pandas
Requires-Dist: pydantic
Requires-Dist: pyopengl-accelerate
Requires-Dist: rich
Requires-Dist: scipy
Requires-Dist: sh
Requires-Dist: torch
Requires-Dist: torchvision
Requires-Dist: xmltodict
Provides-Extra: dev
Requires-Dist: black; extra == 'dev'
Requires-Dist: ipython; extra == 'dev'
Requires-Dist: pdbpp; extra == 'dev'
Requires-Dist: pre-commit; extra == 'dev'
Requires-Dist: pytest; extra == 'dev'
Requires-Dist: pytest-cov; extra == 'dev'
Requires-Dist: rich; extra == 'dev'
Requires-Dist: ruff; extra == 'dev'
Provides-Extra: test
Requires-Dist: pytest-cov; extra == 'test'
Requires-Dist: pytest>=6.0; extra == 'test'
Description-Content-Type: text/markdown

# emscan

[![License](https://img.shields.io/pypi/l/emscan.svg?color=green)](https://github.com/brisvag/emscan/raw/main/LICENSE)
[![PyPI](https://img.shields.io/pypi/v/emscan.svg?color=green)](https://pypi.org/project/emscan)
[![Python Version](https://img.shields.io/pypi/pyversions/emscan.svg?color=green)](https://python.org)
[![CI](https://github.com/brisvag/emscan/actions/workflows/ci.yml/badge.svg)](https://github.com/brisvag/emscan/actions/workflows/ci.yml)
[![codecov](https://codecov.io/gh/brisvag/emscan/branch/main/graph/badge.svg)](https://codecov.io/gh/brisvag/emscan)

emscan is a command line and GUI tool that can be used to cross-correlate 2D projections of unkown objects against the entirety[^1] of the [EMDB](https://www.ebi.ac.uk/emdb). For example, it can be used to find existing homologous (also partial) complexes of unknown particle picks from a cell-extract shotgun cryo-em experiment:

<img width="1091" height="656" alt="Results of a scan with a limited database subset containing a real hit." src="https://github.com/user-attachments/assets/d3b23e9e-09d0-4514-972d-a06cbb9814d3" />

[^1]: not _quite_: some entries are (clearly) discarded in a few specific cases; some parameters allow tweaking this selection.

## _Disclaimer_

emscan requires a lot of time to set up (~days for the first gen-db run) and a large amount of space. While you won't store the whole EMDB (entries are stored downsampled, pre-projected and with limited rotational resolution), it will still use up potentially up to TBs of space.

## Installation

Install from pypi via pip (ideally in a new virtual environment):

```sh
pip install emscan
```

To verify the installation and print out the usage, run:

```sh
emscan -h
```

or for a specific subcommand:

```sh
emscan gen-db -h
```

Read the help messages for more specific information on the various parameters.

### Locked dependencies

If you read this from the future (hi!) and are having dependency issues, you might prefer to install from source with `uv sync`, using the uv.lock in the repository.

## Usage

Using emscan requires a 3 step process:
1. Database generation (downloading, extracting, projecting). This requires the longest time and biggest space on dist.
2. Scanning (comparing the input 2D image against the whole database). Faster than generation but still a heavy job.
3. Inspecting results (visually comparing best hits and investigating the most promising ones). Very fast.

Note that all need to know _where_ your database lives. By default it will be put into your home directory under `~/.emdb_projections`, but you might want to provide a different path via `--db-path` to _all commands_.

To do so, the 3 main commands are:

```sh
emscan --db-path <my_db_path> gen-db
emscan --db-path <my_db_path> scan <some_2d_class>.mrc
emscan --db-path <my_db_path> show <some_2d_class>.mrc
```

Note that `<some_2d_class.mrc>` can actually be a stack of 2D classes!

Since `scan` saves the correlation results for each class individually, you can mix and match various cross-correlation results when running `show`.
For example, if you suspect that two or more different classes might be different views of the same object, put all of them in a stack, e.g. `stack.mrc`. In that case:

```sh
emscan --db-path <my_db_path> show stack.mrc
```

will show the *combined score* of all classes, meaning that EMDB entries that can match well against *all* classes will be at the top. You can select a different subset (eg, the 0th and 3rd one) of classes to see different combinations with:

```sh
emscan --db-path <my_db_path> show stack.mrc -s 0,3
```

