diff scripts/trajectoryinspect.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 4ea021bd7513
children 0bff0ee0683a
line wrap: on
line diff
--- a/scripts/trajectoryinspect.R	Wed Jan 29 17:16:36 2020 -0500
+++ b/scripts/trajectoryinspect.R	Thu Apr 15 18:58:21 2021 +0000
@@ -1,9 +1,9 @@
 #!/usr/bin/env R
-VERSION = "0.2"
+VERSION <- "0.2" # 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,17 +13,17 @@
 source(args[1])
 
 test <- list()
-test$side = 3
-test$line = 2.5
+test$side <- 3
+test$line <- 2.5
 second <- test
-second$cex = 0.5
-second$line = 2.5
+second$cex <- 0.5
+second$line <- 2.5
 
-do.trajectoryinspection.stemID <- function(ltr){
-    makeBranchLink <- function(i,j,k){
-        ingoing <- paste(sort(c(i,j)), collapse=".")
-        outgoing <- paste(sort(c(j,k)), collapse=".")
-        messed <- sort(c(ingoing,outgoing))
+do.trajectoryinspection.stemID <- function(ltr) { # nolint
+    makeBranchLink <- function(i, j, k) { # nolint
+        ingoing <- paste(sort(c(i, j)), collapse = ".")
+        outgoing <- paste(sort(c(j, k)), collapse = ".")
+        messed <- sort(c(ingoing, outgoing))
         return(list(messed[[1]], messed[[2]]))
     }
 
@@ -34,88 +34,99 @@
     )
     write.table(
         head(bra$diffgenes$z, trjsid.numdiffgenes),
-        file=out.diffgenes)
+        file = out.diffgenes)
 
-    par(mfrow = c(2,2), cex=0.5)
-    print(do.call(plotmap, c(bra$scl, final=FALSE, fr=FALSE)))
+    par(mfrow = c(3, 2), cex = 0.5)
+    print(do.call(plotmap, c(bra$scl, final = FALSE, fr = FALSE)))
     print(do.call(mtext, c("Initial Clusters (tSNE)", test)))
-    print(do.call(plotmap, c(bra$scl, final=TRUE, fr=FALSE)))
+    print(do.call(plotmap, c(bra$scl, final = TRUE, fr = FALSE)))
     print(do.call(mtext, c("Final Clusters (tSNE)", test)))
-    print(do.call(plotmap, c(bra$scl, final=FALSE, fr=TRUE)))
+    print(do.call(plotmap, c(bra$scl, final = FALSE, um = TRUE)))
+    print(do.call(mtext, c("Initial Clusters (UMAP)", test)))
+    print(do.call(plotmap, c(bra$scl, final = TRUE, um = TRUE)))
+    print(do.call(mtext, c("Final Clusters (UMAP)", test)))
+    print(do.call(plotmap, c(bra$scl, final = FALSE, fr = TRUE)))
     print(do.call(mtext, c("Initial Clusters (F-R)", test)))
-    print(do.call(plotmap, c(bra$scl, final=TRUE, fr=TRUE)))
+    print(do.call(plotmap, c(bra$scl, final = TRUE, fr = TRUE)))
     print(do.call(mtext, c("Final Clusters (F-R)", test)))
 }
 
