Skip to main content

Python package for working with exclusionms-api and exclusionms-streamlit

Project description

example workflow example workflow

ExclusionMS Package

This Python package provides a way to manage and query exclusion intervals. It uses a 1-dimensional IntervalTree to efficiently store exclusion intervals based on their neutral mass and perform various operations on them.

Installation

To use this library, simply download or clone the repository and import the necessary classes and functions in your Python project.

Repo:

git clone https://github.com/pgarrett-scripps/ExclusionMs.git
cd ExclusionMs
pip install .

or

Pypi:

pip install exclusionms

Usage

Import classes and functions

from exclusion_list.components import ExclusionInterval, ExclusionPoint
from exclusion_list.mass_interval_tree import MassIntervalTree

Create an exclusion interval

ex_interval = ExclusionInterval(
    interval_id="ID1",
    charge=2,
    min_mass=100.0,
    max_mass=200.0,
    min_rt=10.0,
    max_rt=20.0,
    min_ook0=None,
    max_ook0=None,
    min_intensity=None,
    max_intensity=None,
)

Create a mass interval tree and add exclusion intervals

tree = MassIntervalTree()
tree.add(ex_interval)

Query intervals by ID, mass interval, or a specific data point

# Query by ID
result = tree.query_by_id("ID1")

# Query by interval
query_interval = ExclusionInterval(
    interval_id=None,
    charge=None,
    min_mass=50.0,
    max_mass=250.0,
    min_rt=None,
    max_rt=None,
    min_ook0=None,
    max_ook0=None,
    min_intensity=None,
    max_intensity=None,
)
result = tree.query_by_interval(query_interval)

# Query by point
point = ExclusionPoint(charge=2, mass=120.0, rt=15.0, ook0=None, intensity=None)
result = tree.query_by_point(point)

Check if a data point is excluded by any of the intervals in the tree

is_excluded = tree.is_excluded(point)

Remove exclusion intervals

removed_intervals = tree.remove(ex_interval)

Save and load interval trees

tree.save("interval_tree.pickle")
tree.load("interval_tree.pickle")

Clear all data in the interval tree

tree.clear()

Handling None Values in Exclusion Intervals

When defining exclusion intervals, you may want to leave certain attributes unspecified by setting them to None. This can be useful when you want to represent a range that is unbounded or applicable to all values of that attribute. Here's how the library handles None values for various attributes:

  • interval_id: If the interval ID is set to None, the exclusion interval cannot be added to the interval tree. An exception will be raised if you attempt to do so.

  • charge: If the charge is set to None, the interval represents all charge states. It will match any charge value when checking if a data point is excluded or when querying intervals.

  • min_bounds and max_bounds: For attributes such as mass, retention time (rt), ook0, and intensity, you can set the lower (min_bounds) or upper (max_bounds) bounds to None. In such cases, the library will use the following values as default bounds:

    • Lower bound (min_bounds): -sys.float_info.max
    • Upper bound (max_bounds): sys.float_info.max
    • (This means that if you set the lower bound to None, it will be treated as the minimum representable float value. Similarly, if you set the upper bound to None, it will be treated as the maximum representable float value. This effectively makes the range unbounded for the respective attribute.)

By using None values in exclusion intervals, you can create more flexible and versatile exclusion rules that can match a broader range of data points.

Stress Tester

stress_test.py is designed to stress test the ExclusionMS server by generating a large number of random points and intervals, and then querying the server to check for exclusions. The script also plots the query processing time, along with additional information such as the running average and interval addition events. The plot can be updated in real-time or saved as a PNG file.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

exclusionms-0.4.0.tar.gz (23.1 kB view details)

Uploaded Source

Built Distribution

exclusionms-0.4.0-py3-none-any.whl (20.7 kB view details)

Uploaded Python 3

File details

Details for the file exclusionms-0.4.0.tar.gz.

File metadata

  • Download URL: exclusionms-0.4.0.tar.gz
  • Upload date:
  • Size: 23.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for exclusionms-0.4.0.tar.gz
Algorithm Hash digest
SHA256 6aea9015b42ade9708196b9432ab2709e2b9d0de7b97771e71acbfd6081e0dc3
MD5 46ffa4dd4802e044ad195ad97d66f112
BLAKE2b-256 82f7518ff89babaf3ea2dc941912681db1080ef9365d2d1b4f2099c9e5069ba4

See more details on using hashes here.

File details

Details for the file exclusionms-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: exclusionms-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 20.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for exclusionms-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bfbc03f91b33930672d260a5d63c260cc4c82add6991e25ea6d221a3ff6d978c
MD5 68ad840d815f6af59b2714021d223525
BLAKE2b-256 86c30923cd78bb218e9987e52db8c3c9bc7900dd1d98e7f3c7424d7ff26a9342

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page