diff --git a/DESCRIPTION b/DESCRIPTION index 9aae58b1..56030b46 100755 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,16 +1,29 @@ Package: Spectre Type: Package -Title: A computational toolkit in R for the integration, exploration, and analysis of high-dimensional single-cell cytometry and imaging data. -Version: 0.5.1 -Author: Thomas Ashhurst, Felix Marsh-Wakefield, Givanna Putri -Maintainer: Thomas Ashhurst +Version: 0.5.2 +Date: 2021-06-18 +Title: High-dimensional cytometry and imaging analysis. Description: A computational toolkit in R for the integration, exploration, and analysis of high-dimensional single-cell cytometry and imaging data. +Authors@R: c( + person(given = "Thomas", family = "Ashhurst", email = "thomas.ashhurst@sydney.edu.au", role = c("aut", "cre")), + person(given = "Felix", family = "Marsh-Wakefield", email = "felix.marsh-wakefield@sydney.edu.au", role = "aut"), + person(given = "Givanna", family = "Putri", email = "givanna.putri@sydney.edu.au", role = "aut") + ) +URL: https://github.com/ImmuneDynamics/Spectre +BugReports: https://github.com/ImmuneDynamics/Spectre/issues +Maintainer: Thomas Ashhurst Depends: R (>= 3.6.0) License: MIT Licence Encoding: UTF-8 LazyData: true +biocViews: flowCore Imports: + flowCore, + Biobase, + flowViz, + FlowSOM, devtools, + BiocManager, plyr, dplyr, data.table, @@ -48,6 +61,5 @@ Imports: qs, s2, exactextractr, -Suggests: RoxygenNote: 7.1.1 Roxygen: list(markdown = TRUE) diff --git a/NAMESPACE b/NAMESPACE index 40c617ba..dc0d6f56 100755 --- a/NAMESPACE +++ b/NAMESPACE @@ -12,8 +12,8 @@ export(do.align) export(do.asinh) export(do.calculate.area) export(do.clip) -export(do.create.outlines) export(do.combine.cols) +export(do.create.outlines) export(do.embed.columns) export(do.extract) export(do.extract.cell.dat) diff --git a/R/package.check.R b/R/package.check.R index 8dbaf0ee..01b4235e 100755 --- a/R/package.check.R +++ b/R/package.check.R @@ -19,39 +19,176 @@ package.check <- function(type = "general"){ - if(!is.element('data.table', installed.packages()[,1])) message('data.table is required but not installed') - if(!is.element('plyr', installed.packages()[,1])) message('plyr is required but not installed') - if(!is.element('dplyr', installed.packages()[,1])) message('dplyr is required but not installed') - if(!is.element('tidyr', installed.packages()[,1])) message('tidyr is required but not installed') - if(!is.element('rstudioapi', installed.packages()[,1])) message('rstudioapi is required but not installed') - if(!is.element('Rtsne', installed.packages()[,1])) message('Rtsne is required but not installed') - if(!is.element('umap', installed.packages()[,1])) message('umap is required but not installed') - if(!is.element('reticulate', installed.packages()[,1])) message('reticulate is required but not installed') - if(!is.element('ggplot2', installed.packages()[,1])) message('ggplot2 is required but not installed') - if(!is.element('ggthemes', installed.packages()[,1])) message('ggthemes is required but not installed') - if(!is.element('scales', installed.packages()[,1])) message('scales is required but not installed') - if(!is.element('colorRamps', installed.packages()[,1])) message('colorRamps is required but not installed') - if(!is.element('RColorBrewer', installed.packages()[,1])) message('RColorBrewer is required but not installed') - if(!is.element('gridExtra', installed.packages()[,1])) message('gridExtra is required but not installed') - if(!is.element('ggpointdensity', installed.packages()[,1])) message('ggpointdensity is required but not installed') - if(!is.element('pheatmap', installed.packages()[,1])) message('ggpointdensity is required but not installed') - if(!is.element('ggpubr', installed.packages()[,1])) message('ggpointdensity is required but not installed') - if(!is.element('caret', installed.packages()[,1])) message('caret is required for machine learning analysis but is not installed') - if(!is.element('class', installed.packages()[,1])) message('class is required for machine learning analysis but is not installed') + res.list <- list() - if(!is.element('flowCore', installed.packages()[,1])) message('flowCore is required but not installed. Please install from BioConductor.') - if(!is.element('Biobase', installed.packages()[,1])) message('Biobase is required but not installed. Please install from BioConductor.') - if(!is.element('flowViz', installed.packages()[,1])) message('flowViz is required but not installed. Please install from BioConductor.') - if(!is.element('FlowSOM', installed.packages()[,1])) message('FlowSOM is required but not installed. Please install from BioConductor.') + if(!is.element('data.table', installed.packages()[,1])){ + message('data.table is required but not installed') + res.list[['data.table']] <- 'data.table' + } + + if(!is.element('plyr', installed.packages()[,1])) { + message('plyr is required but not installed') + res.list[['plyr']] <- 'plyr' + } + + if(!is.element('dplyr', installed.packages()[,1])) { + message('dplyr is required but not installed') + res.list[['data.table']] <- 'data.table' + } + + if(!is.element('tidyr', installed.packages()[,1])) { + message('tidyr is required but not installed') + res.list[['tidyr']] <- 'tidyr' + } + + if(!is.element('rstudioapi', installed.packages()[,1])) { + message('rstudioapi is required but not installed') + res.list[['rstudioapi']] <- 'rstudioapi' + } + + if(!is.element('Rtsne', installed.packages()[,1])) { + message('Rtsne is required but not installed') + res.list[['Rtsne']] <- 'Rtsne' + } + + if(!is.element('umap', installed.packages()[,1])) { + message('umap is required but not installed') + res.list[['umap']] <- 'umap' + } + + if(!is.element('reticulate', installed.packages()[,1])) { + message('reticulate is required but not installed') + res.list[['reticulate']] <- 'reticulate' + } + + if(!is.element('ggplot2', installed.packages()[,1])) { + message('ggplot2 is required but not installed') + res.list[['ggplot2']] <- 'ggplot2' + } + + if(!is.element('ggthemes', installed.packages()[,1])) { + message('ggthemes is required but not installed') + res.list[['ggthemes']] <- 'ggthemes' + } + + if(!is.element('scales', installed.packages()[,1])) { + message('scales is required but not installed') + res.list[['scales']] <- 'scales' + } + + if(!is.element('colorRamps', installed.packages()[,1])) { + message('colorRamps is required but not installed') + res.list[['colorRamps']] <- 'colorRamps' + } + + if(!is.element('RColorBrewer', installed.packages()[,1])) { + message('RColorBrewer is required but not installed') + res.list[['RColorBrewer']] <- 'RColorBrewer' + } + + if(!is.element('gridExtra', installed.packages()[,1])) { + message('gridExtra is required but not installed') + res.list[['gridExtra']] <- 'gridExtra' + } + + if(!is.element('ggpointdensity', installed.packages()[,1])) { + message('ggpointdensity is required but not installed') + res.list[['ggpointdensity']] <- 'ggpointdensity' + } + + if(!is.element('pheatmap', installed.packages()[,1])) { + message('pheatmap is required but not installed') + res.list[['pheatmap']] <- 'pheatmap' + } + + if(!is.element('ggpubr', installed.packages()[,1])) { + message('ggpubr is required but not installed') + res.list[['ggpubr']] <- 'ggpubr' + } + + if(!is.element('caret', installed.packages()[,1])) { + message('caret is required for machine learning analysis but is not installed') + res.list[['caret']] <- 'caret' + } + + if(!is.element('class', installed.packages()[,1])) { + message('class is required for machine learning analysis but is not installed') + res.list[['class']] <- 'class' + } + + if(!is.element('flowCore', installed.packages()[,1])) { + message('flowCore is required but not installed. Please install from BioConductor.') + res.list[['flowCore']] <- 'flowCore' + } + + if(!is.element('Biobase', installed.packages()[,1])) { + message('Biobase is required but not installed. Please install from BioConductor.') + res.list[['Biobase']] <- 'Biobase' + } + + if(!is.element('flowViz', installed.packages()[,1])) { + message('flowViz is required but not installed. Please install from BioConductor.') + res.list[['flowViz']] <- 'flowViz' + } + + if(!is.element('FlowSOM', installed.packages()[,1])) { + message('FlowSOM is required but not installed. Please install from BioConductor.') + res.list[['FlowSOM']] <- 'FlowSOM' + } + if(type == "spatial"){ - if(!is.element('raster', installed.packages()[,1])) message('raster is required for SPATIAL analysis but is not installed') - if(!is.element('tiff', installed.packages()[,1])) message('tiff is required for SPATIAL analysis but is not installed') - if(!is.element('rgeos', installed.packages()[,1])) message('rgeos is required for SPATIAL analysis but is not installed') - if(!is.element('exactextractr', installed.packages()[,1])) message('exactextractr is required for SPATIAL analysis but is not installed') - if(!is.element('sp', installed.packages()[,1])) message('sp is required for SPATIAL analysis but is not installed') - if(!is.element('sf', installed.packages()[,1])) message('sf is required for SPATIAL analysis but is not installed') - if(!is.element('stars', installed.packages()[,1])) message('stars is required for SPATIAL analysis but is not installed') - if(!is.element('qs', installed.packages()[,1])) message('qs is required for SPATIAL analysis but is not installed') + if(!is.element('raster', installed.packages()[,1])) { + message('raster is required for SPATIAL analysis but is not installed') + res.list[['raster']] <- 'raster' + } + + if(!is.element('tiff', installed.packages()[,1])) { + message('tiff is required for SPATIAL analysis but is not installed') + res.list[['tiff']] <- 'tiff' + } + + if(!is.element('rgeos', installed.packages()[,1])) { + message('rgeos is required for SPATIAL analysis but is not installed') + res.list[['rgeos']] <- 'rgeos' + } + + if(!is.element('exactextractr', installed.packages()[,1])) { + message('exactextractr is required for SPATIAL analysis but is not installed') + res.list[['exactextractr']] <- 'exactextractr' + } + + if(!is.element('sp', installed.packages()[,1])) { + message('sp is required for SPATIAL analysis but is not installed') + res.list[['sp']] <- 'sp' + } + + if(!is.element('sf', installed.packages()[,1])) { + message('sf is required for SPATIAL analysis but is not installed') + res.list[['sf']] <- 'sf' + } + + if(!is.element('stars', installed.packages()[,1])) { + message('stars is required for SPATIAL analysis but is not installed') + res.list[['stars']] <- 'stars' + } + + if(!is.element('qs', installed.packages()[,1])) { + message('qs is required for SPATIAL analysis but is not installed') + res.list[['qs']] <- 'qs' + } + + if(!is.element('s2', installed.packages()[,1])) { + message('s2 is required for SPATIAL analysis but is not installed') + res.list[['s2']] <- 's2' + } } + + + ### Final message + + if(length(res.list) == 0){ + message("All packages successfully installed") + } + } diff --git a/R/package.install.R b/R/package.install.R index a45fe03b..7f5036bb 100755 --- a/R/package.install.R +++ b/R/package.install.R @@ -5,6 +5,7 @@ #' @return returns an error message if one of the common use packages are not installed. Proceeds in order of package importance, and only the first error message encountered will be returned. #' #' @param type DEFAULT = "general". If "general", then checks for the packages required for general Spectre usage. If "spatial", then checks for additional packages required for spatial analysis. +#' @param update DEFAULT = FALSE. If FALSE, will only install packages that are not already installed -- no updates of packages will be performed. If TRUE, will install and update packages. #' #' @author Thomas M Ashhurst, \email{thomas.ashhurst@@sydney.edu.au} #' @@ -18,49 +19,99 @@ #' #' @export -package.install <- function(type = 'general'){ +package.install <- function(type = 'general', update = FALSE){ - if(!require('data.table')) {install.packages('data.table')} - if(!require('plyr')) {install.packages('plyr')} - if(!require('dplyr')) {install.packages('dplyr')} - if(!require('tidyr')) {install.packages('tidyr')} - if(!require('rstudioapi')) {install.packages('rstudioapi')} - if(!require('Rtsne')) {install.packages('Rtsne')} - if(!require('umap')) {install.packages('umap')} - if(!require('ggplot2')) {install.packages('ggplot2')} - if(!require('ggthemes')) {install.packages('ggthemes')} - if(!require('scales')) {install.packages('scales')} - if(!require('colorRamps')) {install.packages('colorRamps')} - if(!require('RColorBrewer')) {install.packages('')} - if(!require('gridExtra')) {install.packages('gridExtra')} - if(!require('ggpointdensity')) {install.packages('ggpointdensity')} - if(!require('pheatmap')) {install.packages('pheatmap')} - if(!require('ggpubr')) {install.packages('ggpubr')} - if(!require('factoextra')) {install.packages('factoextra')} - if(!require('reticulate')) {install.packages('reticulate')} - if(!require('caret')) {install.packages('caret')} - if(!require('class')) {install.packages('class')} - - ## Install BiocManager to download packages from Bioconductor - if (!requireNamespace("BiocManager", quietly = TRUE)) - install.packages("BiocManager") - - ## Download additional BioConductor packages - if(!require('flowCore')) {BiocManager::install('flowCore')} - if(!require('Biobase')) {BiocManager::install('Biobase')} - if(!require('flowViz')) {BiocManager::install('flowViz')} - if(!require('FlowSOM')) {BiocManager::install('FlowSOM')} + ## Update = FALSE + if(isFALSE(update)){ + if(!require('data.table')) {install.packages('data.table')} + if(!require('plyr')) {install.packages('plyr')} + if(!require('dplyr')) {install.packages('dplyr')} + if(!require('tidyr')) {install.packages('tidyr')} + if(!require('rstudioapi')) {install.packages('rstudioapi')} + if(!require('Rtsne')) {install.packages('Rtsne')} + if(!require('umap')) {install.packages('umap')} + if(!require('ggplot2')) {install.packages('ggplot2')} + if(!require('ggthemes')) {install.packages('ggthemes')} + if(!require('scales')) {install.packages('scales')} + if(!require('colorRamps')) {install.packages('colorRamps')} + if(!require('RColorBrewer')) {install.packages('')} + if(!require('gridExtra')) {install.packages('gridExtra')} + if(!require('ggpointdensity')) {install.packages('ggpointdensity')} + if(!require('pheatmap')) {install.packages('pheatmap')} + if(!require('ggpubr')) {install.packages('ggpubr')} + if(!require('factoextra')) {install.packages('factoextra')} + if(!require('reticulate')) {install.packages('reticulate')} + if(!require('caret')) {install.packages('caret')} + if(!require('class')) {install.packages('class')} + + ## Install BiocManager to download packages from Bioconductor + if (!requireNamespace("BiocManager", quietly = TRUE)) + install.packages("BiocManager") + + ## Download additional BioConductor packages + if(!require('flowCore')) {BiocManager::install('flowCore')} + if(!require('Biobase')) {BiocManager::install('Biobase')} + if(!require('flowViz')) {BiocManager::install('flowViz')} + if(!require('FlowSOM')) {BiocManager::install('FlowSOM')} + + if(type == "spatial"){ + if(!require('raster')) {install.packages('raster')} + if(!require('tiff')) {install.packages('tiff')} + if(!require('rgeos')) {install.packages('rgeos')} + if(!require('exactextractr')) {install.packages('exactextractr')} + if(!require('sp')) {install.packages('sp')} + if(!require('sf')) {install.packages('sf')} + if(!require('stars')) {install.packages('stars')} + if(!require('qs')) {install.packages('qs')} + if(!require('s2')) {install.packages('s2')} + } + } + + ## Update = TRUE + if(isTRUE(update)){ + install.packages('data.table') + install.packages('plyr') + install.packages('dplyr') + install.packages('tidyr') + install.packages('rstudioapi') + install.packages('Rtsne') + install.packages('umap') + install.packages('ggplot2') + install.packages('ggthemes') + install.packages('scales') + install.packages('colorRamps') + install.packages('') + install.packages('gridExtra') + install.packages('ggpointdensity') + install.packages('pheatmap') + install.packages('ggpubr') + install.packages('factoextra') + install.packages('reticulate') + install.packages('caret') + install.packages('class') + + ## Install BiocManager to download packages from Bioconductor + install.packages("BiocManager") + + ## Download additional BioConductor packages + BiocManager::install('flowCore') + BiocManager::install('Biobase') + BiocManager::install('flowViz') + BiocManager::install('FlowSOM') + + if(type == "spatial"){ + install.packages('raster') + install.packages('tiff') + install.packages('rgeos') + install.packages('exactextractr') + install.packages('sp') + install.packages('sf') + install.packages('stars') + install.packages('qs') + install.packages('s2') + } + } - if(type == "spatial"){ - if(!require('raster')) {install.packages('raster')} - if(!require('tiff')) {install.packages('tiff')} - if(!require('rgeos')) {install.packages('rgeos')} - if(!require('exactextractr')) {install.packages('exactextractr')} - if(!require('sp')) {install.packages('sp')} - if(!require('sf')) {install.packages('sf')} - if(!require('stars')) {install.packages('stars')} - if(!require('qs')) {install.packages('qs')} - } } diff --git a/R/package.load.R b/R/package.load.R index 3f5fc7ad..d505cf14 100755 --- a/R/package.load.R +++ b/R/package.load.R @@ -55,5 +55,6 @@ package.load <- function(type = "general"){ require('sf') require('stars') require('qs') + require('s2') } } diff --git a/R/prep.cytonorm.R b/R/prep.cytonorm.R index 92cef765..fcd0077e 100755 --- a/R/prep.cytonorm.R +++ b/R/prep.cytonorm.R @@ -54,7 +54,7 @@ prep.cytonorm <- function(dat, require(Spectre) require(data.table) require(CytoNorm) - require(flowCore) + # require(flowCore) require(Biobase) ### Directory setup diff --git a/R/run.cytonorm.R b/R/run.cytonorm.R index 1c132276..4c8bccd2 100755 --- a/R/run.cytonorm.R +++ b/R/run.cytonorm.R @@ -168,7 +168,8 @@ run.cytonorm <- function(dat, dir.create("tmp-target") setwd("tmp-target") - ff <- flowCore::read.FCS(file) + # ff <- flowCore::read.FCS(file) + ff <- read.FCS(file) setwd(dir) dir.create("tmp-target", showWarnings = FALSE) @@ -188,8 +189,9 @@ run.cytonorm <- function(dat, paste0(gsub("[:/]","_",file), "_fsom", cluster, ".fcs")) suppressWarnings( - flowCore::write.FCS(ff[cellClusterIDs[[file]] == cluster], - file = f) + # flowCore::write.FCS(ff[cellClusterIDs[[file]] == cluster], + # file = f) + write.FCS(ff[cellClusterIDs[[file]] == cluster], file = f) ) } } @@ -228,7 +230,10 @@ run.cytonorm <- function(dat, for(i in cluster.files){ # i <- cluster.files[[1]] - temp <- flowCore::read.FCS(i) + + #temp <- flowCore::read.FCS(i) + temp <- read.FCS(i) + dt <- as.data.table(temp@exprs) mc <- sub(".*.fcs_", "", i) diff --git a/R/run.flowsom.R b/R/run.flowsom.R index 952cb4ee..c152f200 100755 --- a/R/run.flowsom.R +++ b/R/run.flowsom.R @@ -53,7 +53,7 @@ run.flowsom <- function(dat, ### Require packages require(Spectre) - require(flowCore) + # require(flowCore) require(Biobase) require(FlowSOM) require(data.table) @@ -91,7 +91,7 @@ run.flowsom <- function(dat, exprs=as.matrix(dat), # in order to create a flow frame, data needs to be read as matrix parameters=Biobase::AnnotatedDataFrame(metadata)) - head(flowCore::exprs(dat.ff)) + #head(flowCore::exprs(dat.ff)) dat_FlowSOM <- dat.ff rm(dat) diff --git a/R/train.cytonorm.R b/R/train.cytonorm.R index 93543139..31777a0e 100755 --- a/R/train.cytonorm.R +++ b/R/train.cytonorm.R @@ -53,7 +53,7 @@ train.cytonorm <- function(model, require(Spectre) require(data.table) require(CytoNorm) - require(flowCore) + # require(flowCore) require(Biobase) ### Check the alignment model object @@ -151,12 +151,18 @@ if(method == 'cytonorm'){ if (sum(FlowSOM::GetMetaclusters(fsom_file, model$fsom$metaclustering) == cluster) > 0) { suppressWarnings( - flowCore::write.FCS( + write.FCS( file.ff[cellClusterIDs == cluster,], file=file.path(getwd(), ##### #outputDir, paste0(gsub("[:/]","_",file), "_fsom",cluster,".fcs")))) + # flowCore::write.FCS( + # file.ff[cellClusterIDs == cluster,], + # file=file.path(getwd(), ##### + # #outputDir, + # paste0(gsub("[:/]","_",file), + # "_fsom",cluster,".fcs")))) } } } diff --git a/man/package.install.Rd b/man/package.install.Rd index f7b5f9f3..69a002cc 100755 --- a/man/package.install.Rd +++ b/man/package.install.Rd @@ -8,6 +8,8 @@ See \url{https://sydneycytometry.org.au/spectre} for usage instructions and vign } \arguments{ \item{type}{DEFAULT = "general". If "general", then checks for the packages required for general Spectre usage. If "spatial", then checks for additional packages required for spatial analysis.} + +\item{update}{DEFAULT = FALSE. If FALSE, will only install packages that are not already installed -- no updates of packages will be performed. If TRUE, will install and update packages.} } \value{ returns an error message if one of the common use packages are not installed. Proceeds in order of package importance, and only the first error message encountered will be returned.