-do.trajectoryinspection.fateID <- function(ltr){
+do.trajectoryinspection.fateID <- function(ltr) { # nolint
     n <- do.call(cellsfromtree, c(ltr, trjfid.cellsfrom))
     x <- getfdata(ltr@sc)
 
-    trjfid.filterset$x = x
-    trjfid.filterset$n = n$f
+    trjfid.filterset$x <- x
+    trjfid.filterset$n <- n$f
     fs <- do.call(filterset, c(trjfid.filterset))
-    trjfid.getsom$x = fs
+    trjfid.getsom$x <- fs
     s1d <- do.call(getsom, c(trjfid.getsom))
-    trjfid.procsom$s1d = s1d
+    trjfid.procsom$s1d <- s1d
     ps <- do.call(procsom, c(trjfid.procsom))
 
     y    <- ltr@sc@cpart[n$f]
     fcol <- ltr@sc@fcol
 
-    trjfid.plotheat$xpart = y
-    trjfid.plotheat$xcol = fcol
+    trjfid.plotheat$xpart <- y
+    trjfid.plotheat$xcol <- fcol
+
+    test$side <- 3
+    test$line <- 3
 
     ##Plot average z-score for all modules derived from the SOM:
-    trjfid.plotheat$x = ps$nodes.z
-    trjfid.plotheat$ypart = unique(ps$nodes)
+    trjfid.plotheat$x <- ps$nodes.z
+    trjfid.plotheat$ypart <- unique(ps$nodes)
     print(do.call(plotheatmap, c(trjfid.plotheat)))
-    print(do.call(mtext, c("Average z-score for all modules derived from SOM", test)))
+    print(do.call(mtext, c("Average z-score for all modules derived from SOM",
+                           test)))
     ##Plot z-score profile of each gene ordered by SOM modules:
-    trjfid.plotheat$x = ps$all.z
-    trjfid.plotheat$ypart = ps$nodes
+    trjfid.plotheat$x <- ps$all.z
+    trjfid.plotheat$ypart <- ps$nodes
     print(do.call(plotheatmap, c(trjfid.plotheat)))
-    print(do.call(mtext, c("z-score profile of each gene ordered by SOM modules", test)))
+    print(do.call(mtext, c(paste0("z-score profile of each gene",
+                                  "ordered by SOM modules"), test)))
     ##Plot normalized expression profile of each gene ordered by SOM modules:
-    trjfid.plotheat$x = ps$all.e
-    trjfid.plotheat$ypart = ps$nodes
+    trjfid.plotheat$x <- ps$all.e
+    trjfid.plotheat$ypart <- ps$nodes
     print(do.call(plotheatmap, c(trjfid.plotheat)))
-    print(do.call(mtext, c("Normalized expression profile of each gene ordered by SOM modules", test)))
-    ##Plot binarized expression profile of each gene (z-score < -1, -1 < z-score < 1, z-score > 1):
-    trjfid.plotheat$x = ps$all.b
-    trjfid.plotheat$ypart = ps$nodes
+    print(do.call(mtext, c(paste0("Normalized expression profile of each",
+                                  "gene ordered by SOM modules"), test)))
+    ##Plot binarized expression profile of each gene
+    ##(z-score < -1, -1 < z-score < 1, z-score > 1)
+    trjfid.plotheat$x <- ps$all.b
+    trjfid.plotheat$ypart <- ps$nodes
     print(do.call(plotheatmap, c(trjfid.plotheat)))
     print(do.call(mtext, c("Binarized expression profile of each gene", test)))
     ## This should be written out, and passed back into the tool
     ## to perform sominspect
-    return(list(fs=fs,ps=ps,y=y,fcol=fcol,nf=n$f))
+    return(list(fs = fs, ps = ps, y = y, fcol = fcol, nf = n$f))
 }
 
-do.trajectoryinspection.fateID.sominspect <- function(domo){
+do.trajectoryinspection.fateID.sominspect <- function(domo) { # nolint
     g <- trjfidsomi.use.genes
-    if (class(g) == "numeric"){
+    if (class(g) == "numeric") {
         g <- names(ps$nodes)[ps$nodes %in% g]
     }
 
-    typ = NULL
-    if (!is.null(trjfidsomi.use.types)){
-        typ = sub(trjfidsomi.use.types,"", domo$nf)
+    typ <- NULL
+    if (!is.null(trjfidsomi.use.types)) {
+        typ <- sub(trjfidsomi.use.types, "", domo$nf)
     }
 
-    trjfidsomi$x = domo$fs
-    trjfidsomi$y = domo$y
-    trjfidsomi$g = g
-    trjfidsomi$n = domo$nf
-    trjfidsomi$col = domo$fcol
-    trjfidsomi$types = typ
+    trjfidsomi$x <- domo$fs
+    trjfidsomi$y <- domo$y
+    trjfidsomi$g <- g
+    trjfidsomi$n <- domo$nf
+    trjfidsomi$col <- domo$fcol
+    trjfidsomi$types <- typ
 
     ## The average pseudo-temporal expression profile of this group
     ## can be plotted by the function plotexpression:
-    par(mfrow = c(1,1))
-    test$cex = 1
-    second$line = 1.5
-    if (trjfidsomi$name == "Title") trjfidsomi$name = ""
+    par(mfrow = c(1, 1))
+    test$cex <- 1
+    second$line <- 1.5
+    if (trjfidsomi$name == "Title") trjfidsomi$name <- ""
     print(do.call(plotexpression, c(trjfidsomi)))
-    mess2 <- paste(c(trjfidsomi.use.genes), collapse=", ")
+    mess2 <- paste(c(trjfidsomi.use.genes), collapse = ", ")
     mess1 <- "Average pseudo-temporal expression profile"
     print(do.call(mtext, c(mess1, test)))
     print(do.call(mtext, c(mess2, second)))