Skip to content
Snippets Groups Projects

Correction

Closed Ilyess Rachedi requested to merge Correction into master
Files
9
+ 178
24
library(SingleCellExperiment)
checkTsneObject <- function(obj){
if (!class(obj) == "Tsne")
return(FALSE)
}
checkDbscanObject <- function(obj){
if (!class(obj) == "Dbscan")
return(FALSE)
}
## scRNAseq class
scRNAseq <- setClass(
# Set the name for the class
"scRNAseq",
# Define the slots
slots = c(
experimentName = "character",
countMatrix = "matrix",
@@ -19,44 +26,191 @@ scRNAseq <- setClass(
clusters = "SingleCellExperiment"
),
# Make a function that can test to see if the data is consistent.
# This is not called if you have an initialize function defined!
validity = function(object)
{
prototype=list(
normalizedCountMatrix = SingleCellExperiment(),
tSNEList = list(),
dbscanList = list()
# cellsSimilarityMatrix = matrix(),
# clustersSimilarityMatrix = matrix(),
# clusters = SingleCellExperiment()
),
validity = function(object){
errors <- character()
## Test experimentName slot
experimentName = getExperimentName(object)
if (!is.character(experimentName) | (grepl(" ", experimentName))){
msg <- paste("Experiment name should contain a single string ",
"describing the experiment, '",
experimentName,
"' is not correct.\n",
sep = "")
errors <- c(errors, msg)
}
## Test countMatrix slot
countMatrix = getCountMatrix(object)
if(ncol(countMatrix) < 100) {
return("Not enough cells in the count matrix")
msg <- paste("Not enough cells in the count matrix. ",
"Should be at leat 100 cells. ",
"The current count matrix contains ",
ncol(countMatrix), " cells.\n",
sep = "")
errors <- c(errors, msg)
}
## Test normalizedCountMatrix slot
normalizedCountMatrix=getNormalizedCountMatrix(object)
if (!class(normalizedCountMatrix) == "SingleCellExperiment"){
msg <- paste("Normalized count matrix should be ",
"SingleCellExperiment, ",
"not '",
class(normalizedCountMatrix),
"'.\n",
sep = "")
errors <- c(errors, msg)
}
## Test colData slot
colData=getColData(object)
if ((!is.null(colData) & (!is.element('cellName', colnames(colData))))){
msg <- paste("colData should be a data frame containing ",
"at least 'cellName' column.\n",
sep = "")
errors <- c(errors, msg)
}
## Test species slot
species=getSpecies(object)
if (!is.element(species, c("mmu","human"))){
msg <- paste("species should be 'mmu' or 'human'. '",
species, "' is not available.\n",
sep = "")
errors <- c(errors, msg)
}
## Test tSNEList slot
tSNEList=getTSNEList(object)
if (!all(unlist(sapply(tSNEList, checkTsneObject)))){
msg <- paste("tSNE list should contain only objects ",
"of 'Tsne class.'\n",
sep = "")
errors <- c(errors, msg)
}
## Test dbscan slot
dbscanList=getDbscanList(object)
if (!all(unlist(sapply(dbscanList, checkDbscanObject)))){
msg <- paste("dbscan list should contain only objects ",
"of 'Dbscan class.'\n",
sep = "")
errors <- c(errors, msg)
}
## Validity return errors messages if they exist
if (length(errors) == 0) {
return(TRUE)
} else {
return(stop(errors))
}
# Vérifiez les types des slots
return(TRUE)
}
)
## Tsne class
Tsne <- setClass(
# Set the name for the class
"Tsne",
# Define the slots
slots = c(
name = "character",
pc = "numeric",
perplexity = "numeric",
coordinates = "list"
)
coordinates = "matrix"
),
prototype=list(
name = character(),
pc = numeric(),
perplexity = numeric(),
coordinates = matrix()
),
validity = function(object){
errors <- character()
## Test slot Name
name = getName(object)
if (!is.character(name)){
msg <- paste("Name of Tsne object'" , name , "' is incorrect. ",
"It should be a string.\n",
sep = "")
errors <- c(errors, msg)
}
## Test slot pc
pc = getPC(object)
if (!is.numeric(pc)){
msg <- paste("PC '" , pc , "' is incorrect. ",
"It should be a numeric.\n",
sep = "")
errors <- c(errors, msg)
}
## Test slot perplexity
perplexity = getPerplexity(object)
if (!is.numeric(perplexity)){
msg <- paste("Perplexity '" , perplexity , "' is incorrect. ",
"It should be a numeric.\n",
sep = "")
errors <- c(errors, msg)
}
## Test slot coordinates
coordinates = getCoordinates(object)
if (!is.matrix(coordinates)){
msg <- paste("Coordinates should be matrix",
sep = "")
errors <- c(errors, msg)
}
}
)
# Dbscan class
Dbscan <- setClass(
# Set the name for the class
"Dbscan",
# Define the slots
slots = c(
name = "character",
clustering = "matrix",
epsilon = "numeric",
minPoints = "numeric"
)
minPoints = "numeric",
clustering = "matrix"
),
prototype=list(
name = character(),
epsilon = numeric(),
minPoints = numeric(),
clustering = matrix()
),
validity = function(object){
errors <- character()
## Test slot Name
name = getName(object)
if (!is.character(name)){
msg <- paste("Name of Dbscan object '" , name , "' is incorrect. ",
"It should be a string.\n",
sep = "")
errors <- c(errors, msg)
}
## Test slot epsilon
epsilon = getEpsilon(object)
if (!is.numeric(pc)){
msg <- paste("Epsilon '" , epsilon , "' is incorrect. ",
"It should be a numeric.\n",
sep = "")
errors <- c(errors, msg)
}
## Test slot minPoints
minPoints = getMinPoints(object)
if (!is.numeric(minPoints)){
msg <- paste("minPoints '" , minPoints , "' is incorrect. ",
"It should be a numeric.\n",
sep = "")
errors <- c(errors, msg)
}
## Test slot clustering
clustering = getClustering(object)
if (!is.matrix(clustering)){
msg <- paste("Coordinates should be matrix",
sep = "")
errors <- c(errors, msg)
}
}
)
Loading