Skip to content

Commit

Permalink
I had broken generate.celltype.data while trying to make it run faste…
Browse files Browse the repository at this point in the history
…r. It was just summing reads instead of calculating their mean. Fixed. Thanks to Kaitlyn Price of Toronto for spotting the bug!

Former-commit-id: 7ded1d0
  • Loading branch information
Nathan Skene committed Sep 2, 2020
1 parent e3f8f2c commit 4e66454
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions R/generate.celltype.data.r
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,16 @@ generate.celltype.data <- function(exp,annotLevels,groupName,no_cores=1,savePath
}
ctd_oneLevel$mean_exp = as.matrix(expMatrix)
}else{
# Sum reads in each cell type
#mean_exp = apply(expMatrix,1,aggregate.over.celltypes,ctd_oneLevel$annot)
mm <- model.matrix(~ 0 + ctd_oneLevel$annot)
colnames(mm) <- names(table(ctd_oneLevel$annot))
mat.summary.mm1 <- expMatrix %*% mm

# Divide by the number of cells to get the mean
cellCounts = table(ctd_oneLevel$annot)
for(i in 1:dim(mat.summary.mm1)[2]){mat.summary.mm1[,i] = mat.summary.mm1[,i]/cellCounts[i]}

ctd_oneLevel$mean_exp = as.matrix(mat.summary.mm1)
}
return(ctd_oneLevel)
Expand Down

0 comments on commit 4e66454

Please sign in to comment.