-
Notifications
You must be signed in to change notification settings - Fork 2
/
usingIlincsApis.Rmd
297 lines (243 loc) · 10.7 KB
/
usingIlincsApis.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
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
---
title: "iLINCS API R Notebook"
output:
html_document:
df_print: paged
pdf_document: default
---
<style type="text/css">
.main-container {
max-width: 1200px;
margin-left: auto;
margin-right: auto;
}
</style>
<!-- ## Prerequisites -->
```{r include = FALSE}
library(knitr)
library(tinytex)
library(httr)
library(jsonlite)
library(htmltools)
```
```{r set-options, echo=FALSE, cache=FALSE}
options(width = "200")
```
## Display Signature Libraries
```{r list signature libraries}
apiUrl <- "http://www.ilincs.org/api/SignatureLibraries"
req <- GET(apiUrl)
json <- httr::content(req, as = "text")
ilincs_libraries <- fromJSON(json)
ilincs_libraries[,c("libraryID","libraryName")]
```
## Searching for signature using BROAD ID
##### Searching for signature for given term. In this example **"Diclofenac"** coumpound will be shown as an example.
```{r search signatures}
term <- "Diclofenac"
ilincs_libId<-"LIB_5"
apiUrl <- paste("http://www.ilincs.org/api/SignatureMeta/findTermWithSynonyms?term=",term,"&library=",ilincs_libId,sep="")
req <- GET(apiUrl)
ilincs_result_df<-fromJSON(httr::content(req,type="text"))$data
head(ilincs_result_df[,c("cellline","compound","concentration","signatureid","is_exemplar")])
```
### Selecting a signature to analyze
```{r selectedSignature}
ilincs_signatureId <- ilincs_result_df[1,"signatureid"]
ilincs_signatureId
```
## Getting signature data and vulcano plot
##### The first step is to retrieve the session id for creation of the signature data table
```{r retrieve signature data}
req <- POST("http://www.ilincs.org/api/ilincsR/downloadSignature", body = list(sigID = paste(ilincs_signatureId), display = FALSE), encode = "json")
ilincs_sessionId<-unlist(httr::content(req))
ilincs_sessionId
```
### Retrieving data
```{r volcano data}
fileUrl=paste("http://www.ilincs.org/tmp/",ilincs_sessionId,".xls",sep="")
signatureData<-read.table(fileUrl,sep="\t",header=T,stringsAsFactors = F)
head(signatureData)
```
### Insert volcano plot
```{r volcano plot}
apiUrl <- paste("http://www.ilincs.org/api/ilincsR/volcanoPlot?file=",ilincs_sessionId,".xls",sep="")
req <- GET(apiUrl)
ilincs_volcanoUrl<-paste("http://www.ilincs.org",httr::content(req)$url,sep="")
include_graphics(ilincs_volcanoUrl)
```
## Get connected signatures
```{r connected signatures}
apiUrl <- paste("http://www.ilincs.org/api/SignatureMeta/findConcordantSignatures?sigID=",ilincs_signatureId,"&lib=",ilincs_libId,sep="")
req <- GET(apiUrl)
# prettify(httr::content(req,type="text"))
ilincs_conn_df<-fromJSON(httr::content(req,type="text"))
head(ilincs_conn_df)
```
## Find LINCS signatures connected to user a submitted signature
##### Creating user submitted signature in the form of a gene list
```{r subsetting signature}
# top100signature <- signatureData[order(signatureData$Significance_pvalue)[1:100],c("Name_GeneSymbol","Value_LogDiffExp","Significance_pvalue")]
top100signature <- signatureData[order(signatureData$Significance_pvalue)[1:100],]
head(top100signature)
```
### Uploading signature as a list genes for enrichment
```{r connectivity by gene list}
apiUrl="http://www.ilincs.org/api/ilincsR/findConcordancesSC"
req <- POST(apiUrl, body = list(mode="geneList",metadata=TRUE,signatureProfile = list(genes=top100signature$Name_GeneSymbol)),encode = "json")
ilincsEnrichedSignatures <- data.table::rbindlist(httr::content(req)$sigScores, use.names = TRUE, fill = TRUE)
head(ilincsEnrichedSignatures)
```
## Get GSEA plot
```{r GSEA plot, out.width="910px"}
apiUrl <- "http://www.ilincs.org/api/ilincsR/plotGSEA"
req <- POST(apiUrl, body = list(signatureId = ilincs_signatureId,genes = top100signature$ID_geneid, output="png"), encode = "json")
gseaPlotPng <- httr::content(req)$fileName
gseaPlotUrl <- paste("http://www.ilincs.org/tmp/",gseaPlotPng,".png",sep="")
include_graphics(gseaPlotUrl)
```
## Signature as a list of up and down genes
```{r up and down genes}
apiUrl="http://www.ilincs.org/api/ilincsR/findConcordancesSC"
topUpRegulatedGenes <- list(genesUp=top100signature$Name_GeneSymbol[top100signature$Value_LogDiffExp > 0])
topDownregulatedGenes <- list(genesDown=top100signature$Name_GeneSymbol[top100signature$Value_LogDiffExp < 0])
req <- POST("http://www.ilincs.org/api/ilincsR/findConcordancesSC", body = list(mode="UpDn",metadata=TRUE,signatureProfile = c(topUpRegulatedGenes, topDownregulatedGenes)),encode = "json")
ilincsUpDnConnectedSignatures <- data.table::rbindlist(httr::content(req)$concordanceTable, use.names = TRUE, fill = TRUE)
head(ilincsUpDnConnectedSignatures)
```
## Group analysis of top 20 most connected signatures with signature of interest
```{r group analysis}
signatureGroup <-ilincsUpDnConnectedSignatures$signatureID[1:20]
apiUrl<-"http://www.ilincs.org/api/ilincsR/GroupLincsAnalysis"
req<-POST(apiUrl, body = list(idList = signatureGroup,noOfGenes = 50), encode = "json")
groupAnalysisSessionID <- httr::content(req)$data[[2]]
groupAnalysisSessionID
```
### [Signature group heatmap on iLINCS](http://www.ilincs.org/apps/heatmap/?sessionID=`r groupAnalysisSessionID`&property=signatureID)
```{r interactive heatmap, out.width="1200px"}
heatmap_url<-paste("http://www.ilincs.org/apps/heatmap/?sessionID=",groupAnalysisSessionID,"&property=signatureID",sep = "")
# browseURL(heatmap_url) ##uncoment to launch the browser
# include_url(heatmap_url, height = "900px") ##uncomment to embed in iframe
```
### [Signature group PCA and tSNE app on iLINCS](http://www.ilincs.org/apps/pca/?sessionID=`r groupAnalysisSessionID`&property=signatureID)
```{r dimensionality reduction, out.width="1200px", fig.align="center"}
pca_url<-paste("http://www.ilincs.org/apps/pca/?sessionID=",groupAnalysisSessionID,"&property=signatureID",sep = "")
# browseURL(pca_url) ##uncoment to launch the browser
# include_url(pca_url, height = "900px") ##uncomment to embed in iframe
```
### Load r ExpressionSet from the signature analysis
```{r group analysis data}
load(url(paste("http://www.ilincs.org/tmp/filteredeset_",groupAnalysisSessionID,".RData",sep="")),verbose=T)
eset<-get(paste("filteredeset_",groupAnalysisSessionID,sep=""))
eset
```
### Download gct from the signature analysis
```{r group analysis data gct}
download.file(paste("http://www.ilincs.org/tmp/filteredeset_",groupAnalysisSessionID,".gct",sep=""),destfile="sigs.gct")
sigs <- readLines(con <- file("sigs.gct"))
head(sigs,n=10)
```
## Find connected signatures based on user submitted full signature
##### Creating a file to upload from previouslsy downloaded signature file
```{r}
write.table(signatureData,file="sigFile.tsv",sep="\t",row.names=F,col.names = T,quote=F)
system(paste("head sigFile.tsv"))
```
### Upload the file
```{r connected signatures by uploading signature file}
apiUrl<-"http://www.ilincs.org/api/SignatureMeta/upload"
sigFile <- "sigFile.tsv"
req <- POST(apiUrl, body=list(file=upload_file("sigFile.tsv")))
signatureFile <- httr::content(req)$status$fileName[[1]]
signatureFile
```
### Find connected signatures
```{r list connected signatures}
apiUrl <- "http://www.ilincs.org/api/ilincsR/findConcordances"
req <- (POST(apiUrl, body = list(file=signatureFile, lib="LIB_5"), encode = "form"))
output <- data.table::rbindlist(httr::content(req)$concordanceTable, use.names = TRUE, fill = TRUE)
head(output)
```
## Find connected compound perturbations
```{r connected compound perturbations}
apiUrl <- paste("http://www.ilincs.org/api/ilincsR/signatureEnrichment?sigFile=",signatureFile,"&library=LIB_5&metadata=TRUE",sep="")
req <- GET(apiUrl)
json <- httr::content(req, as = "text")
iLincsConnectedCompoundPerturbations <- fromJSON(json)$enrichment
head(iLincsConnectedCompoundPerturbations)
```
## Get connected genetic perturbations
```{r connected genetic perturbations}
apiUrl <- paste("http://www.ilincs.org/api/ilincsR/signatureEnrichment?sigFile=",signatureFile,"&library=LIB_6",sep="")
req <- GET(apiUrl)
json <- httr::content(req, as = "text")
iLincsConnectedGeneticPerturbations <- fromJSON(json)$enrichment
head(iLincsConnectedGeneticPerturbations)
```
## Retriving Signature Metadata
```{r signature metadata}
apiUrl <- paste("http://www.ilincs.org/api/SignatureMeta/",ilincs_signatureId,sep="")
req <- GET(apiUrl)
ilincsJSON<-httr::content(req,type="text")
prettify(ilincsJSON)
```
```{r as a list}
ilincsSigMetaData<-fromJSON(ilincsJSON)
head(ilincsSigMetaData)
```
### List of LINCS Datasets
```{r listing datasets}
apiUrl <- "http://www.ilincs.org/api/PublicDatasets/getDatasets?lincs=true"
req <- GET(apiUrl)
json <- httr::content(req, as = "text")
lincs_datasets <- fromJSON(json)
lincsDatasets <- data.frame(lincs_datasets$data)
lincsDatasets[c("experiment","assay","dataType")]
```
### Dataset metadata
**Example:** EDS-1014
```{r dataset metadata}
experiment <- "EDS-1014"
apiUrl <- paste("http://www.ilincs.org/api/PublicDatasets/",experiment,sep="")
req <- GET(apiUrl)
json <- httr::content(req, as = "text")
datasetMetaData <- fromJSON(json)
datasetMetaData
```
[Heatmap for dataset `r experiment` on iLINCS](http://www.ilincs.org/apps/heatmap/?data_set=`r experiment`)
[PCA and tSNE for dataset `r experiment` on iLINCS](http://www.ilincs.org/apps/pca/?data_set=`r experiment`)
### Dataset sample metadata
```{r samples metadata}
apiUrl <- paste("http://www.ilincs.org/api/ilincsR/getSamples?id=",experiment,sep="")
req <- GET(apiUrl)
json <- httr::content(req, as = "text")
sampleMeta <- fromJSON(json)
sampleMetaData <- data.frame(sampleMeta$data$rows)
head(sampleMetaData)
```
## Creating signature using iLINCS
[Create signature from dataset `r experiment` on iLINCS](http://www.ilincs.org/ilincs/dataset/`r experiment`/createSignature)
## Creating signature using iLINCS API
```{r creating signature from dataset}
property <- "ER"
level1 <- "ER:+"
level2 <- "ER:-"
apiUrl <- "http://www.ilincs.org/api/ilincsR/LincsDataAnalysis"
req <- POST(apiUrl, body = list(exp = paste(experiment),prop = property,filterchk=paste(level1,level2,sep = ",,,"),includeORexclude=1), encode = "json")
createdSignaturesSessionID <- httr::content(req)$sessionID
createdSignaturesSessionID
```
## Top 100 genes in created signature
```{r top 100 genes in signature}
l <- lapply(httr::content(req)$geneData, function(x) unlist(x))
ilincs_result <- data.frame(t(sapply(l,c)))
top100signatureData <- ilincs_result[1:100,c("Name_GeneSymbol","Value_LogDiffExp","Significance_pvalue")]
head(top100signatureData)
```
### Heatmap of data used in signature creation
### [Signature group heatmap on iLINCS](http://www.ilincs.org/apps/heatmap/?sessionID=`r createdSignaturesSessionID`&property=`r property`&geneCount=100)
```{r, out.width="1200px"}
heatmap_url2<-paste("http://www.ilincs.org/apps/heatmap/?sessionID=",createdSignaturesSessionID,"&property=",property,"&geneCount=100",sep = "")
# browseURL(heatmap_url2) ##uncomment to launch in a browser
# include_url(heatmap_url2, height = "900px") ##uncomment to embed in an iframe
```