Browse code

add DD table functions

From: vandersm <vandersm@mail.uc.edu>

git-svn-id: file:///home/git/hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/KEGGlincs@126853 bc3139a8-67e5-0310-9ffc-ced21a209358

Shana White authored on 21/02/2017 18:16:40
Showing 2 changed files

1 1
new file mode 100644
... ...
@@ -0,0 +1,54 @@
1
+#' Import disease/drug tables from KEGG 
2
+#' @description Get data tables for disease/drug information associated with 
3
+#' selected pathway
4
+#' @param pathwayid A KEGG pathway ID of the form "hsa12345" 
5
+#' (only human pathways currently)
6
+#' @return A data.frame object with either disease or drug information
7
+#' @export
8
+#' @examples
9
+#' RA_drug_table <- get_drug_table("hsa05323")
10
+
11
+get_drug_table <- function(pathwayid){
12
+    
13
+    url <- paste0("http://www.kegg.jp/kegg-bin/pathway_dd_list?map=",
14
+                  pathwayid)
15
+    dd_table <- data.frame(
16
+                XML::readHTMLTable(url, header = T, which = 4, as.data.frame = FALSE), 
17
+                stringsAsFactors = FALSE)
18
+    if (nrow(dd_table) > 0){
19
+        d_table <- subset(dd_table, substring(dd_table$Disease.drug, 1, 1) == "D")
20
+        if(nrow(d_table) == 0){
21
+            warning("No associated drug targets in selected pathway")
22
+            return()
23
+        }
24
+        return(d_table)
25
+    }
26
+    else {
27
+        warning("No drugs or diseases associated with selected pathway")
28
+        return()
29
+    }
30
+}
31
+#' @rdname get_drug_table 
32
+get_disease_table <- function(pathwayid){
33
+    
34
+    url <- paste0("http://www.kegg.jp/kegg-bin/pathway_dd_list?map=",
35
+                  pathwayid)
36
+    dd_table <- data.frame(
37
+        XML::readHTMLTable(url, header = T, which = 4, as.data.frame = FALSE), 
38
+        stringsAsFactors = FALSE)
39
+    if (nrow(dd_table) > 0){
40
+        d_table <- subset(dd_table, substring(dd_table$Disease.drug, 1, 1) == "H")
41
+        if(nrow(d_table) == 0){
42
+            warning("No diseases associated with selected pathway")
43
+            return()
44
+        }
45
+        return(d_table)
46
+    }
47
+    else {
48
+        warning("No drugs or diseases associated with selected pathway")
49
+        return()
50
+    }
51
+}
52
+
53
+#' @examples
54
+#' RA_disease_table <- get_disease_table("hsa05323")
0 55
new file mode 100644
... ...
@@ -0,0 +1,26 @@
1
+% Generated by roxygen2: do not edit by hand
2
+% Please edit documentation in R/get_dd_tables.R
3
+\name{get_drug_table}
4
+\alias{get_disease_table}
5
+\alias{get_drug_table}
6
+\title{Import disease/drug tables from KEGG}
7
+\usage{
8
+get_drug_table(pathwayid)
9
+
10
+get_disease_table(pathwayid)
11
+}
12
+\arguments{
13
+\item{pathwayid}{A KEGG pathway ID of the form "hsa12345" 
14
+(only human pathways currently)}
15
+}
16
+\value{
17
+A data.frame object with either disease or drug information
18
+}
19
+\description{
20
+Get data tables for disease/drug information associated with 
21
+selected pathway
22
+}
23
+\examples{
24
+RA_drug_table <- get_drug_table("hsa05323")
25
+}
26
+