mwtab-file-parsing
Summary
Parse mwTab-formatted files into structured Python objects to extract metadata and tabular data sections for MS and NMR experiments. This skill enables programmatic access to mass spectrometry and nuclear magnetic resonance experimental data archived in the Metabolomics Workbench using the mwtab library.
When to use
You have mwTab format files (Mass Spectrometry or Nuclear Magnetic Resonance experimental data from Metabolomics Workbench) that need to be loaded into Python for downstream analysis, validation, conversion to JSON, or programmatic manipulation of metadata and data sections.
When NOT to use
- Input is already a JSON representation or equivalent structured object (use JSON direct ingestion instead)
- File is in NetCDF, mzML, or other non-mwTab metabolomics formats (use format-specific parsers)
- Task requires only metadata extraction without touching tabular data (consider lightweight regex parsing)
Inputs
- mwTab-formatted text file (local path or remote ANALYSIS_ID)
- File handle or string path to .txt mwTab file
- ANALYSIS_ID string for remote Metabolomics Workbench fetch
Outputs
- MWTabFile instance (generator-yielded or list collected)
- Dictionary of named data blocks (metadata and tabular sections)
- Structured metadata (STUDY_ID, ANALYSIS_ID, SOURCE, instrument parameters)
- Tabular data sections (accessible via block keys and pandas conversion)
How to apply
Use the mwtab library's MWTabFile parser to load mwTab files, either from local disk or by ANALYSIS_ID from the Metabolomics Workbench remote service. The parser yields MWTabFile instances that provide dictionary-like access to named data blocks (metadata sections and tabular data). Extract study identifiers (STUDY_ID, ANALYSIS_ID), source metadata, and tabular blocks by iterating over the generator or accessing keys on each instance. The parser handles the mwTab text format specification internally, normalizing metadata key–value pairs and structuring tabular sections for downstream access via pandas DataFrames or direct inspection.
Related tools
- mwtab (Core library for reading, writing, and parsing mwTab format files into Python MWTabFile objects) — https://github.com/MoseleyBioinformaticsLab/mwtab
- jsonschema (Validates parsed mwTab data against JSON schema definitions after file parsing, enabling conformance checking)
- pandas (Converts mwTab tabular data sections into DataFrames for analysis and manipulation)
Examples
import mwtab
for mwfile in mwtab.read_files("1", "2"):
print("STUDY_ID:", mwfile.study_id)
print("ANALYSIS_ID:", mwfile.analysis_id)
print("Blocks:", list(mwfile.keys()))
Evaluation signals
- MWTabFile instance is successfully created without parse errors or exceptions
- STUDY_ID and ANALYSIS_ID are non-null and match expected identifiers from input file or remote source
- Named blocks (keys) from mwTab file are accessible via dict-like interface on MWTabFile instance
- Metadata key–value pairs are correctly normalized and present in extracted metadata dictionary
- Tabular data sections (e.g., Sample data, Raw data) can be retrieved and have expected column counts
Limitations
- Parser assumes valid mwTab format syntax; malformed files will raise exceptions and require manual repair
- Remote fetch via ANALYSIS_ID requires network access to Metabolomics Workbench API and valid credentials if applicable
- Large mwTab files with many samples or high-dimensional raw data may consume significant memory when fully loaded into memory
Evidence
- [readme] The
mwtab package is a Python library that facilitates reading and writing files in mwTab format used by the Metabolomics Workbench_ for archival of Mass Spectrometry (MS) and Nuclear Magnetic Resonance (NMR) experimental data.: "The mwtab package is a Python library that facilitates reading and writing files in mwTab format used by the Metabolomics Workbench_ for archival of Mass Spectrometry (MS) and Nuclear"
- [other] Create the :class:
~mwtab.mwtab.MWTabFile generator function that will generate (yield) a single :class:~mwtab.mwtab.MWTabFile instance at a time.: "Create the :class:~mwtab.mwtab.MWTabFile generator function that will generate (yield) a single :class:~mwtab.mwtab.MWTabFile instance at a time."
- [other] Process each :class:
~mwtab.mwtab.MWTabFile instance: Process mwTab files in a for-loop, one file at a time.: "Process each :class:~mwtab.mwtab.MWTabFile instance: Process mwTab files in a for-loop, one file at a time."
- [readme] As a library for accessing and manipulating data stored in
mwTab format files.: "As a library for accessing and manipulating data stored in mwTab format files."
- [readme] Here we use ANALYSIS_ID of file to fetch data from URL: "Here we use ANALYSIS_ID of file to fetch data from URL"
1---2name: mwtab-file-parsing3description: Use when you have mwTab format files (Mass Spectrometry or Nuclear Magnetic Resonance experimental data from Metabolomics Workbench) that need to be loaded into Python for downstream analysis, validation, conversion to JSON, or programmatic manipulation of metadata and data sections.4license: CC-BY-4.05---67# mwtab-file-parsing89## Summary1011Parse mwTab-formatted files into structured Python objects to extract metadata and tabular data sections for MS and NMR experiments. This skill enables programmatic access to mass spectrometry and nuclear magnetic resonance experimental data archived in the Metabolomics Workbench using the mwtab library.1213## When to use1415You have mwTab format files (Mass Spectrometry or Nuclear Magnetic Resonance experimental data from Metabolomics Workbench) that need to be loaded into Python for downstream analysis, validation, conversion to JSON, or programmatic manipulation of metadata and data sections.1617## When NOT to use1819- Input is already a JSON representation or equivalent structured object (use JSON direct ingestion instead)20- File is in NetCDF, mzML, or other non-mwTab metabolomics formats (use format-specific parsers)21- Task requires only metadata extraction without touching tabular data (consider lightweight regex parsing)2223## Inputs2425- mwTab-formatted text file (local path or remote ANALYSIS_ID)26- File handle or string path to .txt mwTab file27- ANALYSIS_ID string for remote Metabolomics Workbench fetch2829## Outputs3031- MWTabFile instance (generator-yielded or list collected)32- Dictionary of named data blocks (metadata and tabular sections)33- Structured metadata (STUDY_ID, ANALYSIS_ID, SOURCE, instrument parameters)34- Tabular data sections (accessible via block keys and pandas conversion)3536## How to apply3738Use the mwtab library's MWTabFile parser to load mwTab files, either from local disk or by ANALYSIS_ID from the Metabolomics Workbench remote service. The parser yields MWTabFile instances that provide dictionary-like access to named data blocks (metadata sections and tabular data). Extract study identifiers (STUDY_ID, ANALYSIS_ID), source metadata, and tabular blocks by iterating over the generator or accessing keys on each instance. The parser handles the mwTab text format specification internally, normalizing metadata key–value pairs and structuring tabular sections for downstream access via pandas DataFrames or direct inspection.3940## Related tools4142- **mwtab** (Core library for reading, writing, and parsing mwTab format files into Python MWTabFile objects) — https://github.com/MoseleyBioinformaticsLab/mwtab43- **jsonschema** (Validates parsed mwTab data against JSON schema definitions after file parsing, enabling conformance checking)44- **pandas** (Converts mwTab tabular data sections into DataFrames for analysis and manipulation)4546## Examples4748```49import mwtab50for mwfile in mwtab.read_files("1", "2"):51 print("STUDY_ID:", mwfile.study_id)52 print("ANALYSIS_ID:", mwfile.analysis_id)53 print("Blocks:", list(mwfile.keys()))54```5556## Evaluation signals5758- MWTabFile instance is successfully created without parse errors or exceptions59- STUDY_ID and ANALYSIS_ID are non-null and match expected identifiers from input file or remote source60- Named blocks (keys) from mwTab file are accessible via dict-like interface on MWTabFile instance61- Metadata key–value pairs are correctly normalized and present in extracted metadata dictionary62- Tabular data sections (e.g., Sample data, Raw data) can be retrieved and have expected column counts6364## Limitations6566- Parser assumes valid mwTab format syntax; malformed files will raise exceptions and require manual repair67- Remote fetch via ANALYSIS_ID requires network access to Metabolomics Workbench API and valid credentials if applicable68- Large mwTab files with many samples or high-dimensional raw data may consume significant memory when fully loaded into memory6970## Evidence7172- [readme] The ``mwtab`` package is a Python library that facilitates reading and writing files in ``mwTab`` format used by the `Metabolomics Workbench`_ for archival of Mass Spectrometry (MS) and Nuclear Magnetic Resonance (NMR) experimental data.: "The ``mwtab`` package is a Python library that facilitates reading and writing files in ``mwTab`` format used by the `Metabolomics Workbench`_ for archival of Mass Spectrometry (MS) and Nuclear"73- [other] Create the :class:`~mwtab.mwtab.MWTabFile` generator function that will generate (yield) a single :class:`~mwtab.mwtab.MWTabFile` instance at a time.: "Create the :class:`~mwtab.mwtab.MWTabFile` generator function that will generate (yield) a single :class:`~mwtab.mwtab.MWTabFile` instance at a time."74- [other] Process each :class:`~mwtab.mwtab.MWTabFile` instance: Process ``mwTab`` files in a for-loop, one file at a time.: "Process each :class:`~mwtab.mwtab.MWTabFile` instance: Process ``mwTab`` files in a for-loop, one file at a time."75- [readme] As a library for accessing and manipulating data stored in ``mwTab`` format files.: "As a library for accessing and manipulating data stored in ``mwTab`` format files."76- [readme] Here we use ANALYSIS_ID of file to fetch data from URL: "Here we use ANALYSIS_ID of file to fetch data from URL"