Skip to content

Commit

Permalink
Merge pull request #65 from wilhelm-lab/release/0.4.1
Browse files Browse the repository at this point in the history
Release/0.4.1
  • Loading branch information
picciama authored Aug 3, 2023
2 parents a0a8d21 + 7a42c1c commit 8a7a9ca
Show file tree
Hide file tree
Showing 13 changed files with 959 additions and 800 deletions.
2 changes: 1 addition & 1 deletion .cookietemple.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ full_name: Victor Giurcoiu
email: [email protected]
project_name: spectrum_fundamentals
project_short_description: Fundamentals public repo
version: 0.4.0
version: 0.4.1
license: MIT
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[flake8]
select = B,B9,C,D,DAR,E,F,N,RST,S,W
ignore = E203,E501,RST201,RST203,RST301,W503,D100,D212,S101,E731,S404,S603,S607
ignore = E203,E501,RST201,RST203,RST301,W503,D100,D212,S101,E731,S404,S603,S607,B905
max-line-length = 120
max-complexity = 10
docstring-convention = google
Expand Down
4 changes: 2 additions & 2 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name-template: "0.4.0 🌈" # <<COOKIETEMPLE_FORCE_BUMP>>
tag-template: 0.4.0 # <<COOKIETEMPLE_FORCE_BUMP>>
name-template: "0.4.1 🌈" # <<COOKIETEMPLE_FORCE_BUMP>>
tag-template: 0.4.1 # <<COOKIETEMPLE_FORCE_BUMP>>
exclude-labels:
- "skip-changelog"

Expand Down
2 changes: 1 addition & 1 deletion cookietemple.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.4.0
current_version = 0.4.1

