diff --git a/routes/rna-star-groups-dge.sh b/routes/rna-star-groups-dge.sh index 5ef1eb3..c22b6bc 100755 --- a/routes/rna-star-groups-dge.sh +++ b/routes/rna-star-groups-dge.sh @@ -138,7 +138,7 @@ sleep 3 ######################### -echo -e "\n ========== test R ========== \n" +echo -e "\n ========== test R environment ========== \n" # load relevant modules module unload java @@ -154,10 +154,9 @@ echo " * Rscript: $(readlink -f $(which Rscript)) " echo " * Rscript version: $(Rscript --version 2>&1) " echo -# test R installation and setting -bash_cmd="Rscript --vanilla ${code_dir}/scripts/test-packages.R" -echo "CMD: $bash_cmd" -($bash_cmd) +Rscript --vanilla ${code_dir}/scripts/test-package.R optparse +Rscript --vanilla ${code_dir}/scripts/test-package.R mnormt +Rscript --vanilla ${code_dir}/scripts/test-package.R limma sleep 3 diff --git a/scripts/dge-deseq2.R b/scripts/dge-deseq2.R index 3a7360f..5d95fe7 100755 --- a/scripts/dge-deseq2.R +++ b/scripts/dge-deseq2.R @@ -28,6 +28,9 @@ genes_gtf = args[1] counts_table_file = args[2] groups_table_file = args[3] +# check for arguments +if (length(args) < 3) stop("not enough arguments provided") + # check that input files exist if (!file.exists(counts_table_file)) stop("file does not exist: ", counts_table_file) if (!file.exists(groups_table_file)) stop("file does not exist: ", groups_table_file) diff --git a/scripts/load-install-packages.R b/scripts/load-install-packages.R index deb01f9..dc8b776 100755 --- a/scripts/load-install-packages.R +++ b/scripts/load-install-packages.R @@ -12,30 +12,17 @@ load_install_packages = function(package_list) { # create local user library path (not present by default) dir.create(path = Sys.getenv("R_LIBS_USER"), showWarnings = FALSE, recursive = TRUE) - # try to install from CRAN if package is not already installed + # try to install using biocLite() (installs both Bioconductor and CRAN packages) # use require() instead of installed.packages() to check that package is both installed and usable - - # biocLite can install CRAN as well - # if (!require(p, character.only = TRUE, quietly = TRUE)) { - # message("try installing package from CRAN: ", p) - # # install to local user library path (destination needs to be specified the first time) - # install.packages(p, lib = Sys.getenv("R_LIBS_USER"), repos = "https://cran.rstudio.com/", quiet = TRUE) - # } - - # try to install from Bioconductor if package is not already installed - # biocLite() installs Bioconductor and CRAN packages if (!require(p, character.only = TRUE, quietly = TRUE)) { - # message("package not available on CRAN: ", p) - # message("try installing package from Bioconductor: ", p) - message("try installing package: ", p) + message("installing package: ", p) source("https://bioconductor.org/biocLite.R") biocLite(p, suppressUpdates = TRUE, lib = Sys.getenv("R_LIBS_USER")) } # package still not available (after CRAN and Bioconductor) if (!require(p, character.only = TRUE, quietly = TRUE)) { - # message("package not available on Bioconductor: ", p) - message("package not available: ", p) + message("package not available on CRAN or Bioconductor: ", p) } # load package diff --git a/scripts/test-package.R b/scripts/test-package.R new file mode 100755 index 0000000..620cde5 --- /dev/null +++ b/scripts/test-package.R @@ -0,0 +1,28 @@ +#!/usr/bin/env Rscript + + +## +## Try loading an R package. Install to local user library if not present. +## +## usage: Rscript --vanilla test-package.R package +## + + +# get scripts directory (directory of this file) and load relevant functions +args_all = commandArgs(trailingOnly = FALSE) +scripts_dir = normalizePath(dirname(sub("^--file=", "", args_all[grep("^--file=", args_all)]))) +source(paste0(scripts_dir, "/load-install-packages.R")) + +# relevent arguments +args = commandArgs(trailingOnly = TRUE) +package_name = args[1] + +# check for arguments +if (length(args) < 1) stop("not enough arguments provided") + +# load relevant packages +load_install_packages(package_name) + + + +# end diff --git a/scripts/test-packages.R b/scripts/test-packages.R index 59aea65..ea4cf87 100755 --- a/scripts/test-packages.R +++ b/scripts/test-packages.R @@ -2,7 +2,7 @@ ## -## Try loading (installing if not available) a few R packages. +## Try loading some common R packages. Install to local user library if not present. ## ## usage: Rscript --vanilla test-packages.R ## @@ -13,7 +13,7 @@ args_all = commandArgs(trailingOnly = FALSE) scripts_dir = normalizePath(dirname(sub("^--file=", "", args_all[grep("^--file=", args_all)]))) source(paste0(scripts_dir, "/load-install-packages.R")) -# load some packages (some will probably need to be installed) +# load some packages (some are rare and will probably need to be installed) # used by GATK: ggplot2, gplots, reshape, gsalib test_packages = c("optparse", "bitops", "mnormt", "reshape", "gplots", "ggplot2", "gsalib", "dplyr", "limma") load_install_packages(test_packages) diff --git a/segments/annot-annovar.sh b/segments/annot-annovar.sh index 262f05b..a579a28 100755 --- a/segments/annot-annovar.sh +++ b/segments/annot-annovar.sh @@ -307,7 +307,7 @@ echo "total muts: $total_muts" coding_muts=$(cat "$annovar_combined" | grep -v 'refGene' | grep 'exon' | wc -l) echo "coding muts: $coding_muts" -nonsyn_muts=$(cat "$annovar_combined" | grep -v 'refGene' | grep -E 'nonsynonymous|stopgain|frameshift' | wc -l) +nonsyn_muts=$(cat "$annovar_combined" | grep -v 'refGene' | grep -E 'nonsynonymous|stopgain|stoploss|frameshift' | wc -l) echo "nonsynonymous muts: $coding_muts" # header for summary file @@ -329,7 +329,10 @@ cat ${summary_dir}/*.${segment_name}.csv | LC_ALL=C sort -t ',' -k1,1 | uniq > " # all mutations combine_all_cmd=" -cat ${annovar_dir}/*.combined.txt | LC_ALL=C sort -k1,1 -k2,2 | uniq > ${annovar_dir}.all.txt +cat ${annovar_dir}/*.combined.txt \ +| LC_ALL=C sort -k1,1 -k2,2 \ +| uniq \ +> ${annovar_dir}.all.txt " echo -e "\n CMD: $combine_all_cmd \n" eval "$combine_all_cmd" @@ -338,7 +341,9 @@ sleep 1 # coding mutations combine_coding_cmd=" -cat ${annovar_dir}.all.txt | grep -E 'refGene|exon|splicing' > ${annovar_dir}.coding.txt +cat ${annovar_dir}.all.txt \ +| grep -E 'refGene|exon|splicing' \ +> ${annovar_dir}.coding.txt " echo -e "\n CMD: $combine_coding_cmd \n" eval "$combine_coding_cmd" @@ -347,7 +352,9 @@ sleep 1 # consequence mutations combine_nonsyn_cmd=" -cat ${annovar_dir}.all.txt | grep -E 'refGene|nonsynonymous|stopgain|splicing|frameshift' > ${annovar_dir}.nonsyn.txt +cat ${annovar_dir}.all.txt \ +| grep -E 'refGene|splicing|nonsynonymous|stopgain|stoploss|frameshift' \ +> ${annovar_dir}.nonsyn.txt " echo -e "\n CMD: $combine_nonsyn_cmd \n" eval "$combine_nonsyn_cmd" diff --git a/segments/fastq-clean.sh b/segments/fastq-clean.sh index e11fdee..57e2654 100755 --- a/segments/fastq-clean.sh +++ b/segments/fastq-clean.sh @@ -12,7 +12,7 @@ echo -e "\n ========== SEGMENT: $segment_name ========== \n" >&2 # check for correct number of arguments if [ ! $# == 2 ] ; then echo -e "\n $script_name ERROR: WRONG NUMBER OF ARGUMENTS SUPPLIED \n" >&2 - echo -e "\n USAGE: $script_name [project dir] [sample name] \n" >&2 + echo -e "\n USAGE: $script_name project_dir sample_name \n" >&2 exit 1 fi