Browse code

solve conflicts

git-svn-id: https://hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/ComplexHeatmap@109710 bc3139a8-67e5-0310-9ffc-ced21a209358

z.gu authored on 16/10/2015 20:24:38
Showing 13 changed files

1 1
old mode 100644
2 2
new mode 100755
3 3
old mode 100644
4 4
new mode 100755
5 5
old mode 100644
6 6
new mode 100755
... ...
@@ -1,7 +1,7 @@
1 1
 Package: ComplexHeatmap
2 2
 Type: Package
3 3
 Title: Making Complex Heatmaps
4
-Version: 1.7.0
4
+Version: 1.7.1
5 5
 Date: 2015-10-10
6 6
 Author: Zuguang Gu
7 7
 Maintainer: Zuguang Gu <z.gu@dkfz.de>
... ...
@@ -4,6 +4,7 @@ exportMethods(column_order)
4 4
 export(ColorMapping)
5 5
 export(HeatmapAnnotation)
6 6
 export(column_anno_boxplot)
7
+export(selectArea)
7 8
 export(row_anno_barplot)
8 9
 export(Heatmap)
9 10
 export(row_anno_points)
... ...
@@ -85,7 +86,6 @@ export(rowAnnotation)
85 86
 export(columnAnnotation)
86 87
 export(decorate_row_names)
87 88
 export(anno_text)
88
-export(selectArea)
89 89
 export(anno_density)
90 90
 
91 91
 import(grid)
... ...
@@ -1,3 +1,10 @@
1
+CHANGES in VERSION 1.7.1
2
+
3
+* `x` and `y` are `unit` object now in `cell_fun`
4
+* add an example to visualize GO game
5
+
6
+================================
7
+
1 8
 CHANGES in VERSION 1.5.1
2 9
 
3 10
 * `oncoPrint`: there are default graphics if type of alterations is 
... ...
@@ -25,10 +25,10 @@ setGeneric('prepare', function(object, ...) standardGeneric('prepare'))
25 25
 
26 26
 setGeneric('draw_annotation', function(object, ...) standardGeneric('draw_annotation'))
27 27
 
28
-setGeneric('get_color_mapping_param_list', function(object, ...) standardGeneric('get_color_mapping_param_list'))
29
-
30 28
 setGeneric('draw_dimnames', function(object, ...) standardGeneric('draw_dimnames'))
31 29
 
30
+setGeneric('get_color_mapping_param_list', function(object, ...) standardGeneric('get_color_mapping_param_list'))
31
+
32 32
 setGeneric('color_mapping_legend', function(object, ...) standardGeneric('color_mapping_legend'))
33 33
 
34 34
 setGeneric('draw', function(object, ...) standardGeneric('draw'))
... ...
@@ -122,7 +122,7 @@ Heatmap = setClass("Heatmap",
122 122
 # -cell_fun self-defined function to add graphics on each cell. Seven parameters will be passed into 
123 123
 #           this function: ``i``, ``j``, ``x``, ``y``, ``width``, ``height``, ``fill`` which are row index,
124 124
 #           column index in ``matrix``, coordinate of the middle points in the heatmap body viewport,
125
-#           the width and height of the cell and the filled color. 
125
+#           the width and height of the cell and the filled color. ``x``, ``y``, ``width`` and ``height`` are all `grid::unit` objects.
126 126
 # -row_title title on row.
127 127
 # -row_title_side will the title be put on the left or right of the heatmap?
128 128
 # -row_title_gp graphic parameters for drawing text.
... ...
@@ -1248,7 +1248,7 @@ setMethod(f = "draw_heatmap_body",
1248 1248
     cell_fun = object@matrix_param$cell_fun
1249 1249
     for(i in row_order) {
1250 1250
         for(j in column_order) {
1251
-            cell_fun(j, i, x[which(column_order == j)], y[which(row_order == i)], unit(1/nc, "npc"), unit(1/nr, "npc"), col_matrix[which(row_order == i), which(column_order == j)])
1251
+            cell_fun(j, i, unit(x[which(column_order == j)], "npc"), unit(y[which(row_order == i)], "npc"), unit(1/nc, "npc"), unit(1/nr, "npc"), col_matrix[which(row_order == i), which(column_order == j)])
1252 1252
         }
1253 1253
     }
1254 1254
 
1255 1255
old mode 100644
1256 1256
new mode 100755
... ...
@@ -76,7 +76,7 @@ Heatmap(matrix, col, name,
76 76
   \item{na_col}{color for \code{NA} values.}
77 77
   \item{rect_gp}{graphic parameters for drawing rectangles (for heatmap body).}
78 78
   \item{color_space}{the color space in which colors are interpolated. Only used if \code{matrix} is numeric and \code{col} is a vector of colors. Pass to \code{\link[circlize]{colorRamp2}}.}
79
-  \item{cell_fun}{self-defined function to add graphics on each cell. Seven parameters will be passed into this function: \code{i}, \code{j}, \code{x}, \code{y}, \code{width}, \code{height}, \code{fill} which are row index,column index in \code{matrix}, coordinate of the middle points in the heatmap body viewport,the width and height of the cell and the filled color. }
79
+  \item{cell_fun}{self-defined function to add graphics on each cell. Seven parameters will be passed into this function: \code{i}, \code{j}, \code{x}, \code{y}, \code{width}, \code{height}, \code{fill} which are row index,column index in \code{matrix}, coordinate of the middle points in the heatmap body viewport,the width and height of the cell and the filled color. \code{x}, \code{y}, \code{width} and \code{height} are all \code{\link[grid]{unit}} objects.}
80 80
   \item{row_title}{title on row.}
81 81
   \item{row_title_side}{will the title be put on the left or right of the heatmap?}
82 82
   \item{row_title_gp}{graphic parameters for drawing text.}
83 83
old mode 100644
84 84
new mode 100755
85 85
old mode 100644
86 86
new mode 100755
... ...
@@ -497,6 +497,98 @@ Heatmap(cor_mat, name = "correlation", col = col_fun, rect_gp = gpar(type = "non
497 497
 Note `cell_fun` is applied to every cell through a `for` loop, so it will be a little bit slow
498 498
 for large matrix.
499 499
 
500
+One last example is to visualize a [GO game](https://en.wikipedia.org/wiki/Go_(game)). The input data takes
501
+records of moves in the game.
502
+
503
+```{r}
504
+str = "B[cp];W[pq];B[dc];W[qd];B[eq];W[od];B[de];W[jc];B[qk];W[qn]
505
+;B[qh];W[ck];B[ci];W[cn];B[hc];W[je];B[jq];W[df];B[ee];W[cf]
506
+;B[ei];W[bc];B[ce];W[be];B[bd];W[cd];B[bf];W[ad];B[bg];W[cc]
507
+;B[eb];W[db];B[ec];W[lq];B[nq];W[jp];B[iq];W[kq];B[pp];W[op]
508
+;B[po];W[oq];B[rp];W[ql];B[oo];W[no];B[pl];W[pm];B[np];W[qq]
509
+;B[om];W[ol];B[pk];W[qp];B[on];W[rm];B[mo];W[nr];B[rl];W[rk]
510
+;B[qm];W[dp];B[dq];W[ql];B[or];W[mp];B[nn];W[mq];B[qm];W[bp]
511
+;B[co];W[ql];B[no];W[pr];B[qm];W[dd];B[pn];W[ed];B[bo];W[eg]
512
+;B[ef];W[dg];B[ge];W[gh];B[gf];W[gg];B[ek];W[ig];B[fd];W[en]
513
+;B[bn];W[ip];B[dm];W[ff];B[cb];W[fe];B[hp];W[ho];B[hq];W[el]
514
+;B[dl];W[fk];B[ej];W[fp];B[go];W[hn];B[fo];W[em];B[dn];W[eo]
515
+;B[gp];W[ib];B[gc];W[pg];B[qg];W[ng];B[qc];W[re];B[pf];W[of]
516
+;B[rc];W[ob];B[ph];W[qo];B[rn];W[mi];B[og];W[oe];B[qe];W[rd]
517
+;B[rf];W[pd];B[gm];W[gl];B[fm];W[fl];B[lj];W[mj];B[lk];W[ro]
518
+;B[hl];W[hk];B[ik];W[dk];B[bi];W[di];B[dj];W[dh];B[hj];W[gj]
519
+;B[li];W[lh];B[kh];W[lg];B[jn];W[do];B[cl];W[ij];B[gk];W[bl]
520
+;B[cm];W[hk];B[jk];W[lo];B[hi];W[hm];B[gk];W[bm];B[cn];W[hk]
521
+;B[il];W[cq];B[bq];W[ii];B[sm];W[jo];B[kn];W[fq];B[ep];W[cj]
522
+;B[bk];W[er];B[cr];W[gr];B[gk];W[fj];B[ko];W[kp];B[hr];W[jr]
523
+;B[nh];W[mh];B[mk];W[bb];B[da];W[jh];B[ic];W[id];B[hb];W[jb]
524
+;B[oj];W[fn];B[fs];W[fr];B[gs];W[es];B[hs];W[gn];B[kr];W[is]
525
+;B[dr];W[fi];B[bj];W[hd];B[gd];W[ln];B[lm];W[oi];B[oh];W[ni]
526
+;B[pi];W[ki];B[kj];W[ji];B[so];W[rq];B[if];W[jf];B[hh];W[hf]
527
+;B[he];W[ie];B[hg];W[ba];B[ca];W[sp];B[im];W[sn];B[rm];W[pe]
528
+;B[qf];W[if];B[hk];W[nj];B[nk];W[lr];B[mn];W[af];B[ag];W[ch]
529
+;B[bh];W[lp];B[ia];W[ja];B[ha];W[sf];B[sg];W[se];B[eh];W[fh]
530
+;B[in];W[ih];B[ae];W[so];B[af]"
531
+```
532
+
533
+Then we convert it into a matrix:
534
+
535
+```{r}
536
+str = gsub("\\n", "", str)
537
+step = strsplit(str, ";")[[1]]
538
+type = gsub("(B|W).*", "\\1", step)
539
+row = gsub("(B|W)\\[(.).\\]", "\\2", step)
540
+column = gsub("(B|W)\\[.(.)\\]", "\\2", step)
541
+
542
+mat = matrix(nrow = 19, ncol = 19)
543
+rownames(mat) = letters[1:19]
544
+colnames(mat) = letters[1:19]
545
+for(i in seq_along(row)) {
546
+    mat[row[i], column[i]] = type[i]
547
+}
548
+mat
549
+```
550
+
551
+Black and white stones are put based on the values in the matrix:
552
+
553
+```{r, fig.width = 8, fig.height = 8}
554
+Heatmap(mat, name = "go", rect_gp = gpar(type = "none"),
555
+    cell_fun = function(j, i, x, y, w, h, col) {
556
+        grid.rect(x, y, w, h, gp = gpar(fill = "#dcb35c", col = NA))
557
+        if(i == 1) {
558
+            grid.segments(x, y-h*0.5, x, y)
559
+        } else if(i == nrow(mat)) {
560
+            grid.segments(x, y, x, y+h*0.5)
561
+        } else {
562
+            grid.segments(x, y-h*0.5, x, y+h*0.5)
563
+        }
564
+        if(j == 1) {
565
+            grid.segments(x, y, x+w*0.5, y)        
566
+        } else if(j == ncol(mat)) {
567
+            grid.segments(x-w*0.5, y, x, y)
568
+        } else {
569
+            grid.segments(x-w*0.5, y, x+w*0.5, y)
570
+        }
571
+
572
+        if(i %in% c(4, 10, 16) & j %in% c(4, 10, 16)) {
573
+            grid.points(x, y, pch = 16, size = unit(2, "mm"))
574
+        }
575
+                
576
+        r = min(unit.c(w, h))*0.45
577
+        if(is.na(mat[i, j])) {
578
+        } else if(mat[i, j] == "W") {
579
+            grid.circle(x, y, r, gp = gpar(fill = "white", col = "white"))
580
+        } else if(mat[i, j] == "B") {
581
+            grid.circle(x, y, r, gp = gpar(fill = "black", col = "black"))
582
+        }
583
+    },
584
+    col = c("B" = "black", "W" = "white"),
585
+    show_row_names = FALSE, show_column_names = FALSE,
586
+    column_title = "One famous GO game",
587
+    heatmap_legend_param = list(title = "Player", at = c("B", "W"), 
588
+        labels = c("player1", "player2"), grid_border = "black")
589
+)
590
+```
591
+
500 592
 ## Session info
501 593
 
502 594
 ```{r}