Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update #47

Merged
merged 34 commits into from
Jun 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
c0c62de
Spatial function uploads
tomashhurst May 17, 2021
da11361
Updates
tomashhurst May 17, 2021
793674f
Updates
tomashhurst May 17, 2021
5b3be34
Updates
tomashhurst May 18, 2021
94324f4
Updates
tomashhurst May 18, 2021
8c07413
Updates
tomashhurst May 18, 2021
5e9614b
Updates
tomashhurst May 19, 2021
3bba78e
Update README.md
tomashhurst May 19, 2021
3152f42
Update README.md
tomashhurst May 19, 2021
dccd2af
Updates
tomashhurst May 20, 2021
f36c008
Updates
tomashhurst May 27, 2021
bc502b5
Updates
tomashhurst May 31, 2021
bd6ee47
Merge pull request #39 from ImmuneDynamics/development
tomashhurst May 31, 2021
07a7335
Update README.md
tomashhurst May 31, 2021
8fcf9f4
Update DESCRIPTION
tomashhurst May 31, 2021
dcac605
Merge pull request #40 from ImmuneDynamics/development
tomashhurst May 31, 2021
99f4e50
Updates
tomashhurst May 31, 2021
3ab3f19
Updates
tomashhurst Jun 3, 2021
3094c45
Merge pull request #42 from ImmuneDynamics/development
tomashhurst Jun 3, 2021
3341440
Update README.md
tomashhurst Jun 3, 2021
ef6d432
Update DESCRIPTION
tomashhurst Jun 3, 2021
717507a
Update README.md
tomashhurst Jun 3, 2021
a14f9c0
Update README.md
tomashhurst Jun 3, 2021
04f80b5
Update README.md
tomashhurst Jun 3, 2021
ae785ef
Update README.md
tomashhurst Jun 3, 2021
e70a6f1
Updates
tomashhurst Jun 3, 2021
29f8c36
Updates
tomashhurst Jun 3, 2021
f2e44c3
Updates
tomashhurst Jun 3, 2021
94e5fec
Merge branch 'master' into spatial
tomashhurst Jun 4, 2021
fe56f15
Merge pull request #43 from ImmuneDynamics/spatial
tomashhurst Jun 4, 2021
9180718
Update DESCRIPTION
tomashhurst Jun 4, 2021
171bc39
Update README.md
tomashhurst Jun 4, 2021
dffb16f
Updates
tomashhurst Jun 4, 2021
c039bd3
Merge pull request #44 from ImmuneDynamics/spatial
tomashhurst Jun 4, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
16 changes: 13 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: Spectre
Type: Package
Title: A computational toolkit in R for the integration, exploration, and analysis of high-dimensional single-cell cytometry data.
Version: 0.4.5
Title: A computational toolkit in R for the integration, exploration, and analysis of high-dimensional single-cell cytometry and imaging data.
Version: 0.5.0
Author: Thomas Ashhurst, Felix Marsh-Wakefield, Givanna Putri
Maintainer: Thomas Ashhurst <thomas.ashhurst@sydney.edu.au>
Description: A computational toolkit in R for the integration, exploration, and analysis of high-dimensional single-cell cytometry data.
Expand Down Expand Up @@ -36,7 +36,17 @@ Imports:
ggraph,
stringr,
rsvd,
irlba
irlba,
gridExtra,
raster,
tiff,
rgeos,
tidyr,
sp,
sf,
stars,
qs,
exactextractr
Suggests:
RoxygenNote: 7.1.1
Roxygen: list(markdown = TRUE)
13 changes: 13 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,26 @@ export(create.dt)
export(create.stats)
export(create.sumtable)
export(do.add.cols)
export(do.add.masks)
export(do.add.percell)
export(do.aggregate)
export(do.align)
export(do.asinh)
export(do.calculate.area)
export(do.clip)
export(do.create.outlines)
export(do.combine.cols)
export(do.embed.columns)
export(do.extract)
export(do.extract.cell.dat)
export(do.filter)
export(do.filter.percell)
export(do.label.from.polygon)
export(do.list.summary)
export(do.list.switch)
export(do.logicle)
export(do.merge.files)
export(do.pull.data)
export(do.reorder)
export(do.rescale)
export(do.stats)
Expand All @@ -27,12 +36,14 @@ export(make.colour.plot)
export(make.multi.plot)
export(make.network.plot)
export(make.pheatmap)
export(make.spatial.plot)
export(make.volcano.plot)
export(package.check)
export(package.install)
export(package.load)
export(prep.cytonorm)
export(read.files)
export(read.spatial.files)
export(run.align)
export(run.chronoclust)
export(run.cytonorm)
Expand All @@ -44,10 +55,12 @@ export(run.pca)
export(run.phenograph)
export(run.prepare.chronoclust)
export(run.ruv)
export(run.spatial.analysis)
export(run.tsne)
export(run.umap)
export(train.cytonorm)
export(train.knn.classifier)
export(write.files)
export(write.hdf5)
export(write.sumtables)
import(data.table)
3 changes: 1 addition & 2 deletions R/create.dt.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
#'
#' @usage create.dt(dat, from)
#'
#' @author
#' Thomas M Ashhurst, \email{thomas.ashhurst@@sydney.edu.au}
#' @author Thomas M Ashhurst, \email{thomas.ashhurst@@sydney.edu.au}
#'
#' @references \url{https://github.com/ImmuneDynamics/Spectre}.
#'
Expand Down
4 changes: 4 additions & 0 deletions R/create.stats.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
#' @param pairwise.test DEFAULT = 'wilcox.test'. Currently the only option
#' @param corrections DEFAULT = 'fdr' (false discovery rate). Currently the only option
#'
#' @author Thomas M Ashhurst, \email{thomas.ashhurst@@sydney.edu.au}
#'
#' @references \url{https://github.com/ImmuneDynamics/Spectre}.
#'
#' @import data.table
#'
#' @export
Expand Down
5 changes: 2 additions & 3 deletions R/create.sumtable.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@
#' use.cols = names(dat)[c(11:19)],
#' counts = counts)
#'
#' @author
#' Thomas M Ashhurst, \email{thomas.ashhurst@@sydney.edu.au}
#' @author Thomas M Ashhurst, \email{thomas.ashhurst@@sydney.edu.au}
#'
#' @references \url{https://sydneycytometry.org.au/spectre}.
#' @references \url{https://github.com/ImmuneDynamics/Spectre}.
#'
#' @export

