Skip to content

Commit

Permalink
#34: Handle some edge cases in warpSet
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobpwagner committed Jul 22, 2020
1 parent 336f98f commit 96eaf10
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
11 changes: 11 additions & 0 deletions R/landmarkMatrix.R
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,17 @@ landmarkMatrix <- function(data, fres, parm, border=0.05, peakNr=NULL, densities
matD[i,cl$cluster] <- cl$dist/diff(ranges[[1]][,parm])
}
resRegions <- resRegions[rownames(mat)]

# TODO: Somehow it is possible for a landmark column to be NA for all samples
# and this is seed-dependent. This is a deeper bug, but for now remove these
# problematic landmarks so they don't cause obscure errors later
valid_landmarks <- apply(mat, 2, function(col) !all(is.na(col)))
mat <- mat[,valid_landmarks]
regRegions <- lapply(resRegions, function(sample_regions){
sample_regions[valid_landmarks,]
})

matD <- matD[,valid_landmarks]
attr(mat, "regions") <- resRegions
attr(mat, "cdists") <- matD
return(mat)
Expand Down
14 changes: 12 additions & 2 deletions R/warpSet.R
Original file line number Diff line number Diff line change
Expand Up @@ -704,8 +704,18 @@ warpSet.flowSet <- function(x, stains, grouping=NULL, monwrd=TRUE, subsample=NUL
stop("'", grouping, "' is not a phenoData variable.")
grps <- as.factor(pData(x)[,grouping])
anv <- numeric(ncol(landmarks))
for(i in seq_len(ncol(landmarks)))
anv[i] <- anova(lm(landmarks[,i] ~ grps))$Pr[1]

for(i in seq_len(ncol(landmarks))){
grps_present <- unique(grps[!is.na(landmarks[,i])])
if(length(grps_present == 1)){
warning(paste0("The following landmark is only present in a single group --",
"\nstain: ", p,
"\nmean value: ", mean(landmarks[!is.na(landmarks[,i]),i])))
anv[i] = 1.0 # pass the variance check below to avoid double warning
}else{
anv[i] <- anova(lm(landmarks[,i] ~ grps))$Pr[1]
}
}
if(any(anv < sig))
warning("Within-group variances are smaller than ",
"across-group variances for stain ", p,
Expand Down

0 comments on commit 96eaf10

Please sign in to comment.