forked from PNNL-CompBio/BeatAMLproteomics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10-make_synapse_tables.Rmd
90 lines (76 loc) · 2.8 KB
/
10-make_synapse_tables.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
---
title: "Make Synapse tables for Ex10 proteomics"
author: "Michael Nestor ([email protected])"
date: "5/27/2021"
output: html_document
---
```{r helpers, echo=FALSE}
library(dplyr)
library(tidyr)
library(tibble)
library(amlresistancenetworks)
syn <- synapseLogin()
make_global_table <- function(crosstab.syn, metadata.syn,
tabname, parentId) {
# get metadata
path_to_metadata <- syn$get(metadata.syn)$path
metadata <- read.table(path_to_metadata, header=T, sep="\t",
colClasses="character")
metadata <- metadata %>% dplyr::rename(`PNNL ID` = SampleID.abbrev)
# get crosstab
path_to_crosstab <- syn$get(crosstab.syn)$path
crosstab <- read.table(path_to_crosstab,
sep='\t', header=T, check.names=F)
crosstab <- as.data.frame(crosstab)
crosstab$Gene <- rownames(crosstab)
crosstab <- crosstab %>% select(Gene, everything())
# merge
crosstab_long <- crosstab %>%
pivot_longer(cols = c(everything(), -Gene),
names_to='Sample', values_to='LogRatio') %>%
filter(!is.na(LogRatio)) %>%
left_join(metadata, by = c("Sample" ="PNNL ID"))
}
make_phospho_table <- function(crosstab.syn, metadata.syn,
tabname, parentId) {
# get metadata
path_to_metadata <- syn$get(metadata.syn)$path
metadata <- read.table(path_to_metadata, header=T, sep="\t",
colClasses="character")
metadata <- metadata %>% dplyr::rename(`PNNL ID` = SampleID.abbrev)
# get crosstab
path_to_crosstab <- syn$get(crosstab.syn)$path
crosstab <- read.table(path_to_crosstab,
sep='\t', header=T, check.names=F)
crosstab <- as.data.frame(crosstab)
crosstab$SiteID <- rownames(crosstab)
crosstab$Gene <- sub("^(.*)-.*$", "\\1", crosstab$SiteID)
crosstab <- crosstab %>% select(Gene, SiteID, everything())
# merge
crosstab_long <- crosstab %>%
pivot_longer(cols = c(everything(), -Gene, -SiteID),
names_to='Sample', values_to='LogRatio') %>%
filter(!is.na(LogRatio)) %>%
left_join(metadata, by = c("Sample" ="PNNL ID"))
}
```
```{r main_loop}
library(readxl)
synapseDict <- read_xlsx("data/Ex10synapseDictionary.xlsx")
syn <- synapseLogin()
for (i in 1:nrow(synapseDict)) {
tabName <- synapseDict$tabName[i]
crosstab.syn <- synapseDict$crosstab.syn[i]
metadata.syn <- synapseDict$metadata.syn[i]
synid <- synapseDict$table.syn[i]
if (grepl("Proteomics", tabName)) {
tab <- make_global_table(crosstab.syn, metadata.syn)
} else if (grepl("Phosphoproteomics", tabName)) {
tab <- make_phospho_table(crosstab.syn, metadata.syn)
}
# synTableStore(tab = tab,
# tabname = "amlDrugCombos Molm14 Proteomics",
# parentId = parentId)
synTableUpdate(tab, synid)
}
```