Skip to content

Instantly share code, notes, and snippets.

@seandavi
Created January 8, 2018 13:48
Show Gist options
  • Save seandavi/91f85823d612116e06e8cd36aa2aff72 to your computer and use it in GitHub Desktop.
Save seandavi/91f85823d612116e06e8cd36aa2aff72 to your computer and use it in GitHub Desktop.
TARGET osteosarcoma oncoprint R code
library(aws.s3)
aws.signature::use_credentials(profile='s3')
disco_maf = s3read_using(readr::read_tsv,object="s3://target-osteosarcoma/TargetOsteoDiscovery/summary/strelka.maf.filtered.tab")
disco_gistic = s3read_using(readr::read_tsv,object="s3://target-osteosarcoma/TargetOsteoDiscovery/all_thresholded.by_genes.txt")
library(tidyr)
library(dplyr)
library(ComplexHeatmap)
x = disco_gistic %>%
gather(key = 'Sample', value='CN', -c('Gene Symbol', "Locus ID", "Cytoband")) %>%
dplyr::select(Sample, Hugo_Symbol = `Gene Symbol`, CN) %>%
dplyr::filter(CN %in% c(2,-2)) %>%
mutate(CNV = ifelse(CN>0, 'Amplification', 'Copy Number Loss')) %>%
dplyr::filter(CNV == 'Copy Number Loss')
p = function(x) paste(x, collapse=";")
y = disco_maf %>%
dplyr::select(Hugo_Symbol, Sample = Tumor_Sample_Barcode, Variant_Classification) %>%
unique() %>%
group_by(Hugo_Symbol, Sample) %>%
dplyr::filter(Variant_Classification %in% c('Missense_Mutation', 'Nonsense_Mutation')) %>%
summarize(Variant_Classification = p(Variant_Classification)) %>%
mutate(Sample = substr(Sample,1,6))
z = x %>% dplyr::full_join(y) %>%
unite(Variants, CNV, Variant_Classification, sep=';') %>%
dplyr::select(-CN) %>%
mutate(Variants=sub('NA;','',Variants)) %>%
mutate(Variants=sub(';NA','',Variants)) %>%
spread(value = Variants, key = Sample)
zmat = as.matrix(z[,-1])
rownames(zmat) = z[[1]]
zmat1 = zmat[apply(zmat,1,function(x) sum(!is.na(x))) > 10 ,]
library(ComplexHeatmap)
col = c(Missense_Mutation = "red", `Copy Number Loss` = "blue",
Nonsense_Mutation = 'orange', Amplification = 'green')
oncoPrint(zmat1, get_type = function(x) strsplit(x, ";")[[1]],
alter_fun = list(
Missense_Mutation = function(x, y, w, h) grid.rect(x, y, w*0.9, h*0.9, gp = gpar(fill = col["Missense_Mutation"], col = NA)),
Nonsense_Mutation = function(x, y, w, h) grid.rect(x, y, w*0.9, h*0.9, gp = gpar(fill = col["Nonsense_Mutation"], col = NA)),
Amplification = function(x, y, w, h) grid.rect(x, y, w*0.9, h*0.4, gp = gpar(fill = col["Amplification"], col = NA)),
`Copy Number Loss` = function(x, y, w, h) grid.rect(x, y, w*0.9, h*0.4, gp = gpar(fill = col["Copy Number Loss"], col = NA))
), col = col)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment