Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/v1.2.0-beta' into introduce_ci
Browse files Browse the repository at this point in the history
  • Loading branch information
ghar1821 committed May 24, 2024
2 parents da1c026 + 1275c87 commit 41369c8
Show file tree
Hide file tree
Showing 24 changed files with 562 additions and 255 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: Spectre
Title: High-dimensional cytometry and imaging analysis.
Version: 1.2.0
Version: 1.2.0-00
Date: 2023-11-12
Authors@R: c(
person("Thomas", "Ashhurst", , "[email protected]", role = c("aut", "cre")),
Expand Down
2 changes: 1 addition & 1 deletion R/do.add.masks.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ do.add.masks <- function(dat, # list of spatial objects

require('raster')
require('rhdf5')
require('HDF5Array')
# require('HDF5Array')

###

Expand Down
13 changes: 11 additions & 2 deletions R/do.calculate.area.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,17 @@ do.calculate.area <- function(dat,

poly.names <- dat[[i]]@MASKS[[region]]$polygons@data

areas <- area(dat[[i]]@MASKS[[region]]$polygons)
areas <- sqrt(areas)
# areas <- area(dat[[i]]@MASKS[[region]]$polygons)

res <- data.table()

for(i in c(1:length(dat[[i]]@MASKS[[region]]$polygons@polygons))){
x <- data.table('ID' = i, 'Area' = dat[[i]]@MASKS[[region]]$polygons@polygons[[i]]@area)
res <- rbindlist(list(res, x))
rm(x)
}

areas <- sqrt(res[,2])
areas <- as.data.table(t(areas))

names(areas) <- as.character(poly.names[[1]])
Expand Down
16 changes: 9 additions & 7 deletions R/do.create.outlines.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,23 @@ do.create.outlines <- function(dat,

#message("This is a developmental Spectre-spatial function that is still in testing phase with limited documentation. We recommend only using this function if you know what you are doing.")

require(s2)
require(sf)
require(raster)
require(tiff)
require(rgeos)
require(tidyr)
require(ggplot2)
require(dplyr)
require(sp)

# polygons.name <- paste0(mask.name, "_polygons")
# outlines.name <- paste0(mask.name, "_outlines")
# centroids.name <- paste0(mask.name, "_centroids")

### Initial warning

os.deets <- devtools::session_info()
if(grepl('Windows', os.deets$platform$os)){
os.deets <- sessionInfo()
if(grepl('Windows', os.deets$running)){
message("Warning: the generation of mask outlines may differ between Mac and Windows. See 'https://github.com/ImmuneDynamics/Spectre/issues/56' for more information.")
}

Expand All @@ -50,7 +52,7 @@ do.create.outlines <- function(dat,
}

if(method == 'gdal'){
message("GDAL version not currently supportedb -- reverting to stars method")
message("GDAL version not currently supported -- reverting to stars method")
# if(length(Sys.which("gdal_polygonize.py")) > 1){
# message(paste0("Creating polygons, outlines, and centroids using GDAL -- this step may take some time, please be patient"))
# }
Expand All @@ -59,7 +61,7 @@ do.create.outlines <- function(dat,
### Run

for(i in names(dat)){
# i <- names(spatial.dat)[[1]]
# i <- names(dat)[[1]]
start.time <- Sys.time()

mask <- dat[[i]]@MASKS[[mask.name]]$maskraster
Expand All @@ -78,7 +80,6 @@ do.create.outlines <- function(dat,

require(stars)
require(sf)
require(sp)
require(s2)

names(mask) <- "TEMP_MASK"
Expand Down Expand Up @@ -120,7 +121,8 @@ do.create.outlines <- function(dat,
message(" ... outlines complete")

### Create centroids
centroids <- gCentroid(polygon,byid=TRUE)
centroids <- sp::coordinates(polygon#,byid=TRUE
)
dat[[i]]@MASKS[[mask.name]][["centroids"]] <- centroids
message(" ... centroids complete")
}
Expand Down
20 changes: 15 additions & 5 deletions R/do.extract.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ do.extract <- function(dat, # spatial.data object

#message("This is a developmental Spectre-spatial function that is still in testing phase with limited documentation. We recommend only using this function if you know what you are doing.")

require('rgeos')
require('sp')
require('sf')
require('rgdal')
require('exactextractr')
require('data.table')

Expand Down Expand Up @@ -58,12 +56,24 @@ do.extract <- function(dat, # spatial.data object
ply.df <- as.data.frame(roi.poly)
ply.df

ply.centroids <- gCentroid(roi.poly,byid=TRUE)
ply.centroids <- sp::coordinates(roi.poly)

ply.centroids.df <- as.data.frame(ply.centroids)
ply.centroids.df # mask number, with X and Y coordinates

ply.centroids.df <- cbind(ply.centroids.df, as.data.frame(area(roi.poly)))
names(ply.centroids.df)[3] <- "Area"
# ply.centroids.df <- cbind(ply.centroids.df, as.data.frame(area(roi.poly)))

res <- data.table()

for(i in c(1:length(roi.poly@polygons))){
x <- data.table('ID' = i, 'Area' = roi.poly@polygons[[i]]@area)
res <- rbindlist(list(res, x))
rm(x)
}

ply.centroids.df <- cbind(ply.centroids.df, res[,2])

names(ply.centroids.df) <- c("x", "y", "Area")

## RASTERS

Expand Down
8 changes: 4 additions & 4 deletions R/make.spatial.plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,11 @@ make.spatial.plot <- function(dat, # spatial data object
outline <- dat[[roi]]@MASKS[[mask.outlines]]$outlines
centroids <- dat[[roi]]@MASKS[[mask.outlines]]$centroids

centroid.xmin <- centroids@bbox[1]
centroid.xmax <- centroids@bbox[3]
centroid.xmin <- min(centroids[,1])
centroid.xmax <- max(centroids[,1])

centroid.ymin <- centroids@bbox[2]
centroid.ymax <- centroids@bbox[4]
centroid.ymin <- min(centroids[,2])
centroid.ymax <- max(centroids[,2])
}

## Flip y-axis values
Expand Down
5 changes: 0 additions & 5 deletions R/package.check.R
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,6 @@ package.check <- function(type = "general"){
message(' -- rhdf5 is required for SPATIAL analysis but is not installed')
res.list[['rhdf5']] <- 'rhdf5'
}

if(!is.element('HDF5Array', installed.packages()[,1])) {
message(' -- HDF5Array is required for SPATIAL analysis but is not installed')
res.list[['HDF5Array']] <- 'HDF5Array'
}

}

Expand Down
6 changes: 3 additions & 3 deletions R/write.hdf5.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ write.hdf5 <- function(dat, # SpectreMAP object
require('data.table')
require('raster')
require('rhdf5')
require('HDF5Array')
# require('HDF5Array')

### Testing

Expand Down Expand Up @@ -326,7 +326,7 @@ write.hdf5 <- function(dat, # SpectreMAP object
if(!is.null(random.crop.x)){
if(!is.null(random.crop.y)){

if(!paste0(i, "_crop.h5") %in% list.files(getwd())){
if(paste0(i, "_crop.h5") %in% list.files(getwd())){
file.remove(paste0(i, "_crop.h5"))
}

Expand All @@ -347,7 +347,7 @@ write.hdf5 <- function(dat, # SpectreMAP object

} else {

if(!paste0(i, ".h5") %in% list.files(getwd())){
if(paste0(i, ".h5") %in% list.files(getwd())){
file.remove(paste0(i, ".h5"))
}

Expand Down
78 changes: 18 additions & 60 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,93 +2,51 @@

A computational toolkit in R for the integration, exploration, and analysis of high-dimensional single-cell cytometry and imaging data.

<img src="https://raw.githubusercontent.com/tomashhurst/tomashhurst.github.io/master/images/Spectre.png">
<img src="https://raw.githubusercontent.com/tomashhurst/tomashhurst.github.io/master/images/Spectre.png"/>

**Current version**: [`v1.2.0`](https://github.com/ImmuneDynamics/Spectre/releases)
**Current version**: [`v1.2.0-beta`](https://github.com/ImmuneDynamics/Spectre/releases)

[![AppVeyor build status](https://ci.appveyor.com/api/projects/status/akhvb8wub6d6xhtd?svg=true)](https://ci.appveyor.com/project/tomashhurst/spectre)

<br/>

## About

<!--<img src="https://github.com/ImmuneDynamics/Spectre/blob/master/image/Spectre.png?raw=true" alt="logo" width="250" align="right"/>-->

Spectre is an R package that enables comprehensive end-to-end integration and analysis of high-dimensional cytometry data from different batches or experiments. Spectre streamlines the analytical stages of raw data pre-processing, batch alignment, data integration, clustering, dimensionality reduction, visualisation and population labelling, as well as quantitative and statistical analysis. To manage large cytometry datasets, Spectre was built on the data.table framework – this simple table-like structure allows for fast and easy processing of large datasets in R. Critically, the design of Spectre allows for a simple, clear, and modular design of analysis workflows, that can be utilised by data and laboratory scientists. Recently we have extended the functionality of Spectre to support the analysis of Imaging Mass Cytometry (IMC) and scRNAseq data. For more information, please see our paper: [Ashhurst TM, Marsh-Wakefield F, Putri GH et al. (2021). Cytometry A. DOI: 10.1002/cyto.a.24350](https://doi.org/10.1002/cyto.a.24350).
Spectre is an R package that enables comprehensive end-to-end integration and analysis of high-dimensional cytometry data from different batches or experiments. Spectre streamlines the analytical stages of raw data pre-processing, batch alignment, data integration, clustering, dimensionality reduction, visualisation and population labelling, as well as quantitative and statistical analysis. To manage large cytometry datasets, Spectre was built on the data.table framework -- this simple table-like structure allows for fast and easy processing of large datasets in R. Critically, the design of Spectre allows for a simple, clear, and modular design of analysis workflows, that can be utilised by data and laboratory scientists. Recently we have extended the functionality of Spectre to support the analysis of Imaging Mass Cytometry (IMC) and scRNAseq data. For more information, please see our paper: [Ashhurst TM, Marsh-Wakefield F, Putri GH et al. (2021). Cytometry A. DOI: 10.1002/cyto.a.24350](https://doi.org/10.1002/cyto.a.24350).

Spectre was developed by [Thomas Ashhurst](https://immunedynamics.github.io/thomas-ashhurst/), [Felix Marsh-Wakefield](https://immunedynamics.github.io/felix-marsh-wakefield/), and [Givanna Putri](https://immunedynamics.github.io/givanna-putri/).

<br/>

## Citation
If you use Spectre in your work, please consider citing [Ashhurst TM, Marsh-Wakefield F, Putri GH et al. (2021). Cytometry A. DOI: 10.1002/cyto.a.24350](https://doi.org/10.1002/cyto.a.24350). To continue providing open-source tools such as Spectre, it helps us if we can demonstrate that our efforts are contributing to analysis efforts in the community. Please also consider citing the authors of the individual packages or tools (e.g. CytoNorm, FlowSOM, tSNE, UMAP, etc) that are critical elements of your analysis work.

<br/>

## Instructions and protocols
Usage instructions and protocols are available from [https://immunedynamics.github.io/spectre](https://immunedynamics.github.io/spectre).
If you use Spectre in your work, please consider citing [Ashhurst TM, Marsh-Wakefield F, Putri GH et al. (2022). Cytometry A. DOI: 10.1002/cyto.a.24350](https://doi.org/10.1002/cyto.a.24350). To continue providing open-source tools such as Spectre, it helps us if we can demonstrate that our efforts are contributing to analysis efforts in the community. Please also consider citing the authors of the individual packages or tools (e.g. CytoNorm, FlowSOM, tSNE, UMAP, etc) that are critical elements of your analysis work.

<br/>

## Installing Spectre

Detailed installation instructions are available from [https://immunedynamics.github.io/spectre/getting-started](https://immunedynamics.github.io/spectre/getting-started). Spectre can be installed in R directly, or can be used via a pre-compiled Docker image. Brief instructions below.

_**In v1.1 and above we have removed the package dependencies `rgeos` and `rgdal` as these are no longer available on CRAN. The package should install fine without these dependencies, but some spatial functions may not work properly. If required, one can download the archived packages, unzip them, and then placed them in the R library location.**_

<br/>

### Option 1: Install Spectre in R

Install and load the 'devtools' library.
## Getting started

```
if(!require('remotes')) {install.packages('remotes')}
library('remotes')
```
### Installation

Subsequently, use the 'install_github' function to install and load the Spectre package. By default this will load the 'master' branch, which is the same as the latest stable release version (listed at https://github.com/immunedynamics/Spectre/releases). To install a specific release version, see https://cran.r-project.org/web/packages/githubinstall/vignettes/githubinstall.html.
We recommend using Spectre with [R](https://cran.r-project.org/mirrors.html) and [RStudio](https://www.rstudio.com/products/rstudio/download/#download). Once R and RStudio are installed, run the following to install the Spectre package.

```
remotes::install_github(repo = "immunedynamics/spectre")
```
if(!require('remotes')) {install.packages('remotes')} # Installs the package 'remotes'
remotes::install_github(repo = "immunedynamics/spectre") # Install the Spectre package
```

You will see the following returned. We suggest selecting 'none' (in this example, by entering '3' and pressing return) to avoid updating other packages. You can update your packages after installation.
```
Downloading GitHub repo immunedynamics/spectre@master
These packages have more recent versions available.
Which would you like to update?
1: All
2: CRAN packages only
3: None
4: data.table (1.12.0 -> 1.12.2) [CRAN]
... etc
```

If the package is sucessfully installed, you can load the library using:
```
library("Spectre")
```
If you are unfamiliar with using R and RStudio, check out our [R and Spectre basics guides](https://immunedynamics.io/spectre/install/#Basics_guide) for assistance. For detailed installation instructions, and instructions for installing Spectre via Docker, see our [installation guide](https://immunedynamics.io/spectre/install/).

You can then check for whether all of the packages for Spectre have been loaded correctly using the following commands
```
## Check if all required packages have been installed
Spectre::package.check()
## Load all required packages
Spectre::package.load()
```
### New to R or Spectre?

Alternatively, you can go to releases (https://github.com/immunedynamics/spectre/releases) and download the latest stable release -- which can then be installed in R.
New users can check out our [basics guides](https://immunedynamics.io/spectre/install/#Basics_guide) to get acquainted with using R and Spectre.

<br/>
### Workflows and protocols

### Option 2: Install Spectre using Docker
When you are ready to start analysis, check out our structured workflows and tutorials on the following pages:

Install a 'container' version of Spectre using Docker, that contains a pre-built environment with all the required packages necessary to use Spectre. Please see [this page](https://wiki.centenary.org.au/display/SPECTRE/Install+from+Docker) for instructions.
- Analysis of [high-dimensional cytometry](https://immunedynamics.github.io/spectre/cytometry) data
- Analysis of [high-dimensional imaging/spatial](https://immunedynamics.github.io/spectre/spatial/) data
- Analysis of [single-cell genomics](https://immunedynamics.github.io/spectre/single-cell/) data

<br/>

## Acknowledgements
The Spectre package was constructed on the basis of the CAPX workflow in R (https://sydneycytometry.org.au/capx). Along with the various R packages used within Spectre, we would like to acknowledge the Seurat and cytofkit R packages from providing inspiration for elements of the package design.
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 41369c8

Please sign in to comment.