# HG changeset patch # User iuc # Date 1575919936 18000 # Node ID 7319f83ae7345a5617397700e25f6c258d0ed437 # Parent 8d8412d35247a7815c32da5c7340dcbc54b7e0a8 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/seurat commit 88cf23c767023f71b4ea1e72aac568cc694cc34a" diff -r 8d8412d35247 -r 7319f83ae734 Seurat.R --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Seurat.R Mon Dec 09 14:32:16 2019 -0500 @@ -0,0 +1,110 @@ +#' --- +#' title: "Seurat Analysis" +#' author: "Performed using Galaxy" +#' params: +#' counts: "" +#' min_cells: "" +#' min_genes: "" +#' low_thresholds: "" +#' high_thresholds: "" +#' numPCs: "" +#' cells_use: "" +#' resolution: "" +#' min_pct: "" +#' logfc_threshold: "" +#' showcode: "" +#' warn: "" +#' varstate: "" +#' vlnfeat: "" +#' featplot: "" +#' PCplots: "" +#' tsne: "" +#' heatmaps: "" +#' --- + +#+ echo=F, warning = F, message=F +options( show.error.messages=F, error = function () { cat( geterrmessage(), file=stderr() ); q( "no", 1, F ) } ) +showcode <- as.logical(params$showcode) +warn <- as.logical(params$warn) +varstate <- as.logical(params$varstate) +vlnfeat <- as.logical(params$vlnfeat) +featplot <- as.logical(params$featplot) +PCplots <- as.logical(params$PCplots) +tsne <- as.logical(params$tsne) +heatmaps <- as.logical(params$heatmaps) + +# we need that to not crash galaxy with an UTF8 error on German LC settings. +loc <- Sys.setlocale("LC_MESSAGES", "en_US.UTF-8") + + +#+ echo = F, warning = `warn`, include =`varstate` +min_cells <- as.integer(params$min_cells) +min_genes <- as.integer(params$min_genes) +low_thresholds <- as.integer(params$low_thresholds) +high_thresholds <- as.integer(params$high_thresholds) +numPCs <- as.integer(params$numPCs) +cells_use <- as.integer(params$cells_use) +resolution <- as.double(params$resolution) +min_pct <- as.double(params$min_pct) +logfc_threshold <- as.double(params$logfc_thresh) +print(paste0("Minimum cells: ", min_cells)) +print(paste0("Minimum features: ", min_genes)) +print(paste0("Umi low threshold: ", low_thresholds)) +print(paste0("Umi high threshold: ", high_thresholds)) +print(paste0("Number of principal components: ", numPCs)) +print(paste0("Resolution: ", resolution)) +print(paste0("Minimum percent of cells", min_pct)) +print(paste0("Logfold change threshold", logfc_threshold)) + +#+ echo = FALSE +if(showcode == TRUE){print("Read in data, generate inital Seurat object")} +#+ echo = `showcode`, warning = `warn`, message = F +counts <- read.delim(params$counts, row.names=1) +seuset <- Seurat::CreateSeuratObject(counts = counts, min.cells = min_cells, min.features = min_genes) + +#+ echo = FALSE +if(showcode == TRUE && vlnfeat == TRUE){print("Raw data vizualization")} +#+ echo = `showcode`, warning = `warn`, include=`vlnfeat` +Seurat::VlnPlot(object = seuset, features = c("nFeature_RNA", "nCount_RNA"), axis="v") +Seurat::FeatureScatter(object = seuset, feature1 = "nCount_RNA", feature2 = "nFeature_RNA") + +#+ echo = FALSE +if(showcode == TRUE){print("Filter and normalize for UMI counts")} +#+ echo = `showcode`, warning = `warn` +seuset <- subset(seuset, subset = `nCount_RNA` > low_thresholds & `nCount_RNA` < high_thresholds) +seuset <- Seurat::NormalizeData(seuset, normalizeation.method = "LogNormalize", scale.factor = 10000) + +#+ echo = FALSE +if(showcode == TRUE && featplot == TRUE){print("Variable Genes")} +#+ echo = `showcode`, warning = `warn`, include = `featplot` +seuset <- Seurat::FindVariableFeatures(object = seuset, selection.method = "mvp") +Seurat::VariableFeaturePlot(seuset, cols = c("black", "red"), selection.method = "disp") +seuset <- Seurat::ScaleData(object = seuset, vars.to.regress = "nCount_RNA") + +#+ echo = FALSE +if(showcode == TRUE && PCplots == TRUE){print("PCA Visualization")} +#+ echo = `showcode`, warning = `warn`, include = `PCplots` +seuset <- Seurat::RunPCA(seuset, npcs=numPCs) +Seurat::VizDimLoadings(seuset, dims = 1:2) +Seurat::DimPlot(seuset, dims = c(1,2), reduction="pca") +Seurat::DimHeatmap(seuset, dims=1:numPCs, nfeatures=30, reduction="pca") +seuset <- Seurat::JackStraw(seuset, dims=numPCs, reduction = "pca", num.replicate = 100) +seuset <- Seurat::ScoreJackStraw(seuset, dims = 1:numPCs) +Seurat::JackStrawPlot(seuset, dims = 1:numPCs) +Seurat::ElbowPlot(seuset, ndims = numPCs, reduction = "pca") + +#+ echo = FALSE +if(showcode == TRUE && tsne == TRUE){print("tSNE")} +#+ echo = `showcode`, warning = `warn`, include = `tsne` +seuset <- Seurat::FindNeighbors(object = seuset) +seuset <- Seurat::FindClusters(object = seuset) +seuset <- Seurat::RunTSNE(seuset, dims = 1:numPCs, resolution = resolution) +Seurat::DimPlot(seuset, reduction="tsne") + +#+ echo = FALSE +if(showcode == TRUE && heatmaps == TRUE){print("Marker Genes")} +#+ echo = `showcode`, warning = `warn`, include = `heatmaps` +markers <- Seurat::FindAllMarkers(seuset, only.pos = TRUE, min.pct = min_pct, logfc.threshold = logfc_threshold) +top10 <- dplyr::group_by(markers, cluster) +top10 <- dplyr::top_n(top10, 10, avg_logFC) +Seurat::DoHeatmap(seuset, features = top10$gene) diff -r 8d8412d35247 -r 7319f83ae734 seurat.R --- a/seurat.R Sun Aug 26 16:24:02 2018 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,116 +0,0 @@ -options( show.error.messages=F, error = function () { cat( geterrmessage(), file=stderr() ); q( "no", 1, F ) } ) - -# we need that to not crash galaxy with an UTF8 error on German LC settings. -loc <- Sys.setlocale("LC_MESSAGES", "en_US.UTF-8") - -suppressPackageStartupMessages({ - library(Seurat) - library(SingleCellExperiment) - library(dplyr) - library(optparse) -}) - -option_list <- list( - make_option(c("-counts","--counts"), type="character", help="Counts file"), - make_option(c("-numPCs","--numPCs"), type="integer", help="Number of PCs to use in plots"), - make_option(c("-min.cells","--min.cells"), type="integer", help="Minimum cells to include"), - make_option(c("-min.genes","--min.genes"), type="integer", help="Minimum genes to include"), - make_option(c("-low.thresholds","--low.thresholds"), type="double", help="Low threshold for filtering cells"), - make_option(c("-high.thresholds","--high.thresholds"), type="double", help="High threshold for filtering cells"), - make_option(c("-x.low.cutoff","--x.low.cutoff"), type="double", help="X-axis low cutoff for variable genes"), - make_option(c("-x.high.cutoff","--x.high.cutoff"), type="double", help="X-axis high cutoff for variable genes"), - make_option(c("-y.cutoff","--y.cutoff"), type="double", help="Y-axis cutoff for variable genes"), - make_option(c("-cells.use","--cells.use"), type="integer", help="Cells to use for PCHeatmap"), - make_option(c("-resolution","--resolution"), type="double", help="Resolution in FindClusters"), - make_option(c("-min.pct","--min.pct"), type="double", help="Minimum percent cells in FindClusters"), - make_option(c("-logfc.threshold","--logfc.threshold"), type="double", help="LogFC threshold in FindClusters"), - make_option(c("-rds","--rds"), type="logical", help="Output Seurat RDS object") - ) - -parser <- OptionParser(usage = "%prog [options] file", option_list=option_list) -args = parse_args(parser) - -counts <- read.delim(args$counts, row.names=1) -seuset <- CreateSeuratObject(raw.data = counts, min.cells = args$min.cells, min.genes = args$min.cells) - -# Open PDF for plots -pdf("out.pdf") - -VlnPlot(object = seuset, features.plot = c("nGene", "nUMI"), nCol = 2) -GenePlot(object = seuset, gene1 = "nUMI", gene2 = "nGene") - -print("Filtering cells") -if (!is.null(args$low.thresholds)){ - lowthresh <- args$low.thresholds -} else { - lowthresh <- "-Inf" -} -if (!is.null(args$high.thresholds)){ - highthresh <- args$high.thresholds -} else { - highthresh <- "Inf" -} -seuset <- FilterCells(object = seuset, subset.names = c("nUMI"), - low.thresholds=c(lowthresh), high.thresholds = c(highthresh)) - -print("Normalizing the data") -seuset <- NormalizeData(object = seuset, normalization.method = "LogNormalize", - scale.factor = 10000) - -print("Finding variable genes") -seuset <- FindVariableGenes(object = seuset, mean.function = ExpMean, - dispersion.function = LogVMR, - x.low.cutoff = args$x.low.cutoff, - x.high.cutoff = args$x.high.cutoff,, - y.cutoff = args$y.cutoff -) - -print("Scaling the data and removing unwanted sources of variation") -seuset <- ScaleData(object = seuset, vars.to.regress = c("nUMI")) - -print("Performing PCA analysis") -seuset <- RunPCA(object = seuset, pc.genes = seuset@var.genes) -VizPCA(object = seuset, pcs.use = 1:2) -PCAPlot(object = seuset, dim.1 = 1, dim.2 = 2) -PCHeatmap( - object = seuset, - pc.use = 1:args$numPCs, - cells.use = args$cell.use, - do.balanced = TRUE, - label.columns = FALSE, - use.full = FALSE -) - -print("Determining statistically significant principal components") -seuset <- JackStraw(object = seuset, num.replicate = 100, display.progress= FALSE) -JackStrawPlot(object = seuset, PCs = 1:args$numPCs) -PCElbowPlot(object = seuset) - -print("Clustering the cells") -seuset <- FindClusters( - object = seuset, - reduction.type = "pca", - dims.use = 1:args$numPCs, - resolution = args$resolution, - print.output = 0, - save.SNN = TRUE -) - -print("Running non-linear dimensional reduction (tSNE)") -seuset <- RunTSNE(object = seuset, dims.use = 1:args$numPCs, do.fast = TRUE) -TSNEPlot(object = seuset) - -print("Finding differentially expressed genes (cluster biomarkers)") -markers <- FindAllMarkers(object = seuset, only.pos = TRUE, min.pct = args$min.pct, - logfc.threshold = args$logfc.threshold) -top10 <- markers %>% group_by(cluster) %>% top_n(10, avg_logFC) -DoHeatmap(object = seuset, genes.use = top10$gene, slim.col.label = TRUE, remove.key = TRUE) - -# Close PDF for plots -dev.off() - -if (!is.null(args$rds) ) { - saveRDS(seuset, "Seurat.rds") -} - -sessionInfo() \ No newline at end of file diff -r 8d8412d35247 -r 7319f83ae734 seurat.xml --- a/seurat.xml Sun Aug 26 16:24:02 2018 -0400 +++ b/seurat.xml Mon Dec 09 14:32:16 2019 -0500 @@ -1,111 +1,111 @@ - toolkit for exploration of single-cell RNA-seq data - r-base - r-seurat - bioconductor-singlecellexperiment - r-optparse + r-seurat + r-rmarkdown - /dev/null | grep -v -i "WARNING: ")", SingleCellExperiment version" $(R --vanilla --slave -e "library(SingleCellExperiment); cat(sessionInfo()\$otherPkgs\$SingleCellExperiment\$Version)" 2> /dev/null | grep -v -i "WARNING: ")", optparse version" $(R --vanilla --slave -e "library(optparse); cat(sessionInfo()\$otherPkgs\$optparse\$Version)" 2> /dev/null | grep -v -i "WARNING: ") - ]]> - +Rscript -e "library(\"rmarkdown\"); render(\"$__tool_directory__/Seurat.R\", + params = list(counts = \"${counts}\", + min_cells = \"${adv.min_cells}\", + min_genes = \"${adv.min_genes}\", + low_thresholds = \"${adv.low_thresholds}\", + high_thresholds = \"${adv.high_thresholds}\", + numPCs = \"${adv.num_PCs}\", + cells_use = \"${adv.cells_use}\", + resolution = \"${adv.resolution}\", + min_pct = \"${adv.min_pct}\", + logfc_threshold = \"${adv.logfc_threshold}\", + warn = \"${meta.warn}\", + varstate = \"${meta.varstate}\", + showcode = \"${meta.showcode}\", + vlnfeat = \"$vln\", + featplot = \"$feat\", + PCplots = \"$PCs\", + tsne = \"$tsne\", + heatmaps = \"$heatmaps\"), + intermediates_dir = \".\", + output_format = html_document(), + output_dir = \".\", + output_file = \"out.html\")" + ]]> - - - - -
- - - - - - - - - - - - +
+ + + + + + + + +
+
+ + + + + + + + + + +
- - - - rscript - - - rds - + - - - - - - - - - - - - - - - + +
+ + + + + + + + + +
+
+ + + + +
+
+ + + + + + + + + + + + + + + +Seurat Analysis + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
## [1] "Read in data, generate inital Seurat object"
+
counts <- read.delim(params$counts, row.names=1)
+seuset <- Seurat::CreateSeuratObject(counts = counts, min.cells = min_cells, min.features = min_genes)
+
## [1] "Filter and normalize for UMI counts"
+
seuset <- subset(seuset, subset = `nCount_RNA` > low_thresholds & `nCount_RNA` < high_thresholds)
+seuset <- Seurat::NormalizeData(seuset, normalizeation.method = "LogNormalize", scale.factor = 10000)
+
## [1] "Variable Genes"
+
seuset <- Seurat::FindVariableFeatures(object = seuset, selection.method = "mvp")
+Seurat::VariableFeaturePlot(seuset, cols = c("black", "red"), selection.method = "disp")
+

+
seuset <- Seurat::ScaleData(object = seuset, vars.to.regress = "nCount_RNA")
+
## Regressing out nCount_RNA
+
## Centering and scaling data matrix
+ + + + +
+ + + + + + + + + + + + + + + diff -r 8d8412d35247 -r 7319f83ae734 test-data/out.pdf Binary file test-data/out.pdf has changed