/
Indel_filtering_ctDNA.r
144 lines (113 loc) · 5.85 KB
/
Indel_filtering_ctDNA.r
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
############################################################################
#
# ctDNA Indel Data Filtering
#
# Author: Olena Kis
# Last Modified: Aug 25, 2016
# Date Created: June 3, 2015
###############################
# Variables
###############################
project.name <- "MYELSTONE_ctDNA"
setwd("/Users/okis/Data_Analysis/Indels/MYELSTONE/analysis/ctDNA")
file.path <- "/Users/okis/Data_Analysis/Indels/MYELSTONE/maf/ctDNA"
file.ext <- ".maf"
blacklist <- "/Users/okis/Data_Analysis/file_path/pancan_mutation_blacklist.v10.hg19.txt"
###############################
# Arguments #
###############################
# Set the threshold for low coverage filter (minumum depth of coverage required to keep the data)
Cov.thresh <- 5000
# Set the threshold for low confidance skewed indel calls (minumum number of calls required
# in the forward and reverse direction to support the indel call)
Skew.thresh <- 10
summary_vect <- c("Matched_Norm_Sample_Barcode",
"Hugo_Symbol",
"Genome_Change",
"Variant_Type",
"Variant_Classification",
"Chromosome",
"Start_position",
"End_position",
"Reference_Allele",
"Tumor_Seq_Allele1",
"Tumor_Seq_Allele2",
"CGC_Chr.Band",
"AC_consensus",
"AC_any",
"tumor_f",
"tumor_f_any",
"depth_across_samples",
"indel_forward",
"indel_reverse",
"ref_forward",
"ref_reverse",
"dbSNP_Val_Status",
"dbSNP_RS",
"COSMIC_overlapping_mutations")
###############################
# Functions #
###############################
# Data summary for filtered maf results
summary_function <- function(all_ctDNA_indels,summary_vect){
summary_ctDNA_indels<- all_ctDNA_indels[,summary_vect]
return(summary_ctDNA_indels)
}
###############################
# Main #
###############################
# Combined all maf files from ctDNA data directory into one file
filenames <- list.files(path = file.path, pattern = file.ext,
full.names = T, recursive = FALSE,
ignore.case = FALSE, include.dirs = FALSE)
all_ctDNA_indels <- NULL
for (file in filenames){
ctDNA_indels <- read.table(file, header = TRUE, sep = "\t", quote = "",
comment.char = "#", stringsAsFactors =FALSE)
name <- basename(file)
name <- gsub(".bam.vcf.maf","",name)
name <- gsub("_ctDNA","",name)
name <- gsub("-ctDNA","",name)
all_ctDNA_indels <- rbind(all_ctDNA_indels, ctDNA_indels)
}
## Add 'Allele Fraction' and "tumor_f to indel file
allele_count <-unlist(strsplit(all_ctDNA_indels$allele_count,","))
allele_count_consensus <-allele_count[seq(from=1,to=length(allele_count),by=2)]
allele_count_any <-allele_count[seq(from=2,to=length(allele_count),by=2)]
all_ctDNA_indels$AC_consensus <- as.numeric(allele_count_consensus)
all_ctDNA_indels$AC_any <- as.numeric(allele_count_any)
all_ctDNA_indels$tumor_f <-all_ctDNA_indels$AC_consensus/all_ctDNA_indels$depth_across_samples
all_ctDNA_indels$tumor_f_any <-all_ctDNA_indels$AC_any/all_ctDNA_indels$depth_across_samples
## Add forward and reverse reads for Indel-supporti and reference
supporting_reads <-unlist(strsplit(all_ctDNA_indels$SC,","))
indel_forward <-supporting_reads[seq(from=1,to=length(supporting_reads),by=4)]
indel_reverse <-supporting_reads[seq(from=2,to=length(supporting_reads),by=4)]
ref_forward <-supporting_reads[seq(from=3,to=length(supporting_reads),by=4)]
ref_reverse <-supporting_reads[seq(from=4,to=length(supporting_reads),by=4)]
all_ctDNA_indels$indel_forward <- as.numeric(indel_forward)
all_ctDNA_indels$indel_reverse <- as.numeric(indel_reverse)
all_ctDNA_indels$ref_forward <- as.numeric(ref_forward)
all_ctDNA_indels$ref_reverse <- as.numeric(ref_reverse)
write.table(all_ctDNA_indels, file = paste("All_indels",project.name,"txt",sep="."),
row.names=FALSE, append = FALSE,na = "NA", quote = FALSE, sep = "\t", col.names = TRUE)
summary_ctDNA_indels <- summary_function(all_ctDNA_indels, summary_vect)
write.table(summary_ctDNA_indels, file = paste("Indels_summary",project.name,"txt",sep="."),
row.names=FALSE, append = FALSE,na = "NA", quote = FALSE, sep = "\t", col.names = TRUE)
# Filter out validated indels
filtered_ctDNA_indels <- all_ctDNA_indels[all_ctDNA_indels$dbSNP_Val_Status == "",]
nrow(all_ctDNA_indels)
nrow(filtered_ctDNA_indels)
# Filter out low coverage data
filtered_ctDNA_indels <- filtered_ctDNA_indels[filtered_ctDNA_indels$depth_across_samples >= Cov.thresh,]
# Filter out skewed data (if have < MIN number of reads from forward or reverse strand)
filtered_ctDNA_indels <- filtered_ctDNA_indels[filtered_ctDNA_indels$indel_forward >= Skew.thresh,]
filtered_ctDNA_indels <- filtered_ctDNA_indels[filtered_ctDNA_indels$indel_reverse >= Skew.thresh,]
PanCan_mutations <- read.table(blacklist, header = TRUE,
sep = "\t",quote = "", comment.char = "#", stringsAsFactors =FALSE)
PanCan_mutations$locus <- paste("g.chr",PanCan_mutations$chr,":",PanCan_mutations$start,
PanCan_mutations$ref_allele,">",PanCan_mutations$newbase, sep="")
ctDNA_filter_PanCan <- PanCan_mutations$locus
filtered_ctDNA_indels <- filtered_ctDNA_indels[!filtered_ctDNA_indels$Genome_Change %in% ctDNA_filter_PanCan,]
summary_filtered_ctDNA_indels <- summary_function(filtered_ctDNA_indels, summary_vect)
write.table(summary_filtered_ctDNA_indels, file = paste("Summary_filtered_indels",project.name,"txt",sep="."),
row.names=FALSE, append = FALSE,na = "NA", quote = FALSE, sep = "\t", col.names = TRUE)