Browse code

Fixed bug in DJ association

From: davidcoffey <dcoffey@fredhutch.org>

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

d.coffey authored on 06/04/2017 23:56:46
Showing1 changed files
... ...
@@ -40,7 +40,7 @@ chordDiagramVDJ <- function(sample, association = "VJ", colors = c("red", "blue"
40 40
             stop("The source data frame does not contain the required columns 'vFamilyName' and 'jFamilyName'.")
41 41
         }
42 42
         vj <- sample[, c("vFamilyName", "jFamilyName")]
43
-        vj[is.na(vj) | vj == ""] <- "unresolved"
43
+        vj[is.na(vj) | vj == ""] <- "Unresolved"
44 44
         vj$vFamilyName <- as.character(vj$vFamilyName)
45 45
         vj$jFamilyName <- as.character(vj$jFamilyName)
46 46
         table <- table(vj$vFamilyName, vj$jFamilyName)
... ...
@@ -55,8 +55,8 @@ chordDiagramVDJ <- function(sample, association = "VJ", colors = c("red", "blue"
55 55
         if (!all(c("dFamilyName", "jFamilyName") %in% colnames(sample))) {
56 56
             stop("The source data frame does not contain the required columns 'dFamilyName' and 'jFamilyName'.")
57 57
         }
58
-        dj <- sample[, c("vFamilyName", "jFamilyName")]
59
-        dj[is.na(dj) | dj == ""] <- "unresolved"
58
+        dj <- sample[, c("dFamilyName", "jFamilyName")]
59
+        dj[is.na(dj) | dj == ""] <- "Unresolved"
60 60
         dj$dFamilyName <- as.character(dj$dFamilyName)
61 61
         dj$jFamilyName <- as.character(dj$jFamilyName)
62 62
         table <- table(dj$dFamilyName, dj$jFamilyName)
Browse code

Adding pcaExplorer, oppar, pqsfinder, BgeeDB, genbankr, LymphoSeq, pbcmc, InteractionSet, ClusterSignificance

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

mtmorgan@fhcrc.org authored on 06/04/2016 16:10:37
Showing1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,70 @@
1
+#' Chord diagram of VJ or DJ gene associations
2
+#' 
3
+#' Creates a chord diagram showing VJ or DJ gene associations from one or more 
4
+#' samples.
5
+#' 
6
+#' @param sample A data frame consisting of frequencies of antigen receptor 
7
+#' sequences.  "vFamilyName", "jFamilyName", and if applicable, "dFamilyName" 
8
+#' are a required columns.  Using output from the LymphoSeq function topSeqs is
9
+#' recommended.
10
+#' @param association A character vector of gene familes to associate.  Options 
11
+#' include "VJ" or "DJ".
12
+#' @param colors A character vector of 2 colors corresponding to the V/D and J 
13
+#' gene colors respectively.
14
+#' @details The size of the ribbons connecting VJ or DJ genes correspond to the 
15
+#' number of samples or number of sequences that make up that recombination 
16
+#' event.  The thicker the ribbon, the higher the frequency of the recombination.
17
+#' @return Returns a chord diagram showing VJ or DJ gene associations from one or 
18
+#' more samples.
19
+#' @seealso \code{\link{topSeqs}}
20
+#' @examples
21
+#' file.path <- system.file("extdata", "TCRB_sequencing", package = "LymphoSeq")
22
+#' 
23
+#' file.list <- readImmunoSeq(path = file.path)
24
+#' 
25
+#' productive.nt <- productiveSeq(file.list = file.list, aggregate = "nucleotide")
26
+#' 
27
+#' top.seqs <- topSeqs(productive.seqs = productive.nt, top = 1)
28
+#' 
29
+#' chordDiagramVDJ(sample = top.seqs, association = "VJ", colors = c("red", "blue"))
30
+#' 
31
+#' # Remove "TCRB" from gene family name
32
+#' top.seqs <- as.data.frame(apply(top.seqs, 2, function(x) gsub("TCRB", "", x)))
33
+#' 
34
+#' chordDiagramVDJ(sample = top.seqs, association = "VJ", colors = c("red", "blue"))
35
+#' @export
36
+#' @importFrom circlize colorRamp2 chordDiagram
37
+chordDiagramVDJ <- function(sample, association = "VJ", colors = c("red", "blue")) {
38
+    if (association == "VJ") {
39
+        if (!all(c("vFamilyName", "jFamilyName") %in% colnames(sample))) {
40
+            stop("The source data frame does not contain the required columns 'vFamilyName' and 'jFamilyName'.")
41
+        }
42
+        vj <- sample[, c("vFamilyName", "jFamilyName")]
43
+        vj[is.na(vj) | vj == ""] <- "unresolved"
44
+        vj$vFamilyName <- as.character(vj$vFamilyName)
45
+        vj$jFamilyName <- as.character(vj$jFamilyName)
46
+        table <- table(vj$vFamilyName, vj$jFamilyName)
47
+        matrix <- as.matrix(as.data.frame.matrix(table))
48
+        ribbon.color <- circlize::colorRamp2(range(matrix), c("grey", "black"))
49
+        circlize::chordDiagram(matrix, 
50
+                               annotationTrack = c("grid", "name"), 
51
+                               grid.col = c(rep(colors[1], dim(matrix)[1]), rep(colors[2], dim(matrix)[2])), 
52
+                               col = ribbon.color)
53
+    }
54
+    if (association == "DJ") {
55
+        if (!all(c("dFamilyName", "jFamilyName") %in% colnames(sample))) {
56
+            stop("The source data frame does not contain the required columns 'dFamilyName' and 'jFamilyName'.")
57
+        }
58
+        dj <- sample[, c("vFamilyName", "jFamilyName")]
59
+        dj[is.na(dj) | dj == ""] <- "unresolved"
60
+        dj$dFamilyName <- as.character(dj$dFamilyName)
61
+        dj$jFamilyName <- as.character(dj$jFamilyName)
62
+        table <- table(dj$dFamilyName, dj$jFamilyName)
63
+        matrix <- as.matrix(as.data.frame.matrix(table))
64
+        ribbon.color <- circlize::colorRamp2(range(matrix), c("grey", "black"))
65
+        circlize::chordDiagram(matrix, 
66
+                               annotationTrack = c("grid", "name"), 
67
+                               grid.col = c(rep(colors[1], dim(matrix)[1]), rep(colors[2], dim(matrix)[2])), 
68
+                               col = ribbon.color)
69
+    }
70
+}
0 71
\ No newline at end of file