forked from soccin/Goliath
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathload_argos.R
More file actions
91 lines (70 loc) · 2.77 KB
/
load_argos.R
File metadata and controls
91 lines (70 loc) · 2.77 KB
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
suppressPackageStartupMessages({
library(readr)
library(dplyr)
library(purrr)
library(jsonlite)
})
source("create_tables.R")
load_gene_annotations <- function() {
readRDS("data/geneAnnotation.rds")
}
tibble_to_named_list<-function(tbl,col) {
nl=transpose(tbl)
names(nl)=map(nl,col) %>% unlist
nl
}
get_with_default<-function(ll,key) {
if(key %in% names(ll)) {
return(ll[[key]])
} else {
return(NULL)
}
}
load_argos<-function(odir) {
pdir=file.path(odir,"portal")
adir=file.path(odir,"analysis")
dpt=read_tsv(file.path(pdir,"data_clinical_patient.txt"),comment="#")
sampleTbl=read_tsv(file.path(pdir,"data_clinical_sample.txt"),comment="#") %>%
left_join(dpt,by="PATIENT_ID")
#
# Get normal ID and add Matched status
#
inputJsonFile=fs::dir_ls(file.path(odir,"json"),recur=T,regex="argos_qc.*input\\.json$")
inputJson=read_json(inputJsonFile)
pairingTable=tibble(
SAMPLE_ID=unlist(inputJson$tumor_sample_names),
NORMAL_ID=unlist(inputJson$normal_sample_names)
) %>%
mutate(NORMAL_ID=gsub("_","-",NORMAL_ID) %>% gsub("^s-","",.))
sampleTbl=left_join(sampleTbl,pairingTable) %>%
rowwise %>%
mutate(MATCHED=ifelse(grepl(PATIENT_ID,NORMAL_ID),"Matched","UnMatched")) %>%
ungroup
sampleData=tibble_to_named_list(sampleTbl,"SAMPLE_ID")
# maf=read_tsv(file.path(pdir,"data_mutations_extended.txt"),comment="#") %>%
# group_split(Tumor_Sample_Barcode)
# names(maf)=map(maf,\(x){x$Tumor_Sample_Barcode[1]}) %>% unlist
# pmaf=maf
maf=read_tsv(fs::dir_ls(adir,regex=".muts.maf$"),comment="#") %>%
group_split(Tumor_Sample_Barcode)
names(maf)=map(maf,\(x){x$Tumor_Sample_Barcode[1]}) %>% unlist
fusions=read_tsv(file.path(pdir,"data_fusions.txt"),comment="#") %>%
group_split(Tumor_Sample_Barcode)
names(fusions)=map(fusions,\(x){x$Tumor_Sample_Barcode[1]}) %>% unlist
# cnv=read_tsv(file.path(pdir,"data_CNA.txt"),comment="#") %>%
# gather(Tumor_Sample_Barcode,CNV,-Hugo_Symbol) %>%
# filter(CNV!=0 & !is.na(CNV)) %>%
# group_split(Tumor_Sample_Barcode)
# names(cnv)=map(cnv,\(x){x$Tumor_Sample_Barcode[1]}) %>% unlist
cnv=read_tsv(fs::dir_ls(adir,regex=".gene.cna.txt"),comment="#") %>%
mutate(Tumor_Sample_Barcode=gsub("_[^_]*$","",Tumor_Sample_Barcode)) %>%
group_split(Tumor_Sample_Barcode)
names(cnv)=map(cnv,\(x){x$Tumor_Sample_Barcode[1]}) %>% unlist
for(si in names(sampleData)) {
# sampleData[[si]]$pMAF=get_with_default(pmaf,si)
sampleData[[si]]$MAF=get_with_default(maf,si)
sampleData[[si]]$CNV=get_with_default(cnv,si)
sampleData[[si]]$Fusions=get_with_default(fusions,si)
}
sampleData
}