Skip to content

Instantly share code, notes, and snippets.

@seandavi
Created June 7, 2023 16:30
Show Gist options
  • Save seandavi/e577a1d5fcb8a41c8e1f72ff1fa35eef to your computer and use it in GitHub Desktop.
Save seandavi/e577a1d5fcb8a41c8e1f72ff1fa35eef to your computer and use it in GitHub Desktop.
Alabaster process all of annotationhub....
library(alabaster)
library(AnnotationHub)
library(jsonlite)
ah = AnnotationHub()
STAGE_DIR = '/tmp/ah_staging'
dir.create(STAGE_DIR, showWarnings = FALSE)
write_error = function(dirname, e) {
jsonlite::write_json(list(message=jsonlite::unbox(e$message)), file.path(dirname,'error.json'))
}
for(i in seq_along(ah)) {
obj = ah[[i]]
dirname = file.path(STAGE_DIR, sprintf('ah_%d', i))
jsonfname = file.path(dirname, 'metadata.json')
unlink(dirname, recursive = TRUE, force=TRUE)
json = tryCatch(
expr=alabaster.base::stageObject(obj, STAGE_DIR, sprintf('ah_%d', i)),
error = function(e) write_error(dirname, e),
finally=list(error=TRUE)
)
json[['_id']]=i
jsonlite::write_json(json, jsonfname, auto_unbox=TRUE)
message(i)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment