Skip to main content

Miffi: Cryo-EM micrograph filtering utilizing Fourier space information

BioRxiv: https://doi.org/10.1101/2023.12.08.570849

Repository Contents

  • miffi/ - Main Miffi package
  • train/ - Model training scripts (independent from Miffi package)
  • empiar_test_set_labels/ - Labels for EMPIAR test sets

Installation

First create a conda virtual enviroment for Miffi:

conda create -n miffi python=3.9
conda activate miffi

Install from local copy

Obtain source code for Miffi using git clone (downloading zip from GitHub will lead to issue due to missing .git metadata):

git clone https://github.com/ando-lab/miffi.git

Then change directory into the source code folder and install using pip:

cd miffi
pip install .

If you need to install Pytorch with a lower CUDA version due to compatibility issue with your GPU driver, follow the instruction on Pytorch website (https://pytorch.org/get-started/locally/) and install appropriate versions of Pytorch and CUDA using conda or pip before doing pip install . in the step above. Note that full Miffi models were generated with TorchScript in Pytorch version 1.13.1, which may not work in older Pytorch versions. However, state dicts may be used instead, or could be converted to full models using older Pytorch versions.

Usage

The following sections outline basic usage of the Miffi package. To see all available arguments for different commands, refer to --help.

Download Miffi models

Full Miffi models and state dicts are hosted on Zenodo (https://doi.org/10.5281/zenodo.8342009). Programatic download for full models is available as part of the Miffi package. To download the current default model:

miffi download -d path/to/download/dir

To download all available full models, use --all argument. A specific model can be downloaded by using --model-name model_to_download. Currently available models:

  • miffi_v1 - Model trained with finetuning and power spectrum input. (Default model)
  • miffi_no_ps_v1 - Model trained with finetuning but without power spectrum input. May be useful for filtering micrographs with pixel sizes larger than 1.5 Å.
  • miffi_no_pretrain_no_ps_v1 - Model trained without finetuning or power spectrum input. (not recommended for anything, for validation purpose only)

Perform inference on micrographs

Micrograph input can be provided as folder and wildcard to match (--micdir micrograph_dir -w wildcard), or can be obtained from a file (a star file, a cryosparc csg file, a plain text list, or a pkl file containing a list). Example for performing inference on micrographs from a csg file:

miffi inference -f path/to/csgfile -d path/to/data/dir --outname output_name \
                -g gpu_id_to_use -m path/to/model/dir

Details on arguments used above:

  • -f Path to the file specifying input micrograph list (csg file in this case).
  • -d Path to the data directory, which will be prepended to the micrograph path found in the input file. This is needed when micrograph path in the file is not absolute path. For star and csg files, this is usually the path to the root directory of the processing project.
  • --outname Name to be prepended to the output result file.
  • -g GPU id to use for inference.
  • -m Path to the directory containing full model files.

Output containing prediction confidence scores will be saved as a dictionary in a pkl file.

Categorize micrographs

After inference, micrographs can be split into multiple categories based on inference results. Output format can be one of the following: plain text list files, star files, or cs files. To output star and cs files, the original star file or the original csg file needs to be provided. Example for categorizing and outputing cs files:

miffi categorize -t cs -i path/to/inference/result --csg path/to/original/csgfile \
                 --sb --sc

Details on arguments used above:

  • -t Type of the output, can be one of the following: list, star, cs.
  • -i Path to the inference result file.
  • --csg Path to the original csg file, which is necessary for outputting cs files. To output star files, path to the original star file needs to be provided through --star.
  • --sb Split all singly bad micrographs into individual categories. If this argument is not used, only film and minor crystalline categories will be written.
  • --sc Split all categories into high and low confidence based on a cutoff value. Default confidence cutoff is 0.7, but can be configured through --gc for good predictions and --bc for bad predictions. Argument --bci can be used to set confidence cutoff for bad predictions of each category individually.

To load output cs files into cryosparc, use "Import Result Group" job and input the output csg file of the corresponding category.

Write png files for micrographs

Miffi package also includes a tool for writing micrographs with their power spectrum as png files for easy visual inspection. The file input options are idential to inference. Example for writing png files from a star file:

miffi write_png -f path/to/starfile -d path/to/data/dir -o path/to/output/dir \
                -q -n number_of_threads

Details on arguments used above:

  • -f Path to the file containing input micrograph list.
  • -d Path to the data directory.
  • -o Path to the output directory.
  • -q Do not preprocess (split into square micrographs and downasmple) before writing png files.
  • -n Number of threads to use for writing png files.

Train new models

See README.md file in the train folder.

Release files for miffi 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for miffi 1.0.1
File Size Uploaded
miffi-1.0.1.tar.gz 86.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for miffi 1.0.1
File Interpreter ABI Platform
miffi-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 119.8 kB

Release files / miffi-1.0.1.tar.gz

Download URL miffi-1.0.1.tar.gz
Size 86.9 kB
Tags Source
SHA-256 checksum
How to use checksums
101c0d954ede083a7cfa2bf64b3d3dc22a1bcee48df734649adb76e5dea1543f
BLAKE2b-256 checksum
How to use checksums
cc8ebf1c2858d4ed4f569902c91c45ed165fb216169f6de626d9a5b12384d3ef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.9.18

Release files / miffi-1.0.1-py3-none-any.whl

Download URL miffi-1.0.1-py3-none-any.whl
Size 33.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
24931841367bb5121f76410533caccc429287a3cbc99efa4f407a16769984220
BLAKE2b-256 checksum
How to use checksums
779ac18d5db0c7acb01e0cd4826f39fd5698be861413b4bac8ca8eca8c3db5f9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.9.18

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page