From 75f13e71f4c67ef363b0e955efc1cb5975aff0c4 Mon Sep 17 00:00:00 2001 From: Mischa ter Smitten Date: Sun, 24 Apr 2016 23:00:15 +0200 Subject: [PATCH] Add bioconductor install functionality --- README.md | 7 ++++++- defaults/main.yml | 3 +++ meta/main.yml | 3 +++ tasks/install.yml | 4 ++-- tasks/packages.yml | 16 +++++++++++---- tasks/repository.yml | 2 +- templates/usr/local/bin/R-install-package.j2 | 21 +++++++++++++++----- tests/test.retry | 1 + tests/test.yml | 3 +++ vars/main.yml | 1 + 10 files changed, 48 insertions(+), 13 deletions(-) create mode 100644 tests/test.retry diff --git a/README.md b/README.md index f84dcec..4300bf2 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,8 @@ Set up the latest version of R in Ubuntu systems. #### Variables * `r_cran mirror`: [default: `http://cran.rstudio.com/`]: Your favorite [CRAN mirror](http://cran.r-project.org/mirrors.html) +* `r_bioclite_url`: [default: `https://bioconductor.org/biocLite.R`]: The `biocLite.R` script URL for [Bioconductor](http://bioconductor.org/) installs + * `r_install_dev`: [default: `false`]: Whether or not install the `r-base-dev` package * `r_install`: [default: `[]`]: Additional (apt) packages to install (e.g. `r-recommended`) @@ -20,6 +22,7 @@ Set up the latest version of R in Ubuntu systems. * `r_packages`: [default: `[]`]: (CRAN) Packages to install or remove * `r_packages.{n}.name`: [required]: The name of the package * `r_packages.{n}.state`: [optional, default: `present`]: The state of the package +* `r_packages.{n}.type`: [optional, default: `cran`]: The type of the package (e.g. `bioconductor`) * `r_packages.{n}.lib`: [optional, default: `r_packages_lib`]: The library directory to install the package to * `r_packages.{n}.repos`: [optional, default: `r_packages_repos`]: The URL to install the package from @@ -50,9 +53,11 @@ None # apt packages r_install: - r-recommended - # cran-r packages + # cran or bioconductor (R) packages r_packages: - name: dplyr + - name: Biobase + type: bioconductor ``` #### License diff --git a/defaults/main.yml b/defaults/main.yml index 20ae948..35b6142 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,9 +1,12 @@ # defaults file for r --- r_cran_mirror: http://cran.rstudio.com/ +r_bioclite_url: https://bioconductor.org/biocLite.R + r_install_dev: false r_install: [] +r_packages_type: cran r_packages_repos: "{{ r_cran_mirror }}" r_packages_lib: /usr/local/lib/R/site-library r_packages: [] diff --git a/meta/main.yml b/meta/main.yml index 89dd29b..a5dc395 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -13,4 +13,7 @@ galaxy_info: - trusty galaxy_tags: - system + - r + - cran-r + - statistics dependencies: [] diff --git a/tasks/install.yml b/tasks/install.yml index cc6e5fd..cba9e78 100644 --- a/tasks/install.yml +++ b/tasks/install.yml @@ -6,7 +6,7 @@ state: latest update_cache: true cache_valid_time: "{{ apt_update_cache_valid_time | default(3600) }}" - with_items: r_dependencies + with_items: "{{ r_dependencies }}" when: "item | trim != ''" tags: - r-install-dependencies @@ -15,6 +15,6 @@ apt: name: "{{ item }}" state: latest - with_items: r_install + with_items: "{{ r_install }}" tags: - r-install-additional diff --git a/tasks/packages.yml b/tasks/packages.yml index 68d6212..9a99254 100644 --- a/tasks/packages.yml +++ b/tasks/packages.yml @@ -14,19 +14,27 @@ dest: R-remove-package - name: packages | install - command: "R-install-package {{ item.name }}{% if item.lib is defined %} {{ item.lib }}{% endif %}{% if item.repos is defined %} {{ item.repos }}{% endif %}" + command: > + R-install-package + {{ item.name }} + {{ item.type | default(r_packages_type) }} + {% if item.lib is defined %}{{ item.lib }}{% endif %} + {% if item.repos is defined %}{{ item.repos }}{% endif %} register: r_install_package changed_when: "r_install_package.stdout_lines[-1] is defined and r_install_package.stdout_lines[-1] == 'changed'" - with_items: r_packages + with_items: "{{ r_packages }}" when: item.state is undefined or item.state == 'present' tags: - r-packages-install - name: packages | remove - command: "R-remove-package {{ item.name }}{% if item.lib is defined %} {{ item.lib }}{% endif %}" + command: > + R-remove-package + {{ item.name }} + {% if item.lib is defined %}{{ item.lib }}{% endif %} register: r_remove_package changed_when: "r_remove_package.stdout_lines[-1] is defined and r_remove_package.stdout_lines[-1] == 'changed'" - with_items: r_packages + with_items: "{{ r_packages }}" when: item.state is defined and item.state == 'absent' tags: - r-packages-remove diff --git a/tasks/repository.yml b/tasks/repository.yml index 42df405..d90e5ac 100644 --- a/tasks/repository.yml +++ b/tasks/repository.yml @@ -13,6 +13,6 @@ repo: "{{ item.type }} {{ item.url }}" state: present update_cache: true - with_items: r_repository + with_items: "{{ r_repository }}" tags: - r-repository-add diff --git a/templates/usr/local/bin/R-install-package.j2 b/templates/usr/local/bin/R-install-package.j2 index 14db6b1..a6e7251 100644 --- a/templates/usr/local/bin/R-install-package.j2 +++ b/templates/usr/local/bin/R-install-package.j2 @@ -1,16 +1,27 @@ #!/usr/bin/env r if (is.null(argv) | length(argv) < 1) { - cat("Usage: R-install-package package [lib] [repos]\n"); + cat("Usage: R-install-package package [type] [lib] [repos]\n"); q(status = 1); } package = argv[1] -lib = ifelse(is.na(argv[2]), '{{ r_packages_lib }}', argv[2]); -repos = ifelse(is.na(argv[3]), '{{ r_packages_repos }}', argv[3]); +type = ifelse(is.na(argv[2]), '{{ r_packages_type }}', argv[2]); +lib = ifelse(is.na(argv[3]), '{{ r_packages_lib }}', argv[3]); -if (!(package %in% installed.packages(lib.loc = lib)[,'Package'])) { - withCallingHandlers(install.packages(package, lib, repos), warning = stop); +if (!(package %in% installed.packages(lib.loc = lib)[, 'Package'])) { + if (type == "cran") { + repos = ifelse(is.na(argv[4]), '{{ r_packages_repos }}', argv[4]); + withCallingHandlers(install.packages(package, lib, repos), warning = stop); + } else if (type == "bioconductor") { + withCallingHandlers({ + source("{{ r_bioclite_url }}"); + biocLite(package, lib=lib, suppressUpdates=TRUE, suppressAutoUpdate=TRUE, ask=FALSE); + }, warning = stop) + } else { + cat("Unrecognised type\n"); + q(status = 1); + } cat("changed\n"); } else { cat("unchanged\n"); diff --git a/tests/test.retry b/tests/test.retry new file mode 100644 index 0000000..2fbb50c --- /dev/null +++ b/tests/test.retry @@ -0,0 +1 @@ +localhost diff --git a/tests/test.yml b/tests/test.yml index d69a882..284e967 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -18,3 +18,6 @@ - name: foreign state: absent + + - name: Biobase + type: bioconductor diff --git a/vars/main.yml b/vars/main.yml index 66df8e8..33c5521 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -3,6 +3,7 @@ r_repository: - type: deb url: "{{ r_cran_mirror }}/bin/linux/ubuntu {{ ansible_distribution_release }}/" + r_dependencies: - r-base - littler