Skip to content

Error readCosMX #49

Description

@ccruizm

Good day!

I am trying to read our CosMX dataset (6K-plex gene panel), but got an error

(sfe_cosmx <- readCosMX(dir_use, add_molecules = TRUE))
>>> Constructing cell polygons

Warning message in .df2sf_check(df, spatialCoordsNames, gt, group_col, id_col, subid_col):
“Removed 6 items that have fewer than the minimum of 3 vertices for geometry type POLYGON”
>>> ..removing 7 empty polygons

>>> Checking polygon validity

>>> Reading transcript coordinates

>>> Converting transcript spots to geometry

>>> Writing reformatted transcript spots to disk

Error: Capacity error: array cannot contain more than 2147483646 bytes, have 2148149336
Traceback:

1. readCosMX(dir_use, add_molecules = TRUE)
2. addTxTech(sfe, data_dir, sample_id, tech = "CosMX", z = z, file_out = file_out, 
 .     BPPARAM = BPPARAM, split_cell_comps = split_cell_comps, z_option = z_option)
3. addTxSpots(sfe, file = fn, sample_id = sample_id, spatialCoordsNames = spatialCoordsNames, 
 .     gene_col = gene_col, z = z, phred_col = "qv", min_phred = min_phred, 
 .     split_col = split_col, z_option = z_option, flip = flip, 
 .     file_out = file_out, BPPARAM = BPPARAM)
4. formatTxSpots(file, dest = dest, spatialCoordsNames = spatialCoordsNames, 
 .     gene_col = gene_col, z = z, phred_col = phred_col, min_phred = min_phred, 
 .     split_col = split_col, flip = flip, z_option = z_option, 
 .     file_out = file_out, BPPARAM = BPPARAM, return = TRUE)
5. suppressWarnings(sfarrow::st_write_parquet(mols, file_out))
6. withCallingHandlers(expr, warning = function(w) if (inherits(w, 
 .     classes)) tryInvokeRestart("muffleWarning"))
7. sfarrow::st_write_parquet(mols, file_out)
8. arrow::Table$create(df)
9. Table__from_dots(dots, schema, option_use_threads())

Is there a way to circumvent that? for now I can create the SFE object setting add_molecules=FALSE

Thanks in advance!

Activity

  1. lambdamoses commented on Mar 28, 2025

    @lambdamoses
    Collaborator

    That comes from arrow. See pachterlab/SpatialFeatureExperiment#48
    I'm working on rewriting all functions using transcript spots to use arrow::open_dataset() to not to load all transcripts into memory and process the transcript gene by gene. It requires extensive changes to the code.

  2. swbioinf commented on Jul 9, 2025

    @swbioinf

    @ccruizm Late the party, but I had the same issue. My workaround was as you say, make the no-molecule sfe object first, then add molecules (via a bumpymatrix build from the tx file) to it after.

    For the next person; my code is in the 'load_sfe_with_molecules()' function here; https://github.com/swbioinf/spatialsnippets/blob/main/code/d_cosmxIBD_sfe_script.R

    User bewared, I tested only on 1-2 datasets, may be bugged, and is definately not optimised! There's some other guff in there around missing polygons, but you can safely skip that if your object doesn't need it.

    Sarah.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions