Skip to content

Instantly share code, notes, and snippets.

@crazyhottommy
Created February 14, 2018 23:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crazyhottommy/f3d1866cb771b81cda3b0f65d5f9174e to your computer and use it in GitHub Desktop.
Save crazyhottommy/f3d1866cb771b81cda3b0f65d5f9174e to your computer and use it in GitHub Desktop.
library('TCGAbiolinks')
library('plyr')
library('devtools')

projects<- "TCGA-LUAD"

clin <- lapply(projects, function(p) {
    message(paste(Sys.time(), 'processing project', p))
    result <- tryCatch({
        query <- GDCquery(project = p, data.category = 'Clinical')
        GDCdownload(query)
        GDCprepare_clinic(query, clinical.info = 'patient')
    }, error = function(e) {
        message(paste0('Error clinical: ', p))
        return(NULL)
    })
    return(result)
})
names(clin) <- projects

## Merge all
clin_all <- rbind.fill(clin)

## Fix columns that have '' that should be NAs
for(j in seq_len(ncol(clin_all))) {
    i <- which(clin_all[, j] == '')
    if(length(i) > 0) clin_all[i, j] <- NA
}

save(clin_all, file = 'clin_all.Rdata')

write.table(clin_all, file = 'clin_all.tsv', quote = FALSE, row.names = FALSE,
    sep = '\t')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment