Created
February 5, 2019 00:01
-
-
Save jvansan/a2f627eb19435ba3986ac45751557b5f to your computer and use it in GitHub Desktop.
Convert to-from M/Z Peaks:Intensity for mzXML peak list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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