Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ometa-evan opened this issue Jul 31, 2024 · 0 comments

Comments

@ometa-evan
Copy link

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}
@ometa-evan ometa-evan changed the title [bug] TypeError when selectedIon "charge state" is None during integer coercion [bug] TypeError when "selectedIon" "charge state" is None during integer coercion Jul 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant