Skip to content

Commit

Permalink
ENH: Calculate p-values for all wells; not just RNAi
Browse files Browse the repository at this point in the history
  • Loading branch information
pan14001 committed Jan 27, 2017
1 parent b177297 commit c7bc7c0
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions analysis-only_overlap.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ wells_control <- data.frame(
well = c("C03", "C22", "D12", "D13", "E05", "E20", "F11", "F14",
"G07", "G18", "H09", "H16", "I09", "I16", "J07", "J18",
"K11", "K14", "L05", "L20", "M12", "M13", "N03", "N22"),
type = "Lacz") %>%
type = "Lacz",
control = "negative") %>%
rbind(data.frame(
type = c("BROWN", "CAL1", "FACT", "Rho1", "thread", "water"),
well = c("I04", "E09", "L03", "E16", "L16", "H21")
well = c("I04", "E09", "L03", "E16", "L16", "H21"),
control = c(NA, NA, "positive", NA, NA, NA)
))

## Database boilerplate.
Expand Down Expand Up @@ -54,20 +56,23 @@ wells <- merge(cells, select(images, imagenumber, image_metadata_well,
# Check the controls.
controls_plate1 <- merge(wells, wells_control) %>%
filter(plate == "160415_015529-V") %>%
group_by(type) %>%
summarise(n = sum(n), n_coloc = sum(n_coloc), coloc = n_coloc / n)
group_by(type, control) %>%
summarise(n = sum(n),
n_coloc = sum(n_coloc),
coloc = n_coloc / n)
print(controls_plate1)

controls_all <- merge(wells, wells_control) %>%
group_by(type) %>%
group_by(type, control) %>%
summarise(n = sum(n), n_coloc = sum(n_coloc), coloc = n_coloc / n)
print(controls_all)

wells_rnai <- data.frame(
well = setdiff(wells$well, wells_control$well),
type = "RNAi")
type = "RNAi",
control = NA)

rnai <- filter(wells, well %in% wells_rnai) %>%
rnai <- filter(wells, well %in% wells_rnai$well) %>%
mutate(coloc = n_coloc / n)
print(rnai)

Expand All @@ -91,19 +96,18 @@ p_value <- function(x) {
x <- x[1L, 1L]
phyper(x - 1, m, n, k, lower.tail = FALSE)
}
cells <- filter(wells_all, type == "RNAi") %>% select(n) %>% unlist
overlaps <- filter(wells_all, type == "RNAi") %>% select(n_coloc) %>%
cells <- filter(wells_all) %>% select(n) %>% unlist
overlaps <- filter(wells_all) %>% select(n_coloc) %>%
unlist
cells_all <- sum(cells)
overlaps_all <- sum(overlaps)
cells_all <- sum(filter(cells, type == "RNAi"))
overlaps_all <- sum(filter(overlaps, type == "RNAi"))
contingency_matrix <- rbind(cells, overlaps,
cells_all, overlaps_all)
## Organize array to have 2x2 margin instead of 1x4.
dim(contingency_matrix) <- c(2, 2, length(contingency_matrix) / 4)
p_values_uncorrected <- apply(contingency_matrix, 3, p_value)
p_values <- p.adjust(p_values_uncorrected, method = "bonferroni")
wells_all$p_value <- NA
wells_all[wells_all$type == "RNAi", "p_value"] <- p_values_uncorrected
wells_all$p_value <- p_values_uncorrected

write.csv(wells_all %>% arrange(p_value), file = "rnai-p_values.csv",
quote = FALSE, row.names = FALSE)

0 comments on commit c7bc7c0

Please sign in to comment.