fmi-basel / gliberal-scMultipleX

Feature extraction and linking of multiplexing data.
BSD 3-Clause "New" or "Revised" License
8 stars 0 forks source link

Enhance nuclear linking exception handling #73

Open enricotagliavini opened 1 year ago

enricotagliavini commented 1 year ago

There are two exception cases in NucleiLinking.py that could use some TLC (tender love care). At

https://github.com/fmi-basel/gliberal-scMultipleX/blob/57084fa73f1ce5682a50780892b7f840c950b677/src/scmultiplex/linking/NucleiLinking.py#L127-L128

and at

https://github.com/fmi-basel/gliberal-scMultipleX/blob/57084fa73f1ce5682a50780892b7f840c950b677/src/scmultiplex/linking/NucleiLinking.py#L158-L159

When an exception happens within the try statement scope the error message could be as the following

Executing: python3 scripts/prefect/03_nuclear_multiplex.py --config ./scripts/configs/unified_start.conf --cpus 40 --prefect-logfile /tungstenfs/nobackup/gliberal/taglenri/nicole/scmultipl
ex/prefect-scmultiplex-20230531-15_40_35.log
Running scMultipleX version 0.3.dev36+g5b9d379.d20230411
matching of object_38 and object_35 in day1p5 C03
100% 8/8 [00:00<00:00, 1139.56it/s]
100% 8/8 [00:00<00:00, 903.39it/s]
object_38 object_35 Shape of passed values is (8, 2), indices imply (8, 3)
03_nuclear_multiplex.py completed successfully

This could be clearer and, in the case of the example above, it also makes step 07 completely fail

Executing: python3 scripts/prefect/07_aggregate_nuclear_multiplex.py --config ./scripts/configs/unified_start.conf --cpus 40 --prefect-logfile /tungstenfs/nobackup/gliberal/taglenri/nicole/scmultiplex/prefect-scmultiplex-20230531-15_40_35.log
Running scMultipleX version 0.3.dev36+g5b9d379.d20230411
ERROR! Run organoid linking and linking_nuc_df aggregation of round  R1
ERROR: Task 'merge_scmultiplexed_features_task': Exception encountered during task execution!
Traceback (most recent call last):
  File "/tungstenfs/nobackup/gliberal/taglenri/nicole/scmp_venv/lib64/python3.8/site-packages/prefect/engine/task_runner.py", line 880, in get_task_run_state
    value = prefect.utilities.executors.run_task_with_timeout(
  File "/tungstenfs/nobackup/gliberal/taglenri/nicole/scmp_venv/lib64/python3.8/site-packages/prefect/utilities/executors.py", line 468, in run_task_with_timeout
    return task.run(*args, **kwargs)  # type: ignore 
  File "scripts/prefect/07_aggregate_nuclear_multiplex.py", line 47, in merge_scmultiplexed_features_task
    write_nuclear_linking_over_multiplexing_rounds(round_names, round_summary_csvs)
  File "/tungstenfs/nobackup/gliberal/taglenri/nicole/gliberal-scMultipleX/src/scmultiplex/utils/accumulate_utils.py", line 873, in write_nuclear_linking_over_multiplexing_rounds
    link = links[round_names[i + 1]]  # load linking 
KeyError: 'R1'
Command 'python3 scripts/prefect/07_aggregate_nuclear_multiplex.py --config ./scripts/configs/unified_start.conf --cpus 40 --prefect-logfile /tungstenfs/nobackup/gliberal/taglenri/nicole/scmultiplex/prefect-scmultiplex-20230531-15_40_35.log' returned non-zero exit status 1.