-
Notifications
You must be signed in to change notification settings - Fork 2
/
chemviz_vignette.Rmd
217 lines (157 loc) · 6.58 KB
/
chemviz_vignette.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
---
title: "Chemviz vignette"
author: "Julia Gustavsen"
date: "August 16, 2016"
output:
pdf_document:
fig_caption: yes
keep_tex: yes
latex_engine: lualatex
number_sections: yes
toc: yes
toc_depth: 6
html_document:
keep_md: yes
number_sections: yes
theme: cerulean
toc: yes
toc_depth: 6
---
# Introduction
Scientists can have information about chemical compounds and then want a simple way to visualize the chemical structure and also the to understand the chemical similarity of compounds (Tanimoto similarity). This can be done in Cytoscape using the Chemviz plugin
In this vignette we will use the R package rcellminer to generate some data that we will use to look a some drug compounds. Then, in Cytoscape, we will then see how these drugs are chemically related, look at the 2-dimensional structures of these compounds and then colour the compounds by their mechanism of action to see if it is related to their similarity.
# Required materials:
- Cytoscape (www.cytoscape.org)
- Chemviz - plugin for Cytoscape (http://www.cgl.ucsf.edu/cytoscape/chemViz2/index.shtml)
- Rpackages: RCy3,rcellminer, RColorBrewer
# Load the packages
```{r, message = FALSE}
library(RCy3)
library(rcellminer)
library(RColorBrewer)
#source("./functions_to_add_to_RCy3/working_with_namespaces.R")
```
# Get data from rcellminer
```{r}
df <- getFeatureAnnot(rcellminerData::drugData)[["drug"]]
moaToCompounds <- getMoaToCompounds()
Moa_names <- names(moaToCompounds)
df_knownMoaDrugs <- subset(df, MOA %in% Moa_names)
## use only those with greater than 10 experiments
df_with_knownMoaDrugs <- subset(df_knownMoaDrugs, TOTAL_EXPS > 10)
```
For display purposes we will chop off long names after 12 characters.
```{r}
long_names <- df_with_knownMoaDrugs$NAME[nchar(df_with_knownMoaDrugs$NAME) > 12]
chopped_long_names <- gsub("^(.{12})(.*)$", "\\1", long_names)
df_with_knownMoaDrugs$NAME[nchar(df_with_knownMoaDrugs$NAME) > 12 ] <- chopped_long_names
```
# Set up connection between R and Cytoscape
```{r}
commandsHelp("help chemviz")
```
# Format dataframe from RCellMiner to format that can be sent to Cytoscape
```{r}
g <- new("graphNEL",
nodes = df_with_knownMoaDrugs$NAME,
edgemode = "undirected")
createNetworkFromGraph(g)
```
```{r}
nodeData<- subset(df_with_knownMoaDrugs, select=c("NAME", "SMILES", "NSC", "MOA"))
colnames(nodeData)[1] <- "id"
loadTableData(nodeData, 'id')
```
Network successfully sent to Cytoscape. The node attributes have also been sent.
```{r, echo=FALSE}
Sys.sleep(10)
exportImage("nodes_for_chemviz",
"png",
h = 2000)
knitr::include_graphics("./nodes_for_chemviz.png")
```
# Create similarity network
Next based on the chemical properties of each node (which are associated using the SMILES strings (Simplified Molecular Input Line Entry System which are line representations of chemical structures) we will use chemviz to calculate the similarity of each drug based on its chemical properties (using Tanimoto similarity which is a distance-based measure of chemical similarity).
To begin let's look at some of the commands available to use in chemviz:
```{r}
commandsHelp("help chemviz")
```
Now let's look at the arguments we can use for creating a similarity network:
```{r}
commandsHelp("chemviz/create%20similarity")
```
Set the properties that we would like to use
```{r}
command.name <- "chemviz/create%20similarity"
string.cmd = paste0(command.name, " createNewNetwork=TRUE"," network=",getNetworkSuid(), " nodeList=all")
commandsGET(string.cmd)
```
```{r, echo=FALSE}
Sys.sleep(10)
exportImage("chemviz_similarity_net",
"png",
h =2000)
knitr::include_graphics("./chemviz_similarity_net.png")
```
We currently just have the network in the grid format, but now with edges connecting the nodes we can do a layout that can help us visualize the connections.
```{r}
layoutNetwork("force-directed")
```
```{r, echo=FALSE}
Sys.sleep(10)
exportImage("chemviz_similarity_net_layout_fd",
"png",
h=2000)
knitr::include_graphics("./chemviz_similarity_net_layout_fd.png")
```
# Add 2D chemical structures to nodes
Another thing we can do with chemviz is to add the two dimensional chemical structure on to the nodes of our networks.
Let's look again at the commands available in Chemviz:
```{r}
commandsHelp("help chemviz")
```
And the arguments needed for the command we want to use: "paint structures"
```{r}
commandsHelp("help chemviz/paint%20structures")
```
```{r, results="hide", message = FALSE}
command.name <- "chemviz/paint%20structures"
string.cmd = paste0(command.name, " nodeList=all")
commandsGET(string.cmd)
```
Now we have all of the chemical structures displayed on the nodes of our network.
```{r, echo=FALSE}
Sys.sleep(10)
exportImage("chemviz_similarity_net_node_structures",
"png", h = 2000)
knitr::include_graphics("./chemviz_similarity_net_node_structures.png")
```
\clearpage
# Colour nodes by mechanism of action (MOA)
The nodes that we are examining have mechanisms of action (MOA) associated with them. We can then colour these nodes by their MOA.
```{r}
MOA_classes <- unique(df_with_knownMoaDrugs$MOA)
number_of_unique_MOA <- length(MOA_classes)
colours_for_MOA_classes <- colorRampPalette(brewer.pal(12, "Set3"))(number_of_unique_MOA)
```
We have `r number_of_unique_MOA` different MOA classes and have used RColorBrewer to generate different colours for the different classes.
```{r}
setNodeColorMapping("MOA",
MOA_classes,
colours_for_MOA_classes,
mapping.type = "d",
default.color = "#000000")
## node font looks ugly, let's turn it off for now
setNodeFontSizeDefault(0)
```
We have coloured the nodes nicely, but we do not know which ones are associated with which classes. To know more about this we will print out the legend from Cytoscape. At the moment there is no automated way to do this so we need to go into Cytoscape, click on the "Style" tab and then click on the little arrow (that has a mouseover text of "Options"). Once the menu opens there you will find a dialogue that lets you export a legend (in gif, svg, or pdf formats). Once exported we will look at the legend beside our new coloured network.
```{r, echo=FALSE}
Sys.sleep(10)
exportImage("chemviz_similarity_net_coloured_by_MOA",
"png",
h = 2000)
# removed this so that I could knit to pdf
#<img src="./chemviz_similarity_net_coloured_by_MOA.png" width="600"> <img src="./chemviz_legend.svg" width="150">
knitr::include_graphics("./chemviz_similarity_net_coloured_by_MOA.png")
knitr::include_graphics("./chemviz_legend.png")
```