Utilities for handling chemical formulas and mass spec MS2 fragments
Project description
FragFit
A Python library for handling chemical formulas and mass spectrometry MS2 fragments.
Features
- Calculate charged and uncharged masses
- Handle different adducts and their effects on formulas and masses
- Find best-fitting formulas for fragments
- Generate all possible subformulas from a parent formula
- Convert between formula strings and element count vectors
- Command-line interface for common operations
Installation
pip install fragfit
Usage
Basic Mass Calculations
from fragfit import charged_mass, uncharged_mass, form_to_mz
# Calculate the mass of a charged ion
mass = charged_mass("H2O", 1) # Water with +1 charge
print(f"Charged mass: {mass}")
# Calculate m/z value
mz = form_to_mz("C6H12O6", 1) # Glucose with +1 charge
print(f"m/z: {mz}")
Working with Adducts
from fragfit import adduct_mass, to_adduct, from_adduct
# Calculate mass with sodium adduct
sodium_adduct_mass = adduct_mass("C6H12O6", "[M+Na]+")
print(f"Glucose with sodium adduct: {sodium_adduct_mass}")
# Get formula with adduct
sodium_adduct_formula = to_adduct("C6H12O6", "[M+Na]+")
print(f"Glucose with sodium adduct formula: {sodium_adduct_formula}")
Finding Best-Fit Fragment Formulas
from fragfit import find_best_form
# Find the best formula for a fragment
formula, mass, error = find_best_form(
mass=180.063,
parent_form="C10H20O10",
tolerance_da=0.01
)
print(f"Best formula: {formula}, Mass: {mass}, Error: {error}")
Generating All Possible Subformulas
from fragfit import generate_all_forms
# Generate all possible subformulas of glucose
all_forms = generate_all_forms("C6H12O6")
print(f"Found {len(all_forms)} possible subformulas")
Command-Line Interface
FragFit includes a command-line interface for common operations:
Finding the Best Formula for a Mass
fragfit find-formula 180.063 C10H20O10 --tolerance 0.01
Calculating Mass or m/z
# Calculate mass with adduct
fragfit calculate-mass C6H12O6 --adduct "[M+Na]+"
# Calculate m/z with charge
fragfit calculate-mass C6H12O6 --charge 1
Working with Adducts
# Add adduct to formula
fragfit adduct C6H12O6 "[M+Na]+"
# Remove adduct from formula
fragfit adduct C6H12NaO6 "[M+Na]+" --reverse
Listing All Possible Fragments
# List to stdout
fragfit list-fragments C6H12O6
# Output to CSV
fragfit list-fragments C6H12O6 --csv fragments.csv
Analyzing Mass Spec Data from a CSV File
fragfit analyze-file spec_data.csv --parent C5H11N --output results.csv
License
MIT
Author
Gabe Reder gk@reder.io
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fragfit-0.1.2.tar.gz.
File metadata
- Download URL: fragfit-0.1.2.tar.gz
- Upload date:
- Size: 14.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
05c72b95f6b2ff6f7002a44c1e868572a7442955214904d5a6d36cb8e19d9778
|
|
| MD5 |
a113d133c00fdcc8cfdeeb2c08969fa1
|
|
| BLAKE2b-256 |
f59451b723c1c5d4d8930aebe7d8d51969d131536bfb73c39bbc74d8f6be83a2
|
Provenance
The following attestation bundles were made for fragfit-0.1.2.tar.gz:
Publisher:
publish-pypi.yml on gkreder/fragfit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fragfit-0.1.2.tar.gz -
Subject digest:
05c72b95f6b2ff6f7002a44c1e868572a7442955214904d5a6d36cb8e19d9778 - Sigstore transparency entry: 200656550
- Sigstore integration time:
-
Permalink:
gkreder/fragfit@d2eb062398501bb128d93ebbaf1412baa9f621a9 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/gkreder
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@d2eb062398501bb128d93ebbaf1412baa9f621a9 -
Trigger Event:
release
-
Statement type:
File details
Details for the file fragfit-0.1.2-py3-none-any.whl.
File metadata
- Download URL: fragfit-0.1.2-py3-none-any.whl
- Upload date:
- Size: 10.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
29bdae219f1a54de4c6a94c645e3a0ea819d9aaa61a35b596611f3eeee4f6382
|
|
| MD5 |
638430089616ade05794ca2981d1eaaf
|
|
| BLAKE2b-256 |
bfdf77bdc488578bd9829d951a0d4ddbb8fccd4b75af3a13c61d7fcff6c9338c
|
Provenance
The following attestation bundles were made for fragfit-0.1.2-py3-none-any.whl:
Publisher:
publish-pypi.yml on gkreder/fragfit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fragfit-0.1.2-py3-none-any.whl -
Subject digest:
29bdae219f1a54de4c6a94c645e3a0ea819d9aaa61a35b596611f3eeee4f6382 - Sigstore transparency entry: 200656556
- Sigstore integration time:
-
Permalink:
gkreder/fragfit@d2eb062398501bb128d93ebbaf1412baa9f621a9 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/gkreder
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@d2eb062398501bb128d93ebbaf1412baa9f621a9 -
Trigger Event:
release
-
Statement type: