R/neuron-io.R
write.neurons.Rd
Write neurons from a neuronlist object to individual files, or a zip archive
write.neurons(
nl,
dir,
format = NULL,
subdir = NULL,
INDICES = names(nl),
files = NULL,
include.data.frame = FALSE,
metadata = FALSE,
Force = FALSE,
cl = NULL,
...
)
neuronlist object
directory to write neurons, or path to zip archive (see Details).
Unique abbreviation of one of the registered file formats for
neurons including 'swc', 'hxlineset', 'hxskel' (skeletons) and 'ply', 'obj'
(neuron meshes). If no format can be extracted from the filename or the
ext
parameter, then it defaults to 'swc' for skeletons and 'ply' for
meshes.
String naming field in neuron that specifies a subdirectory OR expression to evaluate in the context of neuronlist's df attribute
Character vector of the names of a subset of neurons in neuronlist to write.
Character vector or expression specifying output filenames. See
examples and write.neuron
for details.
Whether to include the metadata when writing a zip
file (it will be called "write.neurons.dataframe.rds"
).
Whether to encode some metadata in the header file (currently
only supported for SWC format). Either a data.frame or TRUE
to
indicate that the attached data.frame should be written. Default
FALSE
.
Whether to overwrite an existing file
Either the integer number of cores to use for parallel writes (2 or
3 seem useful) or a cluster
object created by
makeCluster
. See the cl
argument of
pbsapply
for details.
Additional arguments passed to write.neuron
the path to the output file(s), absolute when this is a zip file.
See write.neuron
for details of how to specify the
file format/extension/name of the output files and how to establish what
output file formats are available. A zip archive of files can be written by
specifying a value of dir
that ends in .zip
. When rds files
(R's binary data representation, which is compressed by default) are stored
inside a zip file the are not further compressed (zip option 0).
write.neuron
, read.neurons
,
fileformats
Other neuronlist:
*.neuronlist()
,
is.neuronlist()
,
neuronlist-dataframe-methods
,
neuronlistfh()
,
neuronlistz()
,
neuronlist()
,
nlapply()
,
read.neurons()
if (FALSE) {
# write some neurons in swc format
write.neurons(Cell07PNs, dir="testwn", format='swc')
# write some neurons in swc format for picky software
write.neurons(Cell07PNs, dir="testwn", format='swc', normalise.ids=TRUE)
# write some neurons in swc format and zip them up
write.neurons(Cell07PNs, dir="testwn.zip", format='swc')
# write some neurons in R's native RDS format using 3 cores for
# parallel writes and then zip them up (storing rather than compressing)
write.neurons(Cell07PNs, dir="testwn.zip", format='rds', cl=3)
# write some neurons in Amira hxlineset format
write.neurons(Cell07PNs, dir="testwn", format='hxlineset')
# write some neuron meshes in Stanford ply format (the default for meshes)
write.neurons(myneurons, dir="testwn")
# specify the format to avoid a warning. Write to a zip file.
write.neurons(myneurons, dir="testmeshes.zip", format='ply')
# Wavefront obj format
write.neurons(myneurons, dir="testwn", format='obj')
# organise new files in directory hierarchy by glomerulus and Scored.By field
write.neurons(Cell07PNs,dir="testwn",
subdir=file.path(Glomerulus,Scored.By),format='hxlineset')
# ensure that the neurons are named according to neuronlist names
write.neurons(Cell07PNs, dir="testwn", files=names(Cell07PNs),
subdir=file.path(Glomerulus,Scored.By),format='hxlineset')
# only write a subset
write.neurons(subset(Cell07PNs, Scored.By="ACH"),dir="testwn2",
subdir=Glomerulus,format='hxlineset')
# The same, but likely faster for big neuronlists
write.neurons(Cell07PNs, dir="testwn3",
INDICES=subset(Cell07PNs,Scored.By="ACH",rval='names'),
subdir=Glomerulus,format='hxlineset')
# set file name explicitly using a field in data.frame
write.neurons(subset(Cell07PNs, Scored.By="ACH"),dir="testwn4",
subdir=Glomerulus, files=paste0(ID,'.am'), format='hxlineset')
}