agentsclimarketplace

In memory optimization for large datasets

Skill HolobiomicsLab/asb-skill-collections/collections/metabolomics/v2/skills/in-memory-optimization-for-large-datasets

Curated, evidence-grounded skill and software-tool collections for scientific AI agents, generated by the AgenticScienceBuilder

Install
npx -y skills add HolobiomicsLab/asb-skill-collections --skill in-memory-optimization-for-large-datasets

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 14 stars14 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

What its author says it does

Copied from the file, not written here

Use when you are repeatedly querying or iterating over multidimensional MS data stored in MZA HDF5 format (retention time, drift time, m/z dimensions) and profiling shows that repeated disk I/O for the same metadata or scan ranges dominates runtime.

The file declares its own license as CC-BY-4.0. That is the author’s claim about this one file, and it is not the same thing as the license GitHub reports for the repository, which is listed with the other numbers below.

SKILL.md

7.9 KB, as published. Nobody here has run it

in-memory-optimization-for-large-datasets

Summary

Selective in-memory caching of metadata headers and scan data in multidimensional MS workflows to accelerate repeated data access without exhausting memory on large HDF5-based datasets. This skill applies the mzapy MZA class's cache_metadata_headers parameter and scan caching methods to balance read performance against memory constraints.

When to use

You are repeatedly querying or iterating over multidimensional MS data stored in MZA HDF5 format (retention time, drift time, m/z dimensions) and profiling shows that repeated disk I/O for the same metadata or scan ranges dominates runtime. Use this skill when you need to extract ion chromatograms, arrival time distributions, or MS1/MS2 spectra multiple times from the same file within a single workflow session.

When NOT to use

  • Your workflow processes each MS scan only once and does not requery metadata or spectra; in this case, streaming reads without caching are more memory-efficient.
  • The entire MZA file fits comfortably in available RAM; selective caching adds complexity without benefit.
  • You are converting vendor MS formats to MZA (use the mza converter tool instead); this skill applies only to reading and querying MZA files post-conversion.

Inputs

  • MZA HDF5 file (.mza format) containing uncompressed or hdf5plugin-compressed MS data
  • Metadata table with columns: Scan, MzaPath, MSLevel, RetentionTime, IonMobilityBin, IonMobilityTime, etc.
  • 1D intensity and m/z arrays stored in HDF5 groups (Arrays_intensity, Arrays_mz, Arrays_mzbin)

Outputs

  • In-memory metadata header cache (dict or pandas DataFrame subset)
  • In-memory scan cache (serialized or deserialized numpy arrays)
  • Saved scan cache file (.pkl or equivalent) for reuse across sessions

How to apply

Initialize the MZA class with the cache_metadata_headers parameter set to control which metadata is held in memory: use an empty list (default) for minimal caching, pass a list of specific header names (e.g., ['RetentionTime', 'IonMobilityTime', 'MzaPath']) to cache selected fields, or pass 'all' to cache all headers if memory permits. Before performing repeated queries (e.g., collecting multiple XIC arrays or MS1 spectra by retention time), call load_scan_cache() to preload frequently accessed scan data into memory. After the analysis, call save_scan_cache() to serialize the cache to disk, enabling reuse in future sessions. This avoids re-decompressing HDF5 arrays on each query. The rationale is that HDF5 decompression (via hdf5plugin) is expensive relative to in-memory array access, so strategic caching trades memory footprint for latency reduction. Always call close() to release file handles and cached data when finished.

Related tools

  • h5py (Low-level HDF5 file I/O and dataset access; underlying layer for MZA class file operations)
  • hdf5plugin (Transparent decompression of HDF5 datasets; caching mitigates repeated decompression overhead)
  • mzapy.MZA (High-level interface implementing cache_metadata_headers parameter and load_scan_cache() / save_scan_cache() methods) — https://github.com/PNNL-m-q/mzapy
  • numpy (In-memory array representation and fast lookup of cached scan data)
  • pandas (Optional structured representation of metadata cache for DataFrame-based queries)

Examples

from mzapy import MZA
mza = MZA('example.mza', cache_metadata_headers=['RetentionTime', 'IonMobilityTime'])
mza.load_scan_cache(scan_range=(100, 500))
xic_data = mza.collect_xic_arrays_by_mz(400.5)
mza.save_scan_cache('cached_scans.pkl')
mza.close()

Evaluation signals

  • Elapsed wall-clock time for repeated queries (e.g., collect_xic_arrays_by_mz, collect_ms1_arrays_by_rt) is significantly lower on the second and subsequent passes compared to the first pass without cache.
  • Memory usage reported by the OS or Python psutil stays below an acceptable threshold (verify cache_metadata_headers='all' is not selected if OOM risk is high).
  • Saved cache file (from save_scan_cache()) exists and is non-zero in size, indicating scans were actually cached.
  • Re-loaded cache from previous session (via load_scan_cache()) yields identical query results as recomputing from disk, confirming correctness.
  • HDF5 decompression library calls (if profiled) drop significantly after cache population, confirming I/O reduction.

Limitations

  • Cache coherency is not automatic: if the underlying MZA file is modified between cache save and load, stale cached data may be returned without warning.
  • The cache_metadata_headers parameter applies only to metadata headers (scan properties like retention time and ion mobility); individual m/z and intensity arrays are only cached via load_scan_cache(), which loads entire scan objects.
  • For very large files with millions of spectra, even selective caching can exhaust RAM; practitioners must choose cache_metadata_headers carefully and avoid load_scan_cache() on the full spectrum range.
  • Cache persistence (save_scan_cache) relies on pickle or equivalent serialization; binary compatibility across Python versions or platforms is not guaranteed.

Evidence

  • [other] The cache_metadata_headers kwarg is used to control which metadata headers are cached in memory for faster access: "The cache_metadata_headers kwarg is used to control which metadata headers are cached in memory for faster access"
  • [other] Provide scan caching methods (load_scan_cache, save_scan_cache) to accelerate repeated data access.: "Provide scan caching methods (load_scan_cache, save_scan_cache) to accelerate repeated data access."
  • [other] Initialize the MZA class with optional cache_metadata_headers parameter (default, empty list, or 'all') to control in-memory caching of metadata.: "Initialize the MZA class with optional cache_metadata_headers parameter (default, empty list, or 'all') to control in-memory caching of metadata."
  • [readme] HDF5 is more efficient when using multiple groups instead of storing many datasets within one group.: "HDF5 is more efficient when using multiple groups instead of storing many datasets within one group."
  • [other] mzapy is a Python package that provides an interface to unprocessed MS data in the MZA format, built using h5py and hdf5plugin as core dependencies for HDF5 file access.: "mzapy is a Python package that provides an interface to unprocessed MS data in the MZA format, built using h5py and hdf5plugin as core dependencies for HDF5 file access."

Keep looking

Skills are one crate of 328,083. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.