Skip to content

Commit

Permalink
Merge pull request #5 from hroest/tapir_branch
Browse files Browse the repository at this point in the history
Tapir branch
  • Loading branch information
hroest authored Mar 29, 2019
2 parents 95e4753 + 08676bc commit f236fdf
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pymzml/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@
import pymzml.spec
import pymzml.obo
import pymzml.minimum
import pymzml.plot
# import pymzml.plot
7 changes: 4 additions & 3 deletions pymzml/obo.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
from __future__ import print_function
import sys
import os

import codecs

class oboTranslator(object):
def __init__(self, version=None):
Expand Down Expand Up @@ -138,7 +138,8 @@ def parseOBO(self):

# Modify the root for cx_freeze
if getattr(sys, 'frozen', False):
obo_root = os.path.dirname(sys.executable)
# obo_root = os.path.dirname(sys._MEIPASS)
obo_root = os.path.dirname(__file__)
else:
obo_root = os.path.dirname(__file__)

Expand All @@ -149,7 +150,7 @@ def parseOBO(self):
)

if os.path.exists(obo_file):
with open(obo_file) as obo:
with codecs.open( obo_file, 'r', encoding = 'utf-8' ) as obo:
collections = {}
collect = False
for line in obo:
Expand Down
7 changes: 7 additions & 0 deletions pymzml/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,13 @@ def __getitem__(self, value):
if len(self.info['offsets']) == 0:
raise IOError("File does support random access: index list missing...")

# Check for conversion of str/int issues
if not value in self.info['offsets']:
try:
value = int(value)
except Exception:
pass

if value in self.info['offsets']:
startPos = self.info['offsets'][value]
endPos_index = bisect.bisect_right(
Expand Down
34 changes: 33 additions & 1 deletion pymzml/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -829,13 +829,25 @@ def _decodeNumpress(self, inData, compression):
coder = pyopenms.MSNumpressCoder()
np_config = pyopenms.NumpressConfig()
np_config.estimate_fixed_point = True
zlib_compression = False
if compression == 'ms-np-linear':
np_config.np_compression = pyopenms.MSNumpressCoder.NumpressCompression.LINEAR
elif compression == 'ms-np-pic':
np_config.np_compression = pyopenms.MSNumpressCoder.NumpressCompression.PIC
elif compression == 'ms-np-slof':
np_config.np_compression = pyopenms.MSNumpressCoder.NumpressCompression.SLOF
coder.decodeNP(inData, result, False, np_config)
elif compression == 'zlib-ms-np-linear':
np_config.np_compression = pyopenms.MSNumpressCoder.NumpressCompression.LINEAR
zlib_compression = True
elif compression == 'zlib-ms-np-pic':
np_config.np_compression = pyopenms.MSNumpressCoder.NumpressCompression.PIC
zlib_compression = True
elif compression == 'zlib-ms-np-slof':
np_config.np_compression = pyopenms.MSNumpressCoder.NumpressCompression.SLOF
zlib_compression = True

coder.decodeNP(inData, result, zlib_compression, np_config)

return result

def _decode(self):
Expand Down Expand Up @@ -885,6 +897,8 @@ def _decode(self):
decodedData = zlib.decompress(decodedData)
elif compression in ['ms-np-linear', 'ms-np-pic', 'ms-np-slof']:
unpackedData = self._decodeNumpress(base64Data, compression)
elif compression in ['zlib-ms-np-linear', 'zlib-ms-np-pic', 'zlib-ms-np-slof']:
unpackedData = self._decodeNumpress(base64Data, compression)
elif compression == 'no':
pass
else:
Expand Down Expand Up @@ -1448,6 +1462,15 @@ def readAccession(self, parElement):
accession = element.get('accession')
self.ms[accession] = element
if element.tag.endswith('cvParam'):

# Combination of zlib + msnumpress
if accession == "MS:1002746":
self['BinaryArrayOrder'].append(('compression', 'zlib-ms-np-linear'))
elif accession == "MS:1002747":
self['BinaryArrayOrder'].append(('compression', 'zlib-ms-np-pic'))
elif accession == "MS:1002748":
self['BinaryArrayOrder'].append(('compression', 'zlib-ms-np-slof'))

if accession in self.param['accessions']:
for mzmlTag in self.param['accessions'][accession]['valuesToExtract']:
try:
Expand Down Expand Up @@ -1493,6 +1516,15 @@ def readAccession(self, parElement):
elif self.param['accessions'][accession]['name'] == 'MS-Numpress short logged float compression':
self['BinaryArrayOrder'].append(('compression', 'ms-np-slof'))

elif self.param['accessions'][accession]['name'] == 'MS-Numpress linear prediction compression followed by zlib compression':
self['BinaryArrayOrder'].append(('compression', 'zlib-ms-np-linear'))

elif self.param['accessions'][accession]['name'] == 'MS-Numpress positive integer compression followed by zlib compression':
self['BinaryArrayOrder'].append(('compression', 'zlib-ms-np-pic'))

elif self.param['accessions'][accession]['name'] == 'MS-Numpress short logged float compression followed by zlib compression':
self['BinaryArrayOrder'].append(('compression', 'zlib-ms-np-slof'))

elif element.tag.endswith('precursorList'):
# TODO remove this completely?
self['precursors'] = []
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
nose
plotly
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from distutils.core import setup
setup(name='pymzml',
version='0.8.0',
version='0.8.1',
packages = ['pymzml'],
package_dir = {'pymzml': 'pymzml'},
package_data={'pymzml': ['obo/*.obo']},
Expand Down

0 comments on commit f236fdf

Please sign in to comment.