Metadata-Version: 2.1
Name: bactfit
Version: 0.1.5
Summary: Coordinate transformations for bacterial cell masks
Author: Piers Turner
Author-email: piers.turner@physics.ox.ac.uk
License: Copyright (c) 2024, Piers Turner
        All rights reserved.
        
        Redistribution and use in source and binary forms, with or without
        modification, are permitted provided that the following conditions are met:
        
        * Redistributions of source code must retain the above copyright notice, this
          list of conditions and the following disclaimer.
        
        * 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.
        
        * Neither the name of 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.
        
Project-URL: Source Code, https://github.com/piedrro/bactfit
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: BSD License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: tifffile
Requires-Dist: numpy
Requires-Dist: opencv-python
Requires-Dist: matplotlib
Requires-Dist: scikit-image
Requires-Dist: scipy
Requires-Dist: shapely
Requires-Dist: tqdm
Requires-Dist: picassosr
Requires-Dist: glob2

## BactFit

[![License BSD-3](https://img.shields.io/pypi/l/bactfit.svg?color=green)](https://github.com/piedrro/bactfit/raw/main/LICENSE)
[![PyPI](https://img.shields.io/pypi/v/bactfit.svg?color=green)](https://pypi.org/project/bactfit)
[![Python Version](https://img.shields.io/pypi/pyversions/bactfit.svg?color=green)](https://python.org)

A package for fitting the shape of rod shaped bacterial cells to an ideal cell model. 
This is an analogue of colicoords, but using allowing cells to have multiple bends as the cell midline can be an N degree polynomial.

Once the cell model(s) have been generated, SMLM localisations can be transformed to an ideal cell model. 
This allows for the generation of heatmaps and cell renders that are representative of the cells in the dataset.

Bactfit is compatible with binary masks and Picasso localisation data, see examples. 
Bactfit Cells and CellLists can be saved/loaded from hdf5 files. 
Multiple CellLists can also be combined and saved as a single CellList.

BactFit has been integrated into **napari-moltrack** and **napari-bacseg**.

Author: Piers Turner, Kapanidis Group, University of Oxford.

## Installation

Create new conda environment (or venv) and activate it:

    conda create -name bactfit python=3.9
    conda activate bactfit

You can install `BactFit` via [pip]:

    pip install bactfit

To update `BactFit` to the latest version, use:

    pip install bactfit --upgrade

To install latest development version from [GitHub]:

    pip install git+https://github.com/piedrro/BactFit.git

## BactFit Algorithm

The cell models consist of polynomial midline and a cell radius. 
1) An initial midline is generated using a Voronoi diagram to the contour/outline of each cell. 
2) By buffering the midline using Shapely, a cell model is generated. 
3) This model is then optimised such that the directed hausdorff distance between the model and the cell contour/outline is minimised.

## BactFit Heatmap

The BactFit heatmap is generated by transforming the localisation coordinates to the ideal cell model. 
Heatmaps can be generated if the localisations include X and Y coordinates. 
This heatmap was made from 700 localisations originating from 800 cells, see example. 

![Feature Image](examples/heatmap.png)

## BactFit Cell Render

The BactFit cell render is generated by transforming the localisation coordinates to the ideal cell model.
Heatmaps can be generated using Picasso SMLM rendering so must include Picasso fit metrics alongside X and Y coordinates.
This render was made from 700 localisations originating from 800 cells, see example.

![Feature Image](examples/render.png)
