| OpenMS 2.5.0

Functions
ms::numpress::MSNumpress Namespace Reference

## Functions

double | optimalLinearFixedPoint (const double *data, size_t dataSize)
double | optimalLinearFixedPointMass (const double *data, size_t dataSize, double mass_acc)
size_t | encodeLinear (const double *data, const size_t dataSize, unsigned char *result, double fixedPoint)
void | encodeLinear (const std::vector< double > &data, std::vector< unsigned char > &result, double fixedPoint)
size_t | decodeLinear (const unsigned char *data, const size_t dataSize, double *result)
void | decodeLinear (const std::vector< unsigned char > &data, std::vector< double > &result)
size_t | encodeSafe (const double *data, const size_t dataSize, unsigned char *result)
size_t | decodeSafe (const unsigned char *data, const size_t dataSize, double *result)
size_t | encodePic (const double *data, const size_t dataSize, unsigned char *result)
void | encodePic (const std::vector< double > &data, std::vector< unsigned char > &result)
size_t | decodePic (const unsigned char *data, const size_t dataSize, double *result)
void | decodePic (const std::vector< unsigned char > &data, std::vector< double > &result)
double | optimalSlofFixedPoint (const double *data, size_t dataSize)
size_t | encodeSlof (const double *data, const size_t dataSize, unsigned char *result, double fixedPoint)
void | encodeSlof (const std::vector< double > &data, std::vector< unsigned char > &result, double fixedPoint)
size_t | decodeSlof (const unsigned char *data, const size_t dataSize, double *result)
void | decodeSlof (const std::vector< unsigned char > &data, std::vector< double > &result)

## Function Documentation

## ◆ decodeLinear() [1/2]

size_t ms::numpress::MSNumpress::decodeLinear | ( | const unsigned char * | data,
|  | const size_t | dataSize,
|  | double * | result
| ) |  |

Decodes data encoded by encodeLinear.

result vector guaranteed to be shorter or equal to (|data| - 8) * 2

Note that this method may throw a const char* if it deems the input data to be corrupt, i.e. that the last encoded int does not use the last byte in the data. In addition the last encoded int need to use either the last halfbyte, or the second last followed by a 0x0 halfbyte.

Parameters

  data | pointer to array of bytes to be decoded (need memorycont. repr.)
  dataSize | number of bytes from *data to decode
  result | pointer to were resulting doubles should be stored
  return | the number of decoded doubles, or -1 if dataSize < 4 or 4 < dataSize < 8

## ◆ decodeLinear() [2/2]

void ms::numpress::MSNumpress::decodeLinear | ( | const std::vector< unsigned char > & | data,
|  | std::vector< double > & | result
| ) |  |

Calls lower level decodeLinear while handling vector sizes appropriately

Note that this method may throw a const char* if it deems the input data to be corrupt, i.e.. that the last encoded int does not use the last byte in the data. In addition the last encoded int need to use either the last halfbyte, or the second last followed by a 0x0 halfbyte.

Parameters

  data | vector of bytes to be decoded
  result | vector of resulting double (will be resized to the number of doubles)

## ◆ decodePic() [1/2]

size_t ms::numpress::MSNumpress::decodePic | ( | const unsigned char * | data,
|  | const size_t | dataSize,
|  | double * | result
| ) |  |

Decodes data encoded by encodePic

result vector guaranteed to be shorter of equal to |data| * 2

Note that this method may throw a const char* if it deems the input data to be corrupt, i.e. that the last encoded int does not use the last byte in the data. In addition the last encoded int need to use either the last halfbyte, or the second last followed by a 0x0 halfbyte.

Parameters

  data | pointer to array of bytes to be decoded (need memorycont. repr.)
  dataSize | number of bytes from *data to decode
  result | pointer to were resulting doubles should be stored

Returns
  the number of decoded doubles

## ◆ decodePic() [2/2]

void ms::numpress::MSNumpress::decodePic | ( | const std::vector< unsigned char > & | data,
|  | std::vector< double > & | result
| ) |  |

Calls lower level decodePic while handling vector sizes appropriately

Note that this method may throw a const char* if it deems the input data to be corrupt, i.e. that the last encoded int does not use the last byte in the data. In addition the last encoded int need to use either the last halfbyte, or the second last followed by a 0x0 halfbyte.

Parameters

  data | vector of bytes to be decoded

Returns
  vector of resulting double (will be resized to the number of doubles)

## ◆ decodeSafe()

size_t ms::numpress::MSNumpress::decodeSafe | ( | const unsigned char * | data,
|  | const size_t | dataSize,
|  | double * | result
| ) |  |

Decodes data encoded by encodeSafe.

result vector is the same size as the input data.

Might throw const char* is something goes wrong during decoding.

Parameters

  data | pointer to array of bytes to be decoded (need memorycont. repr.)
  dataSize | number of bytes from *data to decode
  result | pointer to were resulting doubles should be stored

Returns
  the number of decoded bytes

## ◆ decodeSlof() [1/2]

size_t ms::numpress::MSNumpress::decodeSlof | ( | const unsigned char * | data,
|  | const size_t | dataSize,
|  | double * | result
| ) |  |

Decodes data encoded by encodeSlof

The return will include exactly (|data| - 8) / 2 doubles.

Note that this method may throw a const char* if it deems the input data to be corrupt.

Parameters

  data | pointer to array of bytes to be decoded (need memorycont. repr.)
  dataSize | number of bytes from *data to decode
  result | pointer to were resulting doubles should be stored

Returns
  the number of decoded doubles

## ◆ decodeSlof() [2/2]

void ms::numpress::MSNumpress::decodeSlof | ( | const std::vector< unsigned char > & | data,
|  | std::vector< double > & | result
| ) |  |

Calls lower level decodeSlof while handling vector sizes appropriately

Note that this method may throw a const char* if it deems the input data to be corrupt.

Parameters

  data | vector of bytes to be decoded
  result | vector of resulting double (will be resized to the number of doubles)

## ◆ encodeLinear() [1/2]

size_t ms::numpress::MSNumpress::encodeLinear | ( | const double * | data,
|  | const size_t | dataSize,
|  | unsigned char * | result,
|  | double | fixedPoint
| ) |  |

Encodes the doubles in data by first using a

- lossy conversion to a 4 byte 5 decimal fixed point representation
- storing the residuals from a linear prediction after first two values
- encoding by encodeInt (see above)

The resulting binary is maximally 8 + dataSize * 5 bytes, but much less if the data is reasonably smooth on the first order.

This encoding is suitable for typical m/z or retention time binary arrays. On a test set, the encoding was empirically show to be accurate to at least 0.002 ppm.

Parameters

  data | pointer to array of double to be encoded (need memorycont. repr.)
  dataSize | number of doubles from *data to encode
  result | pointer to where resulting bytes should be stored
  fixedPoint | the scaling factor used for getting the fixed point repr. This is stored in the binary and automatically extracted on decoding.

Returns
  the number of encoded bytes

## ◆ encodeLinear() [2/2]

void ms::numpress::MSNumpress::encodeLinear | ( | const std::vector< double > & | data,
|  | std::vector< unsigned char > & | result,
|  | double | fixedPoint
| ) |  |

Calls lower level encodeLinear while handling vector sizes appropriately

Parameters

  data | vector of doubles to be encoded
  result | vector of resulting bytes (will be resized to the number of bytes)

## ◆ encodePic() [1/2]

size_t ms::numpress::MSNumpress::encodePic | ( | const double * | data,
|  | const size_t | dataSize,
|  | unsigned char * | result
| ) |  |

Encodes ion counts by simply rounding to the nearest 4 byte integer, and compressing each integer with encodeInt.

The handleable range is therefore 0 -> 4294967294. The resulting binary is maximally dataSize * 5 bytes, but much less if the data is close to 0 on average.

Parameters

  data | pointer to array of double to be encoded (need memorycont. repr.)
  dataSize | number of doubles from *data to encode
  result | pointer to where resulting bytes should be stored

Returns
  the number of encoded bytes

## ◆ encodePic() [2/2]

void ms::numpress::MSNumpress::encodePic | ( | const std::vector< double > & | data,
|  | std::vector< unsigned char > & | result
| ) |  |

Calls lower level encodePic while handling vector sizes appropriately

Parameters

  data | vector of doubles to be encoded
  result | vector of resulting bytes (will be resized to the number of bytes)

## ◆ encodeSafe()

size_t ms::numpress::MSNumpress::encodeSafe | ( | const double * | data,
|  | const size_t | dataSize,
|  | unsigned char * | result
| ) |  |

Encodes the doubles in data by storing the residuals from a linear prediction after first two values.

The resulting binary is the same size as the input data.

This encoding is suitable for typical m/z or retention time binary arrays, and is intended to be used before zlib compression to improve compression.

Parameters

  data | pointer to array of doubles to be encoded (need memorycont. repr.)
  dataSize | number of doubles from *data to encode
  result | pointer to were resulting bytes should be stored

## ◆ encodeSlof() [1/2]

size_t ms::numpress::MSNumpress::encodeSlof | ( | const double * | data,
|  | const size_t | dataSize,
|  | unsigned char * | result,
|  | double | fixedPoint
| ) |  |

Encodes ion counts by taking the natural logarithm, and storing a fixed point representation of this. This is calculated as

unsigned short fp = log(d + 1) * fixedPoint + 0.5

the result vector is exactly |data| * 2 + 8 bytes long

Parameters

  data | pointer to array of double to be encoded (need memorycont. repr.)
  dataSize | number of doubles from *data to encode
  result | pointer to were resulting bytes should be stored

Returns
  the number of encoded bytes

## ◆ encodeSlof() [2/2]

void ms::numpress::MSNumpress::encodeSlof | ( | const std::vector< double > & | data,
|  | std::vector< unsigned char > & | result,
|  | double | fixedPoint
| ) |  |

Calls lower level encodeSlof while handling vector sizes appropriately

Parameters

  data | vector of doubles to be encoded

Returns
  vector of resulting bytes (will be resized to the number of bytes)

## ◆ optimalLinearFixedPoint()

double ms::numpress::MSNumpress::optimalLinearFixedPoint | ( | const double * | data,
|  | size_t | dataSize
| ) |  |

Compute the maximal linear fixed point that prevents integer overflow.

Parameters

  data | pointer to array of double to be encoded (need memorycont. repr.)
  dataSize | number of doubles from *data to encode

Returns
  the linear fixed point safe to use

## ◆ optimalLinearFixedPointMass()

double ms::numpress::MSNumpress::optimalLinearFixedPointMass | ( | const double * | data,
|  | size_t | dataSize,
|  | double | mass_acc
| ) |  |

Compute the optimal linear fixed point with a desired m/z accuracy.

Note
  If the desired accuracy cannot be reached without overflowing 64 bit integers, then a negative value is returned. You need to check for this and in that case abandon numpress or use optimalLinearFixedPoint which returns the largest safe value.

Parameters

  data | pointer to array of double to be encoded (need memorycont. repr.)
  dataSize | number of doubles from *data to encode
  mass_acc | desired m/z accuracy in Th

Returns
  the linear fixed point that satisfies the accuracy requirement (or -1 in case of failure).

## ◆ optimalSlofFixedPoint()

double ms::numpress::MSNumpress::optimalSlofFixedPoint | ( | const double * | data,
|  | size_t | dataSize
| ) |  |