Expand Down
4 changes: 2 additions & 2 deletions R/demo.asinh.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
#'
#' @author Thomas M Ashhurst, \email{thomas.ashhurst@@sydney.edu.au}
#'
#' @source Thomas M Ashhurst.
#' @references \url{https://github.com/ImmuneDynamics/Spectre}.
#'
#' @references \url{https://sydneycytometry.org.au/spectre}.
#' @source Thomas M Ashhurst.
#'
#' @examples
#' demo.asinh
Expand Down
2 changes: 1 addition & 1 deletion R/demo.batches.1.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#'
#' @source Thomas M Ashhurst.
#'
#' @references \url{https://sydneycytometry.org.au/spectre}.
#' @references \url{https://github.com/ImmuneDynamics/Spectre}.
#'
#' @examples
#' demo.batches.1
Expand Down
4 changes: 2 additions & 2 deletions R/demo.clustered.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
#'
#' @source Thomas M Ashhurst.
#'
#' @references \url{https://sydneycytometry.org.au/spectre}.
#'
#' @references \url{https://github.com/ImmuneDynamics/Spectre}.
#'
#' @examples
#' demo.clustered
#'
Expand Down
4 changes: 2 additions & 2 deletions R/demo.exp.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
#'
#' @source Thomas M Ashhurst.
#'
#' @references \url{https://sydneycytometry.org.au/spectre}.
#'
#' @references \url{https://github.com/ImmuneDynamics/Spectre}.
#'
#' @examples
#' demo.exp
#'
Expand Down
18 changes: 18 additions & 0 deletions R/demo.spatial.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#' demo.spatial - Demo spatial dataset consisting of 6x regions of interest, acquired using Imaging Mass Cytometry (IMC)
#'
#' @docType data
#'
#' @usage demo.spatial
#'
#' @format An R object (list) containing 6x ROIs, each consisting of raster stacks, masks, and extracted cellular data in a data.table
#'
#' @author Thomas M Ashhurst, \email{thomas.ashhurst@@sydney.edu.au}
#'
#' @source Thomas M Ashhurst.
#'
#' @references \url{https://github.com/ImmuneDynamics/Spectre}.
#'
#' @examples
#' demo.spatial
#'
"demo.spatial"
4 changes: 2 additions & 2 deletions R/demo.start.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
#'
#' @source Thomas M Ashhurst.
#'
#' @references \url{https://sydneycytometry.org.au/spectre}.
#'
#' @references \url{https://github.com/ImmuneDynamics/Spectre}.
#'
#' @examples
#' demo.start
#'
Expand Down
4 changes: 2 additions & 2 deletions R/demo.sum.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
#'
#' @source Thomas M Ashhurst.
#'
#' @references \url{https://sydneycytometry.org.au/spectre}.
#'
#' @references \url{https://github.com/ImmuneDynamics/Spectre}.
#'
#' @examples
#' demo.sum
#'
Expand Down
4 changes: 2 additions & 2 deletions R/do.add.cols.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
#'
#' @author Thomas M Ashhurst, \email{thomas.ashhurst@@sydney.edu.au}
#'
#' @references \url{https://sydneycytometry.org.au/spectre}.
#'
#' @references \url{https://github.com/ImmuneDynamics/Spectre}.
#'
#' @examples
#' add.dt <- data.table('Files' = unique(Spectre::demo.asinh$FileName),
#' 'SampleNumber' = c(1:12))
Expand Down
129 changes: 129 additions & 0 deletions R/do.add.masks.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
#' do.add.masks
#'
#' @param spatial.dat NO DEFAULT. Spatial data list.
#' @param mask.loc NO DEFAULT. Directory of mask files.
#' @param masks NO DEFAULT. Vector of mask file names
#' @param mask.label DEFAULT = "cell_mask"
#' @param mask.ext DEFAULT = "_mask.tif" (will also recognise the '.tiff' file type)
#' @param correct.extent DEFAULT = TRUE
#' @param flip.y DEFAULT = TRUE
#' @param value.modifier DEFAULT = 65535
#' @param array DEFAULT = FALSE
#'
#' @author Thomas M Ashhurst, \email{thomas.ashhurst@@sydney.edu.au}
#'
#' @references \url{https://github.com/ImmuneDynamics/Spectre}.
#'
#' @import data.table
#'
#' @export

