Skip to content

Instantly share code, notes, and snippets.

@jvansan
Created February 5, 2019 00:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jvansan/a2f627eb19435ba3986ac45751557b5f to your computer and use it in GitHub Desktop.
Save jvansan/a2f627eb19435ba3986ac45751557b5f to your computer and use it in GitHub Desktop.
Convert to-from M/Z Peaks:Intensity for mzXML peak list
import numpy as np
import base64, zlib
arrStr = """
203.0530 8901
365.1051 24050
366.1083 2312
"""
dt = np.dtype('>f8')
# For encoding
arr = np.array(arrStr.split())
dim = int(arr.shape[0]/2)
arr = arr.astype(dt).reshape(dim, 2)
content = base64.b64encode(zlib.compress(arr))
# For decoding
arr_decode = np.frombuffer(zlib.decompress(base64.b64decode(content)), dtype=dt)
dim_decode = int(arr_decode.shape[0]/2)
arr_decode = arr_decode.reshape(dim_decode, 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment