compomics / psm_utils

Common utilities for parsing and handling peptide-spectrum matches and search engine results in Python
https://psm-utils.readthedocs.io
Apache License 2.0
24 stars 6 forks source link

NoneType object is not subcriptable #92

Open prvst opened 3 weeks ago

prvst commented 3 weeks ago

Hello, I'm getting this error, can you please help me locate the source of the problem?

                             (1/1): 'merged.idXML'...                           
2024-08-16 23:52:41 ERROR    ms2rescore.__main__ // 'NoneType' object is not    
                             subscriptable                                      
                             ╭─────── Traceback (most recent call last) ───────╮
                             │ /usr/local/lib/python3.11/site-packages/ms2resc │
                             │ ore/__main__.py:237 in main                     │
                             │                                                 │
                             │   234 │   │   │   profiled_rescore = profile(re │
                             │   235 │   │   │   profiled_rescore(configuratio │
                             │   236 │   │   else:                             │
                             │ ❱ 237 │   │   │   rescore(configuration=config) │
                             │   238 │   except Exception as e:                │
                             │   239 │   │   LOGGER.exception(e)               │
                             │   240 │   │   sys.exit(1)                       │
                             │                                                 │
                             │ /usr/local/lib/python3.11/site-packages/ms2resc │
                             │ ore/core.py:47 in rescore                       │
                             │                                                 │
                             │    44 │   logger.debug("Using %i of %i availabl │
                             │       int(cpu_count()))                         │
                             │    45 │                                         │
                             │    46 │   # Parse PSMs                          │
                             │ ❱  47 │   psm_list = parse_psms(config, psm_lis │
                             │    48 │                                         │
                             │    49 │   # Log #PSMs identified before rescori │
                             │    50 │   id_psms_before = _log_id_psms_before( │
                             │       max_rank=config["max_psm_rank_output"])   │
                             │                                                 │
                             │ /usr/local/lib/python3.11/site-packages/ms2resc │
                             │ ore/parse_psms.py:29 in parse_psms              │
                             │                                                 │
                             │    26 │   """                                   │
                             │    27 │   # Read PSMs                           │
                             │    28 │   try:                                  │
                             │ ❱  29 │   │   psm_list = _read_psms(config, psm │
                             │    30 │   except psm_utils.io.PSMUtilsIOExcepti │
                             │    31 │   │   raise MS2RescoreConfigurationErro │
                             │    32 │   │   │   "Error occurred while reading │
                             │                                                 │
                             │ /usr/local/lib/python3.11/site-packages/ms2resc │
                             │ ore/parse_psms.py:107 in _read_psms             │
                             │                                                 │
                             │   104 │   │   │   │   f"Reading PSMs from PSM f │
                             │       '{psm_file}'..."                          │
                             │   105 │   │   │   )                             │
                             │   106 │   │   │   psm_list.extend(              │
                             │ ❱ 107 │   │   │   │   psm_utils.io.read_file(   │
                             │   108 │   │   │   │   │   psm_file,             │
                             │   109 │   │   │   │   │   filetype=config["psm_ │
                             │   110 │   │   │   │   │   show_progressbar=True │
                             │                                                 │
                             │ /usr/local/lib/python3.11/site-packages/psm_uti │
                             │ ls/io/__init__.py:182 in read_file              │
                             │                                                 │
                             │   179 │   │   │   f"Filetype '{filetype}' unkno │
                             │   180 │   │   ) from e                          │
                             │   181 │   reader = reader_cls(filename, *args,  │
                             │ ❱ 182 │   psm_list = reader.read_file()         │
                             │   183 │   return psm_list                       │
                             │   184                                           │
                             │   185                                           │
                             │                                                 │
                             │ /usr/local/lib/python3.11/site-packages/psm_uti │
                             │ ls/io/_base_classes.py:46 in read_file          │
                             │                                                 │
                             │   43 │                                          │
                             │   44 │   def read_file(self) -> PSMList:        │
                             │   45 │   │   """Read full PSM file into a PSMLi │
                             │ ❱ 46 │   │   return PSMList(psm_list=[psm for p │
                             │   47                                            │
                             │   48                                            │
                             │   49 class WriterBase(ABC):                     │
                             │                                                 │
                             │ /usr/local/lib/python3.11/site-packages/psm_uti │
                             │ ls/io/_base_classes.py:46 in <listcomp>         │
                             │                                                 │
                             │   43 │                                          │
                             │   44 │   def read_file(self) -> PSMList:        │
                             │   45 │   │   """Read full PSM file into a PSMLi │
                             │ ❱ 46 │   │   return PSMList(psm_list=[psm for p │
                             │   47                                            │
                             │   48                                            │
                             │   49 class WriterBase(ABC):                     │
                             │                                                 │
                             │ /usr/local/lib/python3.11/site-packages/psm_uti │
                             │ ls/io/idxml.py:112 in __iter__                  │
                             │                                                 │
                             │   109 │   │   """                               │
                             │   110 │   │   for peptide_id in self.peptide_id │
                             │   111 │   │   │   for peptide_hit in peptide_id │
                             │ ❱ 112 │   │   │   │   yield self._parse_psm(sel │
                             │   113 │                                         │
                             │   114 │   def _parse_idxml(self) -> Tuple[oms.P │
                             │       oms.PeptideIdentification]:               │
                             │   115 │   │   """                               │
                             │                                                 │
                             │ /usr/local/lib/python3.11/site-packages/psm_uti │
                             │ ls/io/idxml.py:185 in _parse_psm                │
                             │                                                 │
                             │   182 │   │   return PSM(                       │
                             │   183 │   │   │   peptidoform=peptidoform,      │
                             │   184 │   │   │   spectrum_id=peptide_id.getMet │
                             │ ❱ 185 │   │   │   run=self._get_run(protein_ids │
                             │   186 │   │   │   is_decoy=self._is_decoy(pepti │
                             │   187 │   │   │   score=peptide_hit.getScore(), │
                             │   188 │   │   │   precursor_mz=peptide_id.getMZ │
                             │                                                 │
                             │ /usr/local/lib/python3.11/site-packages/psm_uti │
                             │ ls/io/idxml.py:223 in _get_run                  │
                             │                                                 │
                             │   220 │   │   │   │   .decode()                 │
                             │   221 │   │   │   ).stem                        │
                             │   222 │   │   else:                             │
                             │ ❱ 223 │   │   │   run = Path(protein_ids[0].get │
                             │   224 │   │                                     │
                             │   225 │   │   # Convert back to None value (see │
                             │   226 │   │   if run == "None":                 │
                             ╰─────────────────────────────────────────────────╯
                             TypeError: 'NoneType' object is not subscriptable  
RalfG commented 3 weeks ago

Hi @prvst,

Seems like something goes wrong while reading the run field from the idXML file.

@jonasscheid, would you have time to look into this? Thanks!

Best, Ralf

jonasscheid commented 3 weeks ago

Can you attach the input file or a reduced version of it @prvst?

prvst commented 3 weeks ago

Hello, @jonasscheid. Unfortunately, I cannot share any data, but I believe to have found the source of the problem. The issue happens when you convert a MSFragger-derived pepXML file to idXML using the OpenMS IDFileConverter, several of the UserParam attributes are not ported to the new idXML, including the one below:

<UserParam type="stringList" name="spectra_data" value="[/foo/bar/file.mzML]"/>

This seems to be the line triggering the error on idxml.py:223

RalfG commented 3 weeks ago

Perhaps making _get_run accept empty/missing values would be a workaround here?