Skip to content

Instantly share code, notes, and snippets.

@JakeConway
Created May 25, 2017 22:47
Show Gist options
  • Save JakeConway/c2911ab8015cf2a577ac7b10f78565b0 to your computer and use it in GitHub Desktop.
Save JakeConway/c2911ab8015cf2a577ac7b10f78565b0 to your computer and use it in GitHub Desktop.
pairwiseCorrelationOfGenes <- function(maf, sig.genes) {
genes <- sig.genes[which(sig.genes$p < 0.05 & sig.genes$q < 0.3), ]$gene
df <- as.data.frame(t(combn(genes[1:3], 2)))
names(df) <- c("gene1", "gene2")
apply(df, 1, function(x) {
gene1 <- unname(x["gene1"])
gene2 <- unname(x["gene2"])
samples.w.gene1 <- unique(maf[which(maf$Hugo_Symbol == gene1), ]$Tumor_Sample_Barcode)
samples.w.gene2 <- unique(maf[which(maf$Hugo_Symbol == gene2), ]$Tumor_Sample_Barcode)
samples.w.both.genes <- intersect(samples.w.gene1, samples.w.gene2)
samples.w.gene1 <- samples.w.gene1[which(!samples.w.gene1 %in% samples.w.both.genes)]
samples.w.gene2 <- samples.w.gene2[which(!samples.w.gene2 %in% samples.w.both.genes)]
all.samples.w.genes <- unique(c(samples.w.gene1, samples.w.gene2, samples.w.both.genes))
all.samples <- unique(maf$Tumor_Sample_Barcode)
samples.w.no.genes <- all.samples[which(!all.samples %in% all.samples.w.genes)]
mat <- matrix(c(length(samples.w.both.genes),
length(samples.w.gene2),
length(samples.w.gene1),
length(samples.w.no.genes)),
nrow = 2,
dimnames = list(
c(gene1, paste("No", gene1)),
c(gene2, paste("No", gene2))
))
print(mat)
print(fisher.test(mat))
})
}
correlation.data <- pairwiseCorrelationOfGenes(maf, sig.genes)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment