From ac4420aa346129a5de721c80d87bcc317e5949c6 Mon Sep 17 00:00:00 2001 From: Brandon Monier Date: Wed, 11 Jan 2023 09:21:04 -0500 Subject: [PATCH] Initial commit --- .Rbuildignore | 2 + .gitignore | 52 ++++++++++++++++++++ DESCRIPTION | 26 ++++++++++ NAMESPACE | 3 ++ R/initializer.R | 100 +++++++++++++++++++++++++++++++++++++++ R/utils.R | 19 ++++++++ R/zzz.R | 36 ++++++++++++++ README.md | 28 ++++++++++- bljars.Rproj | 22 +++++++++ man/getCommitMetaData.Rd | 23 +++++++++ man/initializeJars.Rd | 14 ++++++ 11 files changed, 323 insertions(+), 2 deletions(-) create mode 100644 .Rbuildignore create mode 100644 .gitignore create mode 100644 DESCRIPTION create mode 100644 NAMESPACE create mode 100644 R/initializer.R create mode 100644 R/utils.R create mode 100644 R/zzz.R create mode 100644 bljars.Rproj create mode 100644 man/getCommitMetaData.Rd create mode 100644 man/initializeJars.Rd diff --git a/.Rbuildignore b/.Rbuildignore new file mode 100644 index 0000000..4f4107a --- /dev/null +++ b/.Rbuildignore @@ -0,0 +1,2 @@ +^bljars\.Rproj$ +^\.Rproj\.user$ diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..85fb986 --- /dev/null +++ b/.gitignore @@ -0,0 +1,52 @@ +# These are some examples of commonly ignored file patterns. +# You should customize this list as applicable to your project. +# Learn more about .gitignore: +# https://www.atlassian.com/git/tutorials/saving-changes/gitignore + +# Node artifact files +node_modules/ +dist/ + +# Compiled Java class files +*.class + +# Compiled Python bytecode +*.py[cod] + +# Log files +*.log + + +# Maven +target/ +dist/ + +# JetBrains IDE +.idea/ + +# Unit test reports +TEST*.xml + +# Generated by MacOS +.DS_Store + +# Generated by Windows +Thumbs.db + +# Applications +*.app +*.exe +*.war + +# Large media files +*.mp4 +*.tiff +*.avi +*.flv +*.mov +*.wmv + +.Rproj.user + + +inst \ No newline at end of file diff --git a/DESCRIPTION b/DESCRIPTION new file mode 100644 index 0000000..68ff830 --- /dev/null +++ b/DESCRIPTION @@ -0,0 +1,26 @@ +Package: BLJars +Version: 0.0.2 +Date: 2021-07-14 +Title: Data package for distributing rTASSEL and rPHG jar files +Authors@R: + person(given = "Brandon", + family = "Monier", + role = c("aut", "cre"), + email = "bm646@cornell.edu", + comment = c(ORCID = "0000-0001-6797-1221")) +Description: + The role of this R package is to generate a JVM and distribute + necessary jar files for interacting with the TASSEL and PHG APIs. This is + used in two packages generated by the Buckler Lab: rTASSEL and rPHG. +License: `use_gpl3_license()` +URL: + https://bitbucket.org/bucklerlab/bljars/src/master/ +Depends: + rJava +Imports: + cli, + jsonlite +Encoding: UTF-8 +LazyData: true +Roxygen: list(markdown = TRUE) +RoxygenNote: 7.1.2 diff --git a/NAMESPACE b/NAMESPACE new file mode 100644 index 0000000..3364ca2 --- /dev/null +++ b/NAMESPACE @@ -0,0 +1,3 @@ +# Generated by roxygen2: do not edit by hand + +export(initializeJars) diff --git a/R/initializer.R b/R/initializer.R new file mode 100644 index 0000000..4b5e0db --- /dev/null +++ b/R/initializer.R @@ -0,0 +1,100 @@ +## ---- +#' @title Get TASSEL standalone JAR metadata +#' +#' @description Get commit history and download links +#' +#' @param apiPath Path to TASSEL Bitbucket API. +#' @param pageLen Number of pages to return. Defaults to \code{100}. +#' +#' @return A data.frame +getCommitMetaData <- function( + apiPath = "https://api.bitbucket.org/2.0/repositories/tasseladmin/tassel-5-standalone/src/master/", + pageLen = 100 +) { + urlLib <- paste0(apiPath, "/lib?pagelen=", pageLen) + + cli::cli_progress_step("Downloading JSON info", spinner = TRUE) + jsonTop <- jsonlite::fromJSON(apiPath) + jsonLib <- jsonlite::fromJSON(urlLib) + + jsonTop$values$attributes[sapply(jsonTop$values$attributes, is.null)] <- NA + jsonLib$values$attributes[sapply(jsonLib$values$attributes, is.null)] <- NA + + + cli::cli_progress_step("Collecting metdata", spinner = TRUE) + urlLibDF <- data.frame( + jar = jsonLib$values$path, + attribute = unlist(jsonLib$values$attributes), + commitMeta = jsonLib$values$commit$links$self$href, + downLink = jsonLib$values$links$self$href + ) + urlTopDF <- data.frame( + jar = jsonTop$values$path, + attribute = unlist(jsonTop$values$attributes), + commitMeta = jsonTop$values$commit$links$self$href, + downLink = jsonTop$values$links$self$href + ) + + cli::cli_progress_step("Cleaning up data", spinner = TRUE) + urlLibDF <- urlLibDF[!grepl(".ini$|.dylib$", urlLibDF$jar), ] + urlTopDF <- urlTopDF[urlTopDF$jar == "sTASSEL.jar", ] + urlMasterDf <- rbind(urlTopDF, urlLibDF) + urlMasterDf$commitDate <- as.Date("") + + cli::cli_progress_step("Collecting commit history", spinner = TRUE) + j <- 1 + for (i in urlMasterDf$commitMeta) { + tmpJson <- jsonlite::fromJSON(i) + urlMasterDf$commitDate[j] <- as.Date(tmpJson$date) + j <- j + 1 + } + + rownames(urlMasterDf) <- NULL + urlMasterDf$jar <- gsub("lib/", "", urlMasterDf$jar) + + return(urlMasterDf) +} + + + +## ---- +#' @title Initialize \code{BLJars}. +#' +#' @description Download jar files to designated directory +#' +#' @return void +#' @export +initializeJars <- function() { + + fields <- getDirFields() + + if (!dir.exists(fields$fullJava)) { + dir.create(fields$fullJava, recursive = TRUE) + } + + md <- getCommitMetaData() + + if (!dir.exists(fields$fullMeta)) { + dir.create(fields$fullMeta, recursive = TRUE) + } + + write.csv( + x = md, + file = fields$metaPath, + row.names = FALSE, + quote = FALSE + ) + + j <- 1 + cli::cli_progress_bar("Downloading jar files", total = nrow(md)) + for (i in md$downLink) { + dest <- paste0(fields$fullJava, md$jar[j]) + utils::download.file(i, dest, quiet = TRUE) + cli::cli_progress_update() + j <- j + 1 + } + cli::cli_alert_success("Downloaded {nrow(md)} jar files.") +} + + + diff --git a/R/utils.R b/R/utils.R new file mode 100644 index 0000000..b00f902 --- /dev/null +++ b/R/utils.R @@ -0,0 +1,19 @@ +getDirFields <- function(pkg = "BLJars", sep = "/") { + pkgDir <- find.package(pkg) + javaDir <- "java/" + metaDir <- "extdata/" + metaFile <- "bljars_metadata.csv" + + return( + list( + pkgDir = pkgDir, + javaDir = javaDir, + metaDir = metaDir, + fullJava = paste0(pkgDir, sep, javaDir), + fullMeta = paste0(pkgDir, sep, metaDir), + metaPath = paste0(pkgDir, sep, metaDir, metaFile) + ) + ) +} + + diff --git a/R/zzz.R b/R/zzz.R new file mode 100644 index 0000000..3218e45 --- /dev/null +++ b/R/zzz.R @@ -0,0 +1,36 @@ +.onLoad <- function(libname, pkgname) { + ## naive check for JAR detection + fields <- getDirFields() + if (any(grepl("jar", list.files(fields$fullJava)))) { + rJava::.jpackage(pkgname, lib.loc = libname) + rJava::.jaddClassPath(dir(file.path(getwd(), "inst/java"), full.names = TRUE)) + } +} + + +.onAttach <- function(libname, pkgname) { + fields <- getDirFields() + if (!any(grepl("jar", list.files(fields$fullJava)))) { + msg <- paste0( + "This looks like your first time running BLJars:", "\n", + " * Please run 'initializeJars()'", "\n", + " - This will download JAR files to the package.", "\n", + " * Once finished, please reload the BLJars package." + ) + } else { + tasselMain <- rJava::J("net/maizegenetics/tassel/TASSELMainFrame") + + msg <- paste0( + "BLJars package successfully loaded:", "\n", + " * BLJars version....... ", utils::packageVersion("BLJars"), "\n", + " * PHG version.......... ", NULL, "\n", + " * TASSEL version....... ", tasselMain$version, "\n", + " * Build date........... ", tasselMain$versionDate, "\n" + ) + + } + + packageStartupMessage(msg) +} + + diff --git a/README.md b/README.md index af45006..c6dd8a3 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,26 @@ -# bljars -R package for distributing jar files for rTASSEL and rPHG methods. +# BLJars + +## Overview +The role of this R package is to inialize a JVM and distribute +necessary jar files for interacting with the TASSEL and PHG APIs. This is +used in two packages generated by the Buckler Lab: `rTASSEL` and `rPHG`. + +This is currently in a semi-workable stage with the `*/feature/no-jars` +experimental branches of `rTASSEL` and `rPHG`. In order to use this, the +user will need to manually initialize: + +``` +library(BLJars) +``` + +...and then load `rTASSEL` and/or `rPHG`: + +``` +library(rTASSEL) +library(rPHG) +``` + + +## Contacts + +* Brandon Monier (bm646@cornell.edu) - _Author, Maintainer_ diff --git a/bljars.Rproj b/bljars.Rproj new file mode 100644 index 0000000..fa0d77b --- /dev/null +++ b/bljars.Rproj @@ -0,0 +1,22 @@ +Version: 1.0 + +RestoreWorkspace: No +SaveWorkspace: No +AlwaysSaveHistory: Default + +EnableCodeIndexing: Yes +UseSpacesForTab: Yes +NumSpacesForTab: 4 +Encoding: UTF-8 + +RnwWeave: knitr +LaTeX: pdfLaTeX + +AutoAppendNewline: Yes +StripTrailingWhitespace: Yes +LineEndingConversion: Posix + +BuildType: Package +PackageUseDevtools: Yes +PackageInstallArgs: --no-multiarch --with-keep.source +PackageRoxygenize: rd,collate,namespace diff --git a/man/getCommitMetaData.Rd b/man/getCommitMetaData.Rd new file mode 100644 index 0000000..6b2432d --- /dev/null +++ b/man/getCommitMetaData.Rd @@ -0,0 +1,23 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/initializer.R +\name{getCommitMetaData} +\alias{getCommitMetaData} +\title{Get TASSEL standalone JAR metadata} +\usage{ +getCommitMetaData( + + apiPath = "https://api.bitbucket.org/2.0/repositories/tasseladmin/tassel-5-standalone/src/master/", + pageLen = 100 +) +} +\arguments{ +\item{apiPath}{Path to TASSEL Bitbucket API.} + +\item{pageLen}{Number of pages to return. Defaults to \code{100}.} +} +\value{ +A data.frame +} +\description{ +Get commit history and download links +} diff --git a/man/initializeJars.Rd b/man/initializeJars.Rd new file mode 100644 index 0000000..d29c329 --- /dev/null +++ b/man/initializeJars.Rd @@ -0,0 +1,14 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/initializer.R +\name{initializeJars} +\alias{initializeJars} +\title{Initialize \code{BLJars}.} +\usage{ +initializeJars() +} +\value{ +void +} +\description{ +Download jar files to designated directory +}