[bumpversion_files_whitelisted]
init_file = spectrum_fundamentals/__init__.py
Expand Down
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@
# the built documents.
#
# The short X.Y version.
version = "0.4.0"
version = "0.4.1"
# The full version, including alpha/beta/rc tags.
release = "0.4.0"
release = "0.4.1"

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
1,681 changes: 920 additions & 761 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "spectrum_fundamentals"
version = "0.4.0" # <<COOKIETEMPLE_FORCE_BUMP>>
version = "0.4.1" # <<COOKIETEMPLE_FORCE_BUMP>>
description = "Fundamentals public repo"
authors = ["WassimG <[email protected]>"]
license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion spectrum_fundamentals/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Initialize fundamentals."""
__author__ = "Victor Giurcoiu"
__email__ = "[email protected]"
__version__ = "0.4.0"
__version__ = "0.4.1"

import logging
import logging.handlers
Expand Down
2 changes: 1 addition & 1 deletion spectrum_fundamentals/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


@click.command()
@click.version_option(version="0.4.0", message=click.style("spectrum_fundamentals Version: 0.4.0"))
@click.version_option(version="0.4.1", message=click.style("spectrum_fundamentals Version: 0.4.1"))
def main() -> None:
"""spectrum_fundamentals."""

Expand Down
5 changes: 3 additions & 2 deletions spectrum_fundamentals/annotation/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


def match_peaks(
fragments_meta_data: pd.DataFrame,
fragments_meta_data: List[dict],
peaks_intensity: np.ndarray,
peaks_masses: np.ndarray,
tmt_n_term: int,
Expand All @@ -37,7 +37,8 @@ def match_peaks(
next_start_peak = 0
seq_len = len(unmod_sequence)
matched_peak = False
for _, fragment in fragments_meta_data.iterrows():
fragment_no: float
for fragment in fragments_meta_data:
min_mass = fragment["min_mass"]
max_mass = fragment["max_mass"]
fragment_no = fragment["no"]
Expand Down
31 changes: 13 additions & 18 deletions spectrum_fundamentals/fragments.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import logging
from operator import itemgetter
from typing import Dict, List, Optional, Tuple

import numpy as np
import pandas as pd

from . import constants as constants

Expand Down Expand Up @@ -106,7 +106,7 @@ def compute_peptide_mass(sequence: str) -> float:
return forward_sum + ion_type_offsets[0] + ion_type_offsets[1]


def initialize_peaks(sequence: str, mass_analyzer: str, charge: int) -> Tuple[pd.DataFrame, int, str, float]:
def initialize_peaks(sequence: str, mass_analyzer: str, charge: int) -> Tuple[List[dict], int, str, float]:
"""
Generate theoretical peaks for a modified peptide sequence.
Expand All @@ -123,13 +123,9 @@ def initialize_peaks(sequence: str, mass_analyzer: str, charge: int) -> Tuple[pd
else:
modification_deltas, tmt_n_term, peptide_sequence = modifications

col_dtypes = {"ion_type": str, "no": int, "charge": float, "mass": float, "min_mass": float, "max_mass": float}
peptide_length = len(peptide_sequence)

if peptide_length > 30:
df_out = pd.DataFrame(columns=col_dtypes.keys())
df_out = df_out.astype(col_dtypes)
return df_out, -1, "", 0.0
return [{}], -1, "", 0.0

# initialize constants
if int(round(charge)) <= 3:
Expand Down Expand Up @@ -181,18 +177,17 @@ def initialize_peaks(sequence: str, mass_analyzer: str, charge: int) -> Tuple[pd
mass = (ion_type_masses[ion_type] + charge_delta) / charge
min_mass, max_mass = get_min_max_mass(mass_analyzer, mass)
fragments_meta_data.append(
[
ion_types[ion_type], # ion type
i + 1, # no
charge, # charge
mass, # mass
min_mass, # min mass
max_mass, # max mass
]
{
"ion_type": ion_types[ion_type], # ion type
"no": i + 1, # no
"charge": charge, # charge
"mass": mass, # mass
"min_mass": min_mass, # min mass
"max_mass": max_mass, # max mass
}
)
df_out = pd.DataFrame(data=fragments_meta_data, columns=col_dtypes.keys())
df_out.sort_values(by="mass", inplace=True)
return df_out, tmt_n_term, peptide_sequence, (forward_sum + ion_type_offsets[0] + ion_type_offsets[1])
fragments_meta_data = sorted(fragments_meta_data, key=itemgetter("mass"))
return fragments_meta_data, tmt_n_term, peptide_sequence, (forward_sum + ion_type_offsets[0] + ion_type_offsets[1])


def get_min_max_mass(mass_analyzer: str, mass: float) -> Tuple[float, float]:
Expand Down
14 changes: 7 additions & 7 deletions spectrum_fundamentals/metrics/similarity.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ def correlation(
:param method: either pearson or spearman
:return: calculated correlations
"""
observed_intensities = observed_intensities.toarray()
predicted_intensities = predicted_intensities.toarray()
obs_int_arr = observed_intensities.toarray()
pred_int_arr = predicted_intensities.toarray()

if charge != 0:
if charge == 1:
Expand All @@ -232,13 +232,13 @@ def correlation(
boolean_array = constants.Y_ION_MASK

boolean_array = scipy.sparse.csr_matrix(boolean_array)
observed_intensities = scipy.sparse.csr_matrix(observed_intensities)
predicted_intensities = scipy.sparse.csr_matrix(predicted_intensities)
observed_intensities = observed_intensities.multiply(boolean_array).toarray()
predicted_intensities = predicted_intensities.multiply(boolean_array).toarray()
obs_int_arr = scipy.sparse.csr_matrix(obs_int_arr)
pred_int_arr = scipy.sparse.csr_matrix(pred_int_arr)
obs_int_arr = obs_int_arr.multiply(boolean_array).toarray()
pred_int_arr = pred_int_arr.multiply(boolean_array).toarray()

pear_corr = []
for obs, pred in zip(observed_intensities, predicted_intensities):
for obs, pred in zip(obs_int_arr, pred_int_arr):
valid_ion_mask = pred > constants.EPSILON
obs = obs[valid_ion_mask]
pred = pred[valid_ion_mask]
Expand Down
8 changes: 6 additions & 2 deletions tests/unit_tests/test_charge.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ def test_indices_to_one_hot_with_list_and_class(self):

def test_indices_to_one_hot_with_wrong_input_type(self):
"""Test indices_to_one_hot correctly raises TypeError on wrong input type."""
labels = None
self.assertRaises(TypeError, charge.indices_to_one_hot, labels)
try:
labels = None
self.assertRaises(TypeError, charge.indices_to_one_hot, labels)
except Exception as e: # explicitly silence typeguard.TypeCheckError here without importing TypeGuard
if e.__class__.__name__ != "TypeCheckError":
raise

def test_indices_to_one_hot_with_incompatible_classes(self):
"""Test indices_to_one_hot correctly raises TypeError on wrong input type."""
Expand Down

0 comments on commit 8a7a9ca

Please sign in to comment.