Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
btmonier committed Jan 11, 2023
1 parent 9e2dcc0 commit ac4420a
Show file tree
Hide file tree
Showing 11 changed files with 323 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
^bljars\.Rproj$
^\.Rproj\.user$
52 changes: 52 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
26 changes: 26 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]",
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
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Generated by roxygen2: do not edit by hand

export(initializeJars)
100 changes: 100 additions & 0 deletions R/initializer.R
Original file line number Diff line number Diff line change
@@ -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.")
}



19 changes: 19 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
@@ -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)
)
)
}


36 changes: 36 additions & 0 deletions R/zzz.R
Original file line number Diff line number Diff line change
@@ -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)
}


28 changes: 26 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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 ([email protected]) - _Author, Maintainer_
22 changes: 22 additions & 0 deletions bljars.Rproj
Original file line number Diff line number Diff line change
@@ -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
23 changes: 23 additions & 0 deletions man/getCommitMetaData.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions man/initializeJars.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ac4420a

Please sign in to comment.