public class MSNumpress extends Object
Modifier and Type | Field and Description |
---|---|
static String |
ACC_NUMPRESS_LINEAR |
static String |
ACC_NUMPRESS_PIC |
static String |
ACC_NUMPRESS_SLOF |
Constructor and Description |
---|
MSNumpress() |
Modifier and Type | Method and Description |
---|---|
static double[] |
decode(String cvAccession,
byte[] data,
int dataSize)
Convenience function for decoding binary data encoded by MSNumpress.
|
static double |
decodeFixedPoint(byte[] data) |
static int |
decodeLinear(byte[] data,
int dataSize,
double[] result)
Decodes data encoded by encodeLinear.
|
static int |
decodePic(byte[] data,
int dataSize,
double[] result)
Decodes data encoded by encodePic
|
static int |
decodeSlof(byte[] data,
int dataSize,
double[] result)
Decodes data encoded by encodeSlof
|
static void |
encodeFixedPoint(double fixedPoint,
byte[] result) |
protected static int |
encodeInt(long x,
byte[] res,
int resOffset)
This encoding works on a 4 byte integer, by truncating initial zeros or ones.
|
static int |
encodeLinear(double[] data,
int dataSize,
byte[] result,
double fixedPoint)
Encodes the doubles in data by first using a - lossy conversion to a 4 byte 5 decimal fixed
point repressentation - storing the residuals from a linear prediction after first to values -
encoding by encodeInt (see above)
|
static int |
encodePic(double[] data,
int dataSize,
byte[] result)
Encodes ion counts by simply rounding to the nearest 4 byte integer, and compressing each
integer with encodeInt.
|
static int |
encodeSlof(double[] data,
int dataSize,
byte[] result,
double fixedPoint)
Encodes ion counts by taking the natural logarithm, and storing a fixed point representation of
this.
|
static double |
optimalLinearFixedPoint(double[] data,
int dataSize) |
static double |
optimalSlofFixedPoint(double[] data,
int dataSize) |
public static final String ACC_NUMPRESS_LINEAR
public static final String ACC_NUMPRESS_PIC
public static final String ACC_NUMPRESS_SLOF
public static double[] decode(String cvAccession, byte[] data, int dataSize)
ACC_NUMPRESS_LINEAR = "MS:1002312" ACC_NUMPRESS_PIC = "MS:1002313" ACC_NUMPRESS_SLOF = "MS:1002314"
the corresponding decode function will be called.
cvAccession
- The PSI-MS obo CV accession of the encoded data.data
- array of double to be encodeddataSize
- number of doubles from data to encodeprotected static int encodeInt(long x, byte[] res, int resOffset)
0 <= c <= 8 is interpreted as an initial c 0x0 halfbytes 9 <= c <= 15 is interpreted as an initial (c-8) 0xf halfbytes
Ex: int c rest 0 => 0x8 -1 => 0xf 0xf 23 => 0x6 0x7 0x1
x
- the int to be encodedres
- the byte array were halfbytes are storedresOffset
- position in res were halfbytes are writtenpublic static void encodeFixedPoint(double fixedPoint, byte[] result)
public static double decodeFixedPoint(byte[] data)
public static double optimalLinearFixedPoint(double[] data, int dataSize)
public static int encodeLinear(double[] data, int dataSize, byte[] result, double fixedPoint)
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.
data
- array of doubles to be encodeddataSize
- number of doubles from data to encoderesult
- array were resulting bytes should be storedfixedPoint
- the scaling factor used for getting the fixed point repr. This is stored in
the binary and automatically extracted on decoding.public static int decodeLinear(byte[] data, int dataSize, double[] result)
result vector guaranteed to be shorter or equal to (|data| - 8) * 2
Note that this method may throw a ArrayIndexOutOfBoundsException 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.
data
- array of bytes to be decodeddataSize
- number of bytes from data to decoderesult
- array were resulting doubles should be storedpublic static int encodePic(double[] data, int dataSize, byte[] result)
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.
data
- array of doubles to be encodeddataSize
- number of doubles from data to encoderesult
- array were resulting bytes should be storedpublic static int decodePic(byte[] data, int dataSize, double[] result)
result vector guaranteed to be shorter of equal to |data| * 2
Note that this method may throw a ArrayIndexOutOfBoundsException 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.
data
- array of bytes to be decoded (need memorycont. repr.)dataSize
- number of bytes from data to decoderesult
- array were resulting doubles should be storedpublic static double optimalSlofFixedPoint(double[] data, int dataSize)
public static int encodeSlof(double[] data, int dataSize, byte[] result, double fixedPoint)
unsigned short fp = log(d+1) * fixedPoint + 0.5
the result vector is exactly |data| * 2 + 8 bytes long
data
- array of doubles to be encodeddataSize
- number of doubles from data to encoderesult
- array were resulting bytes should be storedfixedPoint
- the scaling factor used for getting the fixed point repr. This is stored in
the binary and automatically extracted on decoding.public static int decodeSlof(byte[] data, int dataSize, double[] result)
The result vector will be exactly (|data| - 8) / 2 doubles. returns the number of doubles read, or -1 is there is a problem decoding.
data
- array of bytes to be decoded (need memorycont. repr.)dataSize
- number of bytes from data to decoderesult
- array were resulting doubles should be storedCopyright © 2021. All rights reserved.