Skip to content

Commit

Permalink
moved progress output from STDOUT to STDERR (knitr compatibility) [fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mschilli87 committed Feb 17, 2017
1 parent 325ba98 commit a019766
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
22 changes: 11 additions & 11 deletions R/seurat.R
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ setMethod("ScaleData", "seurat",
if(do.scale | do.center) {
bin.size <- 1000
max.bin <- floor(length(genes.use)/bin.size) + 1
print("Scaling data matrix")
pb <- txtProgressBar(min = 0, max = max.bin, style = 3)
cat("Scaling data matrix", file = stderr())
pb <- txtProgressBar(min = 0, max = max.bin, style = 3, file = stderr())
for(i in 1:max.bin) {
my.inds <- ((bin.size * (i - 1)):(bin.size * i - 1))+1
my.inds <- my.inds[my.inds <= length(genes.use)]
Expand Down Expand Up @@ -283,7 +283,7 @@ setMethod("LogNormalize", "ANY",
}
# call Rcpp function to normalize
if(display.progress){
print("Performing log-normalization")
cat("Performing log-normalization", file = stderr())
}
norm.data <- LogNorm(data, scale_factor = scale.factor, display_progress = display.progress)
colnames(norm.data) <- colnames(data)
Expand Down Expand Up @@ -573,7 +573,7 @@ setMethod("ClassifyCells", "seurat",
new.data <- rbind(new.data, data.to.add)
new.data <- new.data[features, ]
new.data <- as.matrix(t(new.data))
print("Running Classifier ...")
cat("Running Classifier ...", file = stderr())
prediction <- predict(classifier, new.data)
new.classes <- prediction$predictions
return(new.classes)
Expand Down Expand Up @@ -603,7 +603,7 @@ setMethod("BuildRFClassifier", "seurat",
training.genes <- set.ifnull(training.genes, rownames(object@data))
training.data <- as.data.frame(as.matrix(t(object@data[training.genes, ])))
training.data$class <- factor(training.classes)
if (verbose) print("Training Classifier ...")
if (verbose) cat("Training Classifier ...", file = stderr())
classifier <- ranger(data = training.data, dependent.variable.name = "class", classification = T,
write.forest = T, ...)
return(classifier)
Expand Down Expand Up @@ -906,7 +906,7 @@ setMethod("RegressOut", "seurat",
bin.ind <- ceiling(1:length(genes.regress)/bin.size)
max.bin <- max(bin.ind)
print(paste("Regressing out",latent.vars))
pb <- txtProgressBar(min = 0, max = max.bin, style = 3)
pb <- txtProgressBar(min = 0, max = max.bin, style = 3, file = stderr())
data.resid=c()
data.use=object@data[genes.regress, , drop=FALSE];
if (model.use != "linear") {
Expand Down Expand Up @@ -1098,7 +1098,7 @@ setMethod("ProjectPCA", "seurat",

bin.size <- 1000
max.bin <- floor(length(genes.use)/bin.size) + 1
pb <- txtProgressBar(min = 0, max = max.bin, style = 3)
pb <- txtProgressBar(min = 0, max = max.bin, style = 3, file = stderr())
for(i in 1:max.bin) {
my.inds <- ((bin.size * (i - 1)):(bin.size * i - 1))+1
my.inds <- my.inds[my.inds <= length(genes.use)]
Expand Down Expand Up @@ -2153,7 +2153,7 @@ setMethod("NegBinomDETest", "seurat",
}
# check that variance between groups is not 0
if (var(to.test$GENE) == 0){
print("what")
cat("what", file = stderr())
warning(paste0("Skipping gene --", x, ". No variance in expression between the two clusters.", sep = " "))
return(2)
}
Expand Down Expand Up @@ -2206,7 +2206,7 @@ setMethod("PoissonDETest", "seurat",
}
# check that variance between groups is not 0
if (var(to.test$GENE) == 0){
print("what")
cat("what", file = stderr())
warning(paste0("Skipping gene --", x, ". No variance in expression between the two clusters.", sep = " "))
return(2)
}
Expand Down Expand Up @@ -4501,8 +4501,8 @@ setMethod("MeanVarPlot", signature = "seurat",

bin.size <- 1000
max.bin <- floor(length(genes.use)/bin.size) + 1
print("Calculating gene dispersion")
pb <- txtProgressBar(min = 0, max = max.bin, style = 3)
cat("Calculating gene dispersion", file = stderr())
pb <- txtProgressBar(min = 0, max = max.bin, style = 3, file = stderr())
for(i in 1:max.bin) {
my.inds <- ((bin.size * (i - 1)):(bin.size * i - 1))+1
my.inds <- my.inds[my.inds <= length(genes.use)]
Expand Down
8 changes: 4 additions & 4 deletions R/snn.R
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ CalcSNNSparse <- function(object, n.cells, k.param, nn.large, nn.ranked,
#define the edge weights with Jaccard distance

if (print.output) {
print("Constructing SNN")
pb <- txtProgressBar(min = 0, max = n.cells, style = 3)
cat("Constructing SNN", file = stderr())
pb <- txtProgressBar(min = 0, max = n.cells, style = 3, file = stderr())
}
for (i in 1:n.cells) {
for (j in 1:ncol(nn.large)) {
Expand Down Expand Up @@ -143,8 +143,8 @@ CalcSNNDense <- function(object, n.cells, nn.large, nn.ranked, prune.SNN,
#cell and its 10*k.param-nearest neighbors
#speed things up (don't have to calculate all pairwise distances)
if (print.output){
print("Constructing SNN")
pb <- txtProgressBar(min = 0, max = n.cells, style = 3)
cat("Constructing SNN", file = stderr())
pb <- txtProgressBar(min = 0, max = n.cells, style = 3, file = stderr())
}
for (i in 1:n.cells) {
for (j in 1:ncol(nn.large)) {
Expand Down

0 comments on commit a019766

Please sign in to comment.