-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcountCellFun.R
45 lines (38 loc) · 1.71 KB
/
countCellFun.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
countCellFun <- function(kColNames )
{
cellNlist = list()
jumpInd <-length(uniqueLocations) %/% numberCores
uniqueLocationLevels <- rep(1:numberCores, each = jumpInd)
#add some extra at the end in case levels is shorter:
extraEnd <- length(uniqueLocations) - length(uniqueLocationLevels)
uniqueLocationLevels<- c(uniqueLocationLevels, rep(uniqueLocationLevels[length(uniqueLocationLevels)], extraEnd))
if(length(uniqueLocationLevels) != length(uniqueLocations) | !all(sort(uniqueLocationLevels) == uniqueLocationLevels)) {
stop("making uniqueLocationLevels failed")
}
uniqueLocationGroups = list()
for(countergroups in seq_along(unique(uniqueLocationLevels))) {
uniqueLocationGroups[[countergroups]] <- uniqueLocations[ uniqueLocationLevels == countergroups]
}
# divide data in parts to avoid copying entire object nCore times...
setkey(myDFo, plateWellID)
splitDataL =list()
for(splitLoop in seq_along(uniqueLocationGroups) )
{
splitDataL[[splitLoop]] <- myDFo[uniqueLocationGroups[splitLoop]]
}
print("Calculating min & max parent object counts:")
#kColNames$ImageCountParentsCN <- "imageCountParentObj"
registerDoParallel(cores=numberCores)
cellNlist <- foreach ( cellC = splitDataL, .packages = "data.table") %dopar%
{
parentCounts <- cellC[ , list(minCountParent = min(
get(kColNames$ImageCountParentsCN), na.rm=TRUE),
maxCountParent = max(
get(kColNames$ImageCountParentsCN), na.rm=TRUE),
meanCountParent = round(
mean(get(kColNames$ImageCountParentsCN), na.rm=TRUE), digits= 1)), by = plateWellID]
}
cellNlist <- rbindlist(cellNlist)
write.table(cellNlist,file = "parentObjectCounts.txt", sep ="\t", row.names = FALSE)
return(splitDataL)
}