Pyteomics documentation v3.4.1

featurexml - reader for featureXML files

Contents

featurexml - reader for featureXML files

Summary

featureXML is a format specified in the OpenMS project. It defines a list of LC-MS features observed in an experiment.

This module provides a minimalistic way to extract information from featureXML files. You can use the old functional interface (read()) or the new object-oriented interface (FeatureXML) to iterate over entries in <feature> elements. FeatureXML also supports direct indexing with feature IDs.

Data access

FeatureXML - a class representing a single featureXML file. Other data access functions use this class internally.

read() - iterate through features in a featureXML file. Data from a single feature are converted to a human-readable dict.

chain() - read multiple featureXML files at once.

chain.from_iterable() - read multiple files at once, using an iterable of files.

Dependencies

This module requres lxml.


pyteomics.openms.featurexml.chain(*args, **kwargs)

Chain read() for several files. Positional arguments should be file names or file objects. Keyword arguments are passed to the read() function.

chain.from_iterable(files, **kwargs)

Chain read() for several files. Keyword arguments are passed to the read() function.

Parameters:

files : iterable

Iterable of file names or file objects.

class pyteomics.openms.featurexml.FeatureXML(*args, **kwargs)[source]

Bases: pyteomics.xml.IndexedXML

Parser class for featureXML files.

Methods

build_id_cache(*args, **kwargs) Construct a cache for each element in the document, indexed by id
build_tree(*args, **kwargs) Build and store the ElementTree instance
clear_id_cache() Clear the element ID cache
clear_tree() Remove the saved ElementTree.
get_by_id(*args, **kwargs) Retrieve the requested entity by its id.
iterfind(*args, **kwargs) Parse the XML and yield info on elements with specified local name or by specified “XPath”.
next()
reset()
__init__(*args, **kwargs)

Create an XML parser object.

Parameters:

source : str or file

File name or file-like object corresponding to an XML file.

read_schema : bool, optional

Defines whether schema file referenced in the file header should be used to extract information about value conversion. Default is True.

iterative : bool, optional

Defines whether an ElementTree object should be constructed and stored on the instance or if iterative parsing should be used instead. Iterative parsing keeps the memory usage low for large XML files. Default is True.

use_index : bool, optional

Defines whether an index of byte offsets needs to be created for elements listed in indexed_tags. This is useful for random access to spectra in mzML or elements of mzIdentML files, or for iterative parsing of mzIdentML with retrieve_refs=True. If True, build_id_cache is ignored. If False, the object acts exactly like XML. Default is True.

indexed_tags : container of bytes, optional

If use_index is True, elements listed in this parameter will be indexed. Empty set by default.

build_id_cache(*args, **kwargs)

Construct a cache for each element in the document, indexed by id attribute

build_tree(*args, **kwargs)

Build and store the ElementTree instance for the underlying file

clear_id_cache()

Clear the element ID cache

clear_tree()

Remove the saved ElementTree.

get_by_id(*args, **kwargs)

Retrieve the requested entity by its id. If the entity is a spectrum described in the offset index, it will be retrieved by immediately seeking to the starting position of the entry, otherwise falling back to parsing from the start of the file.

Parameters:

elem_id : str

The id value of the entity to retrieve.

Returns:

dict :

iterfind(*args, **kwargs)

Parse the XML and yield info on elements with specified local name or by specified “XPath”.

Parameters:

path : str

Element name or XPath-like expression. Only local names separated with slashes are accepted. An asterisk (*) means any element. You can specify a single condition in the end, such as: "/path/to/element[some_value>1.5]" Note: you can do much more powerful filtering using plain Python. The path can be absolute or “free”. Please don’t specify namespaces.

**kwargs : passed to self._get_info_smart().

Returns:

out : iterator

pyteomics.openms.featurexml.read(source, read_schema=True, iterative=True, use_index=False)[source]

Parse source and iterate through features.

Parameters:

source : str or file

A path to a target featureXML file or the file object itself.

read_schema : bool, optional

If True, attempt to extract information from the XML schema mentioned in the file header (default). Otherwise, use default parameters. Disable this to avoid waiting on slow network connections or if you don’t like to get the related warnings.

iterative : bool, optional

Defines whether iterative parsing should be used. It helps reduce memory usage at almost the same parsing speed. Default is True.

use_index : bool, optional

Defines whether an index of byte offsets needs to be created for spectrum elements. Default is False.

Returns:

out : iterator

An iterator over the dicts with feature properties.

Contents