Exemplo n.º 1
0
 private static void ZLib(Stream memoryStream, Peak2DArray peakArray)
 {
     using (var deflateStream = new DeflateStream(memoryStream, CompressionMode.Compress, true))
     {
         NoCompression(deflateStream, peakArray);
     }
 }
Exemplo n.º 2
0
 public void Decode(Peak2DArray peakArray, byte[] bytes)
 {
     using (var memoryStream = new MemoryStream(bytes))
     {
         Decode(memoryStream, peakArray);
     }
 }
Exemplo n.º 3
0
 private static void NoCompression(Stream memoryStream, Peak2DArray peakArray)
 {
     using (var writer = new BinaryWriter(memoryStream, Encoding.UTF8, true))
     {
         foreach (var pk in peakArray.Peaks)
         {
             WriteValue(writer, peakArray.IntensityDataType, pk.Intensity);
             WriteValue(writer, peakArray.MzDataType, pk.Mz);
             WriteValue(writer, peakArray.RtDataType, pk.Rt);
         }
     }
 }
Exemplo n.º 4
0
 private static void NoCompression(Stream stream, Peak2DArray peakArray)
 {
     using (var reader = new BinaryReader(stream, Encoding.UTF8, true))
     {
         for (int i = 0; i < peakArray.ArrayLength; i++)
         {
             double intensity = ReadValue(reader, peakArray.IntensityDataType);
             double mz        = ReadValue(reader, peakArray.MzDataType);
             double rt        = ReadValue(reader, peakArray.RtDataType);
             peakArray.Peaks[i] = new Peak2D(intensity, mz, rt);
         }
     }
 }
Exemplo n.º 5
0
        public void Decode(Stream stream, Peak2DArray peakArray)
        {
            switch (peakArray.CompressionType)
            {
            case BinaryDataCompressionType.NoCompression:
                NoCompression(stream, peakArray);
                break;

            case BinaryDataCompressionType.ZLib:
                ZLib(stream, peakArray);
                break;

            default:
                throw new NotSupportedException("Compression type not supported: " + peakArray.CompressionType.ToString());
            }
        }
Exemplo n.º 6
0
        private static void NoCompression(Stream stream, Peak2DArray peakArray)
        {
            using (var reader = new BinaryReader(stream, Encoding.UTF8, true))
            {
                int      len   = reader.ReadInt32();
                Peak2D[] peaks = new Peak2D[len];

                for (int i = 0; i < len; i++)
                {
                    double intensity = ReadValue(reader, peakArray.IntensityDataType);
                    double mz        = ReadValue(reader, peakArray.MzDataType);
                    double rt        = ReadValue(reader, peakArray.RtDataType);
                    peaks[i] = new Peak2D(intensity, mz, rt);
                }

                peakArray.Peaks = peaks.ToMzLiteArray();
            }
        }
Exemplo n.º 7
0
        public byte[] Encode(Peak2DArray peakArray)
        {
            memoryStream.Position = 0;
            switch (peakArray.CompressionType)
            {
            case BinaryDataCompressionType.NoCompression:
                NoCompression(memoryStream, peakArray);
                break;

            case BinaryDataCompressionType.ZLib:
                ZLib(memoryStream, peakArray);
                break;

            default:
                throw new NotSupportedException("Compression type not supported: " + peakArray.CompressionType.ToString());
            }
            memoryStream.Position = 0;
            return(memoryStream.ToArray());
        }