saveNetwork | R Documentation |
Given a list of network objects such as that returned by
buildRepSeqNetwork()
or generateNetworkObjects
,
saves its contents according to the specified file format scheme.
saveNetwork(
net,
output_dir,
output_type = "rds",
output_name = "MyRepSeqNetwork",
pdf_width = 12,
pdf_height = 10,
verbose = FALSE,
output_filename = deprecated()
)
net |
A list of network objects returned by
|
output_dir |
A file path specifying the directory in which to write the file(s). |
output_type |
A character string specifying the file format scheme to use when writing output
to file. Valid options are |
output_name |
A character string. All files saved will have file names beginning with this value. |
pdf_width |
If the list contains plots, this controls the width of each plot when writing
to pdf. Passed to the |
pdf_height |
If the list contains plots, this controls the height of each plot when writing
to pdf. Passed to the |
verbose |
Logical. If |
output_filename |
The list net
must contain the named elements
igraph
(of class igraph
),
adjacency_matrix
(a matrix
or
dgCMatrix
encoding edge connections),
and node_data
(a data.frame
containing node metadata),
all corresponding to the same network. The list returned by
buildRepSeqNetwork()
and
generateNetworkObjects()
is an example of a valid input for the net
argument.
The additional elements cluster_data
(a data.frame
) and
plots
(a list containing objects of class
ggraph
and possibly one matrix
named graph_layout
)
will also be saved, if present.
By default, the list net
is saved to a compressed data file in the
RDS format, while any plots present are printed to a single pdf containing
one plot per page.
The name of each saved file begins with the value of output_name
.
When output_type
is one of "rds"
or "rda"
,
only two files are saved (the rds/rda and the pdf); for each file,
output_name
is followed by the appropriate file extension.
When output_type = "individual"
, each element of net
is saved
as a separate file, where output_name
is followed by:
_NodeMetadata.csv
for node_data
_ClusterMetadata.csv
for cluster_data
_EdgeList.txt
for igraph
_AdjacencyMatrix.mtx
for adjacency_matrix
_Plots.rda
for plots
_GraphLayout.txt
for plots$graph_layout
_Details.rds
for details
node_data
and cluster_data
are saved using
write.csv()
,
with row.names
being TRUE
for node_data
and FALSE
for cluster_data
.
The igraph
is saved using
write_graph()
with format = "edgelist"
.
The adjacency matrix is saved using writeMM()
.
The graph layout is saved using write()
with
ncolumns = 2
.
Returns TRUE
if output is saved, otherwise returns FALSE
(with a warning if output_dir
is non-null and the specified directory does not exist and could not be created).
Brian Neal (Brian.Neal@ucsf.edu)
Hai Yang, Jason Cham, Brian Neal, Zenghua Fan, Tao He and Li Zhang. (2023). NAIR: Network Analysis of Immune Repertoire. Frontiers in Immunology, vol. 14. doi: 10.3389/fimmu.2023.1181825
set.seed(42)
toy_data <- simulateToyData()
net <- buildRepSeqNetwork(
toy_data,
seq_col = "CloneSeq",
node_stats = TRUE,
cluster_stats = TRUE,
color_nodes_by = c("transitivity", "SampleID")
)
# save as single RDS file
saveNetwork(
net,
output_dir = tempdir(),
verbose = TRUE
)
saveNetwork(
net,
output_dir = tempdir(),
output_type = "individual",
verbose = TRUE
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.