Skip to content

Commit

Permalink
Use experimental functions from nat.hdf5
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderbates committed Feb 11, 2021
1 parent ccb2003 commit 83732f7
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 16 deletions.
4 changes: 3 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ Imports:
nat.nblast,
readr,
bit64,
bigstatsr
bigstatsr,
nat.hdf5
Remotes:
natverse/neuprintr,
tidyverse/googlesheets4,
Expand All @@ -66,6 +67,7 @@ Remotes:
natverse/elmr,
natverse/fafbseg,
natverse/nat.nblast
schlegelp/nat.hdf5
Language: en-GB
RoxygenNote: 7.1.1
URL: https://github.com/flyconnectome/hemibrainr, https://flyconnectome.github.io/hemibrainr
Expand Down
1 change: 0 additions & 1 deletion R/quotes.R
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,3 @@ say_encouragement <- function(greet = "user"){
encodeIfNeeded = FALSE)
}
}

44 changes: 33 additions & 11 deletions R/utilities.R
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ remove_unused_filehash <- function(path,
if(sum(!inmeta)){
nlfh = nlfh[inmeta]
update.neuronlistfh(nat::as.neuronlist(nlfh),
rds=rds,
file=rds,
dbClass = "DB1")
}
}
Expand Down Expand Up @@ -464,11 +464,12 @@ download_neuron_obj_batch <- function(ids, numCores = 1, ratio = 1, save.obj = "

# hidden
update.neuronlistfh <- function(x,
rds,
dbClass = c("RDS", "RDS2", "DB1"),
file,
dbClass = c("RDS", "RDS2", "DB1","HDF5"),
remote = NULL,
localdir = NULL,
pref.meta = NULL,
meta = NULL,
...){
dbClass = match.arg(dbClass)
if(dbClass=="DB1"){
Expand All @@ -477,14 +478,25 @@ update.neuronlistfh <- function(x,
file.remove(paste0(data,"___LOCK"))
}
WriteObjects = 'yes'
}else if (dbClass == "HDF5"){
data = file
}else{
data = file.path(dirname(rds),"data")
data = paste0(file.path(dirname(file),"data"),"/")
WriteObjects = "missing"
}
if(file.exists(rds)){
old.neurons = tryCatch(nat::read.neuronlistfh(rds, localdir = localdir), error = function(e) NULL)
if(file.exists(file)){
if(dbClass == "HDF5"){
old.neurons = tryCatch(nat.hdf5::read.neurons.hdf5(file), error = function(e) {
warning(e)
warning("Original neuron file cannot link to data, overwriting ...")
NULL
})
}else{
old.neurons = tryCatch(nat::read.neuronlistfh(file, localdir = localdir), error = function(e) NULL)
}
old.neurons = tryCatch(old.neurons[!sapply(old.neurons, function(x) isFALSE(x))], error = function(e) {
warning("Original .rds file cannot link to data, overwriting ...")
warning(e)
warning("Original neuron file cannot link to data, overwriting ...")
NULL
})
if(!is.null(old.neurons)||!length(old.neurons)){
Expand All @@ -496,15 +508,25 @@ update.neuronlistfh <- function(x,
}
if(nat::is.neuronlist(x)){
if(dbClass=="DB1"){file.remove(data)}
if(!is.null(meta)){
if(!all(names(x)%in%rownames(meta))){
stop("Each neuron name in x must be a rowname in meta")
}
x[,] = meta[names(x),]
}
if(!is.null(pref.meta)){
shared.cols = intersect(pref.meta,colnames(x[,]))
x[,] = x[,shared.cols]
}
given.neurons = nat::as.neuronlistfh(x, dbdir = data, dbClass = dbClass, WriteObjects = WriteObjects, remote = remote, ...)
if(dbClass=="DB1"){
saveRDS(given.neurons, file = rds, ...)
if (dbClass == "HDF5"){
given.neurons = nat.hdf5::write.neurons.hdf5(x, file = data, ...)
}else{
nat::write.neuronlistfh(given.neurons, file=rds, overwrite=TRUE, ...)
given.neurons = nat::as.neuronlistfh(x, dbdir = data, dbClass = dbClass, WriteObjects = WriteObjects, remote = remote, ...)
if(dbClass=="DB1"){
saveRDS(given.neurons, file = file)
}else{
nat::write.neuronlistfh(given.neurons, file=file, overwrite=TRUE, ...)
}
}
}else{
warning("Could not create neuronlistfh object")
Expand Down
6 changes: 3 additions & 3 deletions man/lineage_clones.Rd

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

0 comments on commit 83732f7

Please sign in to comment.