Browse code

Fix check errors

Yichen Wang authored on 28/06/2022 22:07:14
Showing1 changed files
... ...
@@ -18,7 +18,6 @@
18 18
 #' data("mouseBrainSubsetSCE")
19 19
 #' plotPCA(mouseBrainSubsetSCE, colorBy = "level1class",
20 20
 #'         reducedDimName = "PCA_counts")
21
-#'
22 21
 plotPCA <- function(inSCE, colorBy=NULL, shape=NULL, pcX="PC1",
23 22
                     pcY="PC2", reducedDimName="PCA", runPCA=FALSE,
24 23
                     useAssay="logcounts"){
Browse code

Added more unit tests

Yichen Wang authored on 28/06/2022 20:51:30
Showing1 changed files
... ...
@@ -19,7 +19,7 @@
19 19
 #' plotPCA(mouseBrainSubsetSCE, colorBy = "level1class",
20 20
 #'         reducedDimName = "PCA_counts")
21 21
 #'
22
-plotPCA <- function(inSCE, colorBy="No Color", shape="No Shape", pcX="PC1",
22
+plotPCA <- function(inSCE, colorBy=NULL, shape=NULL, pcX="PC1",
23 23
                     pcY="PC2", reducedDimName="PCA", runPCA=FALSE,
24 24
                     useAssay="logcounts"){
25 25
   if(!(reducedDimName %in% names(SingleCellExperiment::reducedDims(inSCE)))){
... ...
@@ -40,17 +40,11 @@ plotPCA <- function(inSCE, colorBy="No Color", shape="No Shape", pcX="PC1",
40 40
     stop("pcY dimension ", pcY, " is not in the reducedDim data")
41 41
   }
42 42
 
43
-  
43
+
44 44
   # Need to add back in variances in the plot axis labels
45 45
   pcXlab <- pcX
46 46
   pcYlab <- pcY
47 47
 
48
-  if (colorBy == "No Color"){
49
-    colorBy <- NULL
50
-  }
51
-  if (shape == "No Shape"){
52
-    shape <- NULL
53
-  }
54 48
   if (!is.null(colorBy)){
55 49
     pcaDf$color <- SingleCellExperiment::colData(inSCE)[, colorBy]
56 50
   }
Browse code

Added 'runDimensionalityReduction' wrapper function and changed name of getPCA() function to scaterPCA to conform the currently used naming convention.

Irzam Sarfraz authored on 30/04/2021 13:30:37
Showing1 changed files
... ...
@@ -24,11 +24,11 @@ plotPCA <- function(inSCE, colorBy="No Color", shape="No Shape", pcX="PC1",
24 24
                     useAssay="logcounts"){
25 25
   if(!(reducedDimName %in% names(SingleCellExperiment::reducedDims(inSCE)))){
26 26
     if (runPCA){
27
-      inSCE <- getPCA(inSCE, useAssay = useAssay,
27
+      inSCE <- scaterPCA(inSCE, useAssay = useAssay,
28 28
                       reducedDimName = reducedDimName)
29 29
     } else {
30 30
       stop(reducedDimName,
31
-           " dimension not found. Run getPCA() or set runPCA to TRUE.")
31
+           " dimension not found. Run scaterPCA() or set runPCA to TRUE.")
32 32
     }
33 33
   }
34 34
   pcaDf <- data.frame(SingleCellExperiment::reducedDim(inSCE,
Browse code

Removed SCtkExperiment class and methods. Removed all references in the documentation

Joshua D. Campbell authored on 02/07/2020 04:10:40
Showing1 changed files
... ...
@@ -5,7 +5,7 @@
5 5
 #' @param pcY User choice for the second principal component
6 6
 #' @param runPCA Run PCA if the reducedDimName does not exist. the Default is
7 7
 #' FALSE.
8
-#' @param inSCE Input SCTKExperiment object. Required.
8
+#' @param inSCE Input \linkS4class{SingleCellExperiment} object.
9 9
 #' @param useAssay Indicate which assay to use. The default is "logcounts".
10 10
 #' @param reducedDimName a name to store the results of the dimension reduction
11 11
 #' coordinates obtained from this method. This is stored in the SingleCellExperiment
... ...
@@ -40,24 +40,10 @@ plotPCA <- function(inSCE, colorBy="No Color", shape="No Shape", pcX="PC1",
40 40
     stop("pcY dimension ", pcY, " is not in the reducedDim data")
41 41
   }
42 42
 
43
-  if (class(inSCE) == "SCtkExperiment"){
44
-    if (all(c(pcX, pcY) %in% rownames(pcaVariances(inSCE)))){
45
-      #use the variances in pcaVariances
46
-      variances <- pcaVariances(inSCE)
47
-      pcXlab <- paste0(
48
-        pcX, " ", toString(round(variances[pcX, ] * 100, 2)), "%")
49
-      pcYlab <- paste0(
50
-        pcY, " ", toString(round(variances[pcY, ] * 100, 2)), "%")
51
-    } else {
52
-      #do not use variances in the plot
53
-      pcXlab <- pcX
54
-      pcYlab <- pcY
55
-    }
56
-  } else {
57
-    #do not use variances in the plot
58
-    pcXlab <- pcX
59
-    pcYlab <- pcY
60
-  }
43
+  
44
+  # Need to add back in variances in the plot axis labels
45
+  pcXlab <- pcX
46
+  pcYlab <- pcY
61 47
 
62 48
   if (colorBy == "No Color"){
63 49
     colorBy <- NULL
Browse code

Remove deprecated is.null call to reduceDim

David Jenkins authored on 25/09/2019 03:20:24
Showing1 changed files
... ...
@@ -22,7 +22,7 @@
22 22
 plotPCA <- function(inSCE, colorBy="No Color", shape="No Shape", pcX="PC1",
23 23
                     pcY="PC2", reducedDimName="PCA", runPCA=FALSE,
24 24
                     useAssay="logcounts"){
25
-  if (is.null(SingleCellExperiment::reducedDim(inSCE, reducedDimName))){
25
+  if(!(reducedDimName %in% names(SingleCellExperiment::reducedDims(inSCE)))){
26 26
     if (runPCA){
27 27
       inSCE <- getPCA(inSCE, useAssay = useAssay,
28 28
                       reducedDimName = reducedDimName)
Browse code

removed duplicates which came up due to @describeIn section from dependent PCA, tSNE methods

Mohammed Muzamil Khan authored on 29/03/2019 19:11:25
Showing1 changed files
... ...
@@ -1,13 +1,17 @@
1
-#' @describeIn getPCA plot PCA results
2
-#'
1
+#' Plot PCA run data from its components.
3 2
 #' @param colorBy The variable to color clusters by
4 3
 #' @param shape Shape of the points
5 4
 #' @param pcX User choice for the first principal component
6 5
 #' @param pcY User choice for the second principal component
7 6
 #' @param runPCA Run PCA if the reducedDimName does not exist. the Default is
8 7
 #' FALSE.
8
+#' @param inSCE Input SCTKExperiment object. Required.
9
+#' @param useAssay Indicate which assay to use. The default is "logcounts".
10
+#' @param reducedDimName a name to store the results of the dimension reduction
11
+#' coordinates obtained from this method. This is stored in the SingleCellExperiment
12
+#' object in the reducedDims slot. Required.
9 13
 #'
10
-#' @return plotPCA(): A PCA plot
14
+#' @return A PCA plot
11 15
 #'
12 16
 #' @export
13 17
 #' @examples
Browse code

Consistent use of inSCE to refer to the input SCtkExperiment object. Combined documentation for functions with similar functionality. Version bump

David Jenkins authored on 12/04/2018 22:21:24
Showing1 changed files
... ...
@@ -1,39 +1,33 @@
1
-#' Plot PCA
1
+#' @describeIn getPCA plot PCA results
2 2
 #'
3
-#' Use this function to plot PCA results
4
-#'
5
-#' @param countData A SCE object
6 3
 #' @param colorBy The variable to color clusters by
7 4
 #' @param shape Shape of the points
8 5
 #' @param pcX User choice for the first principal component
9 6
 #' @param pcY User choice for the second principal component
10
-#' @param reducedDimName PCA dimension name. The default is PCA.
11
-#' The toolkit will store data with the pattern <ASSAY>_<ALGORITHM>.
12 7
 #' @param runPCA Run PCA if the reducedDimName does not exist. the Default is
13 8
 #' FALSE.
14
-#' @param useAssay Indicate which assay to use for PCA. Default is "logcounts"
15
-
16 9
 #'
17
-#' @return A PCA plot
10
+#' @return plotPCA(): A PCA plot
11
+#'
18 12
 #' @export
19 13
 #' @examples
20 14
 #' data("mouseBrainSubsetSCE")
21 15
 #' plotPCA(mouseBrainSubsetSCE, colorBy = "level1class",
22 16
 #'         reducedDimName = "PCA_counts")
23 17
 #'
24
-plotPCA <- function(countData, colorBy="No Color", shape="No Shape", pcX="PC1",
18
+plotPCA <- function(inSCE, colorBy="No Color", shape="No Shape", pcX="PC1",
25 19
                     pcY="PC2", reducedDimName="PCA", runPCA=FALSE,
26 20
                     useAssay="logcounts"){
27
-  if (is.null(SingleCellExperiment::reducedDim(countData, reducedDimName))){
21
+  if (is.null(SingleCellExperiment::reducedDim(inSCE, reducedDimName))){
28 22
     if (runPCA){
29
-      countData <- getPCA(countData, useAssay = useAssay,
30
-                          reducedDimName = reducedDimName)
23
+      inSCE <- getPCA(inSCE, useAssay = useAssay,
24
+                      reducedDimName = reducedDimName)
31 25
     } else {
32 26
       stop(reducedDimName,
33 27
            " dimension not found. Run getPCA() or set runPCA to TRUE.")
34 28
     }
35 29
   }
36
-  pcaDf <- data.frame(SingleCellExperiment::reducedDim(countData,
30
+  pcaDf <- data.frame(SingleCellExperiment::reducedDim(inSCE,
37 31
                                                        reducedDimName))
38 32
   if (!(pcX %in% colnames(pcaDf))){
39 33
     stop("pcX dimension ", pcX, " is not in the reducedDim data")
... ...
@@ -42,10 +36,10 @@ plotPCA <- function(countData, colorBy="No Color", shape="No Shape", pcX="PC1",
42 36
     stop("pcY dimension ", pcY, " is not in the reducedDim data")
43 37
   }
44 38
 
45
-  if (class(countData) == "SCtkExperiment"){
46
-    if (all(c(pcX, pcY) %in% rownames(pcaVariances(countData)))){
39
+  if (class(inSCE) == "SCtkExperiment"){
40
+    if (all(c(pcX, pcY) %in% rownames(pcaVariances(inSCE)))){
47 41
       #use the variances in pcaVariances
48
-      variances <- pcaVariances(countData)
42
+      variances <- pcaVariances(inSCE)
49 43
       pcXlab <- paste0(
50 44
         pcX, " ", toString(round(variances[pcX, ] * 100, 2)), "%")
51 45
       pcYlab <- paste0(
... ...
@@ -68,12 +62,12 @@ plotPCA <- function(countData, colorBy="No Color", shape="No Shape", pcX="PC1",
68 62
     shape <- NULL
69 63
   }
70 64
   if (!is.null(colorBy)){
71
-    pcaDf$color <- SingleCellExperiment::colData(countData)[, colorBy]
65
+    pcaDf$color <- SingleCellExperiment::colData(inSCE)[, colorBy]
72 66
   }
73 67
   if (!is.null(shape)){
74
-    pcaDf$shape <- factor(SingleCellExperiment::colData(countData)[, shape])
68
+    pcaDf$shape <- factor(SingleCellExperiment::colData(inSCE)[, shape])
75 69
   }
76
-  pcaDf$Sample <- colnames(countData)
70
+  pcaDf$Sample <- colnames(inSCE)
77 71
   g <- ggplot2::ggplot(pcaDf, ggplot2::aes_string(pcX, pcY, label = "Sample")) +
78 72
     ggplot2::geom_point() +
79 73
     ggplot2::labs(x = pcXlab, y = pcYlab)
Browse code

Consistent use of camel case throughout the app

David Jenkins authored on 06/04/2018 20:11:01
Showing1 changed files
... ...
@@ -2,7 +2,7 @@
2 2
 #'
3 3
 #' Use this function to plot PCA results
4 4
 #'
5
-#' @param count_data A SCE object
5
+#' @param countData A SCE object
6 6
 #' @param colorBy The variable to color clusters by
7 7
 #' @param shape Shape of the points
8 8
 #' @param pcX User choice for the first principal component
... ...
@@ -11,41 +11,45 @@
11 11
 #' The toolkit will store data with the pattern <ASSAY>_<ALGORITHM>.
12 12
 #' @param runPCA Run PCA if the reducedDimName does not exist. the Default is
13 13
 #' FALSE.
14
-#' @param use_assay Indicate which assay to use for PCA. Default is "logcounts"
14
+#' @param useAssay Indicate which assay to use for PCA. Default is "logcounts"
15 15
 
16 16
 #'
17 17
 #' @return A PCA plot
18 18
 #' @export
19 19
 #' @examples
20
-#' data("mouse_brain_subset_sce")
21
-#' plotPCA(mouse_brain_subset_sce, colorBy = "level1class",
20
+#' data("mouseBrainSubsetSCE")
21
+#' plotPCA(mouseBrainSubsetSCE, colorBy = "level1class",
22 22
 #'         reducedDimName = "PCA_counts")
23 23
 #'
24
-plotPCA <- function(count_data, colorBy="No Color", shape="No Shape", pcX="PC1",
24
+plotPCA <- function(countData, colorBy="No Color", shape="No Shape", pcX="PC1",
25 25
                     pcY="PC2", reducedDimName="PCA", runPCA=FALSE,
26
-                    use_assay="logcounts"){
27
-  if (is.null(SingleCellExperiment::reducedDim(count_data, reducedDimName))){
26
+                    useAssay="logcounts"){
27
+  if (is.null(SingleCellExperiment::reducedDim(countData, reducedDimName))){
28 28
     if (runPCA){
29
-      count_data <- getPCA(count_data, use_assay = use_assay,
30
-                           reducedDimName = reducedDimName)
29
+      countData <- getPCA(countData, useAssay = useAssay,
30
+                          reducedDimName = reducedDimName)
31 31
     } else {
32
-      stop(reducedDimName, " dimension not found. Run getPCA() or set runPCA to TRUE.")
32
+      stop(reducedDimName,
33
+           " dimension not found. Run getPCA() or set runPCA to TRUE.")
33 34
     }
34 35
   }
35
-  pca_df <- data.frame(SingleCellExperiment::reducedDim(count_data, reducedDimName))
36
-  if (!(pcX %in% colnames(pca_df))){
36
+  pcaDf <- data.frame(SingleCellExperiment::reducedDim(countData,
37
+                                                       reducedDimName))
38
+  if (!(pcX %in% colnames(pcaDf))){
37 39
     stop("pcX dimension ", pcX, " is not in the reducedDim data")
38 40
   }
39
-  if (!(pcY %in% colnames(pca_df))){
41
+  if (!(pcY %in% colnames(pcaDf))){
40 42
     stop("pcY dimension ", pcY, " is not in the reducedDim data")
41 43
   }
42 44
 
43
-  if (class(count_data) == "SCtkExperiment"){
44
-    if (all(c(pcX, pcY) %in% rownames(pca_variances(count_data)))){
45
-      #use the variances in pca_variances
46
-      variances <- pca_variances(count_data)
47
-      pcXlab <- paste0(pcX, " ", toString(round(variances[pcX, ] * 100, 2)), "%")
48
-      pcYlab <- paste0(pcY, " ", toString(round(variances[pcY, ] * 100, 2)), "%")
45
+  if (class(countData) == "SCtkExperiment"){
46
+    if (all(c(pcX, pcY) %in% rownames(pcaVariances(countData)))){
47
+      #use the variances in pcaVariances
48
+      variances <- pcaVariances(countData)
49
+      pcXlab <- paste0(
50
+        pcX, " ", toString(round(variances[pcX, ] * 100, 2)), "%")
51
+      pcYlab <- paste0(
52
+        pcY, " ", toString(round(variances[pcY, ] * 100, 2)), "%")
49 53
     } else {
50 54
       #do not use variances in the plot
51 55
       pcXlab <- pcX
... ...
@@ -64,13 +68,13 @@ plotPCA <- function(count_data, colorBy="No Color", shape="No Shape", pcX="PC1",
64 68
     shape <- NULL
65 69
   }
66 70
   if (!is.null(colorBy)){
67
-    pca_df$color <- SingleCellExperiment::colData(count_data)[, colorBy]
71
+    pcaDf$color <- SingleCellExperiment::colData(countData)[, colorBy]
68 72
   }
69 73
   if (!is.null(shape)){
70
-    pca_df$shape <- factor(SingleCellExperiment::colData(count_data)[, shape])
74
+    pcaDf$shape <- factor(SingleCellExperiment::colData(countData)[, shape])
71 75
   }
72
-  pca_df$Sample <- colnames(count_data)
73
-  g <- ggplot2::ggplot(pca_df, ggplot2::aes_string(pcX, pcY, label = "Sample")) +
76
+  pcaDf$Sample <- colnames(countData)
77
+  g <- ggplot2::ggplot(pcaDf, ggplot2::aes_string(pcX, pcY, label = "Sample")) +
74 78
     ggplot2::geom_point() +
75 79
     ggplot2::labs(x = pcXlab, y = pcYlab)
76 80
   if (!is.null(colorBy)){
Browse code

bugfix to support numeric conditions. package linted. Clarification about what kind of data to use for each algorithm

David Jenkins authored on 29/03/2018 03:48:01
Showing1 changed files
... ...
@@ -33,14 +33,14 @@ plotPCA <- function(count_data, colorBy="No Color", shape="No Shape", pcX="PC1",
33 33
     }
34 34
   }
35 35
   pca_df <- data.frame(SingleCellExperiment::reducedDim(count_data, reducedDimName))
36
-  if(!(pcX %in% colnames(pca_df))){
36
+  if (!(pcX %in% colnames(pca_df))){
37 37
     stop("pcX dimension ", pcX, " is not in the reducedDim data")
38 38
   }
39
-  if(!(pcY %in% colnames(pca_df))){
39
+  if (!(pcY %in% colnames(pca_df))){
40 40
     stop("pcY dimension ", pcY, " is not in the reducedDim data")
41 41
   }
42 42
 
43
-  if(class(count_data) == "SCtkExperiment"){
43
+  if (class(count_data) == "SCtkExperiment"){
44 44
     if (all(c(pcX, pcY) %in% rownames(pca_variances(count_data)))){
45 45
       #use the variances in pca_variances
46 46
       variances <- pca_variances(count_data)
Browse code

Removed examples that weren't being used. Updated requirement to 3.5 for bioconductor release, changednged the name of the GSE60361 dataset to be more descriptive. Added a link to the data source. Fixed DESeq2 bug. Version bump

David Jenkins authored on 20/03/2018 23:51:57
Showing1 changed files
... ...
@@ -17,8 +17,8 @@
17 17
 #' @return A PCA plot
18 18
 #' @export
19 19
 #' @examples
20
-#' data("GSE60361_subset_sce")
21
-#' plotPCA(GSE60361_subset_sce, colorBy = "level1class",
20
+#' data("mouse_brain_subset_sce")
21
+#' plotPCA(mouse_brain_subset_sce, colorBy = "level1class",
22 22
 #'         reducedDimName = "PCA_counts")
23 23
 #'
24 24
 plotPCA <- function(count_data, colorBy="No Color", shape="No Shape", pcX="PC1",
Browse code

Updates to pass BiocCheck

David Jenkins authored on 22/02/2018 23:37:15
Showing1 changed files
... ...
@@ -24,7 +24,7 @@
24 24
 plotPCA <- function(count_data, colorBy="No Color", shape="No Shape", pcX="PC1",
25 25
                     pcY="PC2", reducedDimName="PCA", runPCA=FALSE,
26 26
                     use_assay="logcounts"){
27
-  if (is.null(reducedDim(count_data, reducedDimName))){
27
+  if (is.null(SingleCellExperiment::reducedDim(count_data, reducedDimName))){
28 28
     if (runPCA){
29 29
       count_data <- getPCA(count_data, use_assay = use_assay,
30 30
                            reducedDimName = reducedDimName)
... ...
@@ -32,7 +32,7 @@ plotPCA <- function(count_data, colorBy="No Color", shape="No Shape", pcX="PC1",
32 32
       stop(reducedDimName, " dimension not found. Run getPCA() or set runPCA to TRUE.")
33 33
     }
34 34
   }
35
-  pca_df <- data.frame(reducedDim(count_data, reducedDimName))
35
+  pca_df <- data.frame(SingleCellExperiment::reducedDim(count_data, reducedDimName))
36 36
   if(!(pcX %in% colnames(pca_df))){
37 37
     stop("pcX dimension ", pcX, " is not in the reducedDim data")
38 38
   }
... ...
@@ -64,10 +64,10 @@ plotPCA <- function(count_data, colorBy="No Color", shape="No Shape", pcX="PC1",
64 64
     shape <- NULL
65 65
   }
66 66
   if (!is.null(colorBy)){
67
-    pca_df$color <- eval(parse(text = paste("colData(count_data)$", colorBy, sep = "")))
67
+    pca_df$color <- SingleCellExperiment::colData(count_data)[, colorBy]
68 68
   }
69 69
   if (!is.null(shape)){
70
-    pca_df$shape <- factor(eval(parse(text = paste("colData(count_data)$", shape, sep = ""))))
70
+    pca_df$shape <- factor(SingleCellExperiment::colData(count_data)[, shape])
71 71
   }
72 72
   pca_df$Sample <- colnames(count_data)
73 73
   g <- ggplot2::ggplot(pca_df, ggplot2::aes_string(pcX, pcY, label = "Sample")) +
Browse code

Added runnable examples to more functions

David Jenkins authored on 20/02/2018 02:44:56
Showing1 changed files
... ...
@@ -16,6 +16,10 @@
16 16
 #'
17 17
 #' @return A PCA plot
18 18
 #' @export
19
+#' @examples
20
+#' data("GSE60361_subset_sce")
21
+#' plotPCA(GSE60361_subset_sce, colorBy = "level1class",
22
+#'         reducedDimName = "PCA_counts")
19 23
 #'
20 24
 plotPCA <- function(count_data, colorBy="No Color", shape="No Shape", pcX="PC1",
21 25
                     pcY="PC2", reducedDimName="PCA", runPCA=FALSE,
Browse code

Documentation updates to add examples and fix indentation

David Jenkins authored on 16/02/2018 22:45:56
Showing1 changed files
... ...
@@ -15,7 +15,7 @@
15 15
 
16 16
 #'
17 17
 #' @return A PCA plot
18
-#' @export plotPCA
18
+#' @export
19 19
 #'
20 20
 plotPCA <- function(count_data, colorBy="No Color", shape="No Shape", pcX="PC1",
21 21
                     pcY="PC2", reducedDimName="PCA", runPCA=FALSE,
... ...
@@ -35,7 +35,7 @@ plotPCA <- function(count_data, colorBy="No Color", shape="No Shape", pcX="PC1",
35 35
   if(!(pcY %in% colnames(pca_df))){
36 36
     stop("pcY dimension ", pcY, " is not in the reducedDim data")
37 37
   }
38
-  
38
+
39 39
   if(class(count_data) == "SCtkExperiment"){
40 40
     if (all(c(pcX, pcY) %in% rownames(pca_variances(count_data)))){
41 41
       #use the variances in pca_variances
Browse code

Support for loading in SingleCellExperiment objects that don't contain a matrix called counts

David Jenkins authored on 14/02/2018 23:09:32
Showing1 changed files
... ...
@@ -35,12 +35,18 @@ plotPCA <- function(count_data, colorBy="No Color", shape="No Shape", pcX="PC1",
35 35
   if(!(pcY %in% colnames(pca_df))){
36 36
     stop("pcY dimension ", pcY, " is not in the reducedDim data")
37 37
   }
38
-
39
-  if (all(c(pcX, pcY) %in% rownames(pca_variances(count_data)))){
40
-    #use the variances in pca_variances
41
-    variances <- pca_variances(count_data)
42
-    pcXlab <- paste0(pcX, " ", toString(round(variances[pcX, ] * 100, 2)), "%")
43
-    pcYlab <- paste0(pcY, " ", toString(round(variances[pcY, ] * 100, 2)), "%")
38
+  
39
+  if(class(count_data) == "SCtkExperiment"){
40
+    if (all(c(pcX, pcY) %in% rownames(pca_variances(count_data)))){
41
+      #use the variances in pca_variances
42
+      variances <- pca_variances(count_data)
43
+      pcXlab <- paste0(pcX, " ", toString(round(variances[pcX, ] * 100, 2)), "%")
44
+      pcYlab <- paste0(pcY, " ", toString(round(variances[pcY, ] * 100, 2)), "%")
45
+    } else {
46
+      #do not use variances in the plot
47
+      pcXlab <- pcX
48
+      pcYlab <- pcY
49
+    }
44 50
   } else {
45 51
     #do not use variances in the plot
46 52
     pcXlab <- pcX
Browse code

Fix for slow loading gene names in pcaplot. PCA dimensions are now read from the selected reducedDim matrix

David Jenkins authored on 13/02/2018 23:18:45
Showing1 changed files
... ...
@@ -29,7 +29,24 @@ plotPCA <- function(count_data, colorBy="No Color", shape="No Shape", pcX="PC1",
29 29
     }
30 30
   }
31 31
   pca_df <- data.frame(reducedDim(count_data, reducedDimName))
32
-  variances <- pca_variances(count_data)
32
+  if(!(pcX %in% colnames(pca_df))){
33
+    stop("pcX dimension ", pcX, " is not in the reducedDim data")
34
+  }
35
+  if(!(pcY %in% colnames(pca_df))){
36
+    stop("pcY dimension ", pcY, " is not in the reducedDim data")
37
+  }
38
+
39
+  if (all(c(pcX, pcY) %in% rownames(pca_variances(count_data)))){
40
+    #use the variances in pca_variances
41
+    variances <- pca_variances(count_data)
42
+    pcXlab <- paste0(pcX, " ", toString(round(variances[pcX, ] * 100, 2)), "%")
43
+    pcYlab <- paste0(pcY, " ", toString(round(variances[pcY, ] * 100, 2)), "%")
44
+  } else {
45
+    #do not use variances in the plot
46
+    pcXlab <- pcX
47
+    pcYlab <- pcY
48
+  }
49
+
33 50
   if (colorBy == "No Color"){
34 51
     colorBy <- NULL
35 52
   }
... ...
@@ -45,8 +62,7 @@ plotPCA <- function(count_data, colorBy="No Color", shape="No Shape", pcX="PC1",
45 62
   pca_df$Sample <- colnames(count_data)
46 63
   g <- ggplot2::ggplot(pca_df, ggplot2::aes_string(pcX, pcY, label = "Sample")) +
47 64
     ggplot2::geom_point() +
48
-    ggplot2::labs(x = paste0(pcX, " ", toString(round(variances[pcX, ] * 100, 2)), "%"),
49
-                  y = paste0(pcY, " ", toString(round(variances[pcY, ] * 100, 2)), "%"))
65
+    ggplot2::labs(x = pcXlab, y = pcYlab)
50 66
   if (!is.null(colorBy)){
51 67
     g <- g + ggplot2::aes_string(color = "color") +
52 68
       ggplot2::labs(color = colorBy)
Browse code

Spell check

David Jenkins authored on 12/12/2017 22:11:05
Showing1 changed files
... ...
@@ -1,15 +1,15 @@
1 1
 #' Plot PCA
2 2
 #'
3
-#' Use this function to plot PCA or tSNE results
3
+#' Use this function to plot PCA results
4 4
 #'
5 5
 #' @param count_data A SCE object
6 6
 #' @param colorBy The variable to color clusters by
7 7
 #' @param shape Shape of the points
8 8
 #' @param pcX User choice for the first principal component
9
-#' @param pcY User choice for the second prinicipal component
9
+#' @param pcY User choice for the second principal component
10 10
 #' @param reducedDimName PCA dimension name. The default is PCA.
11
-#' The toolkit will store data with the pattern <ASSSAY>_<ALGORITHM>.
12
-#' @param runPCA Run PCA if the reducedDimName doesn't exist. the Default is
11
+#' The toolkit will store data with the pattern <ASSAY>_<ALGORITHM>.
12
+#' @param runPCA Run PCA if the reducedDimName does not exist. the Default is
13 13
 #' FALSE.
14 14
 #' @param use_assay Indicate which assay to use for PCA. Default is "logcounts"
15 15
 
Browse code

Select assay for MAST analysis, linted code

David Jenkins authored on 29/10/2017 22:25:34
Showing1 changed files
... ...
@@ -45,8 +45,8 @@ plotPCA <- function(count_data, colorBy="No Color", shape="No Shape", pcX="PC1",
45 45
   pca_df$Sample <- colnames(count_data)
46 46
   g <- ggplot2::ggplot(pca_df, ggplot2::aes_string(pcX, pcY, label = "Sample")) +
47 47
     ggplot2::geom_point() +
48
-    ggplot2::labs(x = paste0(pcX, " ", toString(round(variances[pcX,] * 100, 2)), "%"),
49
-                  y = paste0(pcY, " ", toString(round(variances[pcY,] * 100, 2)), "%"))
48
+    ggplot2::labs(x = paste0(pcX, " ", toString(round(variances[pcX, ] * 100, 2)), "%"),
49
+                  y = paste0(pcY, " ", toString(round(variances[pcY, ] * 100, 2)), "%"))
50 50
   if (!is.null(colorBy)){
51 51
     g <- g + ggplot2::aes_string(color = "color") +
52 52
       ggplot2::labs(color = colorBy)
Browse code

Updated pca_variances for example data. Fixed MAST heatmap issues and various bugfixes

David Jenkins authored on 24/10/2017 20:35:51
Showing1 changed files
... ...
@@ -11,7 +11,7 @@
11 11
 #' The toolkit will store data with the pattern <ASSSAY>_<ALGORITHM>.
12 12
 #' @param runPCA Run PCA if the reducedDimName doesn't exist. the Default is
13 13
 #' FALSE.
14
-#' @param use_assay Indicate which assay to use for PCA. Default is "counts"
14
+#' @param use_assay Indicate which assay to use for PCA. Default is "logcounts"
15 15
 
16 16
 #'
17 17
 #' @return A PCA plot
Browse code

Changed default behavior of plot functions to not run the dimred because of time concerns. Linted some code

David Jenkins authored on 22/10/2017 23:25:10
Showing1 changed files
... ...
@@ -7,20 +7,29 @@
7 7
 #' @param shape Shape of the points
8 8
 #' @param pcX User choice for the first principal component
9 9
 #' @param pcY User choice for the second prinicipal component
10
-#' @param use_assay Indicate which assay to use for PCA. Default is "counts"
11 10
 #' @param reducedDimName PCA dimension name. The default is PCA.
12 11
 #' The toolkit will store data with the pattern <ASSSAY>_<ALGORITHM>.
12
+#' @param runPCA Run PCA if the reducedDimName doesn't exist. the Default is
13
+#' FALSE.
14
+#' @param use_assay Indicate which assay to use for PCA. Default is "counts"
15
+
13 16
 #'
14 17
 #' @return A PCA plot
15 18
 #' @export plotPCA
16 19
 #'
17 20
 plotPCA <- function(count_data, colorBy="No Color", shape="No Shape", pcX="PC1",
18
-                    pcY="PC2", use_assay="logcounts", reducedDimName="PCA"){
21
+                    pcY="PC2", reducedDimName="PCA", runPCA=FALSE,
22
+                    use_assay="logcounts"){
19 23
   if (is.null(reducedDim(count_data, reducedDimName))){
20
-    count_data <- getPCA(count_data, use_assay = use_assay, reducedDimName = reducedDimName)
24
+    if (runPCA){
25
+      count_data <- getPCA(count_data, use_assay = use_assay,
26
+                           reducedDimName = reducedDimName)
27
+    } else {
28
+      stop(reducedDimName, " dimension not found. Run getPCA() or set runPCA to TRUE.")
29
+    }
21 30
   }
22 31
   pca_df <- data.frame(reducedDim(count_data, reducedDimName))
23
-  variances <- pca_variances(count_data)$percentVar
32
+  variances <- pca_variances(count_data)
24 33
   if (colorBy == "No Color"){
25 34
     colorBy <- NULL
26 35
   }
... ...
@@ -36,8 +45,8 @@ plotPCA <- function(count_data, colorBy="No Color", shape="No Shape", pcX="PC1",
36 45
   pca_df$Sample <- colnames(count_data)
37 46
   g <- ggplot2::ggplot(pca_df, ggplot2::aes_string(pcX, pcY, label = "Sample")) +
38 47
     ggplot2::geom_point() +
39
-    ggplot2::labs(x = paste(pcX, toString(round(variances[strtoi(strsplit(pcX, "PC")[[1]][-1])] * 100, 2)), "%"),
40
-                  y = paste(pcY, toString(round(variances[strtoi(strsplit(pcY, "PC")[[1]][-1])] * 100, 2)), "%"))
48
+    ggplot2::labs(x = paste0(pcX, " ", toString(round(variances[pcX,] * 100, 2)), "%"),
49
+                  y = paste0(pcY, " ", toString(round(variances[pcY,] * 100, 2)), "%"))
41 50
   if (!is.null(colorBy)){
42 51
     g <- g + ggplot2::aes_string(color = "color") +
43 52
       ggplot2::labs(color = colorBy)
Browse code

Support for choosing availabe assays on dimred tab

David Jenkins authored on 19/10/2017 20:54:23
Showing1 changed files
... ...
@@ -7,16 +7,19 @@
7 7
 #' @param shape Shape of the points
8 8
 #' @param pcX User choice for the first principal component
9 9
 #' @param pcY User choice for the second prinicipal component
10
+#' @param use_assay Indicate which assay to use for PCA. Default is "counts"
11
+#' @param reducedDimName PCA dimension name. The default is PCA.
12
+#' The toolkit will store data with the pattern <ASSSAY>_<ALGORITHM>.
10 13
 #'
11 14
 #' @return A PCA plot
12 15
 #' @export plotPCA
13 16
 #'
14 17
 plotPCA <- function(count_data, colorBy="No Color", shape="No Shape", pcX="PC1",
15
-                    pcY="PC2"){
16
-  if (is.null(reducedDim(count_data, "PCA"))){
17
-    count_data <- getPCA(count_data)
18
+                    pcY="PC2", use_assay="logcounts", reducedDimName="PCA"){
19
+  if (is.null(reducedDim(count_data, reducedDimName))){
20
+    count_data <- getPCA(count_data, use_assay = use_assay, reducedDimName = reducedDimName)
18 21
   }
19
-  pca_df <- data.frame(reducedDim(count_data, "PCA"))
22
+  pca_df <- data.frame(reducedDim(count_data, reducedDimName))
20 23
   variances <- pca_variances(count_data)$percentVar
21 24
   if (colorBy == "No Color"){
22 25
     colorBy <- NULL
... ...
@@ -33,7 +36,8 @@ plotPCA <- function(count_data, colorBy="No Color", shape="No Shape", pcX="PC1",
33 36
   pca_df$Sample <- colnames(count_data)
34 37
   g <- ggplot2::ggplot(pca_df, ggplot2::aes_string(pcX, pcY, label = "Sample")) +
35 38
     ggplot2::geom_point() +
36
-    ggplot2::labs(x = paste(pcX, toString(round(variances[strtoi(strsplit(pcX, "PC")[[1]][-1])] * 100, 2)), "%"), y = paste(pcY, toString(round(variances[strtoi(strsplit(pcY, "PC")[[1]][-1])] * 100, 2)), "%"))
39
+    ggplot2::labs(x = paste(pcX, toString(round(variances[strtoi(strsplit(pcX, "PC")[[1]][-1])] * 100, 2)), "%"),
40
+                  y = paste(pcY, toString(round(variances[strtoi(strsplit(pcY, "PC")[[1]][-1])] * 100, 2)), "%"))
37 41
   if (!is.null(colorBy)){
38 42
     g <- g + ggplot2::aes_string(color = "color") +
39 43
       ggplot2::labs(color = colorBy)
Browse code

Modified the underlaying object by extending the SingleCellExperiment to a SingleCelltkExperiment that stores PCA percent variances within the function. Modifications to the plotting and getting of PCA and TSNE functions to support the new object. Updated the example objects to SingleCelltkExperiment objects

David Jenkins authored on 12/09/2017 23:38:53
Showing1 changed files
... ...
@@ -3,7 +3,6 @@
3 3
 #' Use this function to plot PCA or tSNE results
4 4
 #'
5 5
 #' @param count_data A SCE object
6
-#' @param pca_df PCA data frame
7 6
 #' @param colorBy The variable to color clusters by
8 7
 #' @param shape Shape of the points
9 8
 #' @param pcX User choice for the first principal component
... ...
@@ -12,26 +11,27 @@
12 11
 #' @return A PCA plot
13 12
 #' @export plotPCA
14 13
 #'
15
-plotPCA <- function(count_data, pca_df=NULL, colorBy="No Color", shape="No Shape", pcX="PC1", pcY="PC2"){
16
-  if (is.null(pca_df)){
17
-    pca_df <- getPCA(count_data)
14
+plotPCA <- function(count_data, colorBy="No Color", shape="No Shape", pcX="PC1",
15
+                    pcY="PC2"){
16
+  if (is.null(reducedDim(count_data, "PCA"))){
17
+    count_data <- getPCA(count_data)
18 18
   }
19
+  pca_df <- data.frame(reducedDim(count_data, "PCA"))
20
+  variances <- pca_variances(count_data)$percentVar
19 21
   if (colorBy == "No Color"){
20 22
     colorBy <- NULL
21 23
   }
22 24
   if (shape == "No Shape"){
23 25
     shape <- NULL
24 26
   }
25
-  l <- pca_df
26 27
   if (!is.null(colorBy)){
27
-    l$color <- eval(parse(text = paste("colData(count_data)$", colorBy, sep = "")))
28
+    pca_df$color <- eval(parse(text = paste("colData(count_data)$", colorBy, sep = "")))
28 29
   }
29 30
   if (!is.null(shape)){
30
-    l$shape <- factor(eval(parse(text = paste("colData(count_data)$", shape, sep = ""))))
31
+    pca_df$shape <- factor(eval(parse(text = paste("colData(count_data)$", shape, sep = ""))))
31 32
   }
32
-  l$Sample <- colnames(count_data)
33
-  variances <- attr(pca_df, "percentVar")
34
-  g <- ggplot2::ggplot(l, ggplot2::aes_string(pcX, pcY, label = "Sample")) +
33
+  pca_df$Sample <- colnames(count_data)
34
+  g <- ggplot2::ggplot(pca_df, ggplot2::aes_string(pcX, pcY, label = "Sample")) +
35 35
     ggplot2::geom_point() +
36 36
     ggplot2::labs(x = paste(pcX, toString(round(variances[strtoi(strsplit(pcX, "PC")[[1]][-1])] * 100, 2)), "%"), y = paste(pcY, toString(round(variances[strtoi(strsplit(pcY, "PC")[[1]][-1])] * 100, 2)), "%"))
37 37
   if (!is.null(colorBy)){
Browse code

Modified inputs for functions to support SingleCellExperiment

David Jenkins authored on 08/08/2017 19:54:42
Showing1 changed files
... ...
@@ -12,8 +12,7 @@
12 12
 #' @return A PCA plot
13 13
 #' @export plotPCA
14 14
 #'
15
-
16
-plotPCA <- function(count_data, pca_df=NULL, colorBy=NULL, shape=NULL, pcX="PC1", pcY="PC2"){
15
+plotPCA <- function(count_data, pca_df=NULL, colorBy="No Color", shape="No Shape", pcX="PC1", pcY="PC2"){
17 16
   if (is.null(pca_df)){
18 17
     pca_df <- getPCA(count_data)
19 18
   }
... ...
@@ -25,23 +24,23 @@ plotPCA <- function(count_data, pca_df=NULL, colorBy=NULL, shape=NULL, pcX="PC1"
25 24
   }
26 25
   l <- pca_df
27 26
   if (!is.null(colorBy)){
28
-    l$color <- eval(parse(text = paste("pData(count_data)$", colorBy, sep = "")))
27
+    l$color <- eval(parse(text = paste("colData(count_data)$", colorBy, sep = "")))
29 28
   }
30 29
   if (!is.null(shape)){
31
-    l$shape <- factor(eval(parse(text = paste("pData(count_data)$", shape, sep = ""))))
30
+    l$shape <- factor(eval(parse(text = paste("colData(count_data)$", shape, sep = ""))))
32 31
   }
33
-  l$Sample <- rownames(pData(count_data))
32
+  l$Sample <- colnames(count_data)
34 33
   variances <- attr(pca_df, "percentVar")
35
-  g <- ggplot(l, aes_string(pcX, pcY, label = "Sample")) +
36
-       geom_point() +
37
-       labs(x = paste(pcX, toString(round(variances[strtoi(strsplit(pcX, "PC")[[1]][-1])] * 100, 2)), "%"), y = paste(pcY, toString(round(variances[strtoi(strsplit(pcY, "PC")[[1]][-1])] * 100, 2)), "%"))
34
+  g <- ggplot2::ggplot(l, ggplot2::aes_string(pcX, pcY, label = "Sample")) +
35
+    ggplot2::geom_point() +
36
+    ggplot2::labs(x = paste(pcX, toString(round(variances[strtoi(strsplit(pcX, "PC")[[1]][-1])] * 100, 2)), "%"), y = paste(pcY, toString(round(variances[strtoi(strsplit(pcY, "PC")[[1]][-1])] * 100, 2)), "%"))
38 37
   if (!is.null(colorBy)){
39
-    g <- g + aes_string(color = "color") +
40
-      labs(color = colorBy)
38
+    g <- g + ggplot2::aes_string(color = "color") +
39
+      ggplot2::labs(color = colorBy)
41 40
   }
42 41
   if (!is.null(shape)){
43
-    g <- g + aes_string(shape = "shape") +
44
-      labs(shape = shape)
42
+    g <- g + ggplot2::aes_string(shape = "shape") +
43
+      ggplot2::labs(shape = shape)
45 44
   }
46 45
   return(g)
47 46
 }
Browse code

Final spacing modification

David Jenkins authored on 26/06/2017 22:25:28
Showing1 changed files
... ...
@@ -1,6 +1,5 @@
1
-
2 1
 #' Plot PCA
3
-#'   
2
+#'
4 3
 #' Use this function to plot PCA or tSNE results
5 4
 #'
6 5
 #' @param count_data A SCE object
... ...
@@ -9,7 +8,7 @@
9 8
 #' @param shape Shape of the points
10 9
 #' @param pcX User choice for the first principal component
11 10
 #' @param pcY User choice for the second prinicipal component
12
-#' 
11
+#'
13 12
 #' @return A PCA plot
14 13
 #' @export plotPCA
15 14
 #'
Browse code

Additional spacing modification

David Jenkins authored on 26/06/2017 21:58:09
Showing1 changed files
... ...
@@ -26,16 +26,16 @@ plotPCA <- function(count_data, pca_df=NULL, colorBy=NULL, shape=NULL, pcX="PC1"
26 26
   }
27 27
   l <- pca_df
28 28
   if (!is.null(colorBy)){
29
-    l$color <- eval(parse(text = paste("pData(count_data)$",colorBy,sep = "")))
29
+    l$color <- eval(parse(text = paste("pData(count_data)$", colorBy, sep = "")))
30 30
   }
31 31
   if (!is.null(shape)){
32
-    l$shape <- factor(eval(parse(text = paste("pData(count_data)$",shape,sep = ""))))
32
+    l$shape <- factor(eval(parse(text = paste("pData(count_data)$", shape, sep = ""))))
33 33
   }
34 34
   l$Sample <- rownames(pData(count_data))
35
-  variances <- attr(pca_df,"percentVar")
35
+  variances <- attr(pca_df, "percentVar")
36 36
   g <- ggplot(l, aes_string(pcX, pcY, label = "Sample")) +
37 37
        geom_point() +
38
-       labs(x = paste(pcX,toString(round(variances[strtoi(strsplit(pcX,"PC")[[1]][-1])] * 100,2)),"%"),y = paste(pcY,toString(round(variances[strtoi(strsplit(pcY,"PC")[[1]][-1])] * 100,2)),"%"))
38
+       labs(x = paste(pcX, toString(round(variances[strtoi(strsplit(pcX, "PC")[[1]][-1])] * 100, 2)), "%"), y = paste(pcY, toString(round(variances[strtoi(strsplit(pcY, "PC")[[1]][-1])] * 100, 2)), "%"))
39 39
   if (!is.null(colorBy)){
40 40
     g <- g + aes_string(color = "color") +
41 41
       labs(color = colorBy)
Browse code

More consistent spacing based on Hadley style guide

David Jenkins authored on 26/06/2017 21:11:45
Showing1 changed files
... ...
@@ -15,33 +15,33 @@
15 15
 #'
16 16
 
17 17
 plotPCA <- function(count_data, pca_df=NULL, colorBy=NULL, shape=NULL, pcX="PC1", pcY="PC2"){
18
-  if(is.null(pca_df)){
18
+  if (is.null(pca_df)){
19 19
     pca_df <- getPCA(count_data)
20 20
   }
21
-  if(colorBy == "No Color"){
21
+  if (colorBy == "No Color"){
22 22
     colorBy <- NULL
23 23
   }
24
-  if(shape == "No Shape"){
24
+  if (shape == "No Shape"){
25 25
     shape <- NULL
26 26
   }
27 27
   l <- pca_df
28
-  if(!is.null(colorBy)){
29
-    l$color <- eval(parse(text = paste("pData(count_data)$",colorBy,sep="")))
28
+  if (!is.null(colorBy)){
29
+    l$color <- eval(parse(text = paste("pData(count_data)$",colorBy,sep = "")))
30 30
   }
31
-  if(!is.null(shape)){
32
-    l$shape <- factor(eval(parse(text = paste("pData(count_data)$",shape,sep=""))))
31
+  if (!is.null(shape)){
32
+    l$shape <- factor(eval(parse(text = paste("pData(count_data)$",shape,sep = ""))))
33 33
   }
34 34
   l$Sample <- rownames(pData(count_data))
35 35
   variances <- attr(pca_df,"percentVar")
36
-  g <- ggplot(l, aes_string(pcX, pcY, label="Sample")) +
37
-       geom_point()+
38
-       labs(x = paste(pcX,toString(round(variances[strtoi(strsplit(pcX,"PC")[[1]][-1])]*100,2)),"%"),y = paste(pcY,toString(round(variances[strtoi(strsplit(pcY,"PC")[[1]][-1])]*100,2)),"%"))
39
-  if(!is.null(colorBy)){
40
-    g <- g + aes_string(color="color") +
36
+  g <- ggplot(l, aes_string(pcX, pcY, label = "Sample")) +
37
+       geom_point() +
38
+       labs(x = paste(pcX,toString(round(variances[strtoi(strsplit(pcX,"PC")[[1]][-1])] * 100,2)),"%"),y = paste(pcY,toString(round(variances[strtoi(strsplit(pcY,"PC")[[1]][-1])] * 100,2)),"%"))
39
+  if (!is.null(colorBy)){
40
+    g <- g + aes_string(color = "color") +
41 41
       labs(color = colorBy)
42 42
   }
43
-  if(!is.null(shape)){
44
-    g <- g + aes_string(shape="shape") +
43
+  if (!is.null(shape)){
44
+    g <- g + aes_string(shape = "shape") +
45 45
       labs(shape = shape)
46 46
   }
47 47
   return(g)
Browse code

Removed excess white space and replaced single quotes with double quotes for consistency

David Jenkins authored on 26/06/2017 18:48:39
Showing1 changed files
... ...
@@ -20,7 +20,7 @@ plotPCA <- function(count_data, pca_df=NULL, colorBy=NULL, shape=NULL, pcX="PC1"
20 20
   }
21 21
   if(colorBy == "No Color"){
22 22
     colorBy <- NULL
23
-  } 
23
+  }
24 24
   if(shape == "No Shape"){
25 25
     shape <- NULL
26 26
   }
... ...
@@ -33,7 +33,7 @@ plotPCA <- function(count_data, pca_df=NULL, colorBy=NULL, shape=NULL, pcX="PC1"
33 33
   }
34 34
   l$Sample <- rownames(pData(count_data))
35 35
   variances <- attr(pca_df,"percentVar")
36
-  g <- ggplot(l, aes_string(pcX, pcY, label="Sample")) + 
36
+  g <- ggplot(l, aes_string(pcX, pcY, label="Sample")) +
37 37
        geom_point()+
38 38
        labs(x = paste(pcX,toString(round(variances[strtoi(strsplit(pcX,"PC")[[1]][-1])]*100,2)),"%"),y = paste(pcY,toString(round(variances[strtoi(strsplit(pcY,"PC")[[1]][-1])]*100,2)),"%"))
39 39
   if(!is.null(colorBy)){
Browse code

Merge remote-tracking branch 'refs/remotes/compbiomed/devel'

# Conflicts:
# inst/shiny/server.R
# inst/shiny/ui.R

stc1 authored on 28/05/2017 21:17:27
Showing0 changed files
Browse code

Major overhall to Clustering Tab (w/ Sebastian)

Emma Briars authored on 26/04/2017 13:02:53
Showing1 changed files
1 1
new file mode 100755
... ...
@@ -0,0 +1,48 @@
1
+
2
+#' Plot PCA
3
+#'   
4
+#' Use this function to plot PCA or tSNE results
5
+#'
6
+#' @param count_data A SCE object
7
+#' @param pca_df PCA data frame
8
+#' @param colorBy The variable to color clusters by
9
+#' @param shape Shape of the points
10
+#' @param pcX User choice for the first principal component
11
+#' @param pcY User choice for the second prinicipal component
12
+#' 
13
+#' @return A PCA plot
14
+#' @export plotPCA
15
+#'
16
+
17
+plotPCA <- function(count_data, pca_df=NULL, colorBy=NULL, shape=NULL, pcX="PC1", pcY="PC2"){
18
+  if(is.null(pca_df)){
19
+    pca_df <- getPCA(count_data)
20
+  }
21
+  if(colorBy == "No Color"){
22
+    colorBy <- NULL
23
+  } 
24
+  if(shape == "No Shape"){
25
+    shape <- NULL
26
+  }
27
+  l <- pca_df
28
+  if(!is.null(colorBy)){
29
+    l$color <- eval(parse(text = paste("pData(count_data)$",colorBy,sep="")))
30
+  }
31
+  if(!is.null(shape)){
32
+    l$shape <- factor(eval(parse(text = paste("pData(count_data)$",shape,sep=""))))
33
+  }
34
+  l$Sample <- rownames(pData(count_data))
35
+  variances <- attr(pca_df,"percentVar")
36
+  g <- ggplot(l, aes_string(pcX, pcY, label="Sample")) + 
37
+       geom_point()+
38
+       labs(x = paste(pcX,toString(round(variances[strtoi(strsplit(pcX,"PC")[[1]][-1])]*100,2)),"%"),y = paste(pcY,toString(round(variances[strtoi(strsplit(pcY,"PC")[[1]][-1])]*100,2)),"%"))
39
+  if(!is.null(colorBy)){
40
+    g <- g + aes_string(color="color") +
41
+      labs(color = colorBy)
42
+  }
43
+  if(!is.null(shape)){
44
+    g <- g + aes_string(shape="shape") +
45
+      labs(shape = shape)
46
+  }
47
+  return(g)
48
+}