fast-fmm-rpy2

Python wrapper for the R fastFMM package

https://github.com/nimh-dsst/fast-fmm-rpy2

Science Score: 57.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 6 DOI reference(s) in README
  • Academic publication links
    Links to: zenodo.org
  • Academic email domains
  • Institutional organization owner
    Organization nimh-dsst has institutional domain (cmn.nimh.nih.gov)
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (15.9%) to scientific vocabulary
Last synced: 6 months ago · JSON representation

Repository

Python wrapper for the R fastFMM package

Basic Info
  • Host: GitHub
  • Owner: nimh-dsst
  • License: cc0-1.0
  • Language: Python
  • Default Branch: main
  • Homepage:
  • Size: 23.2 MB
Statistics
  • Stars: 0
  • Watchers: 4
  • Forks: 0
  • Open Issues: 0
  • Releases: 2
Created 12 months ago · Last pushed 9 months ago
Metadata Files
Readme License Zenodo

README.md

fast-fmm-rpy2

Python wrapper for the R fastFMM package

PyPI - Version DOI GitHub License Tests

About

The Python package fast-fmm-rpy2 is a wrapper of the fastFMM R Package. It provides the functions required to reproduce the analyses from the manuscript: A Statistical Framework for Analysis of Trial-Level Temporal Dynamics in Fiber Photometry Experiments.

Dependencies

This package has other software dependencies. The following must already be installed: 1. The R Project for Statistical Computing (R) 2. fastFMM R Package

1. Install R

  • See the official R documentation and Photometry FLMM tutorial for more information on installing R and system requirements for your system. > [!WARNING] > Depending on your system and local environment you may encounter a compatibility issue between the latest version of R (4.5.0) and the latest version of rpy2 (version 3.5.17) on Ubuntu. See rpy2 issue for more info. The issue has been fixed on the master branch of rpy2 but has not shipped with a published release yet.

2. Install fastFMM R Package

Download the $\texttt{R}$ Package fastFMM by running the following command within $\texttt{R}$ or $\texttt{RStudio}$:

{R} install.packages("fastFMM", dependencies = TRUE) For more information see the fastFMM R package repo.

Install

Assuming all the prerequisites in Dependencies are installed, fast-fmm-rpy2 can be installed using pip.

bash pip install fast-fmm-rpy2

As the name implies fast-fmm-rpy2 uses the Python package rpy2 to wrap the R package. Refer to rpy2 documentation for troubleshooting or any issues loading shared C libraries.

API

```python

fastfmmrpy2/fmm_run.py

def fui( csvfilepath: Path | None, formula: str, parallel: bool = True, importrules=localrules, rvarname: str | None = "pydat", ): """ Run the fastFMM model using the specified formula and data.

Parameters
----------
csv_filepath : Path or None
    The file path to the CSV file containing the data.
    If None, `r_var_name` must be provided.
formula : str
    The formula to be used in the fastFMM model.
parallel : bool, optional
    Whether to run the model in parallel. Default is True.
import_rules : object, optional
    The import rules to be used for the local converter.
    Default is `local_rules`.
r_var_name : str or None, optional
    The R variable name to be used for the data. If `csv_filepath` is None,
    this must be provided. Default is "py_dat".

Returns
-------
mod : object
    The fitted fastFMM model.

Raises
------
AssertionError
    If `csv_filepath` is None and `r_var_name` is not provided.
ValueError
    If `csv_filepath` is not None and `r_var_name` is not provided.
"""

```

