3.4. File Access

pymzML offers support for different kinds of mzML files. The following classes are wrappers for different types of mzML files, which allows the implementation of file type specific search and data retrieving algorithms. An explanation of how to implement your own file class can be found in the advanced section.

3.4.1. File Interface

class pymzml.file_interface.FileInterface(path, encoding)[source]
__getitem__(identifier)[source]

Access the item with id ‘identifier’ in the file

Parameters:identifier (str) – native id of the item to access
Returns:data – text associated with the given identifier
Return type:str
__init__(path, encoding)[source]

Initialize a object interface to mzML files

Parameters:
  • path (str) – path to the mzML file
  • encoding (str) – encoding of the file
_indexed_gzip(path)[source]

Check if the given file is an indexed gzip file or not

Parameters:path (str) – path to the file
Returns:True if path is a gzip file with index, else False
Return type:bool
_open(path)[source]

Open a file like object resp. a wrapper for a file like object.

Parameters:path (str) – path to the mzml file
Returns:instance of StandardGzip, IndexedGzip or StandardMzml, based on the file ending of ‘path’
Return type:file_handler
read(size=-1)[source]

Read binary data from file handler.

Keyword Arguments:
 
  • size (int) – Number of bytes to read from file, -1 to
  • read to end of file
Returns:

data – byte string of len size of input data

Return type:

str

3.4.2. File Classes

3.4.2.1. mzML

class pymzml.file_classes.standardMzml.StandardMzml(path, encoding)[source]
__getitem__(identifier)[source]

Access the item with id ‘identifier’ in the file using either linear, binary or interpolated search.

Parameters:identifier (str) – native id of the item to access
Returns:data – text associated with the given identifier
Return type:str
__init__(path, encoding)[source]

Initalize Wrapper object for standard mzML files.

Parameters:
  • path (str) – path to the file
  • encoding (str) – encoding of the file

Use linear interpolation search to find spectra faster.

Parameters:target_index (str or int) – native id of the item to access
Keyword Arguments:
 chunk_size (int) – size of the chunk to read in one go in kb
_search_linear(seeker, index, chunk_size=8)[source]

Fallback to linear search

read(size=-1)[source]

Read binary data from file handler.

Keyword Arguments:
 size (int) – Number of bytes to read from file, -1 to read to end of file
Returns:data – byte string of len size of input data
Return type:str

3.4.2.2. Gzip

class pymzml.file_classes.standardGzip.StandardGzip(path, encoding)[source]
_StandardGzip__build_index()

Cant build index for standard gzip files

__getitem__(identifier)[source]

Access the item with id ‘identifier’ in the file by iterating the XML-tree.

Parameters:identifier (str) – native id of the item to access
Returns:data – text associated with the given identifier
Return type:str
__init__(path, encoding)[source]

Initalize Wrapper object for gzipped mzML files.

Parameters:
  • path (str) – path to the file
  • encoding (str) – encoding of the file
read(size=-1)[source]

Read binary data from file handler.

Keyword Arguments:
 size (int) – Number of bytes to read from file, -1 to read to end of file
Returns:data – byte string of len size of input data
Return type:str

3.4.2.3. iGzip

class pymzml.file_classes.indexedGzip.IndexedGzip(path, encoding)[source]
_IndexedGzip__build_index()

Use the GSGR class to retrieve the index from the file and save it.

__getitem__(identifier)[source]

Access the item with id ‘identifier’ in the file.

Parameters:identifier (str) – native id of the item to access
Returns:data – text associated with the given identifier
Return type:str
__init__(path, encoding)[source]

Initalize Wrapper object for indexed gzipped files.

Parameters:
  • path (str) – path to the file
  • encoding (str) – encoding of the file
read(size=-1)[source]

Read binary data from file handler.

Keyword Arguments:
 size (int) – Number of bytes to read from file, -1 to read to end of file
Returns:data – byte string of len size of input data
Return type:str