MassQueryLanguage icon indicating copy to clipboard operation
MassQueryLanguage copied to clipboard

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

Open ometa-evan opened this issue 1 year ago • 0 comments

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

https://github.com/mwang87/MassQueryLanguage/blob/dc23b1f336631a3286cbc7aca5ad57a23989d7cd/massql/msql_fileloading.py#L437-L438

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}

ometa-evan avatar Jul 31 '24 18:07 ometa-evan