Mercurial > repos > youyuh48 > sleuth
changeset 3:172091d47f5a draft default tip
planemo upload for repository https://github.com/youyuh48/galaxy-sleuth/tree/master/ commit 8d9ff6181e933951e015e67f1719588bab2b3ab5-dirty
author | youyuh48 |
---|---|
date | Tue, 12 Jun 2018 17:58:47 -0400 |
parents | a049d0d5a05e |
children | |
files | r-sleuth.R r-sleuth.xml sleuth.R sleuth.xml test-data/SRR1867792.h5 test-data/SRR1909613.h5 test-data/SRR1909637.h5 test-data/metadata.txt |
diffstat | 4 files changed, 184 insertions(+), 166 deletions(-) [+] |
line wrap: on
line diff
--- a/r-sleuth.R Fri Dec 08 22:15:41 2017 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,87 +0,0 @@ -#!/usr/bin/env Rscript - -# A command-line interface to sleuth for use with Galaxy -# This script modified from -# https://github.com/pachterlab/bears_analyses/blob/master/sleuth.R - -# setup R error handling to go to stderr -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") - -library("getopt") -library("tools") -options(stringAsFactors = FALSE, useFancyQuotes = FALSE) -args <- commandArgs(trailingOnly = TRUE) - -# get options, using the spec as defined by the enclosed list. -spec <- matrix(c( - "quiet", "q", 0, "logical", - "help", "h", 0, "logical", - "indir", "i", 1, "character", - "metadata", "m", 1, "character", - "full_model", "f", 1, "character", - "reduced_model", "r", 1, "character", - "gene_anno_name", "a", 2, "character" - ), byrow=TRUE, ncol=4) -opt <- getopt(spec) - -# if help was asked for print a friendly message -# and exit with a non-zero error code -if (!is.null(opt$help)) { - cat(getopt(spec, usage=TRUE)) - q(status=1) -} - -# enforce the following required arguments -if (is.null(opt$indir)) { - cat("'indir' is required\n") - q(status=1) -} -if (is.null(opt$metadata)) { - cat("'metadata' is required\n") - q(status=1) -} -if (is.null(opt$full_model)) { - cat("'full_model' is required\n") - q(status=1) -} -if (is.null(opt$reduced_model)) { - cat("'reduced_model' is required\n") - q(status=1) -} - -verbose <- if (is.null(opt$quiet)) { - TRUE -} else { - FALSE -} - -suppressPackageStartupMessages({ - library("sleuth") - library("biomaRt") -}) - -s2c <- read.table(file.path(opt$metadata), header = TRUE, stringsAsFactors=FALSE) -run_dirs <- s2c$sample -kal_dirs <- c() - -for (dir in run_dirs) { - kal_dirs <- c(kal_dirs, file.path(opt$indir, dir, "kallisto")) -} - -s2c <- dplyr::mutate(s2c, path = kal_dirs) - -if (!is.null(opt$gene_anno_name)) { - mart <- biomaRt::useMart(biomart = "ensembl", dataset = opt$gene_anno_name) - t2g <- biomaRt::getBM(attributes = c("ensembl_transcript_id", "ensembl_gene_id", "external_gene_name"), mart = mart) - t2g <- dplyr::rename(t2g, target_id = ensembl_transcript_id, ens_gene = ensembl_gene_id, ext_gene = external_gene_name) - so <- sleuth_prep(s2c, as.formula(opt$full_model), target_mapping = t2g, read_bootstrap_tpm=TRUE, extra_bootstrap_summary=TRUE) -} else { - so <- sleuth_prep(s2c, as.formula(opt$full_model), read_bootstrap_tpm=TRUE, extra_bootstrap_summary=TRUE) -} -so <- sleuth_fit(so, as.formula(opt$full_model), "full") -so <- sleuth_fit(so, as.formula(opt$reduced_model), "reduced") -so <- sleuth_lrt(so, "reduced", "full") -sleuth_deploy(so, opt$indir)
--- a/r-sleuth.xml Fri Dec 08 22:15:41 2017 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,79 +0,0 @@ -<tool id="r-sleuth" name="r-sleuth" version="0.29.0"> - <description>Sleuth is an R library for analysis of RNA-Seq experiments for which transcript abundances have been quantified with kallisto.</description> - <requirements> - <requirement type="package" version="1.20.0">r-getopt</requirement> - <requirement type="package" version="0.29.0">r-sleuth</requirement> - <requirement type="package" version="2.34.0">bioconductor-biomart</requirement> - </requirements> - <version_command> - <![CDATA[ - echo $(R --version | grep version | grep -v GNU)", r-sleuth version" $(R --vanilla --slave -e "library(sleuth); cat(sessionInfo()\$otherPkgs\$sleuth\$Version)" 2> /dev/null | grep -v -i "WARNING: ") - ]]> - </version_command> - <command detect_errors="aggressive"> - <![CDATA[ - #import re - ## create symlinks to input datasets - #for $file in $input_files - #set $sname = re.sub('\.h5$', '', str($file.element_identifier)) - mkdir -p 'data/${sname}/kallisto' && - ln -s '$file' 'data/${sname}/kallisto/abundance.h5' && - #end for - - Rscript '${__tool_directory__}/r-sleuth.R' - --indir 'data' - --metadata '$metadata' - --full_model '~${full_model}' - --reduced_model '~${reduced_model}' - --gene_anno_name 'hsapiens_gene_ensembl' && - tar zcvf sleuth_shiny.tar.gz data/app.R data/so.rds - ]]> - </command> - <inputs> - <param name="input_files" type="data" format="h5" label="Select Abundance(HDF5) Datasets" min="2" multiple="True"/> - <param name="metadata" type="data" format="txt,tsv,tabular" label="Metadata file"/> - <param name="full_model" type="text" value="condition" label="Full model"/> - <param name="reduced_model" type="text" value="1" label="Reduced model"/> - <param name="gene_anno_name" type="select" label="BioMart dataset"> - <option value="hsapiens_gene_ensembl" selected="true">homo_sapiens</option> - </param> - </inputs> - <outputs> - <data name="output" format="tar" label="${tool.name} on ${on_string}: R Shiny app" from_work_dir="sleuth_shiny.tar.gz"/> - </outputs> - <tests> - <test> - <param name="input_files" value="SRR1867792.h5,SRR1909613.h5,SRR1909637.h5"/> - <param name="metadata" value="metadata.txt"/> - <output name="output" file="sleuth_shiny.tar.gz" ftype="tar"/> - </test> - </tests> - <help> -<![CDATA[ -This is a Galaxy wrapper for the Sleuth package. - -**Input file format of metadata** - -sample condition ---------------------- -SRR1867792 ESC -SRR1909613 BM-MSC -SRR1909637 BM-MSC - -**Output** - -This wrapper script generates Shiny web application files for RStudio. -Unzip sleuth_shiny.tar.gz file, then run app.R file in RStudio. -]]> - </help> - <citations> - <citation type="bibtex"> - @misc{githubsleuth, - title = {sleuth}, - publisher = {GitHub}, - journal = {GitHub repository}, - url = {https://pachterlab.github.io/sleuth/}, - } - </citation> - </citations> -</tool>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sleuth.R Tue Jun 12 17:58:47 2018 -0400 @@ -0,0 +1,101 @@ +#!/usr/bin/env Rscript + +# A command-line interface to sleuth for use with Galaxy This script modified +# from https://github.com/pachterlab/bears_analyses/blob/master/sleuth.R +# https://github.com/nturaga/bioc-galaxy-integration/blob/master/README.md + +## Command to run tool: +## Rscript sleuth.R --indir test-rscript --metadata test-rscript/metadata.txt +## --full_model '~condition' --reduced_model '~1' +## --gene_anno_name 'hsapiens_gene_ensembl' + +# setup R error handling to go to stderr +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") + +library("getopt") +library("tools") +options(stringAsFactors = FALSE, useFancyQuotes = FALSE) +args <- commandArgs(trailingOnly = TRUE) + +# get options, using the spec as defined by the enclosed list. +spec <- matrix(c( + "quiet", "q", 0, "logical", + "help", "h", 0, "logical", + "indir", "i", 1, "character", + "metadata", "m", 1, "character", + "full_model", "f", 1, "character", + "reduced_model", "r", 1, "character", + "gene_anno_name", "a", 2, "character"), + byrow = TRUE, ncol = 4) +opt <- getopt(spec) + +# if help was asked for print a friendly message and exit with a non-zero error +# code +if (!is.null(opt$help)) { + cat(getopt(spec, usage = TRUE)) + q(status = 1) +} + +# enforce the following required arguments +if (is.null(opt$indir)) { + cat("'indir' is required\n") + q(status = 1) +} +if (is.null(opt$metadata)) { + cat("'metadata' is required\n") + q(status = 1) +} +if (is.null(opt$full_model)) { + cat("'full_model' is required\n") + q(status = 1) +} +if (is.null(opt$reduced_model)) { + cat("'reduced_model' is required\n") + q(status = 1) +} + +verbose <- if (is.null(opt$quiet)) { + TRUE +} else { + FALSE +} + +suppressPackageStartupMessages({ + library("sleuth") + library("biomaRt") +}) + +s2c <- read.table(file.path(opt$metadata), header = TRUE, stringsAsFactors = FALSE) +run_dirs <- s2c$sample +kal_dirs <- c() + +for (dir in run_dirs) { + kal_dirs <- c(kal_dirs, file.path(opt$indir, dir, "kallisto")) +} + +s2c <- dplyr::mutate(s2c, path = kal_dirs) + +if (!is.null(opt$gene_anno_name)) { + mart <- biomaRt::useMart(biomart = "ensembl", dataset = opt$gene_anno_name) + t2g <- biomaRt::getBM(attributes = c("ensembl_transcript_id", "ensembl_gene_id", + "external_gene_name"), mart = mart) + t2g <- dplyr::rename(t2g, target_id = ensembl_transcript_id, ens_gene = ensembl_gene_id, + ext_gene = external_gene_name) + so <- sleuth_prep(s2c, as.formula(opt$full_model), target_mapping = t2g, read_bootstrap_tpm = TRUE, + extra_bootstrap_summary = TRUE) +} else { + so <- sleuth_prep(s2c, as.formula(opt$full_model), read_bootstrap_tpm = TRUE, + extra_bootstrap_summary = TRUE) +} +so <- sleuth_fit(so, as.formula(opt$full_model), "full") +so <- sleuth_fit(so, as.formula(opt$reduced_model), "reduced") +so <- sleuth_lrt(so, "reduced", "full") +sleuth_deploy(so, opt$indir) + +cat("Successfully finished script.\n")
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sleuth.xml Tue Jun 12 17:58:47 2018 -0400 @@ -0,0 +1,83 @@ +<tool id="sleuth" name="sleuth" version="0.30.0"> + <description>Sleuth is an R library for analysis of RNA-Seq experiments for which transcript abundances have been quantified with kallisto.</description> + <requirements> + <container type="docker">youyuh48/sleuth:0.30.0</container> + </requirements> + <version_command> + <![CDATA[ + echo $(R --version | grep version | grep -v GNU)", r-sleuth version" $(R --vanilla --slave -e "library(sleuth); cat(sessionInfo()\$otherPkgs\$sleuth\$Version)" 2> /dev/null | grep -v -i "WARNING: ") + ]]> + </version_command> + <command detect_errors="aggressive"> + <![CDATA[ + #import re + ## create symlinks to input datasets + #for $file in $input_files + #set $sname = re.sub('\.h5$', '', str($file.element_identifier)) + mkdir -p 'data/${sname}/kallisto' && + ln -s '$file' 'data/${sname}/kallisto/abundance.h5' && + #end for + + Rscript '${__tool_directory__}/sleuth.R' + --indir 'data' + --metadata '$metadata' + --full_model '~${full_model}' + --reduced_model '~${reduced_model}' + #if $anno.biomart == "Yes" + --gene_anno_name '$anno.gene_anno_name' + #end if + && tar zcvf sleuth_shiny.tar.gz data/app.R data/so.rds + ]]> + </command> + <inputs> + <param name="input_files" type="data" format="h5" label="Select Abundance(HDF5) Datasets" min="2" multiple="True"/> + <param name="metadata" type="data" format="txt,tsv,tabular" label="Metadata file"/> + <param name="full_model" type="text" value="condition" label="Full model"/> + <param name="reduced_model" type="text" value="1" label="Reduced model"/> + <conditional name="anno"> + <param name="biomart" type="select" label="Use BioMart?" help=""> + <option value="Yes">Yes</option> + <option value="No">No</option> + </param> + <when value="Yes"> + <param name="gene_anno_name" type="select" label="BioMart dataset"> + <option value="hsapiens_gene_ensembl" selected="true">homo_sapiens</option> + </param> + </when> + <when value="No"></when> + </conditional> + </inputs> + <outputs> + <data name="output" format="tar" label="${tool.name} on ${on_string}: R Shiny app" from_work_dir="sleuth_shiny.tar.gz"/> + </outputs> + <tests> + <test> + <param name="input_files" value="SRR1867792.h5,SRR1909613.h5,SRR1909637.h5"/> + <param name="metadata" value="metadata.txt"/> + <output name="output" file="sleuth_shiny.tar.gz" ftype="tar"/> + </test> + </tests> + <help> + <![CDATA[ +This is a Galaxy wrapper for the Sleuth package. + +**Input file format of metadata** + +sample condition +--------------------- +SRR1867792 ESC +SRR1909613 BM-MSC +SRR1909637 BM-MSC + +**Output** + +This wrapper script generates Shiny web application files for RStudio. +Unzip sleuth_shiny.tar.gz file, then run app.R file in RStudio. +]]> + </help> + <citations> + <citation type="bibtex"> + @misc{githubsleuth, title = {sleuth}, publisher = {GitHub}, journal = {GitHub repository}, url = {https://pachterlab.github.io/sleuth/}, } + </citation> + </citations> +</tool>