-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathabundanceFilteringUtils.R
27 lines (23 loc) · 1 KB
/
abundanceFilteringUtils.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
getAbundanceThreshold <- function(sites, numGenes){
orderedAbundances <- sites[order(-sites$estAbundProp)]
#'unique' functionally removes anything that's duplicated, thus preserving order
abundCutoff <- orderedAbundances$nearest_refSeq_gene==unique(orderedAbundances$nearest_refSeq_gene)[numGenes]
abundCutoff <- orderedAbundances[which(abundCutoff)[1]]$estAbundProp
abundCutoff
}
filterLowAbund <- function(sites, abundCutoff){
sites$maskedRefGeneName <- ifelse(sites$estAbundProp > abundCutoff,
sites$nearest_refSeq_gene,
"LowAbund")
sites
}
getAbundanceSums <- function(sites, splitBy){
splitBy <- mcols(sites)[,splitBy]
splitSites <- split(sites, apply(as.data.frame(splitBy), 1, paste, collapse=""))
do.call(rbind, lapply(splitSites, function(sites){
res <- aggregate(estAbundProp~maskedRefGeneName, mcols(sites), sum)
res$Timepoint <- sites[1]$Timepoint
res$CellType <- sites[1]$CellType
res
}))
}