```python

fastfmmrpy2/plot_fui

def plotfui( fuiobj, numrow=None, xlab="Functional Domain", titlenames=None, ylim=None, alignx=None, xrescale=1, yvallim=1.1, yscalorig=0.05, returndata=False, ): """ Plot fixed effects from a functional univariate inference object.

Parameters:
-----------
fuiobj : dict
    A dictionary containing the following keys:
    - betaHat: numpy array of shape (num_vars, num_points) containing
        coefficient estimates
    - betaHat_var: numpy array of shape (num_points, num_points, num_vars)
        containing variance estimates (optional)
    - argvals: numpy array of domain points
    - qn: numpy array of quantiles for joint confidence bands
        (if variance is included)
num_row : int, optional
    Number of rows for subplot grid
xlab : str, optional
    Label for x-axis
title_names : list of str, optional
    Names for each coefficient plot
ylim : tuple, optional
    Y-axis limits (min, max)
align_x : float, optional
    Point to align x-axis to (useful for time domain)
x_rescale : float, optional
    Scale factor for x-axis
y_val_lim : float, optional
    Factor to extend y-axis limits
y_scal_orig : float, optional
    Factor to adjust bottom y-axis limit
return_data : bool, optional
    Whether to return the plotting data

Returns:
--------
matplotlib.figure.Figure or tuple
    If return_data=False, returns the figure
    If return_data=True, returns (figure, list of dataframes)
"""

```

Usage and tutorials

See photometry_FLMM for tutorials on using fast-fmm-rpy2 to create Functional Mixed Models for Fiber Photometry.

Floating point differences

The Python rpy2 implementation of fastFMM uses pandas to read in CSV files. The string of numbers in the CSV file is converted to floating point numbers using the 'roundtrip' converter, see read_csv docs. On different systems this converter may have subtle differences with the read.csv function in R. See the Python docs and R docs for more information on the issues and limitations with floating point numbers. There are many resources outlining these issues, for example the edited reprint of David Goldberg's paper What Every Computer Scientist Should Know About Floating-Point Arithmetic or The Anatomy of a Floating Point Number. Due to numerical precision limitations, arrays in R and Python are tested for near equality instead of exact equality. The tests in this package check if the floating point numbers parsed from the provided CSVs and computed models are equal within a tolerance level for Python and R.

[!NOTE] Depending on the system, there may be subtle differences in floating point numbers if you run fastFMM in R versus using fast-fmm-rpy2.

License

This software is developed under a CC0 1.0 Universal license. See the License file for more details.

Referencing

If you use this package please reference the following papers, as well as our most recent Zenodo release: - Cui et al. (2022) Implementation of the fast univariate inference approach - Loewinger et al. (2024) A statistical framework for analysis of trial-level temporal dynamics in fiber photometry experiments.

Contribute

Bump version

The versioning of this package is managed by bump-my-version. Bumping the version using bump-my-version will update the project version in the pyproject.toml, create a commit and create a tag.

To bump the version 1. Have or install a recent version of uv 2. Setup virtual environment and install dependencies bash uv sync --extra dev 3. Bump version bash uv run bump-my-version bump <major|minor|patch>

Helpful commands

Show the possible versions resulting from the bump subcommand. bash uv run bump-my-version show-bump

Test the bump command, don't write any files, just pretend. bash uv run bump-my-version bump <major|minor|patch> --verbose --dry-run

Owner

  • Name: National Institute of Mental Health Data Science & Sharing Team
  • Login: nimh-dsst
  • Kind: organization
  • Location: United States of America

Supporting investigators within the NIMH intramural research program in creating, distributing, and leveraging large, open datasets to accelerate discovery.

GitHub Events

Total
  • Release event: 1
  • Delete event: 2
  • Member event: 1
  • Push event: 14
  • Pull request review event: 1
  • Pull request event: 3
  • Create event: 3
Last Year
  • Release event: 1
  • Delete event: 2
  • Member event: 1
  • Push event: 14
  • Pull request review event: 1
  • Pull request event: 3
  • Create event: 3

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 54 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 3
  • Total maintainers: 1
pypi.org: fast-fmm-rpy2

FLMM rpy2 wrapper for analyzing Fiber Photometry data

  • Versions: 3
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 54 Last month
Rankings
Dependent packages count: 9.1%
Average: 30.3%
Dependent repos count: 51.5%
Maintainers (1)
Last synced: 7 months ago

Dependencies

.github/workflows/lint.yaml actions
  • actions/checkout v4 composite
  • astral-sh/setup-uv v5 composite
  • github/super-linter/slim v7 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite
.github/workflows/test.yaml actions
  • actions/checkout v4 composite
  • astral-sh/setup-uv v5 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite
pyproject.toml pypi
  • jupyter *
  • matplotlib *
  • pandas *
  • rpy2 *
uv.lock pypi
  • 134 dependencies