# load libraries library(RSQLite) library(cRegulome) library(tidyverse) # get data # Downlaod database file if(!file.exists('cRegulome.db')) { get_db(test = FALSE, destfile = './cRegulome.db') } # Query the database conn <- dbConnect(SQLite(), './cRegulome.db') all_tf <- get_tf(conn, tf = c('ERCC6', 'VEZF1'), study = 'PRAD', targets_only = TRUE) all_mir <- get_mir(conn, mir = c('hsa-mir-23c', 'hsa-mir-378c', 'hsa-mir-761'), study = 'PRAD', targets_only = TRUE) dbDisconnect(conn) # Save data to rds objects write_rds(all_tf, path = 'data/alltf.rds') write_rds(all_mir, path = 'data/allmir.rds') # Identify target genes targets <- c('PEBP1', 'PIK3C3', 'PIK3CB', 'TBC1D25', 'TBC1D5', 'TOLLIP', 'WDR45', 'WIPI1', 'TGFBR1') # Query mir with targets = False conn <- dbConnect(SQLite(), './cRegulome.db') mir <- get_mir(conn, mir = c('hsa-mir-23c', 'hsa-mir-378c', 'hsa-mir-761'), study = 'PRAD', targets = targets) tf <- get_tf(conn, tf = c('ERCC6', 'VEZF1'), study = 'PRAD', targets_only = TRUE, targets = targets) dbDisconnect(conn) # save data to rds objects write_rds(tf, path = 'data/tf.rds') write_rds(mir, path = 'data/mir.rds') # load libraries library(tidyverse) library(xtable) # generate table tf <- read_rds('data/tf.rds') mir <- read_rds('data/mir.rds') names(tf)[1] <- 'tr' names(mir)[1] <- 'tr' bind_rows(list(TF = tf, miRNA = mir), .id = 'type') %>% select(-study) %>% arrange(type, tr) %>% mutate(type = ifelse(duplicated(type), '', type), tr = ifelse(duplicated(tr), '', tr)) %>% setNames(c('Type', 'Transcriptional Regulator', 'Target', 'Correlation')) %>% xtable(caption = '\\textbf{Output of transcription regulators from cRegulome.}', align = 'clllc', label = 'tab:output') %>% print(include.rownames = FALSE, booktabs = TRUE, add.to.row = list(pos = list(16, 6, 13, 18), command = c('\\midrule ', rep('\\cmidrule{2-4} ', 3))), caption.placement = 'top', table.placement = 'H', sanitize.text.function = identity, comment = FALSE, file = paste('manuscript/tables', 'output.tex', sep = '/')) # load libraries library(tidyverse) library(reshape2) library(xtable) # generate table list('get\\_db' = "Download the database file.", 'get\\_mir' = "Get correlations of the input microRNA with all genes or targets only.", 'get\\_tf' = "Get correlations of the input TF with all genes or targets only.", 'cor\\_tidy' = "Transform the objects cTF and cmicroRna to a tidy data.frame.", 'cor\\_hist' = "Makes a histogram of each of the regulome elements correlation values.", 'cor\\_joy' = "Makes a joy plot for each of the regulome elements correlation values.", 'cor\\_plot' = "Makes a dot plot of element correlations with colors corresponding to direction and size to the value of the correlation.", 'cor\\_upset' = "Makes an upset plot of the intersections of sets of regulome elements’ feature/gene hits.", 'cor\\_venn\\_diagram' = "Makes a venn diagram of the numbers and the intersection of the regulome elements’ feature/gene hits.", 'cor\\_igraph' = "Make a directed graph of the regulators TF/microRNA and their targets.") %>% melt() %>% setNames(c('Description', 'Method')) %>% select(Method, Description) %>% xtable(caption = '\\textbf{Description of the package functions and methods.}', align = 'cp{.2\\textwidth}p{.7\\textwidth}', label = 'tab:functions_description') %>% print(include.rownames = FALSE, booktabs = TRUE, add.to.row = list(pos = list(3), command = '\\midrule '), caption.placement = 'top', table.placement = 'H', sanitize.text.function = identity, comment = FALSE, file = paste('manuscript/tables', 'functions_description.tex', sep = '/')) # load libraries library(tidyverse) library(cRegulome) library(cowplot) # generate plot tf <- read_rds('data/tf.rds') ob <- cTF(tf) p1 <- cor_plot(ob) + theme(legend.position = 'top', legend.direction = 'vertical') + scale_size_continuous(breaks = c(.5, .65)) + labs(x = '', y = '') mir <- read_rds('data/mir.rds') ob <- cmicroRNA(mir) p2 <- cor_plot(ob) + theme(legend.position = 'top', legend.direction = 'vertical') + scale_size_continuous(breaks = c(.1, .3)) + labs(x = '', y = '') plot_grid(p1, p2, scale = .9, labels = 'AUTO', label_size = 10, label_fontface = 'plain') %>% ggsave(plot = ., filename = 'manuscript/figures/dotplot.png', width = 20, height = 12, units = 'cm') # load libraries library(tidyverse) library(cRegulome) library(cowplot) library(grid) library(gridExtra) # generate data alltf <- read_rds('data/alltf.rds') ob <- cTF(alltf) cor_upset(ob) grid.edit('arrange', name = 'p1') p1 <- grid.grab() allmir <- read_rds('data/allmir.rds') ob <- cmicroRNA(allmir) cor_upset(ob) grid.edit('arrange', name = 'p2') p2 <- grid.grab() plot_grid(p1, p2, scale = .9, labels = 'AUTO', label_size = 10, label_fontface = 'plain') %>% ggsave(plot = ., filename = 'manuscript/figures/upsetplot.png', width = 20, height = 10, units = 'cm') # load libraries library(tidyverse) library(cRegulome) library(cowplot) # generate data alltf <- read_rds('data/alltf.rds') ob <- cTF(alltf) p1 <- cor_joy(ob) + labs(x = 'Transcription Factor', y = 'Expression Correlation') allmir <- read_rds('data/allmir.rds') ob <- cmicroRNA(allmir) p2 <- cor_joy(ob)+ labs(x = 'microRNA', y = 'Expression Correlation') plot_grid(p1, p2, scale = .9, labels = 'AUTO', label_size = 10, label_fontface = 'plain') %>% ggsave(plot = ., filename = 'manuscript/figures/joyplot.png', width = 20, height = 10, units = 'cm') # load libraries library(tidyverse) library(cRegulome) library(igraph) # generate plot tf <- read_rds('data/tf.rds') ob <- cTF(tf) p1 <- cor_igraph(ob, directed = TRUE) mir <- read_rds('data/mir.rds') ob <- cmicroRNA(mir) p2 <- cor_igraph(ob, directed = TRUE) png(filename = 'manuscript/figures/network.png', width = 20, height = 12, units = 'cm', res = 300) par(mfrow=c(1,2)) set.seed(123456) plot(p1, vertex.color = as.factor(V(p1)$type == 'TF'), edge.arrow.size = .5) mtext('A', line = 3, adj = -.3) plot(p2, vertex.color = as.factor(V(p2)$type == 'microRNA'), edge.arrow.size = .5) mtext('B', line = 3, adj = -.3) dev.off()