Skip to content

Commit fe5cf6c

Browse files
authored
Merge pull request #39 from computational-metabolomics/dev
Add a number of bug fixes and improvements
2 parents 5f7d6ff + e453c90 commit fe5cf6c

File tree

7 files changed

+40
-16
lines changed

7 files changed

+40
-16
lines changed

.travis.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
language: python
22
python:
33
- "2.7"
4+
45
install:
56
- sudo apt-get update
67
- if [[ "$TRAVIS_PYTHON_VERSION" == "2.7" ]]; then
@@ -15,9 +16,13 @@ install:
1516
- conda update -q conda
1617
- conda info -a
1718

18-
- conda create -q -n test-environment python=$TRAVIS_PYTHON_VERSION numpy=1.13.0 scipy=0.19.1 pymzml=0.7.8 pythonnet=2.3.0 h5py=2.7.0 fastcluster=1.1.23 -c conda-forge -c bioconda
19+
- conda create -q -n test-environment python=$TRAVIS_PYTHON_VERSION numpy=1.13.0 scipy=1.0 pymzml=0.7.10 pythonnet=2.3.0 h5py=2.7.0 fastcluster=1.1.23 coverage green codecov -c conda-forge -c bioconda
1920
- source activate test-environment
2021
- python setup.py install
2122

2223
script:
24+
- dimspy --help
2325
- python setup.py test
26+
27+
after_script:
28+
- python -m codecov

README.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
DIMSpy
22
======
3-
|Version| |Py versions| |Git| |Bioconda| |Build Status (Travis)| |Build Status (AppVeyor)| |License| |RTD doc|
3+
|Version| |Py versions| |Git| |Bioconda| |Build Status (Travis)| |Build Status (AppVeyor)| |License| |RTD doc| |codecov|
44

55
Python package to process direct-infusion mass spectrometry-based metabolomics and lipidomics data
66

@@ -64,3 +64,6 @@ Released under the GNU General Public License v3.0 (see `LICENSE file <https://g
6464

6565
.. |RTD doc| image:: https://img.shields.io/badge/documentation-RTD-71B360.svg?style=flat&maxAge=3600
6666
:target: https://computational-metabolomics.github.io/dimspy/
67+
68+
.. |codecov| image:: https://codecov.io/gh/computational-metabolomics/dimspy/branch/master/graph/badge.svg
69+
:target: https://codecov.io/gh/computational-metabolomics/dimspy

dimspy/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import h5py
77
import tools
88
from portals import hdf5_portal
9-
from . import __version__
9+
from dimspy import __version__
1010

1111

1212
def map_delimiter(delimiter):

dimspy/models/peaklist.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ def __len__(self):
9999
def __str__(self):
100100
return self.to_str(', ')
101101

102+
def __repr__(self):
103+
return self.to_str('\t')
104+
102105
def __getitem__(self, item):
103106
if type(item) in (int, slice, list, np.ndarray):
104107
return self.get_peak(item)
@@ -348,7 +351,7 @@ def add_attribute(self, attr_name, attr_value, attr_dtype=None, is_flag=False,
348351
attr_name = str(attr_name) # rfn.append_fields doesn't recognise unicode
349352

350353
adt = bool if is_flag else \
351-
attr_dtype if attr_dtype is not None else \
354+
attr_dtype if attr_dtype not in (None, str, unicode) else \
352355
attr_value.dtype.str if hasattr(attr_value, 'dtype') else \
353356
('S%d' % max(map(len, attr_value))) if type(attr_value[0]) in (unicode, str) else \
354357
type(attr_value[0])

dimspy/portals/thermo_raw_portal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def peaklist(self, scan_id, function_noise="noise_packets"):
6161
else:
6262
mzs, ints, baseline, noise = [], [], [], []
6363

64-
if function_noise == "noise_packets":
64+
if function_noise == "noise_packets" and len(ints) > 0:
6565
snr = [p.SignalToNoise for p in scan.GetCentroids()]
6666
elif function_noise == "median" and len(ints) > 0:
6767
snr = ints / np.median(ints)

dimspy/process/peak_alignment.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,34 @@ def _cluster_peaks(mzs, ppm, distype='euclidean', linkmode='centroid'):
3131
if len(mzs) == 1:
3232
return np.zeros_like(mzs, dtype=int).reshape((-1, 1))
3333

34+
outer_mzs = np.add.outer(mzs, mzs)
35+
np.fill_diagonal(outer_mzs, 0)
36+
37+
# avg_mz_pair = np.divide(outer_mzs, 2)
38+
outer_mzs /= 2 # inplace operation to reduce memory usage
39+
40+
# mdist_mz_pair = squareform(avg_mz_pair)
41+
mdist_mz_pair = squareform(outer_mzs)
42+
del outer_mzs # reduce memory use
43+
3444
m = np.column_stack([mzs])
3545
mdist = fc.pdist(m, metric=distype)
46+
del m
3647

37-
outer_mzs = np.add.outer(mzs, mzs)
38-
np.fill_diagonal(outer_mzs, 0)
39-
avg_mz_pair = np.divide(outer_mzs, 2)
40-
mdist_mz_pair = squareform(avg_mz_pair)
41-
relative_errors = np.multiply(mdist_mz_pair, 1e-6)
48+
# relative_errors = np.multiply(mdist_mz_pair, 1e-6)
49+
mdist_mz_pair *= 1e-6 # inplace operation to reduce memory usage
4250

4351
with np.errstate(divide='ignore', invalid='ignore'): # using errstate context to avoid seterr side effects
44-
m_mass_tol = np.divide(mdist, relative_errors)
45-
m_mass_tol[np.isnan(m_mass_tol)] = 0.0
46-
z = fc.linkage(m_mass_tol, method=linkmode)
52+
# m_mass_tol = np.divide(mdist, relative_errors)
53+
mdist /= mdist_mz_pair # inplace operation to reduce memory usage
54+
# m_mass_tol[np.isnan(m_mass_tol)] = 0.0
55+
mdist[np.isnan(mdist)] = 0.0
56+
57+
# z = fc.linkage(m_mass_tol, method=linkmode)
58+
z = fc.linkage(mdist, method=linkmode)
59+
del mdist, mdist_mz_pair
4760

48-
# cut tree at ppm threshold & order matches the order of mzs
61+
# cut tree at ppm threshold
4962
return cluster.hierarchy.cut_tree(z, height=ppm)
5063

5164

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ numpy==1.13.3
22
scipy==1.0.0
33
fastcluster==1.1.23
44
plotly==2.5.1
5-
pymzml==0.7.8
5+
pymzml==0.7.10
66
h5py==2.7.0
7-
pythonnet==2.3.0
7+
pythonnet>=2.3.0

0 commit comments

Comments
 (0)