Skip to content

Commit

Permalink
Release v1.2.0 (#18)
Browse files Browse the repository at this point in the history
* Add "positive" flag for correlation analysis and update pandas data fra… (#15)

* Add check box to GUI for "filtering" positive correlations

* Update CLI for neutral losses

* Update GitHub actions and configs (#17)

* Update README.rst (Minor)

---------

Co-authored-by: Wanchang Lin <wanchang_lin@outlook.com>
  • Loading branch information
RJMW and wanchanglin committed May 12, 2023
1 parent d87c1d5 commit 66c74c1
Show file tree
Hide file tree
Showing 27 changed files with 1,890 additions and 926 deletions.
13 changes: 7 additions & 6 deletions .github/workflows/build-test.yml
Expand Up @@ -9,7 +9,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: [3.7, 3.8]
python-version: ['3.8', '3.9', '3.10']

env:
OS: ${{ matrix.os }}
Expand All @@ -29,7 +29,7 @@ jobs:
run: |
python --version
conda env update --file environment.yml --name base
conda env update --file environment.yml --name __setup_conda
- name: Lint with flake8
run: |
Expand All @@ -44,15 +44,16 @@ jobs:
- name: Test with pytest-cov
run: |
python setup.py install
beamspy --help
conda install pytest codecov pytest-cov -c conda-forge
python -m pip install --no-deps -e .
beamspy --help
pytest --cov ./ --cov-config=.coveragerc --cov-report=xml
- name: Upload code coverage to codecov
uses: codecov/codecov-action@v1
if: matrix.os == 'ubuntu-latest'
with:
flags: unittests
env_vars: OS,PYTHON
Expand Down
27 changes: 0 additions & 27 deletions .travis.yml

This file was deleted.

5 changes: 1 addition & 4 deletions README.rst
@@ -1,6 +1,6 @@
BEAMSpy - Birmingham mEtabolite Annotation for Mass Spectrometry (Python package)
==================================================================================
|Version| |Py versions| |Git| |Bioconda| |Build Status| |Build Status (AppVeyor)| |License| |RTD doc| |codecov| |mybinder|
|Version| |Py versions| |Git| |Bioconda| |Build Status| |License| |RTD doc| |codecov| |mybinder|

BEAMSpy (Birmingham mEtabolite Annotation for Mass Spectrometry) is a Python package that includes several automated and
seamless computational modules that are applied to putatively annotate metabolites detected in untargeted ultra (high)
Expand Down Expand Up @@ -82,9 +82,6 @@ Released under the GNU General Public License v3.0 (see `LICENSE <https://github
.. |Build Status| image:: https://github.com/computational-metabolomics/beamspy/workflows/beamspy/badge.svg
:target: https://github.com/computational-metabolomics/beamspy/actions

.. |Build Status (AppVeyor)| image:: https://img.shields.io/appveyor/ci/RJMW/beamspy.svg?style=flat&maxAge=3600&label=AppVeyor
:target: https://ci.appveyor.com/project/RJMW/beamspy

.. |Py versions| image:: https://img.shields.io/pypi/pyversions/beamspy.svg?style=flat&maxAge=3600
:target: https://pypi.python.org/pypi/beamspy/

Expand Down
12 changes: 0 additions & 12 deletions appveyor.yml

This file was deleted.

4 changes: 2 additions & 2 deletions beamspy/__init__.py
@@ -1,4 +1,4 @@
__author__ = 'r.j.weber@bham.ac.uk'
__credits__ = 'r.j.weber@bham.ac.uk'
__version__ = '1.1.0'
__license__ = 'GPLv3'
__version__ = '1.2.0'
__license__ = 'GPLv3'
7 changes: 5 additions & 2 deletions beamspy/__main__.py
Expand Up @@ -71,6 +71,9 @@ def main():
parser_gf.add_argument('-p', '--pvalue-threshold', default=0.01, type=float, required=True,
help="Threshold for p-value.")

parser_gf.add_argument('-o', '--positive', action="store_true",
help="Use positive correlation only otherwise use both positive and negative correlation.")

parser_gf.add_argument('-g', '--gml-file', type=str, required=True,
help="Write graph to GraphML format.")

Expand Down Expand Up @@ -237,7 +240,7 @@ def main():
df = in_out.combine_peaklist_matrix(args.peaklist, args.intensity_matrix)
graph = grouping.group_features(df, db_out=args.db, max_rt_diff=args.max_rt_diff,
coeff_thres=args.coeff_threshold, pvalue_thres=args.pvalue_threshold,
method=args.method, ncpus=args.ncpus)
method=args.method, positive=args.positive, ncpus=args.ncpus)
nx.write_gml(graph, str(args.gml_file))

if args.step == "annotate-peak-patterns":
Expand Down Expand Up @@ -274,7 +277,7 @@ def main():
path = 'data/neutral_losses.txt'
p = os.path.join(os.path.dirname(os.path.abspath(__file__)), path)
lib = in_out.read_neutral_losses(p)
annotation.neutral_losses(inp, db_out=args.db, ppm=args.ppm, lib=lib)
annotation.annotate_neutral_losses(inp, db_out=args.db, ppm=args.ppm, lib=lib)

if args.oligomers:
if args.adducts_library:
Expand Down
3 changes: 2 additions & 1 deletion beamspy/annotation.py
Expand Up @@ -1615,7 +1615,8 @@ def summary(df, db, single_row=False, single_column=False, convert_rt=None, ndig

records = [(str(record[0]), str(record[1])) for record in cursor.fetchall()]

G = nx.OrderedDiGraph()
# G = nx.OrderedDiGraph() # networkx version < 3.0
G = nx.DiGraph()
G.add_edges_from(records)

graphs = list(G.subgraph(c) for c in nx.weakly_connected_components(G))
Expand Down
10 changes: 9 additions & 1 deletion beamspy/data/adducts.txt
@@ -1 +1,9 @@
label exact_mass charge ion_mode[M+H]+ 1.007276 1 pos[M+Na]+ 22.989221 1 pos[M+K]+ 38.963158 1 pos[M-H]- -1.007276 1 neg[M+Cl]- 34.969401 1 neg[M+Na-2H]- 20.974668 1 neg[M+K-2H]- 36.948605 1 neg[M+Hac-H]- 59.013853 1 neg
label exact_mass charge ion_mode
[M+H]+ 1.007276 1 pos
[M+Na]+ 22.989221 1 pos
[M+K]+ 38.963158 1 pos
[M-H]- -1.007276 1 neg
[M+Cl]- 34.969401 1 neg
[M+Na-2H]- 20.974668 1 neg
[M+K-2H]- 36.948605 1 neg
[M+Hac-H]- 59.013853 1 neg
7 changes: 6 additions & 1 deletion beamspy/data/isotopes.txt
@@ -1 +1,6 @@
label_x label_y mass_difference abundance_x abundance_y ion_mode chargeC (13C) 1.003355 98.93 1.07 both 1C (13C) 0.5016775 98.93 1.07 both 2S (34S) 1.995796 94.99 4.25 both 1K (41K) 1.998119 93.25 6.73 pos 1Cl (37Cl) 1.99705 75.76 24.24 neg 1
label_x label_y mass_difference abundance_x abundance_y ion_mode charge
C (13C) 1.003355 98.93 1.07 both 1
C (13C) 0.5016775 98.93 1.07 both 2
S (34S) 1.995796 94.99 4.25 both 1
K (41K) 1.998119 93.25 6.73 pos 1
Cl (37Cl) 1.99705 75.76 24.24 neg 1
6 changes: 5 additions & 1 deletion beamspy/data/multiple_charged_ions.txt
@@ -1 +1,5 @@
label exact_mass charge ion_mode[M+H]+ 1.007276 1 pos[M+Na]+ 22.989221 1 pos[M+2H]2+ 1.007276 2 pos[M+H+Na]2+ 11.9982485 2 pos
label exact_mass charge ion_mode
[M+H]+ 1.007276 1 pos
[M+Na]+ 22.989221 1 pos
[M+2H]2+ 1.007276 2 pos
[M+H+Na]2+ 11.9982485 2 pos
4 changes: 3 additions & 1 deletion beamspy/data/neutral_losses.txt
@@ -1 +1,3 @@
label mass_differenceH2O 18.010565CO 27.994915
label mass_difference
H2O 18.010565
CO 27.994915
4 changes: 2 additions & 2 deletions beamspy/grouping.py
Expand Up @@ -6,7 +6,7 @@
import networkx as nx


def group_features(df, db_out, max_rt_diff=5.0, coeff_thres=0.7, pvalue_thres=1.0, method="pearson", block=5000, ncpus=None):
def group_features(df, db_out, max_rt_diff=5.0, coeff_thres=0.7, pvalue_thres=1.0, method="pearson", positive=True, block=5000, ncpus=None):

conn = sqlite3.connect(db_out)
cursor = conn.cursor()
Expand All @@ -25,7 +25,7 @@ def group_features(df, db_out, max_rt_diff=5.0, coeff_thres=0.7, pvalue_thres=1.
mz_diff REAL DEFAULT NULL,
PRIMARY KEY (peak_id_a, peak_id_b));""")

df_coeffs = statistics.correlation_coefficients(df, max_rt_diff, coeff_thres, pvalue_thres, method, block, ncpus)
df_coeffs = statistics.correlation_coefficients(df, max_rt_diff, coeff_thres, pvalue_thres, method, positive, block, ncpus)
graph = statistics.correlation_graphs(df_coeffs, df)
sub_graphs = list(graph.subgraph(c) for c in nx.weakly_connected_components(graph))
for i in range(len(sub_graphs)):
Expand Down
3 changes: 3 additions & 0 deletions beamspy/gui.py
Expand Up @@ -188,6 +188,7 @@ def group_features(self):
self.label_grouping_ncpus.setEnabled(False)
self.doubleSpinBox_ncpus.setEnabled(False)
self.doubleSpinBox_block.setEnabled(False)
self.checkBox_positive_correlation.setEnabled(True)
else:
self.label_max_rt.setEnabled(True)
self.doubleSpinBox_max_rt.setEnabled(True)
Expand All @@ -201,6 +202,7 @@ def group_features(self):
self.label_grouping_ncpus.setEnabled(True)
self.doubleSpinBox_ncpus.setEnabled(True)
self.doubleSpinBox_block.setEnabled(True)
self.checkBox_positive_correlation.setEnabled(True)
self.source_graph_file()

def annotate_peak_patterns(self):
Expand Down Expand Up @@ -355,6 +357,7 @@ def run(self):
coeff_thres=self.doubleSpinBox_coefficent.value(),
pvalue_thres=self.doubleSpinBox_p_value.value(),
method=method,
positive=self.checkBox_positive_correlation.isChecked(),
block=int(self.doubleSpinBox_block.value()),
ncpus=int(self.doubleSpinBox_ncpus.value()))
nx.write_gml(graph, str(self.lineEdit_graph.text()))
Expand Down
4 changes: 2 additions & 2 deletions beamspy/in_out.py
Expand Up @@ -189,9 +189,9 @@ def combine_peaklist_matrix(fn_peaklist, fn_matrix, separator="\t", median_inten

if mapping["intensity"] not in df_peaklist.columns:
if median_intensity:
df_peaklist["intensity"] = pd.Series(df_matrix.median(axis=1, skipna=True), index=df_matrix.index)
df_peaklist["intensity"] = pd.Series(df_matrix.median(axis=1, skipna=True, numeric_only=True), index=df_matrix.index)
else:
df_peaklist["intensity"] = pd.Series(df_matrix.mean(axis=1, skipna=True), index=df_matrix.index)
df_peaklist["intensity"] = pd.Series(df_matrix.mean(axis=1, skipna=True, numeric_only=True), index=df_matrix.index)

if len(df_peaklist[mapping["name"]].unique()) != len(df_peaklist[mapping["name"]]):
raise ValueError("Peaklist: Values column '{}' are not unique".format(mapping["name"]))
Expand Down

0 comments on commit 66c74c1

Please sign in to comment.