-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlioness.Rmd
More file actions
167 lines (92 loc) · 4.36 KB
/
lioness.Rmd
File metadata and controls
167 lines (92 loc) · 4.36 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
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
**NOTE: Each section is run individually on HPC**
# Run LIONESS on AMTEC data
```{r}
library(WGCNA)
library(lionessR)
library(data.table)
#output from main targets workflow
load("output_exprs_lioness.RData")#amtec_tcga_annot, mm, comb_ltpm
#from previous, use of adjacency instead of tom means that the modules can be run seperately
adj.fun <- function(expr){
use.adj <- adjacency(t(expr),
type = "signed hybrid",
power = 2,
corFnc = "bicor", corOptions = "maxPOutliers = 0.1")
use.adj
}
tcga.exprs <- comb_ltpm[mm$gene_id,amtec_tcga_annot[cohort=="TCGA",r_acc]]
#Using TCGA as the main network, add in each sample and run LIONESS to recover
#the patient-specific network
lion.res.biop <- lapply(split(amtec_tcga_annot[cohort=="AMTEC"], by=c("ptid","biopsy")), function(x){
tmp.exprs <- cbind(tcga.exprs, comb_ltpm[rownames(tcga.exprs),x$r_acc,drop=F])
tmp.lion <- lioness(tmp.exprs, f=adj.fun)
tmp.lion.mat <- SummarizedExperiment::assay(tmp.lion)
list(adj=adj.fun(tmp.exprs), edges=tmp.lion.mat[,ncol(tmp.lion.mat),drop=F])
})
#create a melted version
lion.res.dt <- rbindlist(lapply(lion.res.biop, function(x){
data.table(edge=rownames(x$edges), weight=x$edges[,1])
}), idcol="ptid_biop")
lion.res.dt[,trunc_weight:=weight]
lion.res.dt[weight < 0,trunc_weight:=0]
#save an array version
lion.res.dt[,c("gene1", "gene2"):=tstrsplit(edge, "_")]
lion.ar <- reshape2::acast(gene1~gene2~ptid_biop, value.var="trunc_weight",data=lion.res.dt)
save(lion.ar, file="lioness_array.RData")
#Compute network concepts from rescaled network per-module
module.stats <- lapply(split(mm, by="cur_label"), function(m){
message(m$cur_label[1])
lapply(setNames(dimnames(lion.ar)[[3]], dimnames(lion.ar)[[3]]), function(x){
message(x)
tmp.adj <- lion.ar[m$gene_id,m$gene_id,x] / max(lion.ar[m$gene_id,m$gene_id,x])
tmp.conc <- fundamentalNetworkConcepts(tmp.adj)
list(per_gene=cbind(gene_id=rownames(tmp.adj), as.data.table(tmp.conc[c("Connectivity", "ScaledConnectivity", "ClusterCoef", "MAR")])),
overall=as.data.table(tmp.conc[c("Density", "Centralization", "Heterogeneity")]))
})
})
save(module.stats, file="lioness_network_concepts.RData")
```
# Run LIONESS on AMTEC validation data
```{r}
library(WGCNA)
library(lionessR)
library(data.table)
load("valid_exprs_lioness.RData")#valid_tcga_annot, mm, valid_ltpm
#from previous, use of adjacency instead of tom means that the modules can be run seperately
#using run_twok_2p_v4.RData
adj.fun <- function(expr){
use.adj <- adjacency(t(expr),
type = "signed hybrid",
power = 2,
corFnc = "bicor", corOptions = "maxPOutliers = 0.1")
use.adj
}
tcga.exprs <- valid_ltpm[mm$gene_id,valid_tcga_annot[cohort=="TCGA",r_acc]]
lion.res.biop <- lapply(split(valid_tcga_annot[cohort=="Validation"], by=c("ptid","biopsy")), function(x){
tmp.exprs <- cbind(tcga.exprs, valid_ltpm[rownames(tcga.exprs),x$r_acc,drop=F])
tmp.lion <- lioness(tmp.exprs, f=adj.fun)
tmp.lion.mat <- SummarizedExperiment::assay(tmp.lion)
list(adj=adj.fun(tmp.exprs), edges=tmp.lion.mat[,ncol(tmp.lion.mat),drop=F])
})
#create a melted version
lion.res.dt <- rbindlist(lapply(lion.res.biop, function(x){
data.table(edge=rownames(x$edges), weight=x$edges[,1])
}), idcol="ptid_biop")
lion.res.dt[,trunc_weight:=weight]
lion.res.dt[weight < 0,trunc_weight:=0]
lion.res.dt[,c("gene1", "gene2"):=tstrsplit(edge, "_")]
lion.ar <- reshape2::acast(gene1~gene2~ptid_biop, value.var="trunc_weight",data=lion.res.dt)
save(lion.ar, file="valid_lioness_array.RData")
#compute per-module
module.stats <- lapply(split(mm, by="cur_label"), function(m){
message(m$cur_label[1])
lapply(setNames(dimnames(lion.ar)[[3]], dimnames(lion.ar)[[3]]), function(x){
message(x)
tmp.adj <- lion.ar[m$gene_id,m$gene_id,x] / max(lion.ar[m$gene_id,m$gene_id,x])
tmp.conc <- fundamentalNetworkConcepts(tmp.adj)
list(per_gene=cbind(gene_id=rownames(tmp.adj), as.data.table(tmp.conc[c("Connectivity", "ScaledConnectivity", "ClusterCoef", "MAR")])),
overall=as.data.table(tmp.conc[c("Density", "Centralization", "Heterogeneity")]))
})
})
save(module.stats, file="lioness_validation_network_concepts.RData")
```