Created
June 7, 2023 16:30
-
-
Save seandavi/e577a1d5fcb8a41c8e1f72ff1fa35eef to your computer and use it in GitHub Desktop.
Alabaster process all of annotationhub....
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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