forked from fran-romero-campero/ChlamyNET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.R
More file actions
1548 lines (1241 loc) · 57.9 KB
/
app.R
File metadata and controls
1548 lines (1241 loc) · 57.9 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
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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#####################
# CHLAMYNET WEB APP #
#####################
# Copyright (C) 2018 Francisco J. Romero-Campero
#
# This program is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 3 of
# the License, or (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public
# License along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Authors: Francisco J. Romero-Campero
#
# Contact: Francisco J. Romero-Campero - fran@us.es
# Date: February 2019
## Load libraries
library(shiny)
library(gplots)
library(ggplot2)
library(igraph)
library(topGO)
## Data loading
## Load network
network.data <- read.table(file="data/chlamynet_data.tsv",header = TRUE,as.is=TRUE,fill=TRUE)
head(network.data)
## Adjust y positions
network.data$y <- - network.data$y
## Extract gene ids
genes <- sort(network.data$name)
## Extract Pfam structure
pfam <- unique(network.data$pfam)
## Read network in gml format
chlamynet <- read.graph(file = "data/chlamynet.gml",format = "gml")
nodes <- network.data$name
## Reading in data frame with annotation
annotation.data <- read.table(file="data/Creinhardtii_223_annotation_info.txt",sep="\t")
## Load gene expression levels in FPKM
fpkm.data.read <- read.table(file="data/fpkm_data.txt",header=TRUE)
## Setup for GO enrichment based on PFAM annotation
## Load Chlamydomonas reinhardtii gene to GO annotation
geneID2GO <- readMappings(file = "data/Chlamy_PFAM_based_GO_annotation.map")
## Set the background gene set to the whole gene set in Chlamy
## We create a vector with all elements 1 and name it with the gene
## identifiers
gene.names <- attributes(geneID2GO)[[1]]
gene.background.pfam <- rep(1,length(gene.names))
names(gene.background.pfam) <- gene.names
## The function used to selec genes is defined according to the assignment of 0 to the genes
## of interest
cre.gene.selec <- function(gene.list)
{
return(gene.list == 0)
}
## The function used to select genes is defined according to the assignment of 0 to the genes
## of interest
ath.gene.selec <- function(gene.list)
{
return(gene.list == 0)
}
ontology.type <- "BP"
## Load A. thaliana orthology
chlamy.athaliana <- read.table(file="data/Creinhardtii_athaliana.txt")
chlamy.names <- as.vector(chlamy.athaliana[[1]])
athaliana.names <- as.vector(chlamy.athaliana[[2]])
names(athaliana.names) <- chlamy.names
## Loading the probe names and ATG identifiers and their correspondence
probe.atg <- read.table(file="data/probe_names_atg.txt")
probe.names <- as.vector(probe.atg[[1]])
atg.names <- as.vector(probe.atg[[2]])
names(probe.names) <- atg.names
###################
## CHLAMYNET APP ##
###################
ui <- fluidPage(
## Application title
titlePanel(tags$b("ChlamyNET, a ", tags$i("Chlamydomonas reinhardtii"), " Gene Co-expression Network ")),
# Extra line breaks
tags$br(),
tags$br(),
## Introduction to the tool
fluidRow(
column(2,
tags$img(src="ChlamyNet_Logo.jpg",alt="ChlamyNET_logo", width=160,height=160,align="middle")
),
column(3,
tags$ul(style="list-style-type:none",
tags$li(tags$a(href="http://viridiplantae.ibvf.csic.es/ChlamyNet/index.html",
tags$b("Home"))),
tags$li(tags$a(href="http://viridiplantae.ibvf.csic.es/ChlamyNet/clusters.html",
tags$b("ChlamyNet Exploration"))),
tags$li(tags$a(href="http://viridiplantae.ibvf.csic.es/ChlamyNet/clusters.html",
tags$b("Clusters GO Term Enrichment"))),
tags$li(tags$a(href="http://viridiplantae.ibvf.csic.es/ChlamyNet/transcription_factors.html",
tags$b("Transcription Factors and Regulators"))),
tags$li(tags$a(href="http://viridiplantae.ibvf.csic.es/ChlamyNet/tutorial.html",
tags$b("Tutorial"))),
tags$li(tags$a(href="http://viridiplantae.ibvf.csic.es/ChlamyNet/case_studies.html",
tags$b("Case Studies"))),
tags$li(tags$a(href="http://viridiplantae.ibvf.csic.es/ChlamyNet/links.html",
tags$b("Related Links")))
)),
column(7,
p(tags$b("ChlamyNET 2.0 "), "is a web-based tool developed using ",
tags$b(tags$a(href="https://shiny.rstudio.com/","shiny,")), " an R package for the development
of web apps from R code. The aim of ChlamyNET is to facilitate the studies over the
Chlamydomonas transcriptome. Please, take a look at the ",
tags$b(tags$a(href="http://viridiplantae.ibvf.csic.es/ChlamyNet/tutorial.html","tutorial")), " or ",
tags$b(tags$a(href="https://www.youtube.com/watch?v=QuySUPid-rg","watch this video tutorial.")),
"A user can search for a set of genes of interest using the ", tags$b("Gene Selection panel."), " The analysis
of individual genes or sets of genes including their neighbouring genes can be performed using
the ", tags$b("Gene Expression"), " and ", tags$b("GO Enrichment Analysis"), " panels. Please, take a look at the ",
tags$b(tags$a(href="http://viridiplantae.ibvf.csic.es/ChlamyNet/case_studies.html","case studies")),
" for some examples on how to use ChlamyNET 2.0.")
)
),
## Extra line breaks for separation
tags$br(),
tags$br(),
## Sidebar layout is chosen. Panels for analysis will be in the sidebar and in the
## main panel a visualization of the network and results of the analysis (tables and graphs)
## will be displayed.
sidebarLayout(
sidebarPanel(
## ChlamyNET contains FOUR different panels for analysis
## PANEL 1: GENE SELECTION ##
wellPanel(
## Panel title
tags$h3(tags$b("Gene Selection:")),
## Radio buttons to chose between two modes of gene selection
## using gene ID (CreXX.gXXXXXX) or PFAM ID (PFXXXXX)
radioButtons(inputId = "gene_selection_mode",
label = "Mode",
choices = c("Gene ID", "Protein Domain PFAM ID","Gene List"),
selected = "Gene ID"),
## Dynamic panel for selecting genes based on their ID
conditionalPanel(condition = "input.gene_selection_mode == 'Gene ID'",
## Select gene ID
selectizeInput(inputId = "selected.gene",
label = "Gene ID",
choices = genes,
selected = "Cre08.g370400",
multiple = TRUE),
## Select distance of genes to consider
selectInput(inputId = "distance",
label = "Select Co-expressed Genes at Distance:",
choices = 0:3,
selected = 0,
multiple = FALSE),
## Button to trigger selections based on gene ID
actionButton(inputId = "button_gene_id",label="Select Genes")),
conditionalPanel(condition = "input.gene_selection_mode == 'Gene List'",
## Enter gene list
textAreaInput(inputId = "gene.list", label= "Set of genes", width="90%",
height = "200px",placeholder = "Insert set of genes",
value = "Cre01.g011150
Cre04.g224600
Cre07.g332250
Cre14.g620850"),
## Select distance of genes to consider
selectInput(inputId = "distance_gene_list",
label = "Select Co-expressed Genes at Distance:",
choices = 0:3,
selected = 0,
multiple = FALSE),
## Button to trigger selections based on gene ID
actionButton(inputId = "button_gene_list_id",label="Select Genes")),
## Dynamic panel for selecting genes based on their PFAM domain IDs
conditionalPanel(condition = "input.gene_selection_mode == 'Protein Domain PFAM ID'",
## Select PFAM ID
selectizeInput(inputId = "selected_pfam",
label = "PFAM Protein Domain ID",
choices = pfam,
selected = "PF00643,PF06203",#"PF00010",
multiple = TRUE),
## Action button to trigger identification of genes with the selected
## PFAM ID
actionButton(inputId = "go_pfam",label="Search Genes")),
conditionalPanel(condition = "output.number_pfam_genes > 0 && input.gene_selection_mode == 'Protein Domain PFAM ID'",
tags$br(), # extra line break for separation
## Check box to select genes with the given PFAM ID
checkboxGroupInput(inputId = "pfam_genes",
label = "Select Genes:"),
## Select distance
selectInput(inputId = "distance_pfam",
label = "Select Co-expressed Genes at Distance:",
choices = 0:3,
selected = 0,
multiple = FALSE),
## Action button to trigger gene selection based on PFAM ID
actionButton(inputId = "select_neighbours_pfam",label="Select Genes")
)
), #end panel for gene selection
## PANEL 2: GENE EXPRESSION ANALYSIS ##
wellPanel(
# Title, explanatory text and extra line breaks for separation
tags$h3(tags$b("Gene Expression Analysis:")),
tags$b("Generate a line graph of the expression levels of the selected genes:"),
tags$br(),
tags$br(),
# Action button for line graph
actionButton(inputId = "button_linegraph",label="Line Graph"),
# Extra line breaks for separation and explanatory text
tags$br(),
tags$br(),
tags$b("Generate a heatmap of the correlation between the expression levels of the selected genes:"),
tags$br(),
tags$br(),
# Action button for heatmap
actionButton(inputId = "button_heatmap",label="Heatmap")
), #end panel for expression analysis
## PANEL 3: GO ENRICHMENT ANALYSIS ##
wellPanel(
# Title
tags$h3(tags$b("GO Enrichment Analysis:")),
# GO enrichment mode
radioButtons(inputId = "go_mode",
label = "GO Enrichment",
choices = c("Based on Arabidopsis orthology","Based on PFAM Annotation")),
# Action button to trigger GO enrichment analysis
actionButton(inputId = "go_enrichment",label = "GO Enrichment")
), #end panel for GO enrichment
width = 4
),
# In the main panel the network, output graphs and tables are displayed.
mainPanel(
plotOutput("networkPlot", height = "800px"), #click="plot_click",
uiOutput(outputId = "message"),
uiOutput(outputId = "download"),
dataTableOutput(outputId = "output_table"),
plotOutput("output_graph"),
width = 8
)
),
tableOutput("gene_info_table"),
tableOutput("go_table"),
plotOutput("heatmapPlot"),
plotOutput("linePlot"),
plotOutput("go_enrichment_plot")
)
## Server function for ChlamyNET
server <- function(input, output, session) {
## Initial/default visualization of ChlamyNET network
output$networkPlot <- renderPlot({
ggplot(network.data, aes(x,y)) +
theme(panel.background = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.title = element_blank(),
axis.text = element_blank(),
axis.ticks.y = element_blank()) +
geom_point(color=network.data$color,size=1)
})
## Reactive responding to gene selection by ID when clicking button_gene_id
selected_gene_id <- eventReactive(input$button_gene_id,{
target.gene <- input$selected.gene
selection <- c()
for(i in 1:length(target.gene))
{
selection <- c(selection,
nodes[as.vector(ego(graph = chlamynet,nodes = target.gene[i],order=input$distance)[[1]])])
}
selection <- unique(selection)
#print(selection)
#subset(network.data, name %in% nodes[as.vector(ego(graph = chlamynet,nodes = target.gene,order=input$distance)[[1]])])
subset(network.data, name %in% selection)
})
## Reactive responding to gene list selection by ID when clicking button_gene_list_id
selected_gene_list_id <- eventReactive(input$button_gene_list_id,{
target.gene.list <- as.vector(unlist(
strsplit(input$gene.list, split="\n",
fixed = TRUE)[1]))
selection <- c()
genes.not.chlamynet <- setdiff(x = target.gene.list, y = network.data$name)
target.gene.list <- intersect(target.gene.list,network.data$name)
for(i in 1:length(target.gene.list))
{
selection <- c(selection,
nodes[as.vector(ego(graph = chlamynet,nodes = target.gene.list[i],order=input$distance_gene_list)[[1]])])
}
selection <- unique(selection)
#print(paste("distance:",input$distance_gene_list))
#print(selection)
#subset(network.data, name %in% nodes[as.vector(ego(graph = chlamynet,nodes = target.gene,order=input$distance)[[1]])])
subset(network.data, name %in% selection)
})
## Gene selection by PFAM
selected_gene_pfam <- eventReactive(input$go_pfam,{
## Extract x and y position for the selected gene
pfam_selection <- subset(network.data, pfam %in% input$selected_pfam)
pfam_genes_selected <<- pfam_selection$name
#print("selection:")
#print(pfam_genes_selected)
pfam_selection
})
## Reactive to determine selected genes with a given PFAM ID
my_pfam_genes <- reactive({
pfam_selection <- subset(network.data, pfam %in% input$selected_pfam)
pfam_genes_selected <<- pfam_selection$name
return(pfam_genes_selected)
})
## Observe to update the list of genes with a given PFAM ID
observe({
updateCheckboxGroupInput(session, "pfam_genes",
choices = my_pfam_genes()
)
})
## Determination of the number of genes with a given PFAM ID to be
## used in a dynamic conditional panel
output$number_pfam_genes <- eventReactive(input$go_pfam,{
## Extract x and y position for the selected gene
pfam_selection <- subset(network.data, pfam == input$selected_pfam)
pfam_genes_selected <<- pfam_selection$name
#print("selection:")
##print(pfam_genes_selected)
length(pfam_genes_selected)
})
## Necessary for dinamical panel
outputOptions(output, "number_pfam_genes", suspendWhenHidden = FALSE)
## Visualization of selected genes by ID
observeEvent(input$button_gene_id, {
#print("aquí")
#print(selected_gene_id())
gene.list <<- selected_gene_id()$name
output$networkPlot <- renderPlot({
ggplot(network.data, aes(x,y)) +
theme(panel.background = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.title = element_blank(),
axis.text = element_blank(),
axis.ticks.y = element_blank()) +
geom_point(color=network.data$color,size=1) +
geom_point(data=selected_gene_id(), aes(x,y), size=3, fill=selected_gene_id()$color,colour="black",pch=21)
})
## Generate annotation table
genes.annotation.data <- subset(annotation.data, V1 %in% gene.list)
colnames(genes.annotation.data) <- c("Gene id", "PFAM", "PANTHER", "KOG", "EC", "K", "Arabidopsis", "Common name", "Description")
genes.annotation.data <- genes.annotation.data[c("Gene id", "Description", "Common name", "Arabidopsis", "PFAM", "PANTHER", "KOG", "EC", "K")]
output$message <- renderUI({
tagList(
tags$p(tags$b("The table below presents the annotation of the selected genes.
This information can be downloaded by clicking on the following button:")),
tags$br())
})
output$download <- renderUI({
tagList(
downloadButton(outputId= "downloadData", "Get Selected Genes Annotation"),
tags$br(),
tags$br()
)
})
output$downloadData <- downloadHandler(
filename = function()
{
return('selected_genes_annotation.txt')
},
content = function(file) {
write.table(as.data.frame(genes.annotation.data), file=file, sep="\t",quote=FALSE )
})
## Construct data frame with links
genes.ids <- as.vector(genes.annotation.data[["Gene id"]])
genes.pfam <- as.vector(genes.annotation.data[["PFAM"]])
genes.kog <- as.vector(genes.annotation.data[["KOG"]])
genes.ec <- as.vector(genes.annotation.data[["EC"]])
genes.k <- as.vector(genes.annotation.data[["K"]])
genes.pthr <- as.vector(genes.annotation.data[["PANTHER"]])
genes.with.links <- vector(mode="character",length=length(genes.ids))
genes.pfam.with.links <- vector(mode="character",length=length(genes.pfam))
genes.kog.with.links <- vector(mode="character",length=length(genes.kog))
genes.ec.with.links <- vector(mode="character",length=length(genes.ec))
genes.k.with.links <- vector(mode="character",length=length(genes.ec))
genes.pthr.with.links <- vector(mode="character",length=length(genes.pthr))
for(i in 1:length(genes.ids))
{
current.gene <- genes.ids[i]
current.phytozome.link <- paste0("https://phytozome.jgi.doe.gov/pz/portal.html#!results?search=0&crown=1&star=1&method=4614&searchText=",
current.gene,
"&offset=0")
phytozome.href <- paste(c("<a href=\"",
current.phytozome.link,
"\" target=\"_blank\">Phytozome</a>"),
collapse="")
current.circadianet.link <- paste0("http://viridiplantae.ibvf.csic.es/circadiaNet/genes/cre/",
current.gene,
".html")
circadianet.href <- paste(c("<a href=\"",
current.circadianet.link,
"\" target=\"_blank\">CircadiaNET</a>"),
collapse="")
new.gene.id.element <- paste(c(current.gene,
paste(phytozome.href,
circadianet.href,sep=",")),collapse = " ")
current.pfam <- genes.pfam[i]
if(current.pfam != "")
{
pfams.ids <- strsplit(current.pfam,split=",")[[1]]
pfam.href <- vector(mode="character",length=length(pfams.ids))
for(j in 1:length(pfams.ids))
{
pfam.link <- paste0("https://pfam.xfam.org/family/",pfams.ids[j])
pfam.href[j] <- paste(c("<a href=\"",
pfam.link,
"\" target=\"_blank\">",
pfams.ids[j], "</a>"),
collapse="")
}
pfams.hrefs <- paste(pfam.href,collapse=",")
} else
{
pfams.hrefs <- ""
}
## Create kog links
current.kog <- genes.kog[i]
if(current.kog != "")
{
kog.link <- paste0("http://eggnogdb.embl.de/#/app/results?seqid=Q6CPW9&target_nogs=",
current.kog)
kog.href <- paste(c("<a href=\"",
kog.link,
"\" target=\"_blank\">",
current.kog, "</a>"),
collapse="")
} else
{
kog.href <- ""
}
## Create ec link
current.ec <- genes.ec[i]
if(current.ec != "")
{
ec.link <- paste0("https://www.genome.jp/dbget-bin/www_bget?ec:",
current.ec)
ec.href <- paste(c("<a href=\"",
ec.link,
"\" target=\"_blank\">",
current.ec, "</a>"),
collapse="")
} else
{
ec.href <- ""
}
## Create k link
current.k <- genes.k[i]
if(current.k != "")
{
k.link <- paste0("https://www.genome.jp/dbget-bin/www_bget?ko:",
current.k)
k.href <- paste(c("<a href=\"",
k.link,
"\" target=\"_blank\">",
current.k, "</a>"),
collapse="")
} else
{
k.href <- ""
}
## Create pthr link
current.pthr <- genes.pthr[i]
if(current.pthr != "")
{
pthr.link <- paste0("http://www.pantherdb.org/panther/family.do?clsAccession=",
current.pthr)
pthr.href <- paste(c("<a href=\"",
pthr.link,
"\" target=\"_blank\">",
current.pthr, "</a>"),
collapse="")
} else
{
pthr.href <- ""
}
genes.with.links[i] <- new.gene.id.element
genes.pfam.with.links[i] <- pfams.hrefs
genes.kog.with.links[i] <- kog.href
genes.ec.with.links[i] <- ec.href
genes.k.with.links[i] <- k.href
genes.pthr.with.links[i] <- pthr.href
}
genes.annotation.data.with.links <-
data.frame(genes.with.links,
genes.annotation.data[,2:4],
genes.pfam.with.links,
genes.pthr.with.links,
genes.kog.with.links,
genes.ec.with.links,
genes.k.with.links)
colnames(genes.annotation.data.with.links) <- colnames(genes.annotation.data)
output$output_table <- renderDataTable({
as.data.frame(genes.annotation.data.with.links)
},escape=FALSE)
})
## ---------------------------------------
## Visualization of selected genes by ID
observeEvent(input$button_gene_list_id, {
#print("aquí con lista")
#print(selected_gene_id())
gene.list <<- selected_gene_list_id()$name
output$networkPlot <- renderPlot({
ggplot(network.data, aes(x,y)) +
theme(panel.background = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.title = element_blank(),
axis.text = element_blank(),
axis.ticks.y = element_blank()) +
geom_point(color=network.data$color,size=1) +
geom_point(data=selected_gene_list_id(), aes(x,y), size=3, fill=selected_gene_list_id()$color,colour="black",pch=21)
})
## Generate annotation table
genes.annotation.data <- subset(annotation.data, V1 %in% gene.list)
colnames(genes.annotation.data) <- c("Gene id", "PFAM", "PANTHER", "KOG", "EC", "K", "Arabidopsis", "Common name", "Description")
genes.annotation.data <- genes.annotation.data[c("Gene id", "Description", "Common name", "Arabidopsis", "PFAM", "PANTHER", "KOG", "EC", "K")]
target.gene.list <- as.vector(unlist(
strsplit(input$gene.list, split="\n",
fixed = TRUE)[1]))
genes.not.chlamynet <- setdiff(x = target.gene.list, y = network.data$name)
if(length(genes.not.chlamynet) > 0)
{
msg <- paste(c("The following genes are not in ChlamyNET: ", genes.not.chlamynet,
". Check if the IDs are correct and correspond to Chlamydomonas reinhardtii annotation v5. Alternatively, these genes may not be differentially expressed in the conditions integrated in ChlamyNET."),collapse=" ")
} else
{
msg <- ""
}
output$message <- renderUI({
tagList(
tags$p(tags$b(msg)),
tags$p(tags$b("The table below presents the annotation of the selected genes.
This information can be downloaded by clicking on the following button:")),
tags$br())
})
output$download <- renderUI({
tagList(
downloadButton(outputId= "downloadData", "Get Selected Genes Annotation"),
tags$br(),
tags$br()
)
})
output$downloadData <- downloadHandler(
filename = function()
{
return('selected_genes_annotation.txt')
},
content = function(file) {
write.table(as.data.frame(genes.annotation.data), file=file, sep="\t",quote=FALSE )
})
## Construct data frame with links
genes.ids <- as.vector(genes.annotation.data[["Gene id"]])
genes.pfam <- as.vector(genes.annotation.data[["PFAM"]])
genes.kog <- as.vector(genes.annotation.data[["KOG"]])
genes.ec <- as.vector(genes.annotation.data[["EC"]])
genes.k <- as.vector(genes.annotation.data[["K"]])
genes.pthr <- as.vector(genes.annotation.data[["PANTHER"]])
genes.with.links <- vector(mode="character",length=length(genes.ids))
genes.pfam.with.links <- vector(mode="character",length=length(genes.pfam))
genes.kog.with.links <- vector(mode="character",length=length(genes.kog))
genes.ec.with.links <- vector(mode="character",length=length(genes.ec))
genes.k.with.links <- vector(mode="character",length=length(genes.ec))
genes.pthr.with.links <- vector(mode="character",length=length(genes.pthr))
for(i in 1:length(genes.ids))
{
current.gene <- genes.ids[i]
current.phytozome.link <- paste0("https://phytozome.jgi.doe.gov/pz/portal.html#!results?search=0&crown=1&star=1&method=4614&searchText=",
current.gene,
"&offset=0")
phytozome.href <- paste(c("<a href=\"",
current.phytozome.link,
"\" target=\"_blank\">Phytozome</a>"),
collapse="")
current.circadianet.link <- paste0("http://viridiplantae.ibvf.csic.es/circadiaNet/genes/cre/",
current.gene,
".html")
circadianet.href <- paste(c("<a href=\"",
current.circadianet.link,
"\" target=\"_blank\">CircadiaNET</a>"),
collapse="")
new.gene.id.element <- paste(c(current.gene,
paste(phytozome.href,
circadianet.href,sep=",")),collapse = " ")
current.pfam <- genes.pfam[i]
if(current.pfam != "")
{
pfams.ids <- strsplit(current.pfam,split=",")[[1]]
pfam.href <- vector(mode="character",length=length(pfams.ids))
for(j in 1:length(pfams.ids))
{
pfam.link <- paste0("https://pfam.xfam.org/family/",pfams.ids[j])
pfam.href[j] <- paste(c("<a href=\"",
pfam.link,
"\" target=\"_blank\">",
pfams.ids[j], "</a>"),
collapse="")
}
pfams.hrefs <- paste(pfam.href,collapse=",")
} else
{
pfams.hrefs <- ""
}
## Create kog links
current.kog <- genes.kog[i]
if(current.kog != "")
{
kog.link <- paste0("http://eggnogdb.embl.de/#/app/results?seqid=Q6CPW9&target_nogs=",
current.kog)
kog.href <- paste(c("<a href=\"",
kog.link,
"\" target=\"_blank\">",
current.kog, "</a>"),
collapse="")
} else
{
kog.href <- ""
}
## Create ec link
current.ec <- genes.ec[i]
if(current.ec != "")
{
ec.link <- paste0("https://www.genome.jp/dbget-bin/www_bget?ec:",
current.ec)
ec.href <- paste(c("<a href=\"",
ec.link,
"\" target=\"_blank\">",
current.ec, "</a>"),
collapse="")
} else
{
ec.href <- ""
}
## Create k link
current.k <- genes.k[i]
if(current.k != "")
{
k.link <- paste0("https://www.genome.jp/dbget-bin/www_bget?ko:",
current.k)
k.href <- paste(c("<a href=\"",
k.link,
"\" target=\"_blank\">",
current.k, "</a>"),
collapse="")
} else
{
k.href <- ""
}
## Create pthr link
current.pthr <- genes.pthr[i]
if(current.pthr != "")
{
pthr.link <- paste0("http://www.pantherdb.org/panther/family.do?clsAccession=",
current.pthr)
pthr.href <- paste(c("<a href=\"",
pthr.link,
"\" target=\"_blank\">",
current.pthr, "</a>"),
collapse="")
} else
{
pthr.href <- ""
}
genes.with.links[i] <- new.gene.id.element
genes.pfam.with.links[i] <- pfams.hrefs
genes.kog.with.links[i] <- kog.href
genes.ec.with.links[i] <- ec.href
genes.k.with.links[i] <- k.href
genes.pthr.with.links[i] <- pthr.href
}
genes.annotation.data.with.links <-
data.frame(genes.with.links,
genes.annotation.data[,2:4],
genes.pfam.with.links,
genes.pthr.with.links,
genes.kog.with.links,
genes.ec.with.links,
genes.k.with.links)
colnames(genes.annotation.data.with.links) <- colnames(genes.annotation.data)
output$output_table <- renderDataTable({
as.data.frame(genes.annotation.data.with.links)
},escape=FALSE)
})
## ---------------------------------------
## Visualization of identified genes with the given PFAM domains
observeEvent(input$go_pfam, {
#print("pfam")
#print(selected_gene_pfam())
gene.list <<- selected_gene_pfam()$name
output$networkPlot <- renderPlot({
ggplot(network.data, aes(x,y)) +
theme(panel.background = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.title = element_blank(),
axis.text = element_blank(),
axis.ticks.y = element_blank()) +
geom_point(color=network.data$color,size=1) +
geom_point(data=selected_gene_pfam(), aes(x,y), size=3, fill=selected_gene_pfam()$color,colour="black",pch=21)
})
})
## Visualization of selected genes by ID
observeEvent(eventExpr = input$select_neighbours_pfam, {
## Determine the neighbours of the identified genes with the given PFAM
found.pfam.genes <- input$pfam_genes
neighbours.pfam <- c()
for(i in 1:length(found.pfam.genes))
{
neighbours.pfam <- rbind(neighbours.pfam,
subset(network.data, name %in% nodes[as.vector(ego(graph = chlamynet,nodes = found.pfam.genes[i] ,order=input$distance_pfam)[[1]])]))
}
## Set gene list for further analysis
gene.list <<- neighbours.pfam$name
## Network visualization
output$networkPlot <- renderPlot({
ggplot(network.data, aes(x,y)) +
theme(panel.background = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.title = element_blank(),
axis.text = element_blank(),
axis.ticks.y = element_blank()) +
geom_point(color=network.data$color,size=1) +
geom_point(data=neighbours.pfam, aes(x,y), size=3, fill=neighbours.pfam$color,colour="black",pch=21)
})
## Generate annotation table
genes.annotation.data <- subset(annotation.data, V1 %in% gene.list)
colnames(genes.annotation.data) <- c("Gene id", "PFAM", "PANTHER", "KOG", "EC", "K", "Arabidopsis", "Common name", "Description")
genes.annotation.data <- genes.annotation.data[c("Gene id", "Description", "Common name", "Arabidopsis", "PFAM", "PANTHER", "KOG", "EC", "K")]
## Construct data frame with links
genes.ids <- as.vector(genes.annotation.data[["Gene id"]])
genes.pfam <- as.vector(genes.annotation.data[["PFAM"]])
genes.kog <- as.vector(genes.annotation.data[["KOG"]])
genes.ec <- as.vector(genes.annotation.data[["EC"]])
genes.k <- as.vector(genes.annotation.data[["K"]])
genes.pthr <- as.vector(genes.annotation.data[["PANTHER"]])
genes.with.links <- vector(mode="character",length=length(genes.ids))
genes.pfam.with.links <- vector(mode="character",length=length(genes.pfam))
genes.kog.with.links <- vector(mode="character",length=length(genes.kog))
genes.ec.with.links <- vector(mode="character",length=length(genes.ec))
genes.k.with.links <- vector(mode="character",length=length(genes.ec))
genes.pthr.with.links <- vector(mode="character",length=length(genes.pthr))
for(i in 1:length(genes.ids))
{
current.gene <- genes.ids[i]
current.phytozome.link <- paste0("https://phytozome.jgi.doe.gov/pz/portal.html#!results?search=0&crown=1&star=1&method=4614&searchText=",
current.gene,
"&offset=0")
phytozome.href <- paste(c("<a href=\"",
current.phytozome.link,
"\" target=\"_blank\">Phytozome</a>"),
collapse="")
current.circadianet.link <- paste0("http://viridiplantae.ibvf.csic.es/circadiaNet/genes/cre/",
current.gene,
".html")
circadianet.href <- paste(c("<a href=\"",
current.circadianet.link,
"\" target=\"_blank\">CircadiaNET</a>"),
collapse="")
new.gene.id.element <- paste(c(current.gene,
paste(phytozome.href,
circadianet.href,sep=",")),collapse = " ")
current.pfam <- genes.pfam[i]
if(current.pfam != "")
{
pfams.ids <- strsplit(current.pfam,split=",")[[1]]
pfam.href <- vector(mode="character",length=length(pfams.ids))
for(j in 1:length(pfams.ids))
{
pfam.link <- paste0("https://pfam.xfam.org/family/",pfams.ids[j])
pfam.href[j] <- paste(c("<a href=\"",
pfam.link,
"\" target=\"_blank\">",
pfams.ids[j], "</a>"),
collapse="")
}
pfams.hrefs <- paste(pfam.href,collapse=",")
} else
{
pfams.hrefs <- ""
}
## Create kog links
current.kog <- genes.kog[i]
if(current.kog != "")
{
kog.link <- paste0("http://eggnogdb.embl.de/#/app/results?seqid=Q6CPW9&target_nogs=",
current.kog)
kog.href <- paste(c("<a href=\"",
kog.link,
"\" target=\"_blank\">",
current.kog, "</a>"),
collapse="")
} else
{
kog.href <- ""
}
## Create ec link
current.ec <- genes.ec[i]
if(current.ec != "")
{
ec.link <- paste0("https://www.genome.jp/dbget-bin/www_bget?ec:",
current.ec)
ec.href <- paste(c("<a href=\"",
ec.link,
"\" target=\"_blank\">",
current.ec, "</a>"),
collapse="")
} else
{
ec.href <- ""
}
## Create k link
current.k <- genes.k[i]
if(current.k != "")
{
k.link <- paste0("https://www.genome.jp/dbget-bin/www_bget?ko:",
current.k)