44611123e060cd2efeb765ae05ac3b3369acb81b
max
  Thu Nov 6 06:20:34 2025 -0800
addressing Visium V2 format, woodchuck liver dataset

diff --git src/cbPyLib/cellbrowser/R/cellbrowser.R src/cbPyLib/cellbrowser/R/cellbrowser.R
index a04c0ae..f03c3bd 100644
--- src/cbPyLib/cellbrowser/R/cellbrowser.R
+++ src/cbPyLib/cellbrowser/R/cellbrowser.R
@@ -112,33 +112,40 @@
         img = GetImage(obj, mode="raw", image=name); 
         if (is.null(img)) {
             message("The image is not a bitmap image, cannot export yet.")
             return(embeddings.conf)
         }
         imgPath <- file.path(outDir, paste0(name, ".jpg"))
         message("Writing image ", imgPath)
         #writePNG(img, imgPath);  # JPEG seems like a better choice here, 4x smaller at default quality settings.
         writeJPEG(img, target=imgPath, quality=0.95); 
         yMax = dim(img)[1];
         xMax = dim(img)[2]; # there is a difference of 3 pixels on height when comparing "identify file.jpeg" with this. NO IDEA WHY!
         coordsPath <- file.path(outDir, paste0(name, ".coords.tsv")) 
         message("Writing coords for image to ", coordsPath)
         #coords <- GetTissueCoordinates(object = obj[[img]])
 
-        coords <- GetTissueCoordinates(object = obj[[name]])
-        coordsRev <- coords[, c("imagecol", "imagerow")]  # Grrrr... Seurat stores coordinates as (y,x) in this particular case. reverse the order now.
+        if (all(c("imagecol", "imagerow") %in% colnames(coords))) {
+        # Seurat-style naming: reverse order
+          coordsRev <- coords[, c("imagecol", "imagerow")]
           colnames(coordsRev) <- c("x", "y")
+        } else if (all(c("x", "y") %in% colnames(coords))) {
+          # Already in standard x/y format
+          coordsRev <- coords[, c("x", "y")]
+        } else {
+          stop("Error: coordinates must have either (imagecol, imagerow) or (x, y) columns.")
+        }
 
         write.table(coordsRev, coordsPath, sep="\t", row.names=T, quote=F, col.names=NA)
         conf <- sprintf(
          '  {\n    "file": "%s",\n    "shortLabel": "Spatial %s",\n    "flipY":True,\n    "images" : [{"file":"%s"}],\n     "minX":0, "minY":0, "maxX":%d, "maxY":%d\n  }',
          coordsPath,
          name,
          imgPath,
          xMax,
          yMax
         )
         embeddings.conf <- c(conf, embeddings.conf)
     }
     return(embeddings.conf)
 }