Skip to content

Instantly share code, notes, and snippets.

View JakeConway's full-sized avatar

Jake Conway JakeConway

  • Methuen, Massachusetts
View GitHub Profile
@JakeConway
JakeConway / ICGC_Rest_API_to_UpSetR.R
Last active December 27, 2016 06:11
Pull mutation data from projects via the ICGC Rest API
require(jsonlite)
require(curl)
#An example of the function input.
#Specify the project name, fields, and number of entries(size) to pull in each list
data <- list(list(project = "THCA-US", fields = c("id", "mutation", "chromosome", "start", "end"), size = 6659),
list(project = "THCA-SA", fields = c("id", "mutation", "chromosome", "start", "end"), size = 45126),
list(project = "LUSC-US", fields = c("id", "mutation", "chromosome", "start", "end"), size = 65063),
list(project = "LUSC-KR", fields = c("id", "mutation", "chromosome", "start", "end"), size = 64671),
setwd("/Users/jakeconway/Desktop/icgcSampleData/Set 1")
fileList <- list.files()
set1 <- data.frame(); set2 <- data.frame(); set3 <- data.frame();
for(file in fileList){
temp_data <- read.table(file, header=TRUE, sep="\t")
temp_data$Mutation.ID <- as.character(temp_data$Mutation.ID)
set1 <- rbind(set1, temp_data)
rm(temp_data)
}
setwd("/Users/jakeconway/Desktop/icgcSampleData/Set 2")
@JakeConway
JakeConway / fromList.R
Last active December 27, 2016 06:14
Convert list of named vectors to UpSetR input
fromList <- function(input){
elements <- unique(unlist(input))
data <- unlist(lapply(input, function(x){x <- as.vector(match(elements, x))}))
data[is.na(data)] <- as.integer(0); data[data != 0] <- as.integer(1)
data <- data.frame(matrix(data, ncol = length(input), byrow = F))
data <- data[which(rowSums(data) !=0), ]
names(data) <- names(input)
return(data)
}
@JakeConway
JakeConway / fromExpression.R
Last active December 27, 2016 06:14
expression to UpSetR converter
fromExpression <- function(vd){
vd <- list(vd)
intersections <- lapply(vd, function(x) strsplit(names(unlist(x)), "&"))
intersections <- lapply(intersections[[1]], function(x) unlist(as.list(x)))
sets <- unique(unlist(intersections))
data <- na.omit(data.frame(matrix(NA, ncol = length(sets))))
names(data) <- sets
counts <- lapply(vd, function(x) unlist(x))
names(counts[[1]]) <- NULL
counts[[1]] <- as.numeric(counts[[1]])