-
Notifications
You must be signed in to change notification settings - Fork 1
/
data_download_preprocessing.Rmd
365 lines (298 loc) · 16.5 KB
/
data_download_preprocessing.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
---
title: "data_download_preprocessing"
author: "Tao Wu"
date: "`r Sys.Date()`"
output:
rmdformats::readthedown:
highlight: kate
lightbox: false
toc_depth: 3
mathjax: true
---
```{r pre-process-setup, include=FALSE}
options(max.print = "120")
knitr::opts_chunk$set(echo = TRUE, comment = "#>", eval = TRUE, collapse = TRUE,cache = FALSE)
knitr::opts_knit$set(width = 120)
```
```{r lib,echo=TRUE,eval=TRUE,include=FALSE}
library(tidyverse)
library(ggpubr)
library(cowplot)
library(viridis)
library(NeoEnrichment)
library(parallel)
```
This part will describe how and where the data that this project used is downloaded and pre-processed.
## TCGA pancancer data download and clean
### Mutation data
Pre-compiled curated somatic mutations (called by MuTect2) for TCGA cohorts were downloaded from [Xena](https://xenabrowser.net/datapages/?dataset=GDC-PANCAN.mutect2_snv.tsv&host=https%3A%2F%2Fgdc.xenahubs.net&removeHub=https%3A%2F%2Fxena.treehouse.gi.ucsc.edu%3A443) and only keep missense variants for following analysis
```{r mut_data,eval=FALSE}
mutect2 <- data.table::fread("~/useful_data/GDC-PANCAN.mutect2_snv.tsv") %>%
dplyr::filter(effect=="missense_variant" & filter=="PASS")
saveRDS(mutect2,file = "../data/pancancer_mutation.rds")
```
view this file:
```{r view_mut,eval=TRUE}
pancancer_mutation <- readRDS("../data/pancancer_mutation.rds")
DT::datatable(head(pancancer_mutation),
options = list(scrollX = TRUE, keys = TRUE,
columnDefs = list(list(className = 'dt-center', targets = 2))), rownames = FALSE
)
```
To predict neoantigen, mutation files were first transformed into single sample VCF format by maf2vcf tools (This Code can be found in `code/shell/TCGA_neoantigen` folder).
ABSOLUTE-annotated MAF file which contains cancer cell fraction (CCF) information of mutations was downloaded from GDC PanCanAtlas publications ([TCGA_consolidated.abs_mafs_truncated.fixed.txt.gz](https://gdc.cancer.gov/node/905/)), and then we used liftover function from R package “rtracklayer” to convert the this hg37 genome coordinates file to hg38 coordinates:
```{r absolute_data,eval=FALSE}
absolute_maf <- data.table::fread("~/useful_data/TCGA_consolidated.abs_mafs_truncated.fixed.txt")
absolute_maf <- absolute_maf %>%
dplyr::select(Hugo_Symbol,Chromosome,Start_position,End_position,ccf_hat,sample,
Protein_Change,Variant_Classification,Variant_Type,Reference_Allele,
Tumor_Seq_Allele2,ref,alt,purity)
library(GenomicRanges)
absolute_maf$Chromosome <- paste0("chr",absolute_maf$Chromosome)
absolute_granges <- makeGRangesFromDataFrame(absolute_maf,
keep.extra.columns=TRUE,
ignore.strand=TRUE,
seqinfo=NULL,
seqnames.field="Chromosome",
start.field="Start_position",
end.field="End_position",
starts.in.df.are.0based=FALSE)
library(rtracklayer)
chainObject <- import.chain("~/useful_data/hg19ToHg38.over.chain")
results <- as.data.frame(liftOver(absolute_granges, chainObject))
results <- results %>%
filter(width==1)
results <- results %>%
filter(Variant_Classification=="Missense_Mutation") %>%
mutate(index=paste(substr(sample,1,16),seqnames,start,Reference_Allele,Tumor_Seq_Allele2,sep = ":")) %>%
select(sample,index,Hugo_Symbol,Protein_Change,Reference_Allele,Tumor_Seq_Allele2,purity,ccf_hat)
saveRDS(results,file = "../data/all_mut_mis_ccf.rds")
```
Driver mutation data was downloaded from Bailey M H et.al study ([Mutation.CTAT.3D.Scores.txt](https://gdc.cancer.gov/about-data/publications/pancan-driver)). This study used three different categories of tools to find driver mutations:
1. tools distinguishing benign versus pathogenic mutations using sequence (CTAT population);
2. tools distinguishing driver versus passenger mutations using sequence (CTAT cancer);
3. tools discovering statistically significant three-dimensional clusters of missense mutations (structure based).
We keep mutations identified by ≥2 approaches as finial high confident driver mutations, including 3437 unique mutations:
```{r driver_mutation_data,eval=FALSE}
driver <- data.table::fread("~/data/Mutation.CTAT.3D.Scores.txt")
driver_mutations <- driver %>%
mutate(nmethod=`New_Linear (functional) flag`+`New_Linear (cancer-focused) flag`+`New_3D mutational hotspot flag`) %>%
filter(nmethod>=2)
saveRDS(driver_mutations,file = "../data/driver_mutations.rds")
```
### Expression data
The normalized gene-level RNA-seq data (TPM, transcripts per million) for 31 TCGA cohorts were downloaded from Xena ([tcga_RSEM_gene_tpm](https://xenabrowser.net/datapages/?dataset=tcga_RSEM_gene_tpm&host=https%3A%2F%2Ftoil.xenahubs.net&removeHub=https%3A%2F%2Fxena.treehouse.gi.ucsc.edu%3A443)) and transformed from log-form to non-log form (This file is too large to store in Github):
```{r tpm_trans,eval=FALSE}
TPM_log2 <- data.table::fread("~/useful_data/xena_RSEM_TPM/tcga_RSEM_gene_tpm.gz")
mapping <- data.table::fread("~/useful_data/xena_RSEM_TPM/mapping_probe")
mapping <- mapping[,1:2]
TPM_log2_mapping <- left_join(TPM_log2 %>% rename(id=sample),mapping) %>%
select(id,gene,everything())###log2(tpm+0.001)
TPM_log2_mapping <- as.data.frame(TPM_log2_mapping)
tpm_trans <- TPM_log2_mapping
tpm_trans[,3:ncol(tpm_trans)] <- apply(TPM_log2_mapping[,3:ncol(TPM_log2_mapping)],2,
function(x){(2^x) - 0.001})
saveRDS(tpm_trans,file = "~/useful_data/xena_RSEM_TPM/tpm_trans.rds")
```
### HLA typing and immune cell infiltration data
HLA typing data was downloaded from Thorsson et.al study and transformed to the format required by the neoantigen prediction tools:
```{r hla_trans,eval=FALSE}
hla <- read.table("~/useful_data/panCancer_hla.tsv",sep = "\t")
hla <- hla %>%
separate(col = V2,into = c("HLA-A_1","HLA-A_2",
"HLA-B_1","HLA-B_2",
"HLA-C_1","HLA-C_2"),sep = ",")
###no stars
hla <- t(base::apply(hla,1,function(x){
x[which(duplicated(x))] <- NA
x <- gsub("\\*","",x)
x
})) %>% as.data.frame()
colnames(hla)[1] <- "Patient"
write.table(hla,file = "~/useful_data/TCGA_HLA_typing.txt",sep = "\t",quote = F,col.names = T,row.names = F)
```
Immune cell infiltration data for all TCGA tumors was downloaded from ImmuneCellAI study (Miao et al., 2020), which estimates the abundance of 24 immune cells comprised of 18 T-cell subtypes and 6 other immune cells. We can only download indivial cancer type data from the web server, so we need combine them all:
```{r combine_immune,eval=FALSE}
files <- list.files("~/test/immune_score/immuneCellAI/")
re <- vector("list",length(files))
for(i in seq_along(re)){
dt <- data.table::fread(paste0("~/test/immune_score/immuneCellAI/",files[i]),data.table = F) %>%
rename(sample=V1) %>%
mutate(sample=substr(sample,1,16)) %>%
mutate(sample=gsub("\\.","-",sample))
re[[i]] <- dt
}
results <- bind_rows(re)
saveRDS(results,file = "../data/pancancer_subtcells.rds")
```
We can view this file:
```{r view_immune,eval=TRUE}
pancancer_immune <- readRDS("../data/pancancer_subtcells.rds")
DT::datatable(head(pancancer_immune),
options = list(scrollX = TRUE, keys = TRUE), rownames = FALSE
)
```
Other Immune cell infiltration data including CIBERSORT (abs mode), Quantiseq were downloaded from the [TIMER2.0](http://timer.comp-genomics.org/) study.
## TCGA pancancer data processing
This part describes HLA typing and neoantigen prediction of TCGA data.
### HLA typing
For samples which don't have corresponding HLA infromation data in Thorsson et.al study, HLA genotyping was performed with Optitype (Szolek et al., 2014), using default parameters. This corresponding code can be found in `code/python/HLA_typing` (using snakemake pipeline tools).
### Neoantigen prediction
Mutect2 mutation files were first transformed into VCF format by maf2vcf tools, and we used NeoPredPipe to predict neoantigen (Schenck et al., 2019). Single-nucleotide variants leading to a single amino acid change are the focus of this study. From the output results, if the IC50 of a novel peptide is less than 50, the bind level is SB (strong binder, rank is less than 0.5%), and the expression level (TPM) is greater than 1, then this peptide is labeled as neoantigen. A mutation is considered neoantigenic if there is at least one peptide derived from the mutated site is predicted as neoantigen. The neoantigen prediction code using NeoPrePipe can be found in `code/shell/TCGA_neoantigen`. Then we add CCF and mRNA expression information to neoantigen prediction data:
```{r neo-pre,eval=FALSE}
library(dplyr)
setwd("/public/slst/home/wutao2/TCGA_neopredpipe/batch_results")
files <- read.table("files")
for (i in 1:100){
mut <- data.table::fread(paste(files$V1[i],"/batch_",files$V1[i],".neoantigens.unfiltered.txt",sep = ""),fill=TRUE)
mut <- mut %>%
select(c(1,4:11,21:28))
colnames(mut) <- c("sample","chr","position",
"ref","alt","gene","exp","res_pos",
"hla","score_el","rank_el","score_ba",
"rank_ba","IC50","candidate","bindlevel",
"novelty")
mut <- mut %>%
mutate(novelty=ifelse(is.na(novelty),0,novelty)) %>%
mutate(index=paste(sample,chr,position,ref,alt,sep = ":"))
saveRDS(mut,file = paste(files$V1[i],".rds",sep = ""))
}
files <- list.files("~/test/data/2021_03_31/")
re <- vector("list",100)
for (i in 1:100){
mut <- readRDS(paste("~/test/data/2021_03_31/",files[i],sep = ""))
neo <- mut %>%
filter(novelty == 1) %>%
filter(IC50<50 & bindlevel=="SB" & novelty==1 ) %>%
distinct(index,.keep_all = T)
mut <- mut %>%
distinct(index,.keep_all = T) %>%
mutate(neo = ifelse(index %in% neo$index , "neo","not_neo"))
re[[i]] <- mut
}
all_mut <- bind_rows(re)
all_mut <- all_mut %>%
select(sample,chr,position,ref,alt,neo,gene,exp)
all_mut <- all_mut %>%
mutate(gene=gsub("\\:.+","",gene))
saveRDS(all_mut,file = "~/test/data/2021_04_17/all_mut.rds")
tpm <- readRDS("~/useful_data/xena_RSEM_TPM/tpm_trans.rds")
tpm <- tpm[!duplicated(tpm$gene),]
all_mut$tpm_exp <- mapply(function(sample,gene){
tpm[tpm$gene==gene,substr(sample,1,15)]
},all_mut$sample,all_mut$gene)
all_mut1 <- all_mut %>%
filter(lengths(tpm_exp)!=0)
all_mut1$tpm_exp <- as.numeric(all_mut1$tpm_exp)
saveRDS(all_mut1,file = "../data/all_mut_tpm_not_filter.rds")##this file is used to calculte EXP-ES
all_mut1 <- all_mut1 %>%
mutate(neo2=ifelse(neo=="neo" & tpm_exp>1,"neo","not_neo"))
all_mut1 <- all_mut1 %>%
select(-neo,-exp) %>%
rename(neo=neo2)
saveRDS(all_mut1,file = "~/test/all_mut_tpm.rds")
##add ccf
results <- readRDS("~/test/data/2021_04_05/all_mut_mis_ccf.rds")
all_mut_tpm <- readRDS("~/test/all_mut_tpm.rds")
#all_mut_tpm <- readRDS("~/test/all_mut_tpm_not_filter.rds")
all_mut <- all_mut_tpm %>%
mutate(index=paste(sample,chr,position,ref,alt,sep = ":")) %>%
dplyr::rename(ref_allele=ref,alt_allele=alt)
all_mut_ccf <- inner_join(
all_mut,
results %>% select(-sample),
by="index"
)
all_mut_ccf <- all_mut_ccf[!duplicated(all_mut_ccf$index),]
saveRDS(all_mut_ccf,file = "../data/all_mut_ccf_tpm.rds")##This file is used to calculate CCF-ES
```
## Immunotherapy data download and clean
We collected three cohorts of immunotherapy datasets for our analysis. `The Hugo et al. (2016) dataset` was related to anti-PD-1 therapy in metastatic melanoma. This dataset has 37 samples with WES data, 26 were also analyzed by RNA sequencing (RNA-seq). `The Riaz et al. (2017) dataset` was related to anti-PD-1 therapy in metastatic melanoma. This dataset has 56 samples with WES data, 40 with RNA-seq. `The David Liu et.al (2019) cohort` has patients with melanoma treated with anti-PD1 ICB, which 119 samples has WES data, 112 with RNA-seq.
Immune therapy response for patients was defined by RECIST v1.1(CR/PR/SD/PD), responding tumors were derived from patients who have complete or partial responses (CR/PR) in response to anti-PD-1 therapy; non-responding tumors were derived from patients who had progressive disease or stable disease (PD/SD).
The details of mutation calling, producing copy number segment file (using GATK4) and RNA_seq process can be found in Methods. Code can be found in `code/shell/ICI`. The HLA typing and neoantigen prediction was the same as the process in TCGA data as previously described. The code for caculating CCF by ABSOLUTE can be found in `code/R/ICI_ABSOLUTE.R`
After got neoantiogen prediction and ABSOLUTE CCF information, we can combine these data for downstream analysis:
```{r eval=FALSE}
####combine neoantigen prediction data
library(dplyr)
library(readr)
files <- list.files("immunetherapy/")
files <- files[grepl("neoantigens.unfiltered.txt",files)]
re <- vector("list",25)
for (i in 1:25){
mut <- read_table2(paste("immunetherapy/",files[i],sep = ""),col_names = paste0(rep("V",27),c(1:27)))
mut <- mut %>%
select(c(1,3:10,20:27))
colnames(mut) <- c("sample","chr","position",
"ref","alt","gene","exp","res_pos",
"hla","score_el","rank_el","score_ba",
"rank_ba","IC50","candidate","bindlevel",
"novelty")
mut <- mut %>%
mutate(novelty=ifelse(is.na(novelty),0,novelty)) %>%
mutate(index=paste(sample,chr,position,ref,alt,sep = ":"))
neo <- mut %>%
filter(IC50<50 & bindlevel=="SB" & novelty==1 & exp>1) %>%
distinct(index,.keep_all = T)
mut <- mut %>%
distinct(index,.keep_all = T) %>%
mutate(neo = ifelse(index %in% neo$index , "neo","not_neo"))
mut <- mut %>%
select(sample,chr,position,gene,exp,neo) %>%
mutate(gene=gsub("\\:.+","",gene))
mut$sample <- paste(gsub("_.+","",files[i]),mut$sample,sep = "_")
re[[i]] <- mut
}
all_mut <- bind_rows(re)
saveRDS(all_mut,file = "../data/Immunotherapy/all_mut_ici.rds")
###ccf in maf files of ABSOLUTE output
##nadeem
sample_run <- read.table("immunetherapy/nadeem_absolute/Nad_sample_run",sep = ",",stringsAsFactors = F)
files <- list.files("immunetherapy/nadeem_absolute/")[-1]
re <- vector("list",57)
for (i in 1:57){
test <- read.table(paste0("immunetherapy/nadeem_absolute/",files[i]),sep = "\t",header = T) %>%
select(sample,Hugo_Symbol,Chromosome,Start_position,cancer_cell_frac,purity)
test$sample <- paste("nadeem",as.character(sample_run[which(sample_run$V2==unique(test$sample)),"V1"]),
sep = "_")
re[[i]] <- test
}
nadeem_ccf <- bind_rows(re)
##willy
sample_run <- read.table("immunetherapy/willy_absolute/clinical.txt",sep = ",",stringsAsFactors = F)
files <- list.files("immunetherapy/willy_absolute/")[-1]
re <- vector("list",38)
for (i in 1:38){
test <- read.table(paste0("immunetherapy/willy_absolute/",files[i]),sep = "\t",header = T) %>%
select(sample,Hugo_Symbol,Chromosome,Start_position,cancer_cell_frac,purity)
test$sample <- paste("willy",as.character(sample_run[which(sample_run$V2==unique(test$sample)),"V1"]),
sep = "_")
re[[i]] <- test
}
willy_ccf <- bind_rows(re)
###liu
sample_run <- read.table("immunetherapy/liu_absolute/liu_sample_run",sep = ",",stringsAsFactors = F)
files <- list.files("immunetherapy/liu_absolute/")[-1]
re <- vector("list",121)
for (i in 1:121){
test <- read.table(paste0("immunetherapy/liu_absolute/",files[i]),sep = "\t",header = T) %>%
select(sample,Hugo_Symbol,Chromosome,Start_position,cancer_cell_frac,purity)
test$sample <- paste("liu",as.character(sample_run[which(sample_run$V2==unique(test$sample)),"V1"]),
sep = "_")
re[[i]] <- test
}
liu_ccf <- bind_rows(re)
all_ccf <- bind_rows(liu_ccf,nadeem_ccf,willy_ccf)
saveRDS(all_ccf,file = "../data/Immunotherapy/all_ccf.rds")
###merge ccf and neoantigen data
all_mut_ccf <- left_join(
all_mut_ici %>%
mutate(index=paste(sample,chr,position,sep = ":")),
all_ccf %>%
mutate(Chromosome=paste0("chr",Chromosome)) %>%
mutate(index=paste(sample,Chromosome,Start_position,sep = ":")) %>%
select(index,cancer_cell_frac,purity),
by="index"
)
all_mut_ccf <- all_mut_ccf %>% filter(!is.na(cancer_cell_frac))
saveRDS(all_mut_ccf,file = "../data/Immunotherapy/all_mut_ccf_ici.rds")
```