rainbow.agilent.chemstation

Methods for parsing Agilent Chemstation files.

Functions

decode_delta(f, offset)

decode_double_delta(f, offset)

decode_uv_array(f, data_offsets, num_times, ...)

Decode the absorbances of an Agilent .uv file stored as raw doubles.

decode_uv_delta(f, data_offsets, num_times, ...)

Decode the delta-encoded absorbances of an Agilent .uv file.

get_nextstr(str_list, target_str)

Returns the string at the next index in str_list, if it exists.

get_xml_vialnum(path)

Returns the VialNumber from an XML document, if it exists.

parse_allfiles(path[, prec, requested_files])

Finds and parses Agilent Chemstation data files with a .ch, .uv, or .ms extension from a .D directory.

parse_ch(path)

Parses an Agilent .ch file.

parse_ch_fid(path, head)

Parses an Agilent .ch file with FID channel data.

parse_ch_other(path, head)

Parses an Agilent .ch file with CAD, ELSD, or UV channel data.

parse_file(path[, prec])

Parses an Agilent Chemstation data file.

parse_metadata(path, datafiles)

Parses Agilent metadata at the directory level.

parse_ms(path[, prec])

Parses an Agilent .ms file.

parse_ms_partial(path[, prec])

Parses a partial Agilent .ms file.

parse_uv(path)

Parses an Agilent .uv file.

parse_uv_partial(path)

Parses a partial Agilent .uv file.

read_header(f, offsets[, gap])

Extracts metadata from the header of an Agilent data file.

read_string(f, offset[, gap])

Extracts a string from the specified offset.

parse_allfiles(path, prec=0, requested_files=None)[source]

Finds and parses Agilent Chemstation data files with a .ch, .uv, or .ms extension from a .D directory.

Parameters:
  • path (str) – Path to the .D directory.

  • prec (int, optional) – Number of decimals to round mz values.

  • requested_files (list, optional) – List of filenames to parse.

Returns:

List with a DataFile for each parsed data file.

parse_file(path, prec=0)[source]

Parses an Agilent Chemstation data file.

Supported extensions are .ch, .uv, and .ms.

Parameters:
  • path (str) – Path to the data file.

  • prec (int, optional) – Number of decimals to round mz values.

Returns:

DataFile representing the file, if it can be parsed. Otherwise, None.

parse_ch(path)[source]

Parses an Agilent .ch file.

These files contain data from a FID, CAD, ELSD, or UV channel. Files that contain FID data have a different format than other .ch files.

This method calls the appropriate subroutine by file format.

Parameters:

path (str) – Path to the .ch file.

Returns:

DataFile with data from a channel, if the file can be parsed. Otherwise, None.

parse_ch_fid(path, head)[source]

Parses an Agilent .ch file with FID channel data.

This method should not be called directly. Use parse_ch instead.

Learn more about this file format here.

Parameters:

path (str) – Path to the .ch file with FID data.

Returns:

DataFile with FID data, if the file can be parsed. Otherwise, None.

parse_ch_other(path, head)[source]

Parses an Agilent .ch file with CAD, ELSD, or UV channel data.

This method should not be called directly. Use parse_ch instead.

IMPORTANT: ELSD data may be mistakenly labeled as CAD on rare occasions. Users may need to make this distinction on their own when decoding Agilent CAD or ELSD data.

Learn more about this file format here.

Parameters:

path (str) – Path to the .ch file with UV, CAD, or ELSD data.

Returns:

DataFile with CAD, ELSD, or UV data, if parsable. Otherwise, None.

decode_delta(f, offset)[source]
decode_double_delta(f, offset)[source]
decode_uv_delta(f, data_offsets, num_times, num_wavelengths)[source]

Decode the delta-encoded absorbances of an Agilent .uv file.

Each retention time holds num_wavelengths absorbances stored as 16-bit deltas against a running accumulator. The sentinel value -0x8000 instead signals that the next 32-bit integer is a new absolute value.

