参考的代码:
# Check presence of rows with cell_id of 0
cells_0 <- grep("_0$", rownames(exprMat), value = TRUE)
# Check presence of Negative and SystemControl probes columns
negPrb_col <- grep("^Neg", colnames(exprMat), value = TRUE) # Neg columns
sysCon_col <- grep("^SystemControl", colnames(exprMat), value = TRUE) # SystemControl columns
# Show head expression matrix
as.matrix(exprMat[1:6, 1:10])
Chrna4 Slc6a1 Cd109 Ldha Aldoc Drd1 Tank Rit2 Prkag2 Lpar3
c_1_1_0 9 58 11 30 938 6 28 20 15 2
c_1_1_1 0 0 0 0 0 0 0 0 0 0
c_1_1_2 0 0 0 0 0 0 0 0 1 0
c_1_1_3 5 1 0 1 2 0 0 0 0 0
c_1_1_4 1 1 0 1 0 0 0 2 1 0
c_1_1_5 0 0 0 2 2 0 0 0 0 0
但是我用exprMat <- read.csv("Run5961_PDAC_Slide1_exprMat_file.csv", header = TRUE)
得到的结果与参考代码不同
R version 4.4.3 (2025-02-28) -- "Trophy Case"
Copyright (C) 2025 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu
R是自由软件,不附带任何担保。
在某些条件下你可以将其自由分发。
用'license()'或'licence()'来看分发的详细条件。
R是个合作计划,有许多人为之做出了贡献.
用'contributors()'来看合著者的详细情况
用'citation()'会告诉你如何在出版物中正确地引用R或R程序包。
用'demo()'来看一些示例程序,用'help()'来阅读在线帮助文件,或
用'help.start()'通过HTML浏览器来看帮助文件。
输入'q()'退出R.
> setwd("/data1/firefox")
> BiocManager::install("NanoStringNCTtools")
'getOption("repos")' replaces Bioconductor standard repositories, see
'help("repositories", package = "BiocManager")' for details.
Replacement repositories:
CRAN: https://cloud.r-project.org
Bioconductor version 3.20 (BiocManager 1.30.25), R 4.4.3 (2025-02-28)
Installing package(s) 'NanoStringNCTtools'
Installation paths not writeable, unable to update packages
path: /usr/lib/R/library
packages:
boot, codetools, foreign, lattice, Matrix, mgcv, nlme, spatial
Old packages: 'aplot', 'BiocManager', 'BiocParallel', 'bookdown', 'broom', 'Cairo',
'checkmate', 'cli', 'collections', 'colorspace', 'cols4all', 'commonmark',
'cowplot', 'credentials', 'crosstalk', 'curl', 'data.table', 'data.tree',
'dbplyr', 'dbscan', 'Deriv', 'diffobj', 'doBy', 'DT', 'dtplyr', 'evaluate',
'fastcluster', 'fields', 'fitdistrplus', 'forcats', 'fs', 'future',
'future.apply', 'gargle', 'generics', 'ggforce', 'ggfun', 'ggnetwork',
'ggnewscale', 'ggplot2', 'ggplotify', 'ggpubr', 'ggraph', 'ggridges', 'ggsci',
'ggtangle', 'gh', 'globals', 'googledrive', 'googlesheets4', 'haven', 'here',
'httpuv', 'httr2', 'igraph', 'later', 'logger', 'magick', 'magrittr', 'maps',
'miniUI', 'mockr', 'modeltools', 'msigdbr', 'nanoarrow', 'openssl', 'parallelly',
'patchwork', 'pbapply', 'pbkrtest', 'pheatmap', 'pillar', 'pkgbuild', 'pkgdown',
'pkgload', 'plotly', 'progressr', 'promises', 'ps', 'psych', 'purrr', 'R.cache',
'R.oo', 'ragg', 'Rcpp', 'RcppArmadillo', 'RcppParallel', 'reformulas',
'ResidualMatrix', 'restfulr', 'reticulate', 'rlang', 'roxygen2', 'rprojroot',
'rsample', 'RSQLite', 'RUnit', 'rvest', 's2', 'sass', 'scales', 'scatterpie',
'SCpubr', 'sctransform', 'SeuratObject', 'sf', 'shiny', 'spacesXYZ', 'spatstat',
'spatstat.data', 'spatstat.explore', 'spatstat.geom', 'spatstat.linnet',
'spatstat.model', 'spatstat.random', 'spatstat.univar', 'spatstat.utils', 'spdep',
'stringr', 'survminer', 'svglite', 'systemfonts', 'tensor', 'terra',
'textshaping', 'TH.data', 'tibble', 'tinytex', 'usethis', 'utf8', 'V8', 'vroom',
'waldo', 'xfun', 'xgboost', 'XML', 'xml2', 'yulab.utils', 'zip', 'zoo'
Update all/some/none? [a/s/n]:
n
警告信息:
package ‘NanoStringNCTtools’ is not available for Bioconductor version '3.20'
A version of this package for your version of R might be available elsewhere,
see the ideas at
https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages
> BiocManager::install("NanoStringNCTools")
'getOption("repos")' replaces Bioconductor standard repositories, see
'help("repositories", package = "BiocManager")' for details.
Replacement repositories:
CRAN: https://cloud.r-project.org
Bioconductor version 3.20 (BiocManager 1.30.25), R 4.4.3 (2025-02-28)
Installing package(s) 'NanoStringNCTools'
还安装依赖关系‘S7’, ‘scales’, ‘ggplot2’, ‘ggiraph’, ‘ggthemes’
试开URL’https://cloud.r-project.org/src/contrib/S7_0.2.0.tar.gz'
Content type 'application/x-gzip' length 183153 bytes (178 KB)
==================================================
downloaded 178 KB
试开URL’https://cloud.r-project.org/src/contrib/scales_1.4.0.tar.gz'
Content type 'application/x-gzip' length 328671 bytes (320 KB)
==================================================
downloaded 320 KB
试开URL’https://cloud.r-project.org/src/contrib/ggplot2_4.0.0.tar.gz'
Content type 'application/x-gzip' length 3810397 bytes (3.6 MB)
==================================================
downloaded 3.6 MB
试开URL’https://cloud.r-project.org/src/contrib/ggiraph_0.9.1.tar.gz'
Content type 'application/x-gzip' length 392782 bytes (383 KB)
==================================================
downloaded 383 KB
试开URL’https://cloud.r-project.org/src/contrib/ggthemes_5.1.0.tar.gz'
Content type 'application/x-gzip' length 493992 bytes (482 KB)
==================================================
downloaded 482 KB
试开URL’https://bioconductor.org/packages/3.20/bioc/src/contrib/NanoStringNCTools_1.14.0.tar.gz'
Content type 'application/gzip' length 382477 bytes (373 KB)
==================================================
downloaded 373 KB
* installing *source* package ‘S7’ ...
** 成功将‘S7’程序包解包并MD5和检查
** using staged installation
** libs
using C compiler: ‘gcc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0’
gcc -I"/usr/share/R/include" -DNDEBUG -fpic -g -O2 -fdebug-prefix-map=/build/r-base-0GHeEU/r-base-4.4.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -c init.c -o init.o
gcc -I"/usr/share/R/include" -DNDEBUG -fpic -g -O2 -fdebug-prefix-map=/build/r-base-0GHeEU/r-base-4.4.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -c method-dispatch.c -o method-dispatch.o
gcc -I"/usr/share/R/include" -DNDEBUG -fpic -g -O2 -fdebug-prefix-map=/build/r-base-0GHeEU/r-base-4.4.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -c prop.c -o prop.o
gcc -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o S7.so init.o method-dispatch.o prop.o -L/usr/lib/R/lib -lR
installing to /home/user/R/x86_64-pc-linux-gnu-library/4.4/00LOCK-S7/00new/S7/libs
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
** checking absolute paths in shared objects and dynamic libraries
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (S7)
* installing *source* package ‘scales’ ...
** 成功将‘scales’程序包解包并MD5和检查
** using staged installation
** R
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
*** copying figures
** building package indices
** testing if installed package can be loaded from temporary location
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (scales)
* installing *source* package ‘ggplot2’ ...
** 成功将‘ggplot2’程序包解包并MD5和检查
** using staged installation
** R
** data
*** moving datasets to lazyload DB
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
*** copying figures
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (ggplot2)
* installing *source* package ‘ggiraph’ ...
** 成功将‘ggiraph’程序包解包并MD5和检查
** using staged installation
** libs
using C++ compiler: ‘g++ (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0’
g++ -std=gnu++17 -I"/usr/share/R/include" -DNDEBUG -I'/home/user/R/x86_64-pc-linux-gnu-library/4.4/Rcpp/include' -I'/home/user/R/x86_64-pc-linux-gnu-library/4.4/systemfonts/include' -fpic -g -O2 -fdebug-prefix-map=/build/r-base-0GHeEU/r-base-4.4.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -c RcppExports.cpp -o RcppExports.o
g++ -std=gnu++17 -I"/usr/share/R/include" -DNDEBUG -I'/home/user/R/x86_64-pc-linux-gnu-library/4.4/Rcpp/include' -I'/home/user/R/x86_64-pc-linux-gnu-library/4.4/systemfonts/include' -fpic -g -O2 -fdebug-prefix-map=/build/r-base-0GHeEU/r-base-4.4.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -c a_color.cpp -o a_color.o
g++ -std=gnu++17 -I"/usr/share/R/include" -DNDEBUG -I'/home/user/R/x86_64-pc-linux-gnu-library/4.4/Rcpp/include' -I'/home/user/R/x86_64-pc-linux-gnu-library/4.4/systemfonts/include' -fpic -g -O2 -fdebug-prefix-map=/build/r-base-0GHeEU/r-base-4.4.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -c clip.cpp -o clip.o
g++ -std=gnu++17 -I"/usr/share/R/include" -DNDEBUG -I'/home/user/R/x86_64-pc-linux-gnu-library/4.4/Rcpp/include' -I'/home/user/R/x86_64-pc-linux-gnu-library/4.4/systemfonts/include' -fpic -g -O2 -fdebug-prefix-map=/build/r-base-0GHeEU/r-base-4.4.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -c dsvg.cpp -o dsvg.o
g++ -std=gnu++17 -I"/usr/share/R/include" -DNDEBUG -I'/home/user/R/x86_64-pc-linux-gnu-library/4.4/Rcpp/include' -I'/home/user/R/x86_64-pc-linux-gnu-library/4.4/systemfonts/include' -fpic -g -O2 -fdebug-prefix-map=/build/r-base-0GHeEU/r-base-4.4.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -c dsvg_dev.cpp -o dsvg_dev.o
g++ -std=gnu++17 -I"/usr/share/R/include" -DNDEBUG -I'/home/user/R/x86_64-pc-linux-gnu-library/4.4/Rcpp/include' -I'/home/user/R/x86_64-pc-linux-gnu-library/4.4/systemfonts/include' -fpic -g -O2 -fdebug-prefix-map=/build/r-base-0GHeEU/r-base-4.4.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -c geom.cpp -o geom.o
g++ -std=gnu++17 -I"/usr/share/R/include" -DNDEBUG -I'/home/user/R/x86_64-pc-linux-gnu-library/4.4/Rcpp/include' -I'/home/user/R/x86_64-pc-linux-gnu-library/4.4/systemfonts/include' -fpic -g -O2 -fdebug-prefix-map=/build/r-base-0GHeEU/r-base-4.4.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -c indexed.cpp -o indexed.o
g++ -std=gnu++17 -I"/usr/share/R/include" -DNDEBUG -I'/home/user/R/x86_64-pc-linux-gnu-library/4.4/Rcpp/include' -I'/home/user/R/x86_64-pc-linux-gnu-library/4.4/systemfonts/include' -fpic -g -O2 -fdebug-prefix-map=/build/r-base-0GHeEU/r-base-4.4.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -c interactive.cpp -o interactive.o
g++ -std=gnu++17 -I"/usr/share/R/include" -DNDEBUG -I'/home/user/R/x86_64-pc-linux-gnu-library/4.4/Rcpp/include' -I'/home/user/R/x86_64-pc-linux-gnu-library/4.4/systemfonts/include' -fpic -g -O2 -fdebug-prefix-map=/build/r-base-0GHeEU/r-base-4.4.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -c mask.cpp -o mask.o
g++ -std=gnu++17 -I"/usr/share/R/include" -DNDEBUG -I'/home/user/R/x86_64-pc-linux-gnu-library/4.4/Rcpp/include' -I'/home/user/R/x86_64-pc-linux-gnu-library/4.4/systemfonts/include' -fpic -g -O2 -fdebug-prefix-map=/build/r-base-0GHeEU/r-base-4.4.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -c pattern.cpp -o pattern.o
g++ -std=gnu++17 -I"/usr/share/R/include" -DNDEBUG -I'/home/user/R/x86_64-pc-linux-gnu-library/4.4/Rcpp/include' -I'/home/user/R/x86_64-pc-linux-gnu-library/4.4/systemfonts/include' -fpic -g -O2 -fdebug-prefix-map=/build/r-base-0GHeEU/r-base-4.4.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -c raster.cpp -o raster.o
g++ -std=gnu++17 -I"/usr/share/R/include" -DNDEBUG -I'/home/user/R/x86_64-pc-linux-gnu-library/4.4/Rcpp/include' -I'/home/user/R/x86_64-pc-linux-gnu-library/4.4/systemfonts/include' -fpic -g -O2 -fdebug-prefix-map=/build/r-base-0GHeEU/r-base-4.4.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -c shapes.cpp -o shapes.o
g++ -std=gnu++17 -I"/usr/share/R/include" -DNDEBUG -I'/home/user/R/x86_64-pc-linux-gnu-library/4.4/Rcpp/include' -I'/home/user/R/x86_64-pc-linux-gnu-library/4.4/systemfonts/include' -fpic -g -O2 -fdebug-prefix-map=/build/r-base-0GHeEU/r-base-4.4.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -c svg.cpp -o svg.o
g++ -std=gnu++17 -I"/usr/share/R/include" -DNDEBUG -I'/home/user/R/x86_64-pc-linux-gnu-library/4.4/Rcpp/include' -I'/home/user/R/x86_64-pc-linux-gnu-library/4.4/systemfonts/include' -fpic -g -O2 -fdebug-prefix-map=/build/r-base-0GHeEU/r-base-4.4.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -c text.cpp -o text.o
g++ -std=gnu++17 -I"/usr/share/R/include" -DNDEBUG -I'/home/user/R/x86_64-pc-linux-gnu-library/4.4/Rcpp/include' -I'/home/user/R/x86_64-pc-linux-gnu-library/4.4/systemfonts/include' -fpic -g -O2 -fdebug-prefix-map=/build/r-base-0GHeEU/r-base-4.4.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -c tinyxml2.cpp -o tinyxml2.o
g++ -std=gnu++17 -I"/usr/share/R/include" -DNDEBUG -I'/home/user/R/x86_64-pc-linux-gnu-library/4.4/Rcpp/include' -I'/home/user/R/x86_64-pc-linux-gnu-library/4.4/systemfonts/include' -fpic -g -O2 -fdebug-prefix-map=/build/r-base-0GHeEU/r-base-4.4.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -c utils.cpp -o utils.o
g++ -std=gnu++17 -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o ggiraph.so RcppExports.o a_color.o clip.o dsvg.o dsvg_dev.o geom.o indexed.o interactive.o mask.o pattern.o raster.o shapes.o svg.o text.o tinyxml2.o utils.o -lpng -lz -L/usr/lib/R/lib -lR
installing to /home/user/R/x86_64-pc-linux-gnu-library/4.4/00LOCK-ggiraph/00new/ggiraph/libs
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
*** copying figures
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
** checking absolute paths in shared objects and dynamic libraries
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (ggiraph)
* installing *source* package ‘ggthemes’ ...
** 成功将‘ggthemes’程序包解包并MD5和检查
** using staged installation
** R
** data
*** moving datasets to lazyload DB
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded from temporary location
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (ggthemes)
* installing *source* package ‘NanoStringNCTools’ ...
** 成功将‘NanoStringNCTools’程序包解包并MD5和检查
** using staged installation
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (NanoStringNCTools)
下载的程序包在
‘/tmp/Rtmp5RH1TC/downloaded_packages’里
Installation paths not writeable, unable to update packages
path: /usr/lib/R/library
packages:
boot, codetools, foreign, lattice, Matrix, mgcv, nlme, spatial
Old packages: 'aplot', 'BiocManager', 'BiocParallel', 'bookdown', 'broom', 'Cairo',
'checkmate', 'cli', 'collections', 'colorspace', 'cols4all', 'commonmark',
'cowplot', 'credentials', 'crosstalk', 'curl', 'data.table', 'data.tree',
'dbplyr', 'dbscan', 'Deriv', 'diffobj', 'doBy', 'DT', 'dtplyr', 'evaluate',
'fastcluster', 'fields', 'fitdistrplus', 'forcats', 'fs', 'future',
'future.apply', 'gargle', 'generics', 'ggforce', 'ggfun', 'ggnetwork',
'ggnewscale', 'ggplotify', 'ggpubr', 'ggraph', 'ggridges', 'ggsci', 'ggtangle',
'gh', 'globals', 'googledrive', 'googlesheets4', 'haven', 'here', 'httpuv',
'httr2', 'igraph', 'later', 'logger', 'magick', 'magrittr', 'maps', 'miniUI',
'mockr', 'modeltools', 'msigdbr', 'nanoarrow', 'openssl', 'parallelly',
'patchwork', 'pbapply', 'pbkrtest', 'pheatmap', 'pillar', 'pkgbuild', 'pkgdown',
'pkgload', 'plotly', 'progressr', 'promises', 'ps', 'psych', 'purrr', 'R.cache',
'R.oo', 'ragg', 'Rcpp', 'RcppArmadillo', 'RcppParallel', 'reformulas',
'ResidualMatrix', 'restfulr', 'reticulate', 'rlang', 'roxygen2', 'rprojroot',
'rsample', 'RSQLite', 'RUnit', 'rvest', 's2', 'sass', 'scatterpie', 'SCpubr',
'sctransform', 'SeuratObject', 'sf', 'shiny', 'spacesXYZ', 'spatstat',
'spatstat.data', 'spatstat.explore', 'spatstat.geom', 'spatstat.linnet',
'spatstat.model', 'spatstat.random', 'spatstat.univar', 'spatstat.utils', 'spdep',
'stringr', 'survminer', 'svglite', 'systemfonts', 'tensor', 'terra',
'textshaping', 'TH.data', 'tibble', 'tinytex', 'usethis', 'utf8', 'V8', 'vroom',
'waldo', 'xfun', 'xgboost', 'XML', 'xml2', 'yulab.utils', 'zip', 'zoo'
Update all/some/none? [a/s/n]:
n
> library(NanoStringNCTools)
载入需要的程序包:Biobase
载入需要的程序包:BiocGenerics
载入程序包:‘BiocGenerics’
The following objects are masked from ‘package:stats’:
IQR, mad, sd, var, xtabs
The following objects are masked from ‘package:base’:
anyDuplicated, aperm, append, as.data.frame, basename, cbind, colnames,
dirname, do.call, duplicated, eval, evalq, Filter, Find, get, grep,
grepl, intersect, is.unsorted, lapply, Map, mapply, match, mget, order,
paste, pmax, pmax.int, pmin, pmin.int, Position, rank, rbind, Reduce,
rownames, sapply, saveRDS, setdiff, table, tapply, union, unique,
unsplit, which.max, which.min
Welcome to Bioconductor
Vignettes contain introductory material; view with 'browseVignettes()'.
To cite Bioconductor, see 'citation("Biobase")', and for packages
'citation("pkgname")'.
载入需要的程序包:S4Vectors
载入需要的程序包:stats4
载入程序包:‘S4Vectors’
The following object is masked from ‘package:utils’:
findMatches
The following objects are masked from ‘package:base’:
expand.grid, I, unname
载入需要的程序包:ggplot2
> library(Seurat)
载入需要的程序包:SeuratObject
载入需要的程序包:sp
载入程序包:‘SeuratObject’
The following object is masked from ‘package:S4Vectors’:
intersect
The following object is masked from ‘package:BiocGenerics’:
intersect
The following objects are masked from ‘package:base’:
intersect, t
> slide1_obj <- ReadNanostring(
+ data.dir = ".",
+ mtx.file = "GSE277782_Run5961_PDAC_Slide1_exprMat_file.csv.gz",
+ metadata.file = "GSE277782_Run5961_PDAC_Slide1_metadata_file.csv.gz",
+ segmentations.file = "GSE277782_Run5961_PDAC_Slide1-polygons.csv.gz",
+ fov.file = "GSE277782_Run5961_PDAC_Slide1_fov_positions_file.csv.gz",
+ assay = "Spatial"
+ )
错误于ReadNanostring(data.dir = ".", mtx.file = "GSE277782_Run5961_PDAC_Slide1_exprMat_file.csv.gz", :
参数没有用(fov.file = "GSE277782_Run5961_PDAC_Slide1_fov_positions_file.csv.gz", assay = "Spatial")
> slide1_obj <- ReadNanostring(
+ data.dir = ".",
+ mtx.file = "GSE277782_Run5961_PDAC_Slide1_exprMat_file.csv.gz",
+ metadata.file = "GSE277782_Run5961_PDAC_Slide1_metadata_file.csv.gz",
+ segmentations.file = "GSE277782_Run5961_PDAC_Slide1-polygons.csv.gz"
+ )
错误于ReadNanostring(data.dir = ".", mtx.file = "GSE277782_Run5961_PDAC_Slide1_exprMat_file.csv.gz", :
找不到对象'mx'
> slide1_obj <- ReadNanostring(
+ data.dir = "/data1/firefox",
+ mtx.file = "GSE277782_Run5961_PDAC_Slide1_exprMat_file.csv.gz",
+ metadata.file = "GSE277782_Run5961_PDAC_Slide1_metadata_file.csv.gz",
+ segmentations.file = "GSE277782_Run5961_PDAC_Slide1-polygons.csv.gz"
+ )
错误于ReadNanostring(data.dir = "/data1/firefox", mtx.file = "GSE277782_Run5961_PDAC_Slide1_exprMat_file.csv.gz", :
找不到对象'mx'
> required_files <- c(
+ mtx = "GSE277782_Run5961_PDAC_Slide1_exprMat_file.csv.gz",
+ metadata = "GSE277782_Run5961_PDAC_Slide1_metadata_file.csv.gz",
+ segmentations = "GSE277782_Run5961_PDAC_Slide1-polygons.csv.gz"
+ )
> file_check <- sapply(required_files, function(file) {
+ file.exists(file)
+ })
> if (all(file_check)) {
+ cat("✅ 所有必要文件均存在\n")
+ } else {
+ missing_files <- names(file_check)[!file_check]
+ cat("❌ 缺失以下必要文件:\n")
+ cat(paste("-", missing_files, "\n", sep=""))
+ stop("请先确保所有文件存在于指定目录")
+ }
✅ 所有必要文件均存在
> # 检查表达矩阵格式(前5行5列)
> cat("\n=== 验证表达矩阵格式 ===\n")
=== 验证表达矩阵格式 ===
> tryCatch({
+ mtx_sample <- read.csv(required_files["mtx"], nrows=5, header=TRUE)
+ cat("表达矩阵前5行5列预览:\n")
+ print(head(mtx_sample[, 1:5]))
+ if (!is.numeric(as.matrix(mtx_sample[, -1]))) {
+ stop("表达矩阵包含非数值数据")
+ }
+ cat("✅ 表达矩阵格式验证通过\n")
+ }, error = function(e) {
+ cat("❌ 表达矩阵格式错误:", e$message, "\n")
+ stop("请检查表达矩阵文件格式")
+ })
表达矩阵前5行5列预览:
fov cell_ID RAMP2 CD83 RYK
1 1 0 13 59 36
2 1 1 0 0 1
3 1 2 0 0 0
4 1 3 1 0 0
5 1 4 0 0 0
✅ 表达矩阵格式验证通过
> # -----------------------------
> # 步骤2:使用修正参数调用ReadNanostring
> # -----------------------------
> cat("\n=== 尝试加载数据 ===\n")
=== 尝试加载数据 ===
> if (!requireNamespace("NanoStringNCTools", quietly=TRUE)) {
+ stop("NanoStringNCTools包未安装")
+ }
> library(NanoStringNCTools)
> library(Seurat)
> # 尝试使用基础参数加载(避免可能的内部变量冲突)
> tryCatch({
+ # 仅使用必要参数,避免复杂参数组合
+ slide1_obj <- ReadNanostring(
+ data.dir = data_dir,
+ mtx.file = required_files["mtx"],
+ metadata.file = required_files["metadata"],
+ segmentations.file = required_files["segmentations"],
+ verbose = TRUE # 输出详细过程信息
+ )
+ cat("✅ 数据加载成功\n")
+ }, error = function(e) {
+ cat("❌ ReadNanostring调用失败:", e$message, "\n")
+
+ # -----------------------------
+ # 备选方案:手动构建Seurat对象
+ # -----------------------------
+ cat("\n=== 尝试备选方案:手动构建Seurat对象 ===\n")
+
+ # 1. 读取表达矩阵
+ cat("读取表达矩阵...\n")
+ expr_matrix <- read.csv(required_files["mtx"], row.names=1) %>% as.matrix()
+
+ # 2. 读取元数据
+ cat("读取元数据...\n")
+ metadata <- read.csv(required_files["metadata"], row.names=1)
+
+ # 3. 读取空间坐标(从segmentations文件)
+ cat("读取空间坐标...\n")
+ segmentations <- read.csv(required_files["segmentations"])
+ coords <- segmentations %>%
+ select(cell_id, x, y) %>% # 根据实际列名调整
+ column_to_rownames("cell_id")
+
+ # 4. 创建Seurat对象
+ cat("创建Seurat对象...\n")
+ seurat_obj <- CreateSeuratObject(
+ counts = expr_matrix,
+ meta.data = metadata
+ )
+
+ # 5. 添加空间坐标
+ if (nrow(coords) > 0) {
+ seurat_obj@images$image <- new(
+ Class = "SpatialImage",
+ assay = "RNA",
+ coordinates = coords[colnames(seurat_obj), ]
+ )
+ cat("✅ 已添加空间坐标信息\n")
+ }
+
+ # 6. 保存结果
+ saveRDS(seurat_obj, "manual_seurat_object.rds")
+ cat("✅ 备选方案成功:手动创建的Seurat对象已保存为manual_seurat_object.rds\n")
+ cat("请使用以下代码加载:\n")
+ cat("seurat_obj <- readRDS('manual_seurat_object.rds')\n")
+ })
❌ ReadNanostring调用失败: 参数没有用(verbose = TRUE)
=== 尝试备选方案:手动构建Seurat对象 ===
读取表达矩阵...
错误于read.csv(required_files["mtx"], row.names = 1) %>% as.matrix():
没有"%>%"这个函数
Called from: value[[3L]](cond)
Browse[1]> Q
> library(dplyr)
载入程序包:‘dplyr’
The following object is masked from ‘package:NanoStringNCTools’:
groups
The following objects are masked from ‘package:S4Vectors’:
first, intersect, rename, setdiff, setequal, union
The following object is masked from ‘package:Biobase’:
combine
The following objects are masked from ‘package:BiocGenerics’:
combine, intersect, setdiff, union
The following objects are masked from ‘package:stats’:
filter, lag
The following objects are masked from ‘package:base’:
intersect, setdiff, setequal, union
> # 尝试使用基础参数加载(避免可能的内部变量冲突)
> tryCatch({
+ # 仅使用必要参数,避免复杂参数组合
+ slide1_obj <- ReadNanostring(
+ data.dir = data_dir,
+ mtx.file = required_files["mtx"],
+ metadata.file = required_files["metadata"],
+ segmentations.file = required_files["segmentations"],
+ verbose = TRUE # 输出详细过程信息
+ )
+ cat("✅ 数据加载成功\n")
+ }, error = function(e) {
+ cat("❌ ReadNanostring调用失败:", e$message, "\n")
+
+ # -----------------------------
+ # 备选方案:手动构建Seurat对象
+ # -----------------------------
+ cat("\n=== 尝试备选方案:手动构建Seurat对象 ===\n")
+
+ # 1. 读取表达矩阵
+ cat("读取表达矩阵...\n")
+ expr_matrix <- read.csv(required_files["mtx"], row.names=1) %>% as.matrix()
+
+ # 2. 读取元数据
+ cat("读取元数据...\n")
+ metadata <- read.csv(required_files["metadata"], row.names=1)
+
+ # 3. 读取空间坐标(从segmentations文件)
+ cat("读取空间坐标...\n")
+ segmentations <- read.csv(required_files["segmentations"])
+ coords <- segmentations %>%
+ select(cell_id, x, y) %>% # 根据实际列名调整
+ column_to_rownames("cell_id")
+
+ # 4. 创建Seurat对象
+ cat("创建Seurat对象...\n")
+ seurat_obj <- CreateSeuratObject(
+ counts = expr_matrix,
+ meta.data = metadata
+ )
+
+ # 5. 添加空间坐标
+ if (nrow(coords) > 0) {
+ seurat_obj@images$image <- new(
+ Class = "SpatialImage",
+ assay = "RNA",
+ coordinates = coords[colnames(seurat_obj), ]
+ )
+ cat("✅ 已添加空间坐标信息\n")
+ }
+
+ # 6. 保存结果
+ saveRDS(seurat_obj, "manual_seurat_object.rds")
+ cat("✅ 备选方案成功:手动创建的Seurat对象已保存为manual_seurat_object.rds\n")
+ cat("请使用以下代码加载:\n")
+ cat("seurat_obj <- readRDS('manual_seurat_object.rds')\n")
+ })
❌ ReadNanostring调用失败: 参数没有用(verbose = TRUE)
=== 尝试备选方案:手动构建Seurat对象 ===
读取表达矩阵...
错误于h(simpleError(msg, call)):
在为函数“as.matrix”选择方法时计算参数“x”时出错:'row.names'里不能有重复的名称
Called from: h(simpleError(msg, call))
Browse[1]> Q
> ?ReadNanostring
> slide1_obj <- ReadNanostring(
+ data.dir = "/data1/firefox",
+ mtx.file = "GSE277782_Run5961_PDAC_Slide1_exprMat_file.csv.gz",
+ metadata.file = "GSE277782_Run5961_PDAC_Slide1_metadata_file.csv.gz",
+ molecules.file = ""
+ segmentations.file = "GSE277782_Run5961_PDAC_Slide1-polygons.csv.gz"
错误: 意外的符号 于
" molecules.file = ""
segmentations.file"
> slide1_obj <- ReadNanostring(
+ data.dir = "/data1/firefox",
+ mtx.file = "GSE277782_Run5961_PDAC_Slide1_exprMat_file.csv.gz",
+ metadata.file = "GSE277782_Run5961_PDAC_Slide1_metadata_file.csv.gz",
+ segmentations.file = "GSE277782_Run5961_PDAC_Slide1-polygons.csv.gz"
+ )
错误于ReadNanostring(data.dir = "/data1/firefox", mtx.file = "GSE277782_Run5961_PDAC_Slide1_exprMat_file.csv.gz", :
找不到对象'mx'
> rm(mtx_sample)
> setwd("/data1/firefox/GSE277782_Run5961_PDAC_Slide1")
> slide1_obj <- ReadNanostring(
+ data.dir = "/data1/firefox/GSE277782_Run5961_PDAC_Slide1",
+ mtx.file = "Run5961_PDAC_Slide1_exprMat_file.csv",
+ metadata.file = "Run5961_PDAC_Slide1_metadata_file.csv",
+ molecules.file = "Run5961_PDAC_Slide1_tx_file.csv",
+ segmentations.file = "Run5961_PDAC_Slide1-polygons.csv"
+ )
> View(slide1_obj)
> library(magick)
Linking to ImageMagick 6.9.10.23
Enabled features: fontconfig, freetype, fftw, lcms, pango, webp, x11
Disabled features: cairo, ghostscript, heic, raw, rsvg
Using 96 threads
> slide1_obj <- ReadNanostring(
+ data.dir = "/data1/firefox/GSE277782_Run5961_PDAC_Slide1",
+ mtx.file = "Run5961_PDAC_Slide1_exprMat_file.csv",
+ metadata.file = "Run5961_PDAC_Slide1_metadata_file.csv",
+ molecules.file = "Run5961_PDAC_Slide1_tx_file.csv",
+ segmentations.file = "Run5961_PDAC_Slide1-polygons.csv"
+ )
> fov_positions <- read.csv(
+ "Run5961_PDAC_Slide1_fov_positions_file.csv",
+ header = TRUE
+ )
> cat("FOV位置数据列名:", colnames(fov_positions), "\n")
FOV位置数据列名: fov x_global_px y_global_px
> max_x <- max(fov_positions$x_global_px) + 2048
> max_x <- max(fov_positions$x_global_px) + 2048
> max_y <- max(fov_positions$y_global_px) + 2048 # 假设单视野高2048像素
> combined_image <- image_blank(
+ width = max_x,
+ height = max_y,
+ color = "white" # 白色背景
+ )
错误: rsession: width or height exceeds limit `#FFFFFFFFFFFF' @ error/cache.c/OpenPixelCache/3911
> cat("x_global_px范围:", range(fov_positions$x_global_px), "\n")
x_global_px范围: -193718.9 -96445.92
>
> cat("y_global_px范围:", range(fov_positions$y_global_px), "\n")
y_global_px范围: -74903.74 65186.42
>
> View(fov_positions)
> library(data.table) # Efficient data management
data.table 1.17.0,使用了 48 个线程(参见 ?getDTthreads)。 最新的消息:r-datatable.com
**********
Running data.table in English; package support is available in English only. When searching for online help, be sure to also check for the English error message. This can be obtained by looking at the po/R-<locale>.po and po/<locale>.po files in the package source, where the native language and English error messages can be found side-by-side. You can also try calling Sys.setLanguage('en') prior to reproducing the error message.
**********
载入程序包:‘data.table’
The following objects are masked from ‘package:dplyr’:
between, first, last
The following objects are masked from ‘package:S4Vectors’:
first, second
> library(Matrix) # Sparse matrices
载入程序包:‘Matrix’
The following object is masked from ‘package:S4Vectors’:
expand
> library(here) # Enhanced file referencing in project-oriented workflows
here() starts at /data1/firefox/GSE277782_Run5961_PDAC_Slide1
> library(vecsets) # Enhanced version of the Set Operations from "base"
错误于library(vecsets): 不存在叫‘vecsets’这个名称的程序包
> BiocManager::install("vecsets")
'getOption("repos")' replaces Bioconductor standard repositories, see 'help("repositories",
package = "BiocManager")' for details.
Replacement repositories:
CRAN: https://cloud.r-project.org
Bioconductor version 3.20 (BiocManager 1.30.25), R 4.4.3 (2025-02-28)
Installing package(s) 'vecsets'
还安装依赖关系‘pracma’
试开URL’https://cloud.r-project.org/src/contrib/pracma_2.4.4.tar.gz'
Content type 'application/x-gzip' length 397815 bytes (388 KB)
==================================================
downloaded 388 KB
试开URL’https://cloud.r-project.org/src/contrib/vecsets_1.4.tar.gz'
Content type 'application/x-gzip' length 5714 bytes
==================================================
downloaded 5714 bytes
* installing *source* package ‘pracma’ ...
** 成功将‘pracma’程序包解包并MD5和检查
** using staged installation
** R
** data
*** moving datasets to lazyload DB
** demo
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded from temporary location
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (pracma)
* installing *source* package ‘vecsets’ ...
** 成功将‘vecsets’程序包解包并MD5和检查
** using staged installation
** R
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded from temporary location
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (vecsets)
下载的程序包在
‘/tmp/Rtmp5RH1TC/downloaded_packages’里
Installation paths not writeable, unable to update packages
path: /usr/lib/R/library
packages:
boot, codetools, foreign, lattice, Matrix, mgcv, nlme, spatial
Old packages: 'aplot', 'BiocManager', 'BiocParallel', 'bookdown', 'broom', 'Cairo',
'checkmate', 'cli', 'collections', 'colorspace', 'cols4all', 'commonmark', 'cowplot',
'credentials', 'crosstalk', 'curl', 'data.table', 'data.tree', 'dbplyr', 'dbscan',
'Deriv', 'diffobj', 'doBy', 'DT', 'dtplyr', 'evaluate', 'fastcluster', 'fields',
'fitdistrplus', 'forcats', 'fs', 'future', 'future.apply', 'gargle', 'generics',
'ggforce', 'ggfun', 'ggnetwork', 'ggnewscale', 'ggplotify', 'ggpubr', 'ggraph',
'ggridges', 'ggsci', 'ggtangle', 'gh', 'globals', 'googledrive', 'googlesheets4', 'haven',
'here', 'httpuv', 'httr2', 'igraph', 'later', 'logger', 'magick', 'magrittr', 'maps',
'miniUI', 'mockr', 'modeltools', 'msigdbr', 'nanoarrow', 'openssl', 'parallelly',
'patchwork', 'pbapply', 'pbkrtest', 'pheatmap', 'pillar', 'pkgbuild', 'pkgdown',
'pkgload', 'plotly', 'progressr', 'promises', 'ps', 'psych', 'purrr', 'R.cache', 'R.oo',
'ragg', 'Rcpp', 'RcppArmadillo', 'RcppParallel', 'reformulas', 'ResidualMatrix',
'restfulr', 'reticulate', 'rlang', 'roxygen2', 'rprojroot', 'rsample', 'RSQLite', 'RUnit',
'rvest', 's2', 'sass', 'scatterpie', 'SCpubr', 'sctransform', 'SeuratObject', 'sf',
'shiny', 'spacesXYZ', 'spatstat', 'spatstat.data', 'spatstat.explore', 'spatstat.geom',
'spatstat.linnet', 'spatstat.model', 'spatstat.random', 'spatstat.univar',
'spatstat.utils', 'spdep', 'stringr', 'survminer', 'svglite', 'systemfonts', 'tensor',
'terra', 'textshaping', 'TH.data', 'tibble', 'tinytex', 'usethis', 'utf8', 'V8', 'vroom',
'waldo', 'xfun', 'xgboost', 'XML', 'xml2', 'yulab.utils', 'zip', 'zoo'
Update all/some/none? [a/s/n]:
n
> library(vecsets) # Enhanced version of the Set Operations from "base"
> library(dplyr) # For the use of pipes %>%
> library(kableExtra) # For table formatting
错误于library(kableExtra): 不存在叫‘kableExtra’这个名称的程序包
> BiocManager::install("kableExtra")
'getOption("repos")' replaces Bioconductor standard repositories, see 'help("repositories",
package = "BiocManager")' for details.
Replacement repositories:
CRAN: https://cloud.r-project.org
Bioconductor version 3.20 (BiocManager 1.30.25), R 4.4.3 (2025-02-28)
Installing package(s) 'kableExtra'
试开URL’https://cloud.r-project.org/src/contrib/kableExtra_1.4.0.tar.gz'
Content type 'application/x-gzip' length 1824636 bytes (1.7 MB)
==================================================
downloaded 1.7 MB
* installing *source* package ‘kableExtra’ ...
** 成功将‘kableExtra’程序包解包并MD5和检查
** using staged installation
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (kableExtra)
下载的程序包在
‘/tmp/Rtmp5RH1TC/downloaded_packages’里
Installation paths not writeable, unable to update packages
path: /usr/lib/R/library
packages:
boot, codetools, foreign, lattice, Matrix, mgcv, nlme, spatial
Old packages: 'aplot', 'BiocManager', 'BiocParallel', 'bookdown', 'broom', 'Cairo',
'checkmate', 'cli', 'collections', 'colorspace', 'cols4all', 'commonmark', 'cowplot',
'credentials', 'crosstalk', 'curl', 'data.table', 'data.tree', 'dbplyr', 'dbscan',
'Deriv', 'diffobj', 'doBy', 'DT', 'dtplyr', 'evaluate', 'fastcluster', 'fields',
'fitdistrplus', 'forcats', 'fs', 'future', 'future.apply', 'gargle', 'generics',
'ggforce', 'ggfun', 'ggnetwork', 'ggnewscale', 'ggplotify', 'ggpubr', 'ggraph',
'ggridges', 'ggsci', 'ggtangle', 'gh', 'globals', 'googledrive', 'googlesheets4', 'haven',
'here', 'httpuv', 'httr2', 'igraph', 'later', 'logger', 'magick', 'magrittr', 'maps',
'miniUI', 'mockr', 'modeltools', 'msigdbr', 'nanoarrow', 'openssl', 'parallelly',
'patchwork', 'pbapply', 'pbkrtest', 'pheatmap', 'pillar', 'pkgbuild', 'pkgdown',
'pkgload', 'plotly', 'progressr', 'promises', 'ps', 'psych', 'purrr', 'R.cache', 'R.oo',
'ragg', 'Rcpp', 'RcppArmadillo', 'RcppParallel', 'reformulas', 'ResidualMatrix',
'restfulr', 'reticulate', 'rlang', 'roxygen2', 'rprojroot', 'rsample', 'RSQLite', 'RUnit',
'rvest', 's2', 'sass', 'scatterpie', 'SCpubr', 'sctransform', 'SeuratObject', 'sf',
'shiny', 'spacesXYZ', 'spatstat', 'spatstat.data', 'spatstat.explore', 'spatstat.geom',
'spatstat.linnet', 'spatstat.model', 'spatstat.random', 'spatstat.univar',
'spatstat.utils', 'spdep', 'stringr', 'survminer', 'svglite', 'systemfonts', 'tensor',
'terra', 'textshaping', 'TH.data', 'tibble', 'tinytex', 'usethis', 'utf8', 'V8', 'vroom',
'waldo', 'xfun', 'xgboost', 'XML', 'xml2', 'yulab.utils', 'zip', 'zoo'
Update all/some/none? [a/s/n]:
n
> library(kableExtra) # For table formatting
载入程序包:‘kableExtra’
The following object is masked from ‘package:dplyr’:
group_rows
> library(Seurat) # Seurat object
> metadata <- read.csv( "Run5961_PDAC_Slide1_metadata_file.csv", header = TRUE)
> exprMat <- read.csv("Run5961_PDAC_Slide1_exprMat_file.csv", row.names = 1 )
错误于read.table(file = file, header = header, sep = sep, quote = quote, :
'row.names'里不能有重复的名称
> exprMat <- read.csv("Run5961_PDAC_Slide1_exprMat_file.csv", header = TRUE)
> head(fov_positions)
fov x_global_px y_global_px
1 31 -167790.5 60037.54
2 33 -168926.1 50800.38
3 35 -167131.8 36894.30
4 34 -166881.8 32628.33
5 30 -153631.6 35808.63
6 45 -143096.8 38916.08
>
> metadata[1:6,1:6]
fov cell_ID Area AspectRatio CenterX_local_px CenterY_local_px
1 1 1 10063 1.39 93 4209
2 1 2 2783 1.43 1214 4232
3 1 3 7246 2.34 2498 4223
4 1 4 8318 1.35 2769 4211
5 1 5 4371 1.10 3226 4221
6 1 6 6603 1.41 3009 4217
>
> cells_0 <- grep("_0$", rownames(exprMat), value = TRUE)
>
> negPrb_col <- grep("^Neg", colnames(exprMat), value = TRUE) # Neg columns
>
> sysCon_col <- grep("^SystemControl", colnames(exprMat), value = TRUE) # SystemControl columns
>
> as.matrix(exprMat[1:6, 1:10])
fov cell_ID RAMP2 CD83 RYK CD5L NLRP2 BIRC5 LIF H2AZ1
1 1 0 13 59 36 33 20 26 54 84
2 1 1 0 0 1 1 0 1 1 0
3 1 2 0 0 0 0 0 0 0 0
4 1 3 1 0 0 0 0 0 0 0
5 1 4 0 0 0 0 0 0 0 0
6 1 5 0 0 0 0 0 0 0 0