Browse code

Update epiMap.R

xiaowen chen authored on 21/10/2020 00:10:01 • GitHub committed on 21/10/2020 00:10:01
Showing1 changed files
... ...
@@ -79,10 +79,10 @@ epiMap <- function(compare.matrix, value, annotate,
79 79
     loci.percent = 0.1, show.rows = FALSE, show.columns = FALSE,
80 80
     font.size = 6, pdf.height = 10, pdf.width = 10,
81 81
     sve = FALSE, ...) {
82
-    values = c("read", "pdr", "meth", "epipoly", "shannon")
82
+    values = c("read", "pdr", "meth", "epipoly", "shannon", "myValues")
83 83
     if (!(value %in% values)) {
84 84
         stop("Invalid value '", value, "': Possible values are 'read',
85
-           'pdr', 'meth', 'epipoly', or 'shannon'")
85
+           'pdr', 'meth', 'epipoly', 'myValues' or 'shannon'")
86 86
     }
87 87
     value.matrix <- compare.matrix[compare.matrix$type == value,
88 88
         -(length(compare.matrix) - 1)]
Browse code

modifyMA, check OK. modify epiNetwork, epiPathwayno check

Mingsheng Zhang authored on 30/11/2018 23:03:44
Showing1 changed files
... ...
@@ -59,7 +59,7 @@
59 59
 #' 3),stringsAsFactors =FALSE )
60 60
 #'
61 61
 #' subtype <- data.frame(Type= c(rep('CEBPA_sil', 3), rep('Normal', 3)),
62
-#' row.names <- colnames(comp.Matrix)[1:6],stringsAsFactors = FALSE)
62
+#' row.names = colnames(comp.Matrix)[1:6],stringsAsFactors = FALSE)
63 63
 #'
64 64
 #' pmap <- epiMap(compare.matrix = comp.Matrix,
65 65
 #' value = 'epipoly',annotate = subtype,
Browse code

modify compMatrix, DiffHet, epiBox, epiMap. reverse DESCRIPTION, NAMESPACE

Mingsheng Zhang authored on 30/11/2018 21:05:51
Showing1 changed files
... ...
@@ -42,7 +42,7 @@
42 42
 #' @return A pheatmap object that contains the tree data for
43 43
 #' both rows and columns and the final pheatmap plot
44 44
 #' @examples
45
-#' comp.Matrix=data.frame(
45
+#' comp.Matrix<-data.frame(
46 46
 #' p1=c(0.6,0.3,0.5,0.5,0.5,0.6,0.45,0.57,0.45,0.63,0.58,0.67,0.5,0.42,0.67),
47 47
 #' p2=c(0.62,0.63,0.55,0.75,0.84,0.58,1,0.33,1,0.97,0.57,0.68,0.73,0.72,0.82),
48 48
 #' p3=c(0.72,0.53,0.62,0.69,0.37,0.85,1,0.63,0.87,0.87,0.82,0.81,0.79,
... ...
@@ -58,10 +58,10 @@
58 58
 #' "chr22-761:771:773:781","chr22-821:837:844:849","chr22-838:845:850:858"),
59 59
 #' 3),stringsAsFactors =FALSE )
60 60
 #'
61
-#' subtype = data.frame(Type= c(rep('CEBPA_sil', 3), rep('Normal', 3)),
62
-#' row.names = colnames(comp.Matrix)[1:6],stringsAsFactors = FALSE)
61
+#' subtype <- data.frame(Type= c(rep('CEBPA_sil', 3), rep('Normal', 3)),
62
+#' row.names <- colnames(comp.Matrix)[1:6],stringsAsFactors = FALSE)
63 63
 #'
64
-#' pmap = epiMap(compare.matrix = comp.Matrix,
64
+#' pmap <- epiMap(compare.matrix = comp.Matrix,
65 65
 #' value = 'epipoly',annotate = subtype,
66 66
 #' clustering_distance_rows = "euclidean",
67 67
 #' clustering_distance_cols = "euclidean",
... ...
@@ -71,7 +71,7 @@
71 71
 #' show.columns = TRUE, font.size = 15,
72 72
 #' pdf.height = 10, pdf.width = 10, sve = TRUE)
73 73
 #' @export
74
-epiMap = function(compare.matrix, value, annotate,
74
+epiMap <- function(compare.matrix, value, annotate,
75 75
     clustering_distance_rows = "euclidean",
76 76
     clustering_distance_cols = "euclidean",
77 77
     clustering_method = "complete", annotate.colors = NA,
... ...
@@ -84,19 +84,18 @@ epiMap = function(compare.matrix, value, annotate,
84 84
         stop("Invalid value '", value, "': Possible values are 'read',
85 85
            'pdr', 'meth', 'epipoly', or 'shannon'")
86 86
     }
87
-    stopifnot(is(annotate,"data.frame"))
88
-    value.matrix = compare.matrix[compare.matrix$type == value,
87
+    value.matrix <- compare.matrix[compare.matrix$type == value,
89 88
         -(length(compare.matrix) - 1)]
90
-    rownames(value.matrix) = value.matrix$location
91
-    value.matrix = value.matrix[, -length(value.matrix)]
89
+    rownames(value.matrix) <- value.matrix$location
90
+    value.matrix <- value.matrix[, -length(value.matrix)]
92 91
     value.matrix$sd = apply(value.matrix, 1, sd, na.rm = TRUE)
93
-    value.matrix = value.matrix[order(-value.matrix$sd), ]
94
-    value.matrix = value.matrix[, -length(value.matrix)]
95
-    loci.number = floor(loci.percent * nrow(value.matrix))
96
-    title = paste0("Top ", loci.percent * 100, "% of ", value, " values")
97
-    matrix = value.matrix[seq_len(loci.number), ]
92
+    value.matrix <- value.matrix[order(-value.matrix$sd), ]
93
+    value.matrix <- value.matrix[, -length(value.matrix)]
94
+    loci.number <- floor(loci.percent * nrow(value.matrix))
95
+    title <- paste0("Top ", loci.percent * 100, "% of ", value, " values")
96
+    matrix <- value.matrix[seq_len(loci.number), ]
98 97
     if (sve) {
99
-        pmap = pheatmap::pheatmap(matrix, show_rownames = show.rows,
98
+        pmap <- pheatmap::pheatmap(matrix, show_rownames = show.rows,
100 99
             show_colnames = show.columns, color = color,
101 100
             clustering_distance_rows = clustering_distance_rows,
102 101
             clustering_distance_cols = clustering_distance_cols,
... ...
@@ -106,7 +105,7 @@ epiMap = function(compare.matrix, value, annotate,
106 105
             width = pdf.width, main = title,
107 106
                 filename = paste0(value, "_pheatmap.pdf"), ...)
108 107
     } else {
109
-        pmap = pheatmap::pheatmap(matrix, show_rownames = show.rows,
108
+        pmap <- pheatmap::pheatmap(matrix, show_rownames = show.rows,
110 109
             show_colnames = show.columns, color = color,
111 110
             clustering_distance_rows = clustering_distance_rows,
112 111
             clustering_distance_cols = clustering_distance_cols,
Browse code

change package name from EpiHet to epihet

Mingsheng Zhang authored on 20/11/2018 14:14:36
Showing1 changed files
... ...
@@ -61,7 +61,7 @@
61 61
 #' subtype = data.frame(Type= c(rep('CEBPA_sil', 3), rep('Normal', 3)),
62 62
 #' row.names = colnames(comp.Matrix)[1:6],stringsAsFactors = FALSE)
63 63
 #'
64
-#' pmap = epihet::epiMap(compare.matrix = comp.Matrix,
64
+#' pmap = epiMap(compare.matrix = comp.Matrix,
65 65
 #' value = 'epipoly',annotate = subtype,
66 66
 #' clustering_distance_rows = "euclidean",
67 67
 #' clustering_distance_cols = "euclidean",
Browse code

checked R/*.R 10X, NAMESPACE

Mingsheng Zhang authored on 20/11/2018 01:37:18
Showing1 changed files
... ...
@@ -71,7 +71,7 @@
71 71
 #' show.columns = TRUE, font.size = 15,
72 72
 #' pdf.height = 10, pdf.width = 10, sve = TRUE)
73 73
 #' @export
74
-epiMap = function(compare.matrix, value, annotate = NULL,
74
+epiMap = function(compare.matrix, value, annotate,
75 75
     clustering_distance_rows = "euclidean",
76 76
     clustering_distance_cols = "euclidean",
77 77
     clustering_method = "complete", annotate.colors = NA,
... ...
@@ -84,6 +84,7 @@ epiMap = function(compare.matrix, value, annotate = NULL,
84 84
         stop("Invalid value '", value, "': Possible values are 'read',
85 85
            'pdr', 'meth', 'epipoly', or 'shannon'")
86 86
     }
87
+    stopifnot(is(annotate,"data.frame"))
87 88
     value.matrix = compare.matrix[compare.matrix$type == value,
88 89
         -(length(compare.matrix) - 1)]
89 90
     rownames(value.matrix) = value.matrix$location
... ...
@@ -93,7 +94,7 @@ epiMap = function(compare.matrix, value, annotate = NULL,
93 94
     value.matrix = value.matrix[, -length(value.matrix)]
94 95
     loci.number = floor(loci.percent * nrow(value.matrix))
95 96
     title = paste0("Top ", loci.percent * 100, "% of ", value, " values")
96
-    matrix = value.matrix[1:loci.number, ]
97
+    matrix = value.matrix[seq_len(loci.number), ]
97 98
     if (sve) {
98 99
         pmap = pheatmap::pheatmap(matrix, show_rownames = show.rows,
99 100
             show_colnames = show.columns, color = color,
Browse code

First commit

Haitham Ashoor authored on 23/04/2018 17:08:09
Showing1 changed files
1 1
new file mode 100755
... ...
@@ -0,0 +1,117 @@
1
+#' @title Make Pheatmap from Comparison Matrix
2
+#' @description
3
+#' Creates a pheatmap for the top 'loci.percent' of values
4
+#' of max standard deviation from the comparison matrix
5
+#' generated by compMatrix(). The rows represent the loci
6
+#' of the epiallele and the columns represent the sample
7
+#' names. The columns can be annotated by adding annotation
8
+#' information as a parameter.
9
+#' @param compare.matrix The comparison matrix generated from
10
+#' the compMatrix() function
11
+#' @param value The value to be graphed in the pheatmap.
12
+#' Possible values are 'read', 'pdr', 'meth', 'epipoly',
13
+#' and 'shannon'.
14
+#' @param annotate A dataframe containing the annotation information
15
+#' for the columns of the pheatmap. The row names must be the names
16
+#' of the samples. The columns (any number) are the annotations. E.g. a column
17
+#' called 'TET2' with factors 'Pos' and 'Neg' for each sample that
18
+#' is positive or negative for the TET2 gene
19
+#' @param clustering_distance_rows Distance measure used in clustering rows.
20
+#' @param clustering_distance_cols Distance measure used in clustering columns.
21
+#' @param clustering_method clustering method used.
22
+#' @param annotate.colors A list containing the colors for the
23
+#' annotation information. Each element in the list is a vector
24
+#' of colors with names that correspond to the columns of 'annotate'.
25
+#' @param color a vector of colors used in heatmap.
26
+#' @param loci.percent The top percentage of loci, as a decimal,
27
+#' to be displayed on the pheatmap based on standard deviation,
28
+#' e.g. a value of 0.20 is equivalent to the top 20\% of loci
29
+#' (default: 0.10)
30
+#' @param show.rows A boolean stating if the row names should be
31
+#' displayed on the pheatmap (default: FALSE)
32
+#' @param show.columns A boolean stating if the column names should
33
+#' be displayed on the pheatmap (default: FALSE)
34
+#' @param font.size An integer representing the font size to be used
35
+#' for the pheatmap labels (default: 6)
36
+#' @param pdf.height An integer representing the height (in inches)
37
+#' of the pdf file for the pheatmap (default: 10)
38
+#' @param pdf.width An integer representing the width (in inches)
39
+#' of the pdf file for the pheatmap (default: 10)
40
+#' @param sve A boolean to save the plot (default: FALSE)
41
+#' @param ... any arguments in the function pheatmap()
42
+#' @return A pheatmap object that contains the tree data for
43
+#' both rows and columns and the final pheatmap plot
44
+#' @examples
45
+#' comp.Matrix=data.frame(
46
+#' p1=c(0.6,0.3,0.5,0.5,0.5,0.6,0.45,0.57,0.45,0.63,0.58,0.67,0.5,0.42,0.67),
47
+#' p2=c(0.62,0.63,0.55,0.75,0.84,0.58,1,0.33,1,0.97,0.57,0.68,0.73,0.72,0.82),
48
+#' p3=c(0.72,0.53,0.62,0.69,0.37,0.85,1,0.63,0.87,0.87,0.82,0.81,0.79,
49
+#' 0.62,0.68),
50
+#' N1=c(0.15,0.24,0.15,0.26,0.34,0.32,0.23,0.14,0.26,0.32,0.12,0.16,0.31,
51
+#' 0.24,0.32),
52
+#' N2=c(0.32,0.26,0.16,0.36,0.25,0.37,0.12,0.16,0.41,0.47,0.13,0.52,0.42,
53
+#' 0.41,0.23),
54
+#' N3=c(0.21,0.16,0.32,0.16,0.36,0.27,0.24,0.26,0.11,0.27,0.39,0.5,0.4,
55
+#' 0.31,0.33),
56
+#' type=rep(c("pdr","epipoly","shannon"),c(5,5,5)),
57
+#' location=rep(c("chr22-327:350:361:364","chr22-755:761:771:773",
58
+#' "chr22-761:771:773:781","chr22-821:837:844:849","chr22-838:845:850:858"),
59
+#' 3),stringsAsFactors =FALSE )
60
+#'
61
+#' subtype = data.frame(Type= c(rep('CEBPA_sil', 3), rep('Normal', 3)),
62
+#' row.names = colnames(comp.Matrix)[1:6],stringsAsFactors = FALSE)
63
+#'
64
+#' pmap = epihet::epiMap(compare.matrix = comp.Matrix,
65
+#' value = 'epipoly',annotate = subtype,
66
+#' clustering_distance_rows = "euclidean",
67
+#' clustering_distance_cols = "euclidean",
68
+#' clustering_method = "complete",annotate.colors = NA,
69
+#' color= colorRampPalette(c("blue","white","red"))(1000),
70
+#' loci.percent = 1, show.rows = FALSE,
71
+#' show.columns = TRUE, font.size = 15,
72
+#' pdf.height = 10, pdf.width = 10, sve = TRUE)
73
+#' @export
74
+epiMap = function(compare.matrix, value, annotate = NULL,
75
+    clustering_distance_rows = "euclidean",
76
+    clustering_distance_cols = "euclidean",
77
+    clustering_method = "complete", annotate.colors = NA,
78
+    color = colorRampPalette(c("blue", "white", "red"))(1000),
79
+    loci.percent = 0.1, show.rows = FALSE, show.columns = FALSE,
80
+    font.size = 6, pdf.height = 10, pdf.width = 10,
81
+    sve = FALSE, ...) {
82
+    values = c("read", "pdr", "meth", "epipoly", "shannon")
83
+    if (!(value %in% values)) {
84
+        stop("Invalid value '", value, "': Possible values are 'read',
85
+           'pdr', 'meth', 'epipoly', or 'shannon'")
86
+    }
87
+    value.matrix = compare.matrix[compare.matrix$type == value,
88
+        -(length(compare.matrix) - 1)]
89
+    rownames(value.matrix) = value.matrix$location
90
+    value.matrix = value.matrix[, -length(value.matrix)]
91
+    value.matrix$sd = apply(value.matrix, 1, sd, na.rm = TRUE)
92
+    value.matrix = value.matrix[order(-value.matrix$sd), ]
93
+    value.matrix = value.matrix[, -length(value.matrix)]
94
+    loci.number = floor(loci.percent * nrow(value.matrix))
95
+    title = paste0("Top ", loci.percent * 100, "% of ", value, " values")
96
+    matrix = value.matrix[1:loci.number, ]
97
+    if (sve) {
98
+        pmap = pheatmap::pheatmap(matrix, show_rownames = show.rows,
99
+            show_colnames = show.columns, color = color,
100
+            clustering_distance_rows = clustering_distance_rows,
101
+            clustering_distance_cols = clustering_distance_cols,
102
+            clustering_method = clustering_method,
103
+            annotation_col = annotate, fontsize = font.size,
104
+            annotation_colors = annotate.colors, height = pdf.height,
105
+            width = pdf.width, main = title,
106
+                filename = paste0(value, "_pheatmap.pdf"), ...)
107
+    } else {
108
+        pmap = pheatmap::pheatmap(matrix, show_rownames = show.rows,
109
+            show_colnames = show.columns, color = color,
110
+            clustering_distance_rows = clustering_distance_rows,
111
+            clustering_distance_cols = clustering_distance_cols,
112
+            clustering_method = clustering_method,
113
+            annotation_col = annotate, fontsize = font.size,
114
+            annotation_colors = annotate.colors, main = title, ...)
115
+    }
116
+    pmap
117
+}