If the compiled accelerator (rainbow.agilent._uvdelta) was built it is used for the inner loop; otherwise this falls back to the pure-Python loop below, which produces identical output. See parse_uv.

Parameters:
  • f (_io.BufferedReader) – File opened in ‘rb’ mode.

  • data_offsets (dict) – Offsets for this file format.

  • num_times (int) – Number of retention times.

  • num_wavelengths (int) – Number of wavelengths per time.

Returns:

a uint32 array of raw times and an (num_times, num_wavelengths) int64 array of absorbances.

Return type:

Tuple of (times, data)

decode_uv_array(f, data_offsets, num_times, num_wavelengths)[source]

Decode the absorbances of an Agilent .uv file stored as raw doubles.

Used by the OL format variant, where each absorbance is a little-endian float64 rather than a delta. See parse_uv.

Parameters:
  • f (_io.BufferedReader) – File opened in ‘rb’ mode.

  • data_offsets (dict) – Offsets for this file format.

  • num_times (int) – Number of retention times.

  • num_wavelengths (int) – Number of wavelengths per time.

Returns:

a uint32 array of raw times and an (num_times, num_wavelengths) float64 array of absorbances.

Return type:

Tuple of (times, data)

parse_uv(path)[source]

Parses an Agilent .uv file.

These files contain UV spectra.

Learn more about this file format here.

Parameters:

path (str) – Path to the Agilent .uv file.

Returns:

DataFile with UV data, if the file can be parsed. Otherwise, None.

parse_uv_partial(path)[source]

Parses a partial Agilent .uv file.

Learn more about this file format here.

Parameters:

path (str) – Path to the partial .uv file.

Returns:

DataFile with UV data, if the file can be parsed. Otherwise, None.

parse_ms(path, prec=0)[source]

Parses an Agilent .ms file.

These files contain MS spectra and SIM.

Learn more about this file format here.

Parameters:
  • path (str) – Path to Agilent .ms file.

  • prec (int, optional) – Number of decimals to round mz values.

Returns:

DataFile with MS data, if the file can be parsed. Otherwise, None.

parse_ms_partial(path, prec=0)[source]

Parses a partial Agilent .ms file.

IMPORTANT: This method only supports LC .ms partials.

Learn more about this file format here.

Parameters:
  • path (str) – Path to the partial .ms file.

  • prec (int, optional) – Number of decimal to round mz values.

Returns:

DataFile with MS data, if the file can be parsed. Otherwise, None.

read_header(f, offsets, gap=2)[source]

Extracts metadata from the header of an Agilent data file.

Parameters:
  • f (_io.BufferedReader) – File opened in ‘rb’ mode.

  • offsets (dict) – Dictionary mapping properties to file offsets.

  • gap (int) – Distance between two adjacent characters.

Returns:

Dictionary containing metadata as string key-value pairs.

read_string(f, offset, gap=2)[source]

Extracts a string from the specified offset.

This method is primarily useful for retrieving metadata.

Parameters:
  • f (_io.BufferedReader) – File opened in ‘rb’ mode.

  • offset (int) – Offset to begin reading from.

  • gap (int) – Distance between two adjacent characters.

Returns:

String at the specified offset in the file header.

parse_metadata(path, datafiles)[source]

Parses Agilent metadata at the directory level.

First, the DataFiles are checked for date and vial position metadata.

Then, several files are scanned for the vial position. This method can look inside the AcqData directory, which may be misleading because this method resides in the Chemstation module.

Parameters:
  • path (str) – Path to the directory.

  • datafiles (list) – List of DataFile objects.

Returns:

Dictionary containing directory metadata.

get_xml_vialnum(path)[source]

Returns the VialNumber from an XML document, if it exists.

Parameters:

path (str) – Path to the XML document.

get_nextstr(str_list, target_str)[source]

Returns the string at the next index in str_list, if it exists.

Parameters:
  • str_list (str) – List of strings.

  • target_str (str) – Initial string to find.