diff scripts/clusterinspect.R @ 6:a4b734cd253b draft

"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/raceid3 commit 53916f6803b93234f992f5fd4fad61d7013d82af"
author iuc
date Thu, 15 Apr 2021 18:58:21 +0000
parents ee0bbc160cb1
children 0bff0ee0683a
line wrap: on
line diff
--- a/scripts/clusterinspect.R	Wed Jan 29 17:16:36 2020 -0500
+++ b/scripts/clusterinspect.R	Thu Apr 15 18:58:21 2021 +0000
@@ -1,9 +1,9 @@
 #!/usr/bin/env R
-VERSION = "0.5"
+VERSION <- "0.5"  # nolint
 
-args = commandArgs(trailingOnly = T)
+args <- commandArgs(trailingOnly = T)
 
-if (length(args) != 1){
+if (length(args) != 1) {
      message(paste("VERSION:", VERSION))
      stop("Please provide the config file")
 }
@@ -13,117 +13,124 @@
 
 ## layout
 test <- list()
-test$side = 3
-test$line = 3
+test$side <- 3
+test$line <- 3
 
-do.plotting <- function(sc){
+do.plotting <- function(sc) { # nolint
 
-    sc.tmp <- sc
+    sc_tmp <- sc
 
     ## If it's a subset, we need to get clever and subset specific parts
-    if (!(is.null(plotting.cln) || is.na(plotting.cln))){
-        cellstokeep <- names(sc.tmp@cpart[sc.tmp@cpart %in% plotting.cln])
+    if (!(is.null(plotting.cln) || is.na(plotting.cln))) {
+        cellstokeep <- names(sc_tmp@cpart[sc_tmp@cpart %in% plotting.cln])
 
         ## Subselect partitions for initial and final clusters
-        sc.tmp@cpart <- sc.tmp@cpart[cellstokeep]
-        sc.tmp@cluster$kpart <- sc.tmp@cluster$kpart[cellstokeep]
+        sc_tmp@cpart <- sc_tmp@cpart[cellstokeep]
+        sc_tmp@cluster$kpart <- sc_tmp@cluster$kpart[cellstokeep]
 
         ## Subselect tSNE and FR data
-        ## - Note: no names in tsne, so we assume it follows the ndata naming
-        sc.tmp@tsne <- sc.tmp@tsne[colnames(sc.tmp@ndata) %in% cellstokeep,]
-        sc.tmp@fr <- sc.tmp@fr[cellstokeep,]
+        sc_tmp@tsne <- sc_tmp@tsne[colnames(sc_tmp@ndata) %in% cellstokeep, ]
+        sc_tmp@umap <- sc_tmp@umap[colnames(sc_tmp@ndata) %in% cellstokeep, ]
+        sc_tmp@fr <- sc_tmp@fr[cellstokeep, ]
     }
 
-    print(plotmap(sc.tmp, final = FALSE, fr = FALSE))
+    print(plotmap(sc_tmp, final = FALSE, fr = FALSE))
     print(do.call(mtext, c("Initial Clustering tSNE", test)))
-    print(plotmap(sc.tmp, final = TRUE, fr = FALSE))
+    print(plotmap(sc_tmp, final = TRUE, fr = FALSE))
     print(do.call(mtext, c("Final Clustering tSNE", test)))
-    print(plotmap(sc.tmp, final = FALSE, fr = TRUE))
+    print(plotmap(sc_tmp, final = FALSE, um = TRUE))
+    print(do.call(mtext, c("Initial Clustering UMAP", test)))
+    print(plotmap(sc_tmp, final = TRUE, um = TRUE))
+    print(do.call(mtext, c("Final Clustering UMAP", test)))
+    print(plotmap(sc_tmp, final = FALSE, fr = TRUE))
     print(do.call(mtext, c("Initial Clustering Fruchterman-Reingold", test)))
-    print(plotmap(sc.tmp, final = TRUE, fr = TRUE))
+    print(plotmap(sc_tmp, final = TRUE, fr = TRUE))
     print(do.call(mtext, c("Final Clustering Fruchterman-Reingold", test)))
 }
 
 
-do.inspect.symbolmap <- function(sc){
-    if (!is.null(plotsym.use.typeremoveregex)){
-        plotsym$types = sub(plotsym.use.typeremoveregex, "", colnames(sc@ndata))
+do.inspect.symbolmap <- function(sc) {  # nolint
+    if (!is.null(plotsym.use.typeremoveregex)) {
+        plotsym$types <- sub(plotsym.use.typeremoveregex, "",
+                             colnames(sc@ndata))
 
-        if (!is.null(plotsym.use.typeremoveregex.subselect)){
-            plotsym$subset = plotsym$types[grep(plotsym.use.typeremoveregex.subselect, plotsym$types)]
+        if (!is.null(plotsym.use.typeremoveregex.subselect)) {
+            plotsym$subset <- plotsym$types[grep(
+                                          plotsym.use.typeremoveregex.subselect,
+                                          plotsym$types)]
         }
     }
-    plotsym$fr = FALSE
+    plotsym$fr <- FALSE
     print(do.call(plotsymbolsmap, c(sc, plotsym)))
     print(do.call(mtext, c("Symbols tSNE", test)))
-    plotsym$fr = TRUE
+    plotsym$fr <- TRUE
     print(do.call(plotsymbolsmap, c(sc, plotsym)))
     print(do.call(mtext, c("Symbols FR", test)))
 }
 
-do.inspect.diffgene <- function(sc){
+do.inspect.diffgene <- function(sc) {  # nolint
 
-    getSubNames <- function(lob, sc){
-        use.names <- NULL
-        if (!is.null(lob$manual)){
-            use.names <- lob$manual
+    getSubNames <- function(lob, sc) {  # nolint
+        use_names <- NULL
+        if (!is.null(lob$manual)) {
+            use_names <- lob$manual
         }
-        else if (!is.null(lob$regex)){
+        else if (!is.null(lob$regex)) {
             nm <- colnames(sc@ndata)
-            use.names <- nm[grep(lob$regex, nm)]
+            use_names <- nm[grep(lob$regex, nm)]
         }
-        else if (!is.null(lob$cln)){
-            use.names <- names(sc@cpart)[sc@cpart %in% lob$cln]
+        else if (!is.null(lob$cln)) {
+            use_names <- names(sc@cpart)[sc@cpart %in% lob$cln]
         }
-        if (is.null(use.names)){
+        if (is.null(use_names)) {
             stop("A or B names not given!")
         }
-        return(use.names)
+        return(use_names)
     }
 
-    A <- getSubNames(gfdat.A.use, sc)
-    B <- getSubNames(gfdat.B.use, sc)
+    A <- getSubNames(gfdat.A.use, sc) # nolint
+    B <- getSubNames(gfdat.B.use, sc) # nolint
 
-    fdat <- getfdata(sc, n=c(A,B))
-    dexp <- diffexpnb(fdat, A=A, B=B)
+    fdat <- getfdata(sc, n = c(A, B))
+    dexp <- diffexpnb(fdat, A = A, B = B)
     ## options for diffexpnb are mostly about DESeq, ignore
-    plotdiffg$x = dexp
+    plotdiffg$x <- dexp
     print(do.call(plotdiffgenesnb, c(plotdiffg)))
     print(do.call(mtext, c("Diff Genes", test)))
 }
 
 
-do.inspect.genesofinterest <- function(sc){
-    if (is.null(plotexp$n)){ ## No title, and one gene? Use gene name
-        if (length(plotexp$g) == 1){
+do.inspect.genesofinterest <- function(sc) {  # nolint
+    if (is.null(plotexp$n)) { ## No title, and one gene? Use gene name
+        if (length(plotexp$g) == 1) {
             plotexp$n <- plotexp$g
         } else {
-            plotexp$n <- paste(plotexp$g, collapse=", ")
+            plotexp$n <- paste(plotexp$g, collapse = ", ")
         }
     }
 
     title <- paste(":", plotexp$n)
     plotexp$n <- ""
 
-    plotexp$logsc=FALSE; plotexp$fr = FALSE
+    plotexp$logsc <- FALSE; plotexp$fr <- FALSE
     print(do.call(plotexpmap, c(sc, plotexp)))
     print(do.call(mtext, c(paste("tSNE", title), test)))
 
-    plotexp$logsc=TRUE; plotexp$fr = FALSE
+    plotexp$logsc <- TRUE; plotexp$fr <- FALSE
     print(do.call(plotexpmap, c(sc, plotexp)))
     print(do.call(mtext, c(paste("tSNE (Log)", title), test)))
 
-    plotexp$logsc=FALSE; plotexp$fr = TRUE
+    plotexp$logsc <- FALSE; plotexp$fr <- TRUE
     print(do.call(plotexpmap, c(sc, plotexp)))
     print(do.call(mtext, c(paste("FR", title), test)))
 
-    plotexp$logsc=TRUE; plotexp$fr = TRUE
+    plotexp$logsc <- TRUE; plotexp$fr <- TRUE
     print(do.call(plotexpmap, c(sc, plotexp)))
     print(do.call(mtext, c(paste("FR (Log)", title), test)))
 
-    if (!is.null(plotmarkg$samples)){
+    if (!is.null(plotmarkg$samples)) {
         reg <- plotmarkg$samples
-        plotmarkg$samples <- sub("(\\_\\d+)$","", colnames(sc@ndata))
+        plotmarkg$samples <- sub("(\\_\\d+)$", "", colnames(sc@ndata))
     }
     print(do.call(plotmarkergenes, c(sc, plotmarkg)))
 }