rajewsky-lab / spacemake

Other
39 stars 11 forks source link

Error in detect_tissue: setting an array element with a sequence #125

Open QuinceyLv opened 4 weeks ago

QuinceyLv commented 4 weeks ago

Hi, Thanks for the great package. I was running spacemake with visium data, and got an exception:

rule run_automated_analysis: input: projects/visium_demo/processed_data/DSG_Control/illumina/complete_data/dge/dge.exon.polyA_adapter_trimmed.mm_included.spatial_beads_visium.h5ad output: projects/visium_demo/processed_data/DSG_Control/illumina/complete_data/automated_analysis/visium/umi_cutoff_1000/DSG_Control_visium_results.h5ad jobid: 47 wildcards: project_id=visium_demo, sample_id=DSG_Control, data_root_type=complete_data, downsampling_percentage=, run_mode=visium, umi_cutoff=1000, puck_barcode_file_id_qc=visium

Rscript --vanilla -e 'rmarkdown::render("/fakepath/openst_test_20240924/result/spacemake_20241021/.snakemake/scripts/tmpd9cfk6th.qc_sequencing_create_sheet.Rmd", output_file="/fakepath/openst_test_20240924/result/spacemake_20241021/projects/visium_demo/processed_data/DSG_Control/illumina/complete_data/qc_sheets/qc_sheet_DSG_Control_visium.html", quiet=TRUE, knit_root_dir = "/fakepath/openst_test_20240924/result/spacemake_20241021", params = list(rmd="/fakepath/openst_test_20240924/result/spacemake_20241021/.snakemake/scripts/tmpd9cfk6th.qc_sequencing_create_sheet.Rmd"))' /fakepath/software/miniconda3/envs/spacemake/bin/python3.10 /fakepath/openst_test_20240924/result/spacemake_20241021/.snakemake/scripts/tmprifp4gew.automated_analysis.py

Finished job 61. 22 of 39 steps (56%) done Traceback (most recent call last): File "/fakepath/openst_test_20240924/result/spacemake_20241021/.snakemake/scripts/tmprifp4gew.automated_analysis.py", line 19, in adata = detect_tissue(adata, umi_cutoff) File "/fakepath/software/miniconda3/envs/spacemake/lib/python3.10/site-packages/spacemake/spatial/util.py", line 139, in detect_tissue tissue_islands = np.delete(islands, np.argmax(island_sizes)) File "/fakepath/software/miniconda3/envs/spacemake/lib/python3.10/site-packages/numpy/lib/function_base.py", line 5245, in delete arr = asarray(arr) ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (39,) + inhomogeneous part.

Then I checked the code in spacemake.spatial.utils.detect_tissue: https://github.com/rajewsky-lab/spacemake/blob/9ce7d8905a8402f2115ec22ea7890fa64b81fe84/spacemake/spatial/util.py#L139

ChatGPT says this should be:

islands_array = np.array(islands, dtype=object)
max_index = np.argmax(island_sizes)
tissue_islands = np.delete(islands_array, max_index)
tissue_islands = tissue_islands.tolist()

I'm using spacemake 0.7.9 with numpy 1.26.4. Is that correct? Thanks in advance.

nukappa commented 3 weeks ago

Hi there, thanks for reporting this.

We haven't been using this functionality in a while. Did you try implementing the correction you mentioned above and see if it works?

QuinceyLv commented 3 weeks ago

Hi there, thanks for reporting this.

We haven't been using this functionality in a while. Did you try implementing the correction you mentioned above and see if it works?

Yes, it worked.