Skip to content

[bug] TypeError when "selectedIon" "charge state" is None during integer coercion #248

@ometa-evan

Description

@ometa-evan

A TypeError is raised if "charge state" is present in the selected ion dictionary, but has a value of None

if "charge state" in spectrum["precursorList"]["precursor"][0]["selectedIonList"]["selectedIon"][0]:
msn_charge = int(spectrum["precursorList"]["precursor"][0]["selectedIonList"]["selectedIon"][0]["charge state"])

This could be resolved with a try/except TypeError or with another if conditional checking the spectrum["precursorList"]["precursor"][0]["selectedIonList"]["selectedIon"][0]["charge state"] is not None.

Traceback (most recent call last):
  File "/home/user/miniforge3/envs/dev/bin/massql", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/user/miniforge3/envs/dev/lib/python3.11/site-packages/massql/msql_cmd.py", line 58, in main
    results_df = msql_engine.process_query(query, 
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/miniforge3/envs/dev/lib/python3.11/site-packages/massql/msql_engine.py", line 64, in process_query
    return _evalute_variable_query(parsed_dict, input_filename, cache=cache, parallel=parallel, ms1_df=ms1_df, ms2_df=ms2_df)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/miniforge3/envs/dev/lib/python3.11/site-packages/massql/msql_engine.py", line 157, in _evalute_variable_query
    ms1_df, ms2_df = msql_fileloading.load_data(input_filename, cache=cache)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/miniforge3/envs/dev/lib/python3.11/site-packages/massql/msql_fileloading.py", line 45, in load_data
    ms1_df, ms2_df = _load_data_mzML_pyteomics(input_filename) # Faster version using pymzML
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/miniforge3/envs/dev/lib/python3.11/site-packages/massql/msql_fileloading.py", line 374, in _load_data_mzML_pyteomics
    msn_charge = int(spectrum["precursorList"]["precursor"][0]["selectedIonList"]["selectedIon"][0]["charge state"])
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'NoneType'

Checking the dict with a breakpoint() using try:/except TypeError: breakpoint()

try:
    msn_charge = int(spectrum["precursorList"]["precursor"][0]["selectedIonList"]["selectedIon"][0]["charge state"])
except TypeError:
    breakpoint()
(Pdb) spectrum["precursorList"]["precursor"][0]["selectedIonList"]["selectedIon"][0]
{'selected ion m/z': 441.234252929688, 'peak intensity': 32556556.45361, 'charge state': None}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions