agentsclimarketplace

Xml element parsing and object serialization

Skill HolobiomicsLab/asb-skill-collections/packs/metabolomics/ms-generic/skills/xml-element-parsing-and-object-serialization

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 xml-element-parsing-and-object-serialization

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 have spectrum or chromatogram data stored as XML strings (e.g., in a SQLite database indexed by spectrum ID) and need to access individual spectra by ID or iterate through them sequentially while working with a library like pymzML that expects Spectrum or Chromatogram objects.

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

6.3 KB, ~1.1k tokens by cl100k_base, as published. Nobody here has run it

xml-element-parsing-and-object-serialization

Summary

Parse XML element strings retrieved from a data source (e.g., a database) and deserialize them into typed spectrum or chromatogram objects for downstream analysis. This skill bridges storage formats and in-memory object models in mass spectrometry data workflows.

When to use

You have spectrum or chromatogram data stored as XML strings (e.g., in a SQLite database indexed by spectrum ID) and need to access individual spectra by ID or iterate through them sequentially while working with a library like pymzML that expects Spectrum or Chromatogram objects.

When NOT to use

  • Input is already a deserialized Spectrum or Chromatogram object in memory.
  • XML data is embedded in a standard mzML file with built-in indexing; use pymzML.run.Reader directly instead.
  • Performance-critical access patterns require avoiding repeated XML parsing; consider caching deserialized objects.

Inputs

  • XML string representation of a spectrum or chromatogram
  • Spectrum or chromatogram ID (integer or string key)
  • Database handle or file object containing XML strings indexed by ID

Outputs

  • pymzML Spectrum object
  • pymzML Chromatogram object
  • xml.etree.ElementTree Element

How to apply

Use xml.etree.ElementTree.XML to parse an XML string retrieved from storage into an ElementTree Element object. Pass the Element to the spectrum/chromatogram parser provided by your analysis library (e.g., pymzML.spec.Spectrum) to instantiate the typed object. For random-access patterns, implement a getitem method that retrieves the XML string by ID, parses it, and returns the deserialized object. For sequential iteration, implement a read method that yields XML strings in order, allowing the iteration protocol to call the parser on each. This approach decouples storage (flat XML strings) from the in-memory representation (structured objects with methods and attributes).

Related tools

  • pymzML (Provides Spectrum and Chromatogram classes to instantiate from parsed XML; FileInterface allows registration of custom file handlers that implement getitem and read methods for random-access and sequential retrieval.) — https://github.com/pymzml/pymzML
  • xml.etree.ElementTree (Parses XML strings into Element trees that can be passed to pymzML spectrum constructors.)
  • sqlite3 (Retrieves XML strings from a relational database by spectrum ID.)

Examples

import xml.etree.ElementTree as et; import sqlite3; conn = sqlite3.connect('test.db'); cursor = conn.cursor(); cursor.execute('SELECT xml FROM spectra WHERE id=5'); xml_str = cursor.fetchone()[0]; elem = et.XML(xml_str); spectrum = pymzml.spec.Spectrum(xmlElement=elem)

Evaluation signals

  • Deserialized object is an instance of pymzML.spec.Spectrum or pymzML.spec.Chromatogram with accessible attributes (ms_level, ID, mz, intensity arrays).
  • Random-access via db[unique_id] returns a valid Spectrum object without raising KeyError or parsing errors.
  • Sequential iteration via iter() over the file handler returns all spectra in database order without duplicates or missing IDs.
  • XML Element parse time and object instantiation time remain sub-second for typical mzML spectrum XML (~1–10 KB).
  • Round-trip consistency: spectrum.ID matches the query key; spectrum arrays (mz, intensity) match the original mzML values within floating-point tolerance.

Limitations

  • XML parsing is performed on every access; caching is not built in, so repeated access to the same spectrum ID will re-parse the XML.
  • Performance scales with XML document size; large spectra with many m/z–intensity pairs may incur noticeable parse overhead.
  • Custom regex patterns for non-standard spectrum ID formats (e.g., 'scan=1' vs. integers) must be configured separately in the pymzML Reader; this skill assumes IDs are extractable from database keys.
  • Memory usage grows linearly with the number of deserialized objects held in memory simultaneously.

Evidence

  • [other] getitem to execute SELECT queries on the Spectra table and return parsed Spectrum or Chromatogram objects using xml.etree.ElementTree.XML parsing: "getitem executing SQL queries to fetch spectrum XML by key and returning Spectrum or Chromatogram objects"
  • [other] read to sequentially return XML element strings by current_spectrum_id: "read to sequentially return XML element strings by current_spectrum_id"
  • [other] Implement custom file wrapper class that needs to implement the getitem function for random access, and a read function used to sequentiallly read in data: "implement a class, which needs to implement the getitem function for random access, and a read function used to sequentiallly read in data"
  • [readme] Easy access to mass spectrometry (MS) data that allows the rapid development of tools: "easy access to mass spectrometry (MS) data that allows the rapid development of tools"
  • [readme] a very fast parser for mzML data, the standard mass spectrometry data format: "a very fast parser for mzML data, the standard mass spectrometry data format"

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.