Skip to content

Commit

Permalink
Merge pull request #73 from compomics/bug-fix
Browse files Browse the repository at this point in the history
Bug fixes
  • Loading branch information
RalfG authored Mar 27, 2024
2 parents 9f33fc8 + 8c5eef8 commit 3f32f24
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 13 deletions.
27 changes: 27 additions & 0 deletions psm_utils/io/_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import sys
import csv


def set_csv_field_size_limit():
"""
Sets the maximum field size limit for reading CSV files.
This function sets the maximum field size limit for reading CSV files using the `csv` module.
It attempts to set the limit to the maximum integer value (`sys.maxsize`), and if an `OverflowError`
occurs, it reduces the limit by dividing it by 10 until it can be set successfully.
Note:
This function should be called before reading any CSV files to ensure that the field size limit
is properly set.
"""
maxInt = sys.maxsize

while maxInt > 1:
print(maxInt)
try:
csv.field_size_limit(maxInt)
break
except OverflowError:
maxInt = int(maxInt / 10)
13 changes: 8 additions & 5 deletions psm_utils/io/ionbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
from psm_utils.peptidoform import Peptidoform
from psm_utils.psm import PSM
from psm_utils.psm_list import PSMList
from psm_utils.io._utils import set_csv_field_size_limit

set_csv_field_size_limit()

REQUIRED_COLUMNS = [
"database_peptide",
Expand Down Expand Up @@ -89,11 +92,11 @@ def _get_peptide_spectrum_match(self, psm_dict: Dict[str, str | float]) -> PSM:
),
spectrum_id=psm_dict["spectrum_title"],
run=psm_dict["spectrum_file"],
is_decoy=True
if psm_dict["database"] == "D"
else False
if psm_dict["database"] == "T"
else None,
is_decoy=(
True
if psm_dict["database"] == "D"
else False if psm_dict["database"] == "T" else None
),
score=float(psm_dict["psm_score"]),
precursor_mz=float(psm_dict["m/z"]),
retention_time=float(psm_dict["observed_retention_time"]),
Expand Down
3 changes: 3 additions & 0 deletions psm_utils/io/maxquant.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
from psm_utils.io._base_classes import ReaderBase
from psm_utils.peptidoform import Peptidoform
from psm_utils.psm import PSM
from psm_utils.io._utils import set_csv_field_size_limit

set_csv_field_size_limit()

logger = logging.getLogger(__name__)

Expand Down
3 changes: 3 additions & 0 deletions psm_utils/io/msamanda.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
from psm_utils.exceptions import PSMUtilsException
from psm_utils.io._base_classes import ReaderBase
from psm_utils.psm import PSM, Peptidoform
from psm_utils.io._utils import set_csv_field_size_limit

set_csv_field_size_limit()

logger = logging.getLogger(__name__)

Expand Down
3 changes: 3 additions & 0 deletions psm_utils/io/peptide_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@
from psm_utils.peptidoform import Peptidoform
from psm_utils.psm import PSM
from psm_utils.psm_list import PSMList
from psm_utils.io._utils import set_csv_field_size_limit

set_csv_field_size_limit()


class _PeptideRecord:
Expand Down
3 changes: 3 additions & 0 deletions psm_utils/io/percolator.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
from psm_utils.peptidoform import Peptidoform
from psm_utils.psm import PSM
from psm_utils.psm_list import PSMList
from psm_utils.io._utils import set_csv_field_size_limit

set_csv_field_size_limit()


class PercolatorTabReader(ReaderBase):
Expand Down
13 changes: 6 additions & 7 deletions psm_utils/io/sage.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"""


from __future__ import annotations

import csv
Expand All @@ -17,7 +16,9 @@

from psm_utils.io._base_classes import ReaderBase
from psm_utils.psm import PSM
from psm_utils.psm_list import PSMList
from psm_utils.io._utils import set_csv_field_size_limit

set_csv_field_size_limit()


class SageReader(ReaderBase):
Expand Down Expand Up @@ -88,11 +89,9 @@ def _get_peptide_spectrum_match(self, psm_dict) -> PSM:
),
spectrum_id=psm_dict["scannr"],
run=Path(psm_dict["filename"]).stem,
is_decoy=True
if psm_dict["label"] == "-1"
else False
if psm_dict["label"] == "1"
else None,
is_decoy=(
True if psm_dict["label"] == "-1" else False if psm_dict["label"] == "1" else None
),
qvalue=psm_dict["spectrum_q"],
score=float(psm_dict[self.score_column]),
precursor_mz=self._parse_precursor_mz(psm_dict["expmass"], psm_dict["charge"]),
Expand Down
4 changes: 4 additions & 0 deletions psm_utils/io/tsv.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"""

from __future__ import annotations

import ast
Expand All @@ -59,6 +60,9 @@
from psm_utils.io.exceptions import PSMUtilsIOException
from psm_utils.psm import PSM
from psm_utils.psm_list import PSMList
from psm_utils.io._utils import set_csv_field_size_limit

set_csv_field_size_limit()

logger = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ classifiers = [
dynamic = ["version"]
requires-python = ">=3.7"
dependencies = [
"pyteomics >= 4",
"pyteomics >= 4, <4.7",
"pyopenms",
"lxml",
"psims",
Expand Down

0 comments on commit 3f32f24

Please sign in to comment.