forked from taylor-lab/wes-sample-selection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_VAF_from_IMPACT.R
executable file
·52 lines (39 loc) · 2 KB
/
get_VAF_from_IMPACT.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
suppressPackageStartupMessages({
library(data.table)
library(plyr)
library(dplyr)
library(stringr)
})
specify_decimal <- function(x, k) format(round(x, k), nsmall=k)
"%ni%"<-Negate("%in%")
args = commandArgs(TRUE)
if (is.null(args) | length(args)<1) {
message("Usage: Rscript get_VAF_from_IMPACT.R sample.list")
quit()
}
pathology_qc_metrics<-fread("/ifs/res/taylorlab/chavans/WES_sample_selection/MASTER_SAMPLE_LIST_deid.txt")
head(pathology_qc_metrics)
query_file = args[1]
sample_ids = fread(query_file, sep = '\t', header=FALSE)
out_file = paste0(gsub(".txt","",query_file),"_res.txt")
facets_file = paste0(gsub(".txt","",query_file),"_DMPs_for_FACETS_review.txt")
head(sample_ids)
names(sample_ids)[1]="DMP Sample ID"
head(pathology_qc_metrics)
sample_ids$`DMP Sample ID`
missing_in_path<-setdiff(unique(sample_ids$`DMP Sample ID`), unique(pathology_qc_metrics$DMP_ASSAY_ID))
if(length(missing_in_path) >=1){
print(paste("Missing",missing_in_path))
}
res<-left_join(sample_ids,pathology_qc_metrics,by=c(`DMP Sample ID`="DMP_ASSAY_ID")) %>%
dplyr::select(everything(sample_ids),Median_Exonic_Mutation_VAF,Median_Silent_Mutation_VAF)
res <- res %>% mutate(`AF_>=0.10_Exonic`=ifelse(Median_Exonic_Mutation_VAF>=0.10,1,0),
`AF_>=0.10_Silent`=ifelse(Median_Silent_Mutation_VAF>=0.10,1,0),
`AF_<0.20_Exonic`=ifelse(Median_Exonic_Mutation_VAF<0.20,"Yes","No")) # | is.na(Median_Exonic_Mutation_VAF)==T
res_fr = filter(res, `AF_<0.20_Exonic` == "Yes")
print(res_fr)
write.table(res_fr$`DMP Sample ID`,facets_file,sep="\t", row.names=F, quote=F,append=TRUE)
res <- res %>% mutate(`AF_>=0.10_Exonic`=ifelse(sample_ids$`DMP Sample ID` %in% missing_in_path,"Missing_Data",`AF_>=0.10_Exonic`),
`AF_>=0.10_Silent`=ifelse(sample_ids$`DMP Sample ID` %in% missing_in_path,"Missing_Data",`AF_>=0.10_Silent`))
dim(res)
write.table(res, out_file, sep="\t", row.names=F, quote=F)