... | ... |
@@ -1,5 +1,4 @@ |
1 | 1 |
inputObject <- function(testGene, backgroundGene, pathways) { |
2 |
- |
|
3 | 2 |
pathway_genes <- unique(as.character(unlist(pathways))) |
4 | 3 |
testGene_in_pathways <- which(testGene %in% pathway_genes) |
5 | 4 |
back_gene_in_pathways <- which(backgroundGene %in% pathway_genes) |
... | ... |
@@ -35,7 +34,8 @@ inputObject <- function(testGene, backgroundGene, pathways) { |
35 | 34 |
testGene <- unique(as.character(testGene)) |
36 | 35 |
backgroundGene <- unique(as.character(backgroundGene)) |
37 | 36 |
|
38 |
- list(testGene = testGene, |
|
37 |
+ list( |
|
38 |
+ testGene = testGene, |
|
39 | 39 |
backgroundGene = backgroundGene, |
40 | 40 |
pathways = pathways, |
41 | 41 |
pathways_name = names(pathways), |
... | ... |
@@ -82,10 +82,12 @@ runFedup <- function(testGene, backgroundGene, pathways) { |
82 | 82 |
pathways <- inputs$pathways |
83 | 83 |
pathways_name <- inputs$pathways_name |
84 | 84 |
pathways_size <- inputs$pathways_size |
85 |
- message("Data input:\n => ", |
|
85 |
+ message( |
|
86 |
+ "Data input:\n => ", |
|
86 | 87 |
length(test), " test genes\n => ", |
87 | 88 |
length(background), " background genes\n => ", |
88 |
- length(pathways), " pathawys") |
|
89 |
+ length(pathways), " pathawys" |
|
90 |
+ ) |
|
89 | 91 |
|
90 | 92 |
res <- data.table(pathway = pathways_name, size = pathways_size) |
91 | 93 |
res_stats <- vapply(pathways, function(x) { |
... | ... |
@@ -103,16 +105,17 @@ runFedup <- function(testGene, backgroundGene, pathways) { |
103 | 105 |
p <- fisher.test(m, alternative = "two.sided")$p.value |
104 | 106 |
return(c( |
105 | 107 |
real_frac = a_x, expected_frac = b_x, fold_enrich = f, |
106 |
- status = e, pvalue = p, real_gene = paste(a, collapse = "|"))) |
|
108 |
+ status = e, pvalue = p, real_gene = paste(a, collapse = "|") |
|
109 |
+ )) |
|
107 | 110 |
}, character(6)) |
108 | 111 |
|
109 |
- res[, "real_frac" := as.numeric(unlist(res_stats["real_frac",]))] |
|
110 |
- res[, "expected_frac" := as.numeric(unlist(res_stats["expected_frac",]))] |
|
111 |
- res[, "fold_enrichment" := as.numeric(unlist(res_stats["fold_enrich",]))] |
|
112 |
- res[, "status" := unlist(res_stats["status",])] |
|
113 |
- res[, "real_gene" := mapply("[", strsplit(res_stats["real_gene",], "\\|"))] |
|
114 |
- res[, "pvalue" := as.numeric(unlist(res_stats["pvalue",]))] |
|
115 |
- res <- res[order(res$pvalue),] |
|
112 |
+ res[, "real_frac" := as.numeric(unlist(res_stats["real_frac", ]))] |
|
113 |
+ res[, "expected_frac" := as.numeric(unlist(res_stats["expected_frac", ]))] |
|
114 |
+ res[, "fold_enrichment" := as.numeric(unlist(res_stats["fold_enrich", ]))] |
|
115 |
+ res[, "status" := unlist(res_stats["status", ])] |
|
116 |
+ res[, "real_gene" := mapply("[", strsplit(res_stats["real_gene", ], "\\|"))] |
|
117 |
+ res[, "pvalue" := as.numeric(unlist(res_stats["pvalue", ]))] |
|
118 |
+ res <- res[order(res$pvalue), ] |
|
116 | 119 |
res$qvalue <- p.adjust(res$pvalue, method = "BH") |
117 | 120 |
|
118 | 121 |
message("You did it! FEDUP ran successfully, feeling pretty good huh?") |
... | ... |
@@ -19,7 +19,7 @@ |
19 | 19 |
#' data(backgroundGene) |
20 | 20 |
#' data(pathwaysGMT) |
21 | 21 |
#' fedupRes <- runFedup(testGene, backgroundGene, pathwaysGMT) |
22 |
-#' resultsFile <- tempfile("fedupRes", fileext=".txt") |
|
22 |
+#' resultsFile <- tempfile("fedupRes", fileext = ".txt") |
|
23 | 23 |
#' writeFemap(fedupRes, resultsFile) |
24 | 24 |
#' @importFrom data.table fwrite |
25 | 25 |
#' @importFrom dplyr select mutate %>% |
... | ... |
@@ -52,30 +52,34 @@ writeFemap <- function(df, resultsFile) { |
52 | 52 |
#' effect of plotting the EM in an open session of Cytoscape. |
53 | 53 |
#' @examples |
54 | 54 |
#' \dontrun{ |
55 |
-#' # not run because Cytoscape needs to be installed and open |
|
56 |
-#' data(testGene) |
|
57 |
-#' data(backgroundGene) |
|
58 |
-#' data(pathwaysGMT) |
|
59 |
-#' gmtFile <- tempfile("pathwaysGMT", fileext=".gmt") |
|
60 |
-#' fedupRes <- runFedup(testGene, backgroundGene, pathwaysGMT) |
|
61 |
-#' resultsFile <- tempfile("fedupRes", fileext=".txt") |
|
62 |
-#' netFile <- tempfile("FEDUP_EM", fileext=".png") |
|
63 |
-#' writePathways(pathwaysGMT, gmtFile) |
|
64 |
-#' writeFemap(fedupRes, resultsFile) |
|
65 |
-#' plotFemap( |
|
66 |
-#' gmtFile=gmtFile, |
|
67 |
-#' resultsFile=resultsFile, |
|
68 |
-#' qvalue=0.05, |
|
69 |
-#' netName="FEDUP_EM", |
|
70 |
-#' netFile=netFile)} |
|
55 |
+#' # not run because Cytoscape needs to be installed and open |
|
56 |
+#' data(testGene) |
|
57 |
+#' data(backgroundGene) |
|
58 |
+#' data(pathwaysGMT) |
|
59 |
+#' gmtFile <- tempfile("pathwaysGMT", fileext = ".gmt") |
|
60 |
+#' fedupRes <- runFedup(testGene, backgroundGene, pathwaysGMT) |
|
61 |
+#' resultsFile <- tempfile("fedupRes", fileext = ".txt") |
|
62 |
+#' netFile <- tempfile("FEDUP_EM", fileext = ".png") |
|
63 |
+#' writePathways(pathwaysGMT, gmtFile) |
|
64 |
+#' writeFemap(fedupRes, resultsFile) |
|
65 |
+#' plotFemap( |
|
66 |
+#' gmtFile = gmtFile, |
|
67 |
+#' resultsFile = resultsFile, |
|
68 |
+#' qvalue = 0.05, |
|
69 |
+#' netName = "FEDUP_EM", |
|
70 |
+#' netFile = netFile |
|
71 |
+#' ) |
|
72 |
+#' } |
|
71 | 73 |
#' @import RCy3 |
72 | 74 |
#' @export |
73 |
-plotFemap <- function(gmtFile, resultsFile, pvalue=1, qvalue=1, |
|
74 |
- netName="generic", netFile="png") { |
|
75 |
+plotFemap <- function(gmtFile, resultsFile, pvalue = 1, qvalue = 1, |
|
76 |
+ netName = "generic", netFile = "png") { |
|
75 | 77 |
|
76 | 78 |
# Confirm that Cytoscape is installed and opened |
77 | 79 |
cytoscapePing() |
78 |
- if (netName %in% getNetworkList()) { deleteNetwork(netName) } |
|
80 |
+ if (netName %in% getNetworkList()) { |
|
81 |
+ deleteNetwork(netName) |
|
82 |
+ } |
|
79 | 83 |
|
80 | 84 |
message("Building the network") |
81 | 85 |
em_command <- paste( |
... | ... |
@@ -86,35 +90,35 @@ plotFemap <- function(gmtFile, resultsFile, pvalue=1, qvalue=1, |
86 | 90 |
"qvalue=", qvalue, |
87 | 91 |
"similaritycutoff=", 0.375, |
88 | 92 |
"coefficients=", "COMBINED", |
89 |
- "combinedConstant=", 0.5) |
|
93 |
+ "combinedConstant=", 0.5 |
|
94 |
+ ) |
|
90 | 95 |
response <- commandsGET(em_command) |
91 | 96 |
renameNetwork(netName, getNetworkSuid()) |
92 | 97 |
|
93 |
- # Node visualization (enriched = red nodes, depleted = blue nodes) |
|
94 | 98 |
message("Setting network chart data") |
95 | 99 |
ch_command <- paste( |
96 | 100 |
'enrichmentmap chart data="NES_VALUE"', |
97 |
- "colors=", "RD_BU_9") |
|
101 |
+ "colors=", "RD_BU_9" |
|
102 |
+ ) |
|
98 | 103 |
response <- commandsGET(ch_command) |
99 | 104 |
|
100 |
- # Annotate similar pathways using AutoAnnotate |
|
101 | 105 |
message("Annotating the network using AutoAnnotate") |
102 | 106 |
aa_command <- paste( |
103 | 107 |
"autoannotate annotate-clusterBoosted", |
104 | 108 |
"clusterAlgorithm=MCL", |
105 | 109 |
"maxWords=3", |
106 |
- "network=", netName) |
|
110 |
+ "network=", netName |
|
111 |
+ ) |
|
107 | 112 |
response <- commandsGET(aa_command) |
108 | 113 |
|
109 |
- # Network layout |
|
110 | 114 |
message("Applying a force-directed network layout") |
111 | 115 |
ln_command <- paste( |
112 | 116 |
"layout force-directed", |
113 |
- "network=", netName) |
|
117 |
+ "network=", netName |
|
118 |
+ ) |
|
114 | 119 |
response <- commandsGET(ln_command) |
115 | 120 |
fitContent() |
116 | 121 |
|
117 |
- # Draw out network to file |
|
118 | 122 |
message("Drawing out network to ", netFile) |
119 | 123 |
exportImage(netFile) |
120 | 124 |
} |
... | ... |
@@ -16,28 +16,35 @@ |
16 | 16 |
#' @examples |
17 | 17 |
#' pathways <- readPathways( |
18 | 18 |
#' system.file("extdata", "Human_Reactome_November_17_2020_symbol.gmt", |
19 |
-#' package="FEDUP"), minGene=10, maxGene=500) |
|
19 |
+#' package = "FEDUP" |
|
20 |
+#' ), |
|
21 |
+#' minGene = 10, maxGene = 500 |
|
22 |
+#' ) |
|
20 | 23 |
#' pathways <- readPathways( |
21 |
-#' system.file("extdata", "SAFE_terms.xlsx", package="FEDUP"), |
|
22 |
-#' header=TRUE, pathwayCol="Enriched.GO.names", geneCol="Gene.ID") |
|
24 |
+#' system.file("extdata", "SAFE_terms.xlsx", package = "FEDUP"), |
|
25 |
+#' header = TRUE, pathwayCol = "Enriched.GO.names", geneCol = "Gene.ID" |
|
26 |
+#' ) |
|
23 | 27 |
#' @importFrom openxlsx read.xlsx |
24 | 28 |
#' @importFrom tibble deframe |
25 | 29 |
#' @importFrom stats aggregate na.omit |
26 | 30 |
#' @importFrom utils head read.delim tail |
27 | 31 |
#' @export |
28 |
-readPathways <- function(pathwayFile, header=FALSE, |
|
29 |
- pathwayCol=NULL, geneCol=NULL, |
|
30 |
- minGene=1L, maxGene=Inf) { |
|
31 |
- |
|
32 |
+readPathways <- function(pathwayFile, header = FALSE, |
|
33 |
+ pathwayCol = NULL, geneCol = NULL, |
|
34 |
+ minGene = 1L, maxGene = Inf) { |
|
32 | 35 |
s <- c("gmt", "txt", "xlsx") |
33 | 36 |
f <- sub(".*\\.", "", pathwayFile) |
34 | 37 |
if (!f %in% s) { |
35 |
- stop(paste0("Sorry, pathway file type (", f, ") is not supported. ", |
|
36 |
- "Supported extensions: ", paste(s, collapse = ", "), ".")) |
|
38 |
+ stop(paste0( |
|
39 |
+ "Sorry, pathway file type (", f, ") is not supported. ", |
|
40 |
+ "Supported extensions: ", paste(s, collapse = ", "), "." |
|
41 |
+ )) |
|
37 | 42 |
} |
38 | 43 |
if (f == "gmt") { |
39 | 44 |
pathway_in <- strsplit(readLines(pathwayFile), "\t") |
40 |
- if (header) { pathway_in <- pathway_in[-1] } |
|
45 |
+ if (header) { |
|
46 |
+ pathway_in <- pathway_in[-1] |
|
47 |
+ } |
|
41 | 48 |
pathways <- lapply(pathway_in, tail, -2) |
42 | 49 |
names(pathways) <- vapply(pathway_in, head, n = 1, character(1)) |
43 | 50 |
} else { |
... | ... |
@@ -46,31 +53,30 @@ readPathways <- function(pathwayFile, header=FALSE, |
46 | 53 |
} else if (f == "txt") { |
47 | 54 |
pathway_in <- read.delim(pathwayFile, header = header) |
48 | 55 |
} |
49 |
- if (missing(pathwayCol)||!pathwayCol %in% colnames(pathway_in)) { |
|
56 |
+ if (missing(pathwayCol) || !pathwayCol %in% colnames(pathway_in)) { |
|
50 | 57 |
stop("Pathway ID column (", pathwayCol, ") not in file") |
51 |
- } else if (missing(geneCol)||!geneCol %in% colnames(pathway_in)) { |
|
58 |
+ } else if (missing(geneCol) || !geneCol %in% colnames(pathway_in)) { |
|
52 | 59 |
stop("Gene ID column (", geneCol, ") not in file") |
53 | 60 |
} else { |
54 | 61 |
pathway_df <- data.frame( |
55 |
- pathway = pathway_in[,pathwayCol], |
|
56 |
- gene = pathway_in[,geneCol]) |
|
62 |
+ pathway = pathway_in[, pathwayCol], gene = pathway_in[, geneCol] |
|
63 |
+ ) |
|
57 | 64 |
pathway_df[which(pathway_df$gene == ""), "gene"] <- NA |
58 | 65 |
pathway_df <- na.omit(pathway_df) |
59 | 66 |
pathway_df <- aggregate(gene ~ pathway, pathway_df, paste) |
60 | 67 |
pathways <- deframe(pathway_df) |
61 | 68 |
} |
62 | 69 |
} |
63 |
- |
|
64 | 70 |
size <- lapply(pathways, length) |
65 | 71 |
pathways_s <- pathways[which(size >= minGene & size <= maxGene)] |
66 |
- pathways_s <- pathways_s[!duplicated(names(pathways_s))] |
|
67 | 72 |
if (!length(pathways_s)) { |
68 | 73 |
stop("Oops, no pathways left... try different filtering options.") |
69 | 74 |
} |
70 |
- message("Pathway file: ", basename(pathwayFile), |
|
75 |
+ message( |
|
76 |
+ "Pathway file: ", basename(pathwayFile), |
|
71 | 77 |
"\n => n total pathways: ", length(pathways), |
72 |
- "\n => n pathways (",minGene,"-",maxGene, "): ", length(pathways_s)) |
|
73 |
- |
|
78 |
+ "\n => n pathways (", minGene, "-", maxGene, "): ", length(pathways_s) |
|
79 |
+ ) |
|
74 | 80 |
return(pathways_s) |
75 | 81 |
} |
76 | 82 |
|
... | ... |
@@ -86,7 +92,7 @@ readPathways <- function(pathwayFile, header=FALSE, |
86 | 92 |
#' } |
87 | 93 |
#' @examples |
88 | 94 |
#' data(pathwaysXLSX) |
89 |
-#' writePathways(pathwaysXLSX, tempfile("pathwaysXLSX", fileext=".gmt")) |
|
95 |
+#' writePathways(pathwaysXLSX, tempfile("pathwaysXLSX", fileext = ".gmt")) |
|
90 | 96 |
#' @importFrom data.table fwrite |
91 | 97 |
#' @export |
92 | 98 |
writePathways <- function(pathways, gmtFile) { |
... | ... |
@@ -17,28 +17,28 @@ |
17 | 17 |
#' data(backgroundGene) |
18 | 18 |
#' data(pathwaysGMT) |
19 | 19 |
#' fedup_res <- runFedup(testGene, backgroundGene, pathwaysGMT) |
20 |
-#' fedup_plot <- fedup_res[which(fedup_res$qvalue < 0.05),] |
|
20 |
+#' fedup_plot <- fedup_res[which(fedup_res$qvalue < 0.05), ] |
|
21 | 21 |
#' fedup_plot$log10qvalue <- -log10(fedup_plot$qvalue + 1e-10) |
22 | 22 |
#' fedup_plot$pathway <- gsub("\\%.*", "", fedup_plot$pathway) |
23 | 23 |
#' plotDotPlot( |
24 |
-#' df=fedup_plot, |
|
25 |
-#' xVar="log10qvalue", |
|
26 |
-#' yVar="pathway", |
|
27 |
-#' xLab="-log10(Qvalue)", |
|
28 |
-#' fillVar="status", |
|
29 |
-#' fillLab="Enrichment\nstatus", |
|
30 |
-#' sizeVar="fold_enrichment", |
|
31 |
-#' sizeLab="Fold enrichment") |
|
24 |
+#' df = fedup_plot, |
|
25 |
+#' xVar = "log10qvalue", |
|
26 |
+#' yVar = "pathway", |
|
27 |
+#' xLab = "-log10(Qvalue)", |
|
28 |
+#' fillVar = "status", |
|
29 |
+#' fillLab = "Enrichment\nstatus", |
|
30 |
+#' sizeVar = "fold_enrichment", |
|
31 |
+#' sizeLab = "Fold enrichment" |
|
32 |
+#' ) |
|
32 | 33 |
#' @import ggplot2 |
33 | 34 |
#' @importFrom ggthemes theme_clean |
34 | 35 |
#' @importFrom forcats fct_reorder |
35 | 36 |
#' @importFrom RColorBrewer brewer.pal |
36 | 37 |
#' @export |
37 | 38 |
plotDotPlot <- function(df, xVar, yVar, |
38 |
- xLab=xVar, yLab=NULL, pTitle=NULL, |
|
39 |
- fillVar=NULL, fillCol=NULL, fillLab=fillVar, |
|
40 |
- sizeVar=NULL, sizeLab=sizeVar) { |
|
41 |
- |
|
39 |
+ xLab = xVar, yLab = NULL, pTitle = NULL, |
|
40 |
+ fillVar = NULL, fillCol = NULL, fillLab = fillVar, |
|
41 |
+ sizeVar = NULL, sizeLab = sizeVar) { |
|
42 | 42 |
if (!is.null(fillVar) && is.null(fillCol)) { |
43 | 43 |
fill_n <- length(unique(df[[fillVar]])) |
44 | 44 |
pal_n <- ifelse(fill_n >= 3, fill_n, 3) |
... | ... |
@@ -48,24 +48,30 @@ plotDotPlot <- function(df, xVar, yVar, |
48 | 48 |
if (fillVar == "status") { |
49 | 49 |
df[[fillVar]] <- factor( |
50 | 50 |
df[[fillVar]], |
51 |
- levels=c("Enriched", "Depleted")) |
|
51 |
+ levels = c("Enriched", "Depleted") |
|
52 |
+ ) |
|
52 | 53 |
} |
53 | 54 |
|
54 | 55 |
p <- ggplot(df, aes_string( |
55 |
- x=xVar, |
|
56 |
- y=fct_reorder(df[[yVar]], df[[xVar]]), |
|
57 |
- fill=fillVar, |
|
58 |
- size=sizeVar)) + |
|
59 |
- geom_point(shape=21, colour="black") + |
|
60 |
- labs(x=xLab, y=yLab, title=pTitle, |
|
61 |
- fill=fillLab, size=sizeLab) + |
|
62 |
- scale_fill_manual(values=fillCol) + |
|
63 |
- theme_clean(base_size=10) + |
|
64 |
- theme(plot.title=element_text(hjust=0.5), |
|
65 |
- legend.title=element_text(size=10), |
|
66 |
- legend.text=element_text(size=10), |
|
67 |
- legend.key.size=unit(0.1, "line"), |
|
68 |
- plot.background=element_blank()) |
|
56 |
+ x = xVar, |
|
57 |
+ y = fct_reorder(df[[yVar]], df[[xVar]]), |
|
58 |
+ fill = fillVar, |
|
59 |
+ size = sizeVar |
|
60 |
+ )) + |
|
61 |
+ geom_point(shape = 21, colour = "black") + |
|
62 |
+ labs( |
|
63 |
+ x = xLab, y = yLab, title = pTitle, |
|
64 |
+ fill = fillLab, size = sizeLab |
|
65 |
+ ) + |
|
66 |
+ scale_fill_manual(values = fillCol) + |
|
67 |
+ theme_clean(base_size = 10) + |
|
68 |
+ theme( |
|
69 |
+ plot.title = element_text(hjust = 0.5), |
|
70 |
+ legend.title = element_text(size = 10), |
|
71 |
+ legend.text = element_text(size = 10), |
|
72 |
+ legend.key.size = unit(0.1, "line"), |
|
73 |
+ plot.background = element_blank() |
|
74 |
+ ) |
|
69 | 75 |
|
70 | 76 |
# Increase x-axis limits to keep points in plot window |
71 | 77 |
if (is.numeric(df[[xVar]])) { |
... | ... |
@@ -3,10 +3,11 @@ library(tibble) |
3 | 3 |
|
4 | 4 |
pathway_file <- system.file("extdata", "SAFE_terms.txt", package = "FEDUP") |
5 | 5 |
pathwaysTXT <- readPathways( |
6 |
- pathway_file, |
|
7 |
- header = TRUE, |
|
8 |
- pathway_col = "Enriched.GO.names", |
|
9 |
- gene_col = "Gene.ID") |
|
6 |
+ pathway_file, |
|
7 |
+ header = TRUE, |
|
8 |
+ pathway_col = "Enriched.GO.names", |
|
9 |
+ gene_col = "Gene.ID" |
|
10 |
+) |
|
10 | 11 |
|
11 | 12 |
names(pathwaysTXT) <- stringi::stri_trans_general(names(pathwaysTXT), "latin-ascii") |
12 | 13 |
usethis::use_data(pathwaysTXT, compress = "xz", version = 2, overwrite = TRUE) |
... | ... |
@@ -4,10 +4,11 @@ library(tibble) |
4 | 4 |
|
5 | 5 |
pathway_file <- system.file("extdata", "SAFE_terms.xlsx", package = "FEDUP") |
6 | 6 |
pathwaysXLSX <- readPathways( |
7 |
- pathway_file, |
|
8 |
- header = TRUE, |
|
9 |
- pathway_col = "Enriched.GO.names", |
|
10 |
- gene_col = "Gene.ID") |
|
7 |
+ pathway_file, |
|
8 |
+ header = TRUE, |
|
9 |
+ pathway_col = "Enriched.GO.names", |
|
10 |
+ gene_col = "Gene.ID" |
|
11 |
+) |
|
11 | 12 |
|
12 | 13 |
names(pathwaysXLSX) <- stringi::stri_trans_general(names(pathwaysXLSX), "latin-ascii") |
13 | 14 |
usethis::use_data(pathwaysXLSX, compress = "xz", version = 2, overwrite = TRUE) |
... | ... |
@@ -52,16 +52,17 @@ data(testGene) |
52 | 52 |
data(backgroundGene) |
53 | 53 |
data(pathwaysGMT) |
54 | 54 |
fedup_res <- runFedup(testGene, backgroundGene, pathwaysGMT) |
55 |
-fedup_plot <- fedup_res[which(fedup_res$qvalue < 0.05),] |
|
55 |
+fedup_plot <- fedup_res[which(fedup_res$qvalue < 0.05), ] |
|
56 | 56 |
fedup_plot$log10qvalue <- -log10(fedup_plot$qvalue + 1e-10) |
57 | 57 |
fedup_plot$pathway <- gsub("\\\\\%.*", "", fedup_plot$pathway) |
58 | 58 |
plotDotPlot( |
59 |
- df=fedup_plot, |
|
60 |
- xVar="log10qvalue", |
|
61 |
- yVar="pathway", |
|
62 |
- xLab="-log10(Qvalue)", |
|
63 |
- fillVar="status", |
|
64 |
- fillLab="Enrichment\nstatus", |
|
65 |
- sizeVar="fold_enrichment", |
|
66 |
- sizeLab="Fold enrichment") |
|
59 |
+ df = fedup_plot, |
|
60 |
+ xVar = "log10qvalue", |
|
61 |
+ yVar = "pathway", |
|
62 |
+ xLab = "-log10(Qvalue)", |
|
63 |
+ fillVar = "status", |
|
64 |
+ fillLab = "Enrichment\nstatus", |
|
65 |
+ sizeVar = "fold_enrichment", |
|
66 |
+ sizeLab = "Fold enrichment" |
|
67 |
+) |
|
67 | 68 |
} |
... | ... |
@@ -41,20 +41,22 @@ pathways using EnrichmentMap (EM) in Cytoscape. |
41 | 41 |
} |
42 | 42 |
\examples{ |
43 | 43 |
\dontrun{ |
44 |
- # not run because Cytoscape needs to be installed and open |
|
45 |
- data(testGene) |
|
46 |
- data(backgroundGene) |
|
47 |
- data(pathwaysGMT) |
|
48 |
- gmtFile <- tempfile("pathwaysGMT", fileext=".gmt") |
|
49 |
- fedupRes <- runFedup(testGene, backgroundGene, pathwaysGMT) |
|
50 |
- resultsFile <- tempfile("fedupRes", fileext=".txt") |
|
51 |
- netFile <- tempfile("FEDUP_EM", fileext=".png") |
|
52 |
- writePathways(pathwaysGMT, gmtFile) |
|
53 |
- writeFemap(fedupRes, resultsFile) |
|
54 |
- plotFemap( |
|
55 |
- gmtFile=gmtFile, |
|
56 |
- resultsFile=resultsFile, |
|
57 |
- qvalue=0.05, |
|
58 |
- netName="FEDUP_EM", |
|
59 |
- netFile=netFile)} |
|
44 |
+# not run because Cytoscape needs to be installed and open |
|
45 |
+data(testGene) |
|
46 |
+data(backgroundGene) |
|
47 |
+data(pathwaysGMT) |
|
48 |
+gmtFile <- tempfile("pathwaysGMT", fileext = ".gmt") |
|
49 |
+fedupRes <- runFedup(testGene, backgroundGene, pathwaysGMT) |
|
50 |
+resultsFile <- tempfile("fedupRes", fileext = ".txt") |
|
51 |
+netFile <- tempfile("FEDUP_EM", fileext = ".png") |
|
52 |
+writePathways(pathwaysGMT, gmtFile) |
|
53 |
+writeFemap(fedupRes, resultsFile) |
|
54 |
+plotFemap( |
|
55 |
+ gmtFile = gmtFile, |
|
56 |
+ resultsFile = resultsFile, |
|
57 |
+ qvalue = 0.05, |
|
58 |
+ netName = "FEDUP_EM", |
|
59 |
+ netFile = netFile |
|
60 |
+) |
|
61 |
+} |
|
60 | 62 |
} |
... | ... |
@@ -42,8 +42,12 @@ Currently supports the following file format: gmt, txt, xlsx. |
42 | 42 |
\examples{ |
43 | 43 |
pathways <- readPathways( |
44 | 44 |
system.file("extdata", "Human_Reactome_November_17_2020_symbol.gmt", |
45 |
- package="FEDUP"), minGene=10, maxGene=500) |
|
45 |
+ package = "FEDUP" |
|
46 |
+ ), |
|
47 |
+ minGene = 10, maxGene = 500 |
|
48 |
+) |
|
46 | 49 |
pathways <- readPathways( |
47 |
- system.file("extdata", "SAFE_terms.xlsx", package="FEDUP"), |
|
48 |
- header=TRUE, pathwayCol="Enriched.GO.names", geneCol="Gene.ID") |
|
50 |
+ system.file("extdata", "SAFE_terms.xlsx", package = "FEDUP"), |
|
51 |
+ header = TRUE, pathwayCol = "Enriched.GO.names", geneCol = "Gene.ID" |
|
52 |
+) |
|
49 | 53 |
} |
... | ... |
@@ -33,6 +33,6 @@ data(testGene) |
33 | 33 |
data(backgroundGene) |
34 | 34 |
data(pathwaysGMT) |
35 | 35 |
fedupRes <- runFedup(testGene, backgroundGene, pathwaysGMT) |
36 |
-resultsFile <- tempfile("fedupRes", fileext=".txt") |
|
36 |
+resultsFile <- tempfile("fedupRes", fileext = ".txt") |
|
37 | 37 |
writeFemap(fedupRes, resultsFile) |
38 | 38 |
} |
... | ... |
@@ -1,16 +1,16 @@ |
1 | 1 |
context("Enrichment map") |
2 | 2 |
|
3 | 3 |
test_that("Test that writeFemap works", { |
4 |
- data(testGene) |
|
5 |
- data(backgroundGene) |
|
6 |
- data(pathwaysGMT) |
|
7 |
- fedupRes <- runFedup(testGene, backgroundGene, pathwaysGMT) |
|
8 |
- resultsFile <- tempfile("fedupRes", fileext=".txt") |
|
9 |
- writeFemap(fedupRes, resultsFile) |
|
10 |
- femapRes <- read.delim(resultsFile) |
|
4 |
+ data(testGene) |
|
5 |
+ data(backgroundGene) |
|
6 |
+ data(pathwaysGMT) |
|
7 |
+ fedupRes <- runFedup(testGene, backgroundGene, pathwaysGMT) |
|
8 |
+ resultsFile <- tempfile("fedupRes", fileext = ".txt") |
|
9 |
+ writeFemap(fedupRes, resultsFile) |
|
10 |
+ femapRes <- read.delim(resultsFile) |
|
11 | 11 |
|
12 |
- expect_equal(nrow(fedupRes), nrow(femapRes)) |
|
13 |
- expect_true("status" %in% colnames(femapRes)) |
|
14 |
- expect_true(fedupRes[1,"status"] == "Enriched" && femapRes[1,"status"] == 1) |
|
15 |
- expect_true(fedupRes[1436,"status"] == "Depleted" && femapRes[1436,"status"] == -1) |
|
12 |
+ expect_equal(nrow(fedupRes), nrow(femapRes)) |
|
13 |
+ expect_true("status" %in% colnames(femapRes)) |
|
14 |
+ expect_true(fedupRes[1, "status"] == "Enriched" && femapRes[1, "status"] == 1) |
|
15 |
+ expect_true(fedupRes[1436, "status"] == "Depleted" && femapRes[1436, "status"] == -1) |
|
16 | 16 |
}) |
... | ... |
@@ -14,20 +14,20 @@ test_that("Test that FEDUP stops without proper inputs", { |
14 | 14 |
}) |
15 | 15 |
|
16 | 16 |
test_that("Test that FEDUP analysis works", { |
17 |
- data(testGene) |
|
18 |
- data(backgroundGene) |
|
19 |
- data(pathwaysGMT) |
|
17 |
+ data(testGene) |
|
18 |
+ data(backgroundGene) |
|
19 |
+ data(pathwaysGMT) |
|
20 | 20 |
|
21 |
- expect_false(length(testGene) > length(backgroundGene)) |
|
22 |
- expect_true(is.list(pathwaysGMT)) |
|
21 |
+ expect_false(length(testGene) > length(backgroundGene)) |
|
22 |
+ expect_true(is.list(pathwaysGMT)) |
|
23 | 23 |
|
24 |
- fedupRes <- runFedup(testGene, backgroundGene, pathwaysGMT) |
|
25 |
- expect_equal(fedupRes[1, real_frac], 100.00000) |
|
26 |
- expect_equal(fedupRes[1, qvalue], 1.567426e-186) |
|
27 |
- expect_true("NKX2-5" %in% fedupRes[,real_gene][[1]]) |
|
28 |
- expect_true(!"OR11A1" %in% fedupRes[,real_gene][[1]]) |
|
29 |
- expect_equal(fedupRes[1437, real_frac], 0.0000000) |
|
30 |
- expect_equal(fedupRes[1437, qvalue], 1.000000e+00) |
|
31 |
- expect_false("NKX2-5" %in% fedupRes[,real_gene][[1437]]) |
|
32 |
- expect_true(!"OR11A1" %in% fedupRes[,real_gene][[1437]]) |
|
24 |
+ fedupRes <- runFedup(testGene, backgroundGene, pathwaysGMT) |
|
25 |
+ expect_equal(fedupRes[1, real_frac], 100.00000) |
|
26 |
+ expect_equal(fedupRes[1, qvalue], 1.567426e-186) |
|
27 |
+ expect_true("NKX2-5" %in% fedupRes[, real_gene][[1]]) |
|
28 |
+ expect_true(!"OR11A1" %in% fedupRes[, real_gene][[1]]) |
|
29 |
+ expect_equal(fedupRes[1437, real_frac], 0.0000000) |
|
30 |
+ expect_equal(fedupRes[1437, qvalue], 1.000000e+00) |
|
31 |
+ expect_false("NKX2-5" %in% fedupRes[, real_gene][[1437]]) |
|
32 |
+ expect_true(!"OR11A1" %in% fedupRes[, real_gene][[1437]]) |
|
33 | 33 |
}) |
... | ... |
@@ -4,65 +4,72 @@ test_that("Test that readPathways stops without proper inputs", { |
4 | 4 |
expect_error(readPathways("test.123.xls")) |
5 | 5 |
expect_error(readPathways("test.gmt.123")) |
6 | 6 |
|
7 |
- pathwayFile <- system.file("extdata", "SAFE_terms.xlsx", package="FEDUP") |
|
7 |
+ pathwayFile <- system.file("extdata", "SAFE_terms.xlsx", package = "FEDUP") |
|
8 | 8 |
expect_error(readPathways( |
9 |
- pathwayFile, header=TRUE, |
|
10 |
- pathwayCol="Enriched.GO.names", geneCol="oops")) |
|
9 |
+ pathwayFile, |
|
10 |
+ header = TRUE, |
|
11 |
+ pathwayCol = "Enriched.GO.names", geneCol = "oops" |
|
12 |
+ )) |
|
11 | 13 |
expect_error(readPathways( |
12 |
- pathwayFile, header=TRUE, |
|
13 |
- pathwayCol="oops", geneCol="Gene.ID")) |
|
14 |
+ pathwayFile, |
|
15 |
+ header = TRUE, |
|
16 |
+ pathwayCol = "oops", geneCol = "Gene.ID" |
|
17 |
+ )) |
|
14 | 18 |
expect_error(readPathways( |
15 |
- pathwayFile, header=TRUE, minGene=500, |
|
16 |
- pathwayCol="Enriched.GO.names", geneCol="Gene.ID")) |
|
19 |
+ pathwayFile, |
|
20 |
+ header = TRUE, minGene = 500, |
|
21 |
+ pathwayCol = "Enriched.GO.names", geneCol = "Gene.ID" |
|
22 |
+ )) |
|
17 | 23 |
}) |
18 | 24 |
|
19 | 25 |
test_that("Test that readPathways works with GMT input", { |
20 |
- pathwayFile <- system.file("extdata", "Human_Reactome_November_17_2020_symbol.gmt", package="FEDUP") |
|
26 |
+ pathwayFile <- system.file("extdata", "Human_Reactome_November_17_2020_symbol.gmt", package = "FEDUP") |
|
21 | 27 |
s <- c("gmt", "txt", "xlsx") |
22 | 28 |
f <- sub(".*\\.", "", pathwayFile) |
23 | 29 |
expect_true(f %in% s) |
24 | 30 |
|
25 |
- pathways <- readPathways(pathwayFile, minGene=10, maxGene=500) |
|
31 |
+ pathways <- readPathways(pathwayFile, minGene = 10, maxGene = 500) |
|
26 | 32 |
expect_true(is.list(pathways)) |
27 | 33 |
expect_equal(length(pathways), 1437) |
28 |
- expect_false(any(duplicated(names(pathways)))) |
|
29 |
- expect_equal(length(readPathways(pathwayFile, minGene=10, maxGene=500, header=TRUE)), 1436) |
|
34 |
+ expect_equal(length(readPathways(pathwayFile, minGene = 10, maxGene = 500, header = TRUE)), 1436) |
|
30 | 35 |
}) |
31 | 36 |
|
32 | 37 |
test_that("Test that readPathways works with XLSX input", { |
33 |
- pathwayFile <- system.file("extdata", "SAFE_terms.xlsx", package="FEDUP") |
|
38 |
+ pathwayFile <- system.file("extdata", "SAFE_terms.xlsx", package = "FEDUP") |
|
34 | 39 |
s <- c("gmt", "txt", "xlsx") |
35 | 40 |
f <- sub(".*\\.", "", pathwayFile) |
36 | 41 |
expect_true(f %in% s) |
37 | 42 |
|
38 | 43 |
pathways <- readPathways( |
39 |
- pathwayFile, header=TRUE, |
|
40 |
- pathwayCol="Enriched.GO.names", geneCol="Gene.ID") |
|
44 |
+ pathwayFile, |
|
45 |
+ header = TRUE, |
|
46 |
+ pathwayCol = "Enriched.GO.names", geneCol = "Gene.ID" |
|
47 |
+ ) |
|
41 | 48 |
expect_true(is.list(pathways)) |
42 | 49 |
expect_equal(length(pathways), 30) |
43 |
- expect_false(any(duplicated(names(pathways)))) |
|
44 | 50 |
}) |
45 | 51 |
|
46 | 52 |
test_that("Test that readPathways works with TXT input", { |
47 |
- pathwayFile <- system.file("extdata", "SAFE_terms.txt", package="FEDUP") |
|
53 |
+ pathwayFile <- system.file("extdata", "SAFE_terms.txt", package = "FEDUP") |
|
48 | 54 |
s <- c("gmt", "txt", "xlsx") |
49 | 55 |
f <- sub(".*\\.", "", pathwayFile) |
50 | 56 |
expect_true(f %in% s) |
51 | 57 |
|
52 | 58 |
pathways <- readPathways( |
53 |
- pathwayFile, header=TRUE, |
|
54 |
- pathwayCol="Enriched.GO.names", geneCol="Gene.ID") |
|
59 |
+ pathwayFile, |
|
60 |
+ header = TRUE, |
|
61 |
+ pathwayCol = "Enriched.GO.names", geneCol = "Gene.ID" |
|
62 |
+ ) |
|
55 | 63 |
expect_true(is.list(pathways)) |
56 | 64 |
expect_equal(length(pathways), 30) |
57 |
- expect_false(any(duplicated(names(pathways)))) |
|
58 | 65 |
}) |
59 | 66 |
|
60 | 67 |
test_that("Test that writePathways works", { |
61 | 68 |
data(pathwaysXLSX) |
62 |
- gmtFile <- tempfile("pathwaysXLSX", fileext=".gmt") |
|
69 |
+ gmtFile <- tempfile("pathwaysXLSX", fileext = ".gmt") |
|
63 | 70 |
|
64 | 71 |
writePathways(pathwaysXLSX, gmtFile) |
65 |
- pathways <- readPathways(gmtFile, header=FALSE) |
|
72 |
+ pathways <- readPathways(gmtFile, header = FALSE) |
|
66 | 73 |
|
67 | 74 |
expect_equal(length(pathwaysXLSX), length(pathways)) |
68 | 75 |
expect_true(is.list(pathways)) |
... | ... |
@@ -1,25 +1,27 @@ |
1 | 1 |
context("Enrichment dotplot") |
2 | 2 |
|
3 | 3 |
test_that("Test that plotDotPlot works", { |
4 |
- data(testGene) |
|
5 |
- data(backgroundGene) |
|
6 |
- data(pathwaysGMT) |
|
7 |
- fedupRes <- runFedup(testGene, backgroundGene, pathwaysGMT) |
|
8 |
- fedupEnr <- head(fedupRes[with(fedupRes, which(status == "Enriched")),], 10) |
|
9 |
- fedupDep <- head(fedupRes[with(fedupRes, which(status == "Depleted")),], 10) |
|
10 |
- fedupPlot <- rbind(fedupEnr, fedupDep) |
|
11 |
- fedupPlot$log10fdr <- -log10(fedupPlot$fdr + 1e-10) # log10-transform FDR for plotting |
|
12 |
- fedupPlot$pathway <- gsub("\\%.*", "", fedupPlot$pathway) # clean pathway names |
|
13 |
- temp <- tempfile("plot", fileext=".png") |
|
14 |
- png(filename=temp, width=2750, height=1600, res=300) |
|
15 |
- plotDotPlot(df=fedupPlot, |
|
16 |
- xVar="log10fdr", |
|
17 |
- yVar="pathway", |
|
18 |
- xLab="-log10(FDR)", |
|
19 |
- fillVar="status", |
|
20 |
- fillLab="Enrichment status", |
|
21 |
- sizeVar="fold_enrichment", |
|
22 |
- sizeLab="Fold enrichment") |
|
23 |
- dev.off() |
|
24 |
- expect_true(TRUE) |
|
4 |
+ data(testGene) |
|
5 |
+ data(backgroundGene) |
|
6 |
+ data(pathwaysGMT) |
|
7 |
+ fedupRes <- runFedup(testGene, backgroundGene, pathwaysGMT) |
|
8 |
+ fedupEnr <- head(fedupRes[with(fedupRes, which(status == "Enriched")), ], 10) |
|
9 |
+ fedupDep <- head(fedupRes[with(fedupRes, which(status == "Depleted")), ], 10) |
|
10 |
+ fedupPlot <- rbind(fedupEnr, fedupDep) |
|
11 |
+ fedupPlot$log10fdr <- -log10(fedupPlot$fdr + 1e-10) # log10-transform FDR for plotting |
|
12 |
+ fedupPlot$pathway <- gsub("\\%.*", "", fedupPlot$pathway) # clean pathway names |
|
13 |
+ temp <- tempfile("plot", fileext = ".png") |
|
14 |
+ png(filename = temp, width = 2750, height = 1600, res = 300) |
|
15 |
+ plotDotPlot( |
|
16 |
+ df = fedupPlot, |
|
17 |
+ xVar = "log10fdr", |
|
18 |
+ yVar = "pathway", |
|
19 |
+ xLab = "-log10(FDR)", |
|
20 |
+ fillVar = "status", |
|
21 |
+ fillLab = "Enrichment status", |
|
22 |
+ sizeVar = "fold_enrichment", |
|
23 |
+ sizeLab = "Fold enrichment" |
|
24 |
+ ) |
|
25 |
+ dev.off() |
|
26 |
+ expect_true(TRUE) |
|
25 | 27 |
}) |