Skip to main content

OpenFRET Data Format Python Library

This Python library provides tools for reading and writing single-molecule FRET (Förster Resonance Energy Transfer) data according to the OpenFRET data format specification (version 1.0.0).

Installation

pip install openfret

Usage

The library provides classes for representing the different components of the OpenFRET data format: Dataset, Trace, Channel, and Metadata.

Writing Data

from openfret import Dataset, Trace, Channel, Metadata, write_data
from datetime import date

# Create Channel objects
channel1 = Channel("donor", [10.0, 12.0, 15.0], excitation_wavelength=488.0, emission_wavelength=520.0)
channel2 = Channel("acceptor", [2.0, 5.0, 8.0], excitation_wavelength=532.0, emission_wavelength=580.0)

# Create a Trace object
trace1 = Trace([channel1, channel2], metadata=Metadata({"molecule_id": "1"}))

# Create a Dataset object
dataset = Dataset(
    title="My FRET Experiment",
    traces=[trace1],
    description="FRET data of protein folding",
    experiment_type="2-Color FRET",
    authors=["John Doe", "Jane Smith"],
    institution="University X",
    date=date(2024, 1, 1),
    metadata=Metadata({"experiment_id": "20240101_JD_JS_1", "movie_file": "20240101_CoolExperiment.TIF"}),
    sample_details={"buffer_conditions": "Phosphate buffer", "other_details": Metadata({"ph": 7.4})}, #Example of nested metadata
    instrument_details={"microscope": "Olympus IX83", "other_details": Metadata({"objective": "60x oil 1.5 NA"})}, #Example of nested metadata
)

# Write the dataset to a JSON file
write_data(dataset, "fret_data.json", compress=True)

Reading Data

from openfret import read_data

# Read the dataset from a JSON file
loaded_dataset = read_data("fret_data.json.zip")

# Access data
print(loaded_dataset.title)
for trace in loaded_dataset.traces:
    for channel in trace.channels:
        print(f"Channel type: {channel.channel_type}, Data: {channel.data}")
print(loaded_dataset.sample_details["other_details"])
print(loaded_dataset.instrument_details["other_details"])

# Or print the whole dictionary
import json
print(json.dumps(loaded_dataset.to_dict(), indent=4))

Loads traces stored in CSV format

import openfret
root_folder = "fret_data_csv"  # Replace with your root folder path
dataset = openfret.load_csv_traces(root_folder)
openfret.write_data(dataset, "fret_data_from_csv.json", compress=True)
loaded_dataset = openfret.read_data("fret_data_from_csv.json.zip")
print(json.dumps(loaded_dataset.to_dict(), indent=4))
 
 # Example folder structure:
 # fret_data_csv/
 # ├── condition_A/
 # │   ├── trace1.csv
 # │   └── trace2.csv
 # └── condition_B/
 #     ├── trace3.csv
 #     └── trace4.csv

Classes

  • Metadata(dict): Represents user-defined metadata. Inherits from dict to allow arbitrary key-value pairs.
  • Channel: Represents a single data channel with intensity data and associated metadata.
    • channel_type (str): String identifier for the channel (e.g., donor, acceptor, FRET).
    • excitation_wavelength (float, optional): Excitation wavelength in nanometers.
    • emission_wavelength (float, optional): Emission wavelength in nanometers.
    • exposure_time (float, optional): Exposure time per frame in seconds.
    • data (List[float]): Intensity values for the channel.
    • metadata (Metadata, optional): Metadata for the channel.
  • Trace: Represents a single-molecule trace containing multiple channels.
    • channels (List[Channel]): Array of channel data for this trace.
    • metadata (Metadata, optional): Metadata for the trace.
  • Dataset: Represents a collection of single-molecule traces.
    • title (str): Title of the experiment or dataset.
    • description (str, optional): Detailed description of the experiment.
    • experiment_type (str, optional): Type of experiment.
    • authors (List[str], optional): List of authors.
    • institution (str, optional): Institution where the experiment was conducted.
    • date (datetime.date, optional): Date of the experiment.
    • traces (List[Trace]): Array of single-molecule traces.
    • metadata (Metadata, optional): Metadata for the dataset.
    • sample_details (dict, optional): Details about the sample.
    • instrument_details (dict, optional): Details about the instrument.

Functions

  • write_data(dataset: Dataset, filename: str, compress: bool): Writes a Dataset object to a JSON file.
  • read_data(filename: str) -> Dataset: Reads a Dataset object from a JSON file.
  • load_csv_traces(root_folder: str) -> Dataset: Loads a folder of CSV files into a dataset.

Contributing

Contributions are welcome! Please open an issue or submit a pull request on GitHub.

License

MIT License

Acknowledgements

This library is based on the OpenFRET data format specification.

Metadata

Release files for openfret 0.1.3

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

Source distribution (sdist)

Source distribution for openfret 0.1.3
File Size Uploaded Provenance Actions
openfret-0.1.3.tar.gz 9.0 kB Without provenance Details for openfret-0.1.3.tar.gz

Built distribution (wheel)

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

Total release size: 16.9 kB

Release files / openfret-0.1.3.tar.gz

Download URL openfret-0.1.3.tar.gz
Size 9.0 kB
Tags Source
SHA-256 checksum
How to use checksums
136559789ee60f4502f741a86cc1d57506784a8b3f30d07c133df3c3ff18bca3
BLAKE2b-256 checksum
How to use checksums
22b91862199de50790c4eba017aa09add4c053f6ebb92e1fd00e7255a2a85dd7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.9.6

Release files / openfret-0.1.3-py3-none-any.whl

Download URL openfret-0.1.3-py3-none-any.whl
Size 8.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6be28522bb259aa6d559bc072fb4aa77c1b0cdd48153073c4d020ef8df8d0dd7
BLAKE2b-256 checksum
How to use checksums
87ecf7d648bb0c259b3694e120b192b6a82fce03ab97ad86df3c40738a35f558
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.9.6

Security for openfret 0.1.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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