scplotter to work with NanoString CosMx data prepared by Giotto¶

The technology. CosMx SMI (NanoString) is an imaging-based, subcellular platform: a targeted RNA panel is detected in situ and every transcript keeps its own x/y coordinate, alongside cell and subcellular segmentation from morphology images. A single field of view covers only a small area, so one tissue is acquired as many FOVs that Giotto composites into a single coordinate space. Each run also includes negative-control probes, kept as their own feature type here so background can be quantified rather than ignored.

What this notebook covers. The Lung12 NSCLC dataset, exported in the legacy flat-file format where no pre-aggregated matrix is provided. Creating the object across a complete 4x4 block of the 28 available FOVs (16; the tissue is a 4 column x 7 row grid), so the per-FOV view has no empty cells, aggregating subcellular transcripts up to cell polygons through the overlap step, keeping negative probes as a separate feature type, filtering, normalising, clustering, and plotting with SpatDimPlot / SpatFeaturePlot — whole-tissue, per-FOV and small-subset views, with and without the FOV images.

A second CosMx dataset — human pancreas FFPE, which ships a pre-aggregated expression matrix — is covered in the companion notebook Giotto.Nanostring_CosMx_Pancreas.ipynb. It is kept separate because the two exports take very different routes into Giotto and the 28-FOV legacy run is slow enough that bundling them makes the notebook awkward to execute end to end.

Before you run. A Giotto Python environment (aggregation and clustering call into Python), plenty of disk for the subcellular transcript tables, and the Lung12 bundle unpacked under data/. This notebook needs a lot of memory: the legacy export is read FOV by FOV and aggregated in memory.

Upstream tutorial.

  • https://giottosuite.com/articles/nanostring_cosmx_lung_cancer.html

Go back to scplotter documentation: https://pwwang.github.io/scplotter/

In [1]:
library(Giotto)

# Ensure Giotto can access a python env
genv_exists <- suppressMessages(checkGiottoEnvironment())
print(genv_exists)

python_path <- file.path(Sys.getenv("HOME"), "miniconda3", "envs", "giotto_env", "bin", "python")
Sys.setenv(RETICULATE_PYTHON = python_path)

invisible(capture.output(suppressMessages(set_giotto_python_path(python_path = python_path))))

# library(scplotter)
devtools::load_all()
Loading required package: GiottoClass

Giotto Suite 4.2.3

[1] TRUE
ℹ Loading scplotter
In [2]:
library(Giotto)

## Set instructions
results_folder <- "data/Nanostring_CosMx_Subcellular_Lung_Cancer.results"

instrs <- createGiottoInstructions(
    save_dir = results_folder,
    save_plot = FALSE,
    show_plot = TRUE,
    return_plot = TRUE,
    python_path = python_path
)

data_path <- "data/Nanostring_CosMx_Subcellular_Lung_Cancer/Lung12/Lung12-Flat_files_and_images/"

## create giotto cosmx object
cosmx <- suppressWarnings(createGiottoCosMxObject(
    cosmx_dir = data_path,
    version = "legacy", # set to this for legacy NSCLC dataset
    FOVs = seq_len(16), # a complete 4x4 block of the 4x7 FOV grid, so no cell is blank
    load_expression = FALSE, # defaults to FALSE (see feature aggregation step below)
    instructions = instrs
))

force(cosmx)
specified py env from `envname` =
 '/home/ext_wang_panwen_mayo_edu/miniconda3/envs/giotto_env/bin/python' not
 found

Warning message:
“Python is required for full Giotto functionality.
 Turn off this message by setting option
 "giotto.no_python_warn" = TRUE”
checking default envname 'giotto_env'

a system default python environment was found

Using python path:
 "/fslustre/qhs/ext_wang_panwen_mayo_edu/scplotter-giotto/envs/giotto_env/bin/python"

loading feature detections...

Setting feature info [rna]

Setting feature info [negprobes]

loading composite images...

loading overlay images...

loading cell metadata...

An object of class giotto 
>Active spat_unit:  cell 
>Active feat_type:  rna 
dimensions    : 960, 41817 (features, cells)
[SUBCELLULAR INFO]
polygons      : cell 
features      : rna negprobes 
[AGGREGATE INFO]
spatial locations ----------------
  [cell] raw
attached images ------------------
images      : 32 items...


Use objHistory() to see steps and params used
In [3]:
options(repr.plot.width = 10, repr.plot.height = 10)

SpatDimPlot(
    cosmx,
    label = TRUE,
    label_pos = "center",
    group_by = "fov",
    points_size = 0.1,
    image = "black"
)
No description has been provided for this image
In [4]:
options(repr.plot.width = 11, repr.plot.height = 10)
# devtools::load_all()

SpatDimPlot(
    cosmx,
    image = TRUE,  # use all fovs
    features = c(
        "MMP2", "VEGFA", "IGF1R",
        "MKI67", "EPCAM", "KRT8"
    ),
    spat_unit = "cell",
    points_size = 0.01,
    points_palette = "Vivid"
)
No description has been provided for this image
In [5]:
options(repr.plot.width = 11, repr.plot.height = 10)
# Visualize Cell Centroids

SpatDimPlot(
    cosmx,
    image = TRUE,  # use all fovs
    size = 0.1,
    alpha = 0.8,
    color_by = "white",
    title = "centroids"
)
No description has been provided for this image
In [6]:
# Aggregate subcellular features
# Find the feature points overlapped by polygons. This overlap information is then
# returned to the relevant giottoPolygon object"s overlaps slot.
## aggregateFeatures() replaces the two-step calculateOverlapRaster() + overlapToMatrix()
## pair, both deprecated since GiottoClass 0.4.7. The old shim now returns the overlap table
## instead of the gobject, which silently turns `cosmx` into a data.frame and breaks every
## later step. aggregateFeatures() runs the overlap and writes the matrix in one call.
cosmx <- GiottoClass::aggregateFeatures(cosmx, feat_info = "rna", name = "raw")
cosmx <- GiottoClass::aggregateFeatures(cosmx, feat_info = "negprobes", name = "raw")

cosmx <- filterGiotto(cosmx,
    feat_type = "rna",
    expression_threshold = 1,
    feat_det_in_min_cells = 5,
    min_det_feats_per_cell = 5
)

# normalize
# standard method of normalization (log normalization based)
cosmx <- normalizeGiotto(cosmx,
    feat_type = "rna",
    norm_methods = "standard"
)

# new normalization method based on pearson correlations (Lause/Kobak et al. 2021)
# this normalized matrix is given the name "pearson" using the update_slot param
cosmx <- normalizeGiotto(cosmx,
    feat_type = "rna",
    scalefactor = 5000,
    norm_methods = "pearson_resid",
    name = "pearson"
)
# add statistics based on log normalized values
cosmx <- addStatistics(cosmx,
    expression_values = "normalized",
    feat_type = "rna"
)

# add statistics for the raw negative probe values
cosmx <- addStatistics(cosmx,
    expression_values = "raw",
    feat_type = "negprobes"
)

# View cellular data (default is feat = "rna")
showGiottoCellMetadata(cosmx)

# View feature data
showGiottoFeatMetadata(cosmx)
Setting expression [cell][rna] raw

Setting expression [cell][negprobes] raw

completed 1: preparation

completed 2: subset expression data

completed 3: subset spatial locations

completed 4: subset cell metadata

completed 5: subset feature metadata

completed 6: subset spatial network(s)

completed 7: subsetted dimension reductions

completed 8: subsetted nearest network(s)

completed 9: subsetted spatial enrichment results

for cell

--> cell found back in polygon layer: cell

completed 10: subsetted spatial information data

subset feature info: rna

completed 11: subsetted spatial feature data

Feature type:  rna 
Number of cells removed:  597  out of  41817 
Number of feats removed:  0  out of  960 
first scale feats and then cells

Setting expression [cell][rna] normalized

Setting expression [cell][rna] scaled

using 'Lause/Kobak' method to normalize count matrix If used in
        published research, please cite:
        Jan Lause, Philipp Berens, Dmitry Kobak (2020).
        'Analytic Pearson residuals for normalization of single-cell RNA-seq UMI
        data' 

Setting expression [cell][rna] pearson

calculating statistics for "normalized" expression

calculating statistics for "raw" expression

These column names were already used: area
 and will be overwritten

└──Spatial unit "cell"
   ├──Feature type "rna"
   │     An object of class cellMetaObj 
   │     spat_unit : "cell"
   │     feat_type : "rna"
   │     provenance: cell 
   │     dimensions: 4 20 
   │     
   │        cell_ID  Area AspectRatio Width Height Mean.MembraneStain Max.MembraneStain
   │         <char> <int>       <num> <int>  <int>              <int>             <int>
   │     1: c_1_1_1  3411        1.98    93     47               7127             16033
   │     2: c_1_1_2  2993        1.77    78     44              13547             25859
   │     3: c_1_1_3  5590        1.75   112     64              10353             22954
   │        Mean.PanCK Max.PanCK Mean.CD45 Max.CD45 Mean.CD3 Max.CD3 Mean.DAPI Max.DAPI
   │             <int>     <int>     <int>    <int>    <int>   <int>     <int>    <int>
   │     1:       3000     17172        78      588       80     610     12242    47623
   │     2:      12494     23204       102      410        0      85         0        0
   │     3:       7951     21297        79      495        0     133       611    23078
   │           fov nr_feats perc_feats total_expr  area
   │        <char>    <int>      <num>      <num> <num>
   │     1:      1       82   8.541667   493.4018  3411
   │     2:      1       52   5.416667   347.6662  2993
   │     3:      1       75   7.812500   467.2596  5590
   │  
   └──Feature type "negprobes"
         An object of class cellMetaObj 
         spat_unit : "cell"
         feat_type : "negprobes"
         provenance: cell 
         dimensions: 4 4 
         
            cell_ID nr_feats perc_feats total_expr
             <char>    <int>      <num>      <num>
         1: c_1_1_1        1          5          1
         2: c_1_1_2        0          0          0
         3: c_1_1_3        0          0          0
      
└──Spatial unit "cell"
   ├──Feature type "rna"
   │     An object of class featMetaObj 
   │     spat_unit : "cell"
   │     feat_type : "rna"
   │     provenance: cell 
   │     
   │        feat_ID nr_cells perc_cells total_expr mean_expr mean_expr_det
   │         <char>    <int>      <num>      <num>     <num>         <num>
   │     1:    IL7R     3497   8.483746   16765.73 0.4067377      4.794318
   │     2:  SEC61G     4669  11.327026   21753.92 0.5277515      4.659224
   │     3:   IGHA1    11439  27.751092   66760.88 1.6196236      5.836252
   │  
   └──Feature type "negprobes"
         An object of class featMetaObj 
         spat_unit : "cell"
         feat_type : "negprobes"
         provenance: cell 
         
             feat_ID nr_cells perc_cells total_expr  mean_expr mean_expr_det
              <char>    <int>      <num>      <num>      <num>         <num>
         1: NegPrb15     1713   4.155750       1925 0.04670063      1.123759
         2: NegPrb18     2237   5.426977       2556 0.06200873      1.142602
         3:  NegPrb7     2070   5.021834       2412 0.05851528      1.165217
      
In [7]:
options(repr.plot.width = 11, repr.plot.height = 10)

SpatFeaturePlot(
    cosmx,
    image = "black",
    feature = "total_expr",
    points_size = 0.4,
    points_palette = "BluYl"
)
No description has been provided for this image
In [8]:
options(repr.plot.width = 11, repr.plot.height = 10)

SpatFeaturePlot(
    cosmx,
    image = "black",
    points = FALSE,
    shapes_fill_by = "total_expr",  # indicating shapes = TRUE
    shapes_border_size = 0.05
)
No description has been provided for this image
In [9]:
cosmx <- calculateHVF(cosmx,
    method = "var_p_resid",
    var_number = 500, # leaving as NULL results in too few genes to use
    save_plot = TRUE,
    save_param = list(
        save_name = "10_hvf"
    )
)
# If you get an Error related to future.apply, please modify the maximum size
# of global variables by running: options(future.globals.maxSize = 1e10)

# print HVFs
gene_metadata <- fDataDT(cosmx)
gene_metadata[hvf == "yes", feat_ID]

cosmx <- runPCA(cosmx,
    scale_unit = FALSE,
    center = FALSE,
    expression_values = "pearson"
)

cosmx <- runtSNE(cosmx,
    dimensions_to_use = 1:10
)

cosmx <- runUMAP(cosmx,
    dimensions_to_use = 1:10
)

cosmx <- createNearestNetwork(cosmx,
    dimensions_to_use = 1:10,
    k = 10
)

cosmx <- doLeidenCluster(cosmx,
    resolution = 0.07,
    n_iterations = 100
)
  1. 'SEC61G'
  2. 'IGHA1'
  3. 'IL6'
  4. 'KRT86'
  5. 'NEAT1'
  6. 'S100A10'
  7. 'FYN'
  8. 'NDRG1'
  9. 'AGR2'
  10. 'FGR'
  11. 'IL4R'
  12. 'COL16A1'
  13. 'STAT3'
  14. 'MAPK14'
  15. 'VHL'
  16. 'CD44'
  17. 'RAMP1'
  18. 'ZFP36'
  19. 'CD27'
  20. 'GDF15'
  21. 'EPCAM'
  22. 'LTB'
  23. 'COL12A1'
  24. 'HLA-DQB1'
  25. 'CLU'
  26. 'ALCAM'
  27. 'FGF1'
  28. 'NR1H3'
  29. 'EIF5A'
  30. 'LGALS3'
  31. 'CD63'
  32. 'DCN'
  33. 'LIF'
  34. 'HCST'
  35. 'VSIR'
  36. 'STAT1'
  37. 'UBE2C'
  38. 'PDGFC'
  39. 'YES1'
  40. 'TGFBR2'
  41. 'IFIH1'
  42. 'SOX9'
  43. 'MX1'
  44. 'IGKC'
  45. 'CD8A'
  46. 'PTGES3'
  47. 'KRAS'
  48. 'CRYAB'
  49. 'ACTA2'
  50. 'BCL2L1'
  51. 'SRGN'
  52. 'CD53'
  53. 'MTRNR2L1'
  54. 'LAMP2'
  55. 'LAIR1'
  56. 'EFNA1'
  57. 'FZD5'
  58. 'FES'
  59. 'MZT2A'
  60. 'SERPINA1'
  61. 'HIF1A'
  62. 'JUN'
  63. 'THBS1'
  64. 'CD274'
  65. 'CXCL3'
  66. 'IL11'
  67. 'GPX1'
  68. 'EPHA2'
  69. 'TGFB3'
  70. 'CLDN4'
  71. 'KITLG'
  72. 'RPL34'
  73. 'HLA-A'
  74. 'HDAC1'
  75. 'MGP'
  76. 'MRC2'
  77. 'COL4A2'
  78. 'CDH1'
  79. 'ATG10'
  80. 'IL32'
  81. 'SERPINA3'
  82. 'SRC'
  83. 'IGFBP6'
  84. 'IER3'
  85. 'QRFPR'
  86. 'CD276'
  87. 'ITGA9'
  88. 'INHBA'
  89. 'CXCL1'
  90. 'ATG12'
  91. 'ERBB2'
  92. 'FCRLA'
  93. 'EFNB1'
  94. 'IGHG2'
  95. 'SAA1'
  96. 'JUNB'
  97. 'COTL1'
  98. 'CSF1R'
  99. 'TNFAIP6'
  100. 'KIT'
  101. 'CXCR4'
  102. 'RGS1'
  103. 'IGFBP3'
  104. 'NOD2'
  105. 'KRT1'
  106. 'CCL3'
  107. 'CD48'
  108. 'TYK2'
  109. 'TGFB1'
  110. 'CD2'
  111. 'CTSG'
  112. 'CFLAR'
  113. 'IDO1'
  114. 'TIMP1'
  115. 'TGFBR1'
  116. 'BTK'
  117. 'HSPB1'
  118. 'WNT5A'
  119. 'TAP1'
  120. 'CRIP1'
  121. 'ITGA3'
  122. 'CD3E'
  123. 'TGFB2'
  124. 'HLA-DRA'
  125. 'ITGAE'
  126. 'CSF3'
  127. 'COL6A1'
  128. 'IL1RN'
  129. 'CCR7'
  130. 'CD19'
  131. 'VCAN'
  132. 'FAS'
  133. 'EPHB4'
  134. 'TYROBP'
  135. 'KRT14'
  136. 'TACSTD2'
  137. 'JCHAIN'
  138. 'WIF1'
  139. 'ANXA2'
  140. 'CYSTM1'
  141. 'RPL32'
  142. 'CFD'
  143. 'THBS2'
  144. 'IL10RB'
  145. 'CXCL2'
  146. 'GZMH'
  147. 'PECAM1'
  148. 'CCL2'
  149. 'DUSP5'
  150. 'SLC40A1'
  151. 'PTGDR2'
  152. 'ITGB8'
  153. 'SAT1'
  154. 'S100A6'
  155. 'IGFBP7'
  156. 'S100P'
  157. 'IFI27'
  158. 'H4C3'
  159. 'CX3CL1'
  160. 'CALM3'
  161. 'DUSP6'
  162. 'COL6A2'
  163. 'SOX4'
  164. 'KRT19'
  165. 'TPM2'
  166. 'COL1A2'
  167. 'RAC1'
  168. 'RPL21'
  169. 'IL15RA'
  170. 'HMGN2'
  171. 'VEGFA'
  172. 'CDKN1A'
  173. 'COL18A1'
  174. 'SLPI'
  175. 'FLT1'
  176. 'CD9'
  177. 'TNFRSF12A'
  178. 'MIF'
  179. 'YBX3'
  180. 'S100A4'
  181. 'INHA'
  182. 'IGHG1'
  183. 'CLEC12A'
  184. 'NPPC'
  185. 'KRT8'
  186. 'TPSAB1'
  187. 'TUBB'
  188. 'KRT7'
  189. 'CTNNB1'
  190. 'IRF4'
  191. 'SPARCL1'
  192. 'POU5F1'
  193. 'IRF3'
  194. 'MMP7'
  195. 'TNFRSF11B'
  196. 'DDR1'
  197. 'IL1RAP'
  198. 'ITGAM'
  199. 'TWIST1'
  200. 'LDLR'
  201. ⋯
  202. 'CYTOR'
  203. 'RARA'
  204. 'RUNX3'
  205. 'PIGR'
  206. 'RGS2'
  207. 'CDKN3'
  208. 'FZD4'
  209. 'SMO'
  210. 'CD81'
  211. 'PNOC'
  212. 'PLAC8'
  213. 'HLA-DPA1'
  214. 'MXRA8'
  215. 'SNAI1'
  216. 'KLRB1'
  217. 'LUM'
  218. 'ITGB5'
  219. 'LYZ'
  220. 'FFAR3'
  221. 'SOD2'
  222. 'CCR1'
  223. 'WNT10B'
  224. 'RELT'
  225. 'WNT5B'
  226. 'IL12RB2'
  227. 'DUSP2'
  228. 'CD83'
  229. 'HDAC11'
  230. 'IL17RE'
  231. 'COL5A3'
  232. 'WNT7B'
  233. 'IL2RG'
  234. 'APP'
  235. 'CCL4L2'
  236. 'CD68'
  237. 'VIM'
  238. 'H2AZ1'
  239. 'BAX'
  240. 'CD34'
  241. 'CEACAM6'
  242. 'COL9A2'
  243. 'KRT16'
  244. 'FYB1'
  245. 'HSPA1B'
  246. 'DUSP4'
  247. 'CD59'
  248. 'CALM2'
  249. 'HLA-C'
  250. 'IFITM1'
  251. 'MT2A'
  252. 'SMAD2'
  253. 'KRT17'
  254. 'PTK6'
  255. 'SPRY2'
  256. 'IGHM'
  257. 'S100B'
  258. 'TNFSF9'
  259. 'DLL1'
  260. 'CSF1'
  261. 'IL6ST'
  262. 'HDAC4'
  263. 'TOP2A'
  264. 'GAS6'
  265. 'ITGA5'
  266. 'COL5A1'
  267. 'EMP3'
  268. 'EPOR'
  269. 'CHI3L1'
  270. 'PTGDS'
  271. 'RPL37'
  272. 'GPNMB'
  273. 'ETS1'
  274. 'DDC'
  275. 'LGALS1'
  276. 'KRT18'
  277. 'MYL9'
  278. 'ANXA1'
  279. 'BST2'
  280. 'COL4A1'
  281. 'GSN'
  282. 'CD58'
  283. 'CD55'
  284. 'VCAM1'
  285. 'IL12B'
  286. 'RB1'
  287. 'C11orf96'
  288. 'SPINK1'
  289. 'C1QA'
  290. 'ITGAX'
  291. 'JAK1'
  292. 'IL17RB'
  293. 'IFNL3'
  294. 'HLA-DQA1'
  295. 'ETV5'
  296. 'TIGIT'
  297. 'ENTPD1'
  298. 'EPHB3'
  299. 'ICOSLG'
  300. 'CIITA'
  301. 'HBA1'
  302. 'EFNB2'
  303. 'HLA-DRB1'
  304. 'TUBB4B'
  305. 'MAF'
  306. 'SPP1'
  307. 'XCL1'
  308. 'STAT6'
  309. 'COL8A1'
  310. 'LAG3'
  311. 'BMP4'
  312. 'CXCL8'
  313. 'EGFR'
  314. 'FLT3LG'
  315. 'HLA-E'
  316. 'FZD7'
  317. 'OAS3'
  318. 'ICAM2'
  319. 'PDGFA'
  320. 'AREG'
  321. 'IL27RA'
  322. 'GADD45B'
  323. 'HSP90AA1'
  324. 'TPM1'
  325. 'CDH11'
  326. 'PDGFRB'
  327. 'HLA-DPB1'
  328. 'IL1R1'
  329. 'CCL20'
  330. 'NLRC5'
  331. 'LTBR'
  332. 'INSR'
  333. 'IL15'
  334. 'HSP90B1'
  335. 'HSPA1A'
  336. 'BCL2'
  337. 'XBP1'
  338. 'RBPJ'
  339. 'EZH2'
  340. 'EFNA5'
  341. 'FN1'
  342. 'CNTFR'
  343. 'TNFRSF18'
  344. 'COL6A3'
  345. 'ITGB4'
  346. 'IGHD'
  347. 'CD70'
  348. 'MEG3'
  349. 'MAP1LC3B'
  350. 'IL17D'
  351. 'IL20'
  352. 'IL17B'
  353. 'KRT15'
  354. 'RPL22'
  355. 'CCL21'
  356. 'CD24'
  357. 'IL10'
  358. 'BTG1'
  359. 'NFKBIA'
  360. 'PRSS2'
  361. 'CSF2RA'
  362. 'ADIRF'
  363. 'ICOS'
  364. 'KRT6A'
  365. 'FOS'
  366. 'IFNGR2'
  367. 'LGALS3BP'
  368. 'CD69'
  369. 'RELA'
  370. 'CLCF1'
  371. 'FCGR3A'
  372. 'EZR'
  373. 'RAC2'
  374. 'C1QB'
  375. 'PCNA'
  376. 'CD163'
  377. 'ICAM1'
  378. 'JAG1'
  379. 'IL16'
  380. 'PTGES2'
  381. 'HCAR3'
  382. 'BMP1'
  383. 'ENG'
  384. 'CXCL5'
  385. 'ARF1'
  386. 'FFAR2'
  387. 'FZD1'
  388. 'IL17RA'
  389. 'IL1R2'
  390. 'NANOG'
  391. 'FPR1'
  392. 'NR1H2'
  393. 'NOTCH1'
  394. 'CSK'
  395. 'HMGB2'
  396. 'TNFSF14'
  397. 'CCL3L3'
  398. 'VEGFB'
  399. 'ETV4'
  400. 'SOD1'
  401. 'CXCL14'
"hvf" column was found in the feats metadata information and will be
 used to select highly variable features

Setting dimension reduction [cell][rna] pca

Setting dimension reduction [cell][rna] tsne

Setting dimension reduction [cell][rna] umap

As of Giotto 4.2.3 doLeidenCluster() works via {igraph}
 For the python implementation, use doLeidenClusterPython()
 This message appears once per session.

In [10]:
options(repr.plot.width = 11, repr.plot.height = 10)

cosmx@cell_metadata$cell$rna$leiden_clus <- as.character(cosmx@cell_metadata$cell$rna$leiden_clus)
SpatDimPlot(
    cosmx,
    image = TRUE,  # use all fovs
    group_by = "leiden_clus",
    points_size = 1
)
No description has been provided for this image
In [11]:
# Small Subset Visualization

options(repr.plot.width = 13, repr.plot.height = 6)

#subset a Giotto object based on spatial locations
smallfov <- subsetGiottoLocs(cosmx,
    x_max = 3000,
    x_min = 1000,
    y_max = -157800,
    y_min = -159800
)

#extract all genes observed in new object
smallfeats <- fDataDT(smallfov)[, feat_ID]

#plot all genes
ext <- c(900, 3100, -159900, -157700)
p1 <- SpatDimPlot(
    smallfov,
    image = "composite_fov002",
    ext = ext,
    shapes = TRUE,
    features = smallfeats,
    points_size = 0.1,
    shapes_border_size = 0.1,
    shapes_border_color = "white",
    legend.position = "none"
)
p2 <- SpatDimPlot(
    smallfov,
    image = "composite_fov002",
    ext = ext,
    shapes = TRUE,
    points_size = 0.1,
    shapes_border_size = 0.1,
    shapes_border_color = "white",
    shapes_alpha = 0
)
p1 + p2
No description has been provided for this image
In [12]:
options(repr.plot.width = 7, repr.plot.height = 6)

SpatDimPlot(
    smallfov,
    image = "composite_fov002",
    ext = ext,
    shapes = TRUE,
    points_size = 0.1,
    shapes_fill_by = "leiden_clus",
    shapes_border_size = 0.1,
    shapes_border_color = "white"
)
No description has been provided for this image
In [13]:
# create spatial network based on physical distance of cell centroids
cosmx <- createSpatialNetwork(cosmx,
    minimum_k = 2,
    maximum_distance_delaunay = 50
)

# perform Binary Spatial Extraction of genes - NOTE: Depending on your system this could take time
km_spatialfeats <- binSpect(cosmx)
Setting spatial network [cell] Delaunay_network

This is the single parameter version of binSpect

1. matrix binarization complete

2. spatial enrichment test completed

3. (optional) average expression of high
 expressing cells calculated

4. (optional) number of high expressing cells
 calculated

In [14]:
options(repr.plot.width = 14, repr.plot.height = 20)

SpatFeaturePlot(
    cosmx,
    features = km_spatialfeats$feats[1:10],
    points_border_size = 0.01,
    points_size = 0.01,
    facet_ncol = 3,
    padding = 0
)
No description has been provided for this image
In [15]:
options(repr.plot.width = 11, repr.plot.height = 10)

SpatFeaturePlot(
    cosmx,
    image = "black",
    features = "Mean.CD3",
    upper_cutoff = 300,
    palette = "Sunset",
    ## plotthis renamed this argument from palette_reverse to palreverse
    palreverse = TRUE
)
No description has been provided for this image
In [16]:
options(repr.plot.width = 11, repr.plot.height = 10)

SpatFeaturePlot(
    cosmx,
    image = "black",
    features = "Mean.PanCK",
    upper_cutoff = 3e4,
    palette = "Sunset",
    palreverse = TRUE
)
No description has been provided for this image
In [17]:
x <- sessionInfo()
x <- capture.output(print(x))
# hide the BLAS/LAPACK paths
x <- x[!startsWith(x, "BLAS/LAPACK:")]
cat(paste(x, collapse = "\n"))
Warning message in system("timedatectl", intern = TRUE):
“running command 'timedatectl' had status 1”
R version 4.5.1 (2025-06-13)
Platform: x86_64-pc-linux-gnu
Running under: Rocky Linux 8.10 (Green Obsidian)

Matrix products: default
BLAS:   /usr/lib64/libblas.so.3.8.0 
LAPACK: /usr/lib64/liblapack.so.3.8.0  LAPACK version 3.8.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

time zone: UTC
tzcode source: system (glibc)

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] scplotter_0.8.2   testthat_3.3.2    Giotto_4.2.3      GiottoClass_0.5.1

loaded via a namespace (and not attached):
  [1] fs_2.1.0                    matrixStats_1.5.0          
  [3] spatstat.sparse_3.2-0       sf_1.1-2                   
  [5] devtools_2.5.2              httr_1.4.9                 
  [7] RColorBrewer_1.1-3          repr_1.1.7                 
  [9] tools_4.5.1                 sctransform_0.4.3          
 [11] backports_1.5.1             R6_2.6.1                   
 [13] uwot_0.2.5                  withr_3.0.3                
 [15] sp_2.2-3                    gridExtra_2.3.1            
 [17] GiottoUtils_0.2.9           progressr_1.0.0            
 [19] quantreg_6.1                cli_3.6.6                  
 [21] Biobase_2.70.0              textshaping_1.0.5          
 [23] Cairo_1.7-0                 spatstat.explore_3.8-2     
 [25] fastDummies_1.7.6           iNEXT_3.0.2                
 [27] labeling_0.4.3              Seurat_5.5.1               
 [29] arrow_25.0.1                S7_0.2.2                   
 [31] spatstat.data_3.1-9         proxy_0.4-29               
 [33] ggridges_0.5.7              pbapply_1.7-5              
 [35] systemfonts_1.3.2           pbdZMQ_0.3-14              
 [37] dbscan_1.2.6                R.utils_2.13.0             
 [39] stringdist_0.9.17           dichromat_2.0-1            
 [41] parallelly_1.48.0           sessioninfo_1.2.4          
 [43] VGAM_1.1-14                 rstudioapi_0.19.0          
 [45] generics_0.1.4              shape_1.4.6.1              
 [47] gtools_3.9.5                ica_1.0-3                  
 [49] spatstat.random_3.5-1       dplyr_1.2.1                
 [51] Matrix_1.7-6                S4Vectors_0.48.1           
 [53] abind_1.4-8                 R.methodsS3_1.8.2          
 [55] terra_1.9-1                 lifecycle_1.0.5            
 [57] SummarizedExperiment_1.40.0 SparseArray_1.10.10        
 [59] Rtsne_0.17                  grid_4.5.1                 
 [61] promises_1.5.0              crayon_1.5.3               
 [63] miniUI_0.1.2                lattice_0.23-1             
 [65] beachmat_2.26.0             cowplot_1.2.0              
 [67] magick_2.9.1                pillar_1.11.1              
 [69] GenomicRanges_1.62.1        rjson_0.2.23               
 [71] future.apply_1.20.2         codetools_0.2-20           
 [73] glue_1.8.1                  getPass_0.2-4              
 [75] spatstat.univar_3.2-0       data.table_1.18.6.1        
 [77] vctrs_0.7.3                 png_0.1-9                  
 [79] spam_2.11-4                 gtable_0.3.6               
 [81] assertthat_0.2.1            cachem_1.1.0               
 [83] S4Arrays_1.10.1             mime_0.13                  
 [85] tidygraph_1.3.1             Seqinfo_1.0.0              
 [87] survival_3.8-12             SingleCellExperiment_1.32.0
 [89] units_1.0-1                 bluster_1.20.0             
 [91] ellipsis_0.3.3              scRepertoire_2.2.1         
 [93] fitdistrplus_1.2-6          ROCR_1.0-12                
 [95] nlme_3.1-171                usethis_3.2.1              
 [97] bit64_4.8.6                 RcppAnnoy_0.0.23           
 [99] evd_2.3-7.1                 rprojroot_2.1.1            
[101] irlba_2.3.7                 KernSmooth_2.23-27         
[103] otel_0.2.0                  DBI_1.3.0                  
[105] plotthis_0.14.1             colorspace_2.1-3           
[107] BiocGenerics_0.56.0         tidyselect_1.2.1           
[109] bit_4.6.0                   compiler_4.5.1             
[111] BiocNeighbors_2.4.0         SparseM_1.84-2             
[113] xml2_1.6.0                  desc_1.4.3                 
[115] ggdendro_0.2.0              DelayedArray_0.36.1        
[117] plotly_4.12.1               checkmate_2.3.4            
[119] scales_1.4.0                classInt_0.4-11            
[121] lmtest_0.9-40               rappdirs_0.3.4             
[123] goftest_1.2-3               stringr_1.6.0              
[125] SpatialExperiment_1.20.0    digest_0.6.39              
[127] spatstat.utils_3.2-4        XVector_0.50.0             
[129] htmltools_0.5.9             GiottoVisuals_0.2.15.1     
[131] pkgconfig_2.0.3             base64enc_0.1-6            
[133] MatrixGenerics_1.22.0       fastmap_1.2.0              
[135] rlang_1.3.0                 GlobalOptions_0.1.4        
[137] htmlwidgets_1.6.4           shiny_1.14.0               
[139] farver_2.1.2                zoo_1.9-0                  
[141] jsonlite_2.0.0              BiocParallel_1.44.0        
[143] R.oo_1.27.1                 BiocSingular_1.26.1        
[145] magrittr_2.0.5              dotCall64_1.2              
[147] patchwork_1.3.2             IRkernel_1.3.2             
[149] Rcpp_1.1.2                  evmix_2.12                 
[151] ggnewscale_0.5.2            viridis_0.6.5              
[153] reticulate_1.47.0           truncdist_1.0-2            
[155] stringi_1.8.9               ggalluvial_0.12.6          
[157] ggraph_2.2.2                brio_1.1.5                 
[159] MASS_7.3-66                 plyr_1.8.9                 
[161] pkgbuild_1.4.8              parallel_4.5.1             
[163] listenv_1.0.0               ggrepel_0.9.8              
[165] forcats_1.0.1               deldir_2.0-4               
[167] graphlayouts_1.2.5          IRdisplay_1.1              
[169] splines_4.5.1               gridtext_0.1.6             
[171] tensor_1.5.1                circlize_0.4.18            
[173] colorRamp2_0.1.1            igraph_2.3.3               
[175] uuid_1.2-2                  spatstat.geom_3.8-2        
[177] cubature_2.1.4-1            RcppHNSW_0.7.0             
[179] ScaledMatrix_1.18.0         reshape2_1.4.5             
[181] stats4_4.5.1                pkgload_1.5.3              
[183] evaluate_1.0.5              SeuratObject_5.4.0         
[185] tweenr_2.0.3                httpuv_1.6.17              
[187] MatrixModels_0.5-4          RANN_2.6.3                 
[189] tidyr_1.3.2                 purrr_1.2.2                
[191] polyclip_1.10-7             future_1.75.0              
[193] scattermore_1.2             ggplot2_4.0.3              
[195] ggforce_0.5.0               rsvd_1.0.5                 
[197] xtable_1.8-8                e1071_1.7-17               
[199] RSpectra_0.16-2             later_1.4.8                
[201] class_7.3-24                viridisLite_0.4.3          
[203] ragg_1.5.2                  gsl_2.1-9                  
[205] tibble_3.3.1                memoise_2.0.1              
[207] IRanges_2.44.0              cluster_2.1.8.3            
[209] globals_0.19.1