do.add.masks <- function(spatial.dat,
mask.loc,
masks,

mask.label = "cell.mask",
mask.ext = "_mask.tif",

correct.extent = TRUE,
flip.y = TRUE,
value.modifier = 65535,
array = FALSE
){

### Require

require('raster')
require('hdf5r')
require('HDF5Array')

### Setup

message(paste0('Adding masks to ', mask.label))

spat.names <- names(spatial.dat)
spat.names

mask.names <- gsub(mask.ext, "", masks)
mask.names

mask.check <- (spat.names == mask.names)
mask.check

if(all(mask.check) == FALSE){
stop('Error -- list of ROIs does not match the list of masks')
}

### Read in mask files

setwd(mask.loc)

for(i in spat.names){
# i <- spat.names[[1]]

message(paste0(" -- processing ", i))

if(grepl('.h5', mask.ext)){
file.ext <- '.h5'
} else {
file.ext <- 'other'
}

## If HDF5 files

if(file.ext == '.h5'){

message(" ... reading HDF5 file")

# h5closeAll()
# h5ls(paste0(i, mask.ext))

mask.img <- h5read(paste0(i, mask.ext), name = 'exported_data')
mask.img <- array(as.numeric(mask.img), dim(mask.img))
mask.img <- matrix(mask.img, nrow = dim(mask.img)[3], ncol = dim(mask.img)[2])
mask.img <- raster(mask.img)

} else {

## If NOT HDF5 files

if(array == FALSE){
mask.img <- readTIFF(paste0(i, mask.ext))
mask.img <- raster(mask.img)
}

if(array == TRUE){

message(" ... reading array")

mask.img <- raster(paste0(i, mask.ext))
}

}

## Correct extent

if(correct.extent == TRUE){
message(" ... correcting extent")
extent(mask.img) <- c(0, dim(mask.img)[2], 0,dim(mask.img)[1]) # Y axis - X axis
}

## Flip Y

if(flip.y == TRUE){
message(" ... flipping Y")
mask.img <- flip(mask.img, 'y')
}

## Finalise

raster::values(mask.img) <- raster::values(mask.img) * value.modifier
names(mask.img) <- mask.label
spatial.dat[[i]]$MASKS[[mask.label]]$maskraster <- mask.img

}

message("Returning spatial data object with added masks")
return(spatial.dat)
}

29 changes: 29 additions & 0 deletions R/do.add.percell.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#' do.add.percell
#'
#' @author Thomas M Ashhurst, \email{thomas.ashhurst@@sydney.edu.au}
#'
#' @references \url{https://github.com/ImmuneDynamics/Spectre}.
#'
#' @import data.table
#'
#' @export

do.add.percell <- function(spatial.dat,
percell.dat,
roi.col,
name = "per.cell"){

### Setup
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.")

### Loop

for(i in names(spatial.dat)){
# i <- "20171228_spleen315_500x500_editedforFAS_s1_p9_r2_a2_ac"
temp <- percell.dat[percell.dat[[roi.col]] == i,]
spatial.dat[[i]]$CPDATA[[name]] <- temp
}

return(spatial.dat)

}
3 changes: 3 additions & 0 deletions R/do.aggregate.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
#' plot.title = "Pheatmap",
#' sample.col = "Population",
#' plot.cols = names(exp)[c(2:10)])
#' @author Thomas M Ashhurst, \email{thomas.ashhurst@@sydney.edu.au}
#'
#' @references \url{https://github.com/ImmuneDynamics/Spectre}.
#'
#' @import data.table
#'
Expand Down
Loading