% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/class-network.R
\name{as_cograph}
\alias{as_cograph}
\alias{to_cograph}
\title{Convert to Cograph Network}
\usage{
as_cograph(x, directed = NULL, simplify = FALSE, ...)

to_cograph(x, directed = NULL, ...)
}
\arguments{
\item{x}{Network input. Can be:
\itemize{
\item A square numeric matrix (adjacency/weight matrix)
\item A data frame with edge list (from, to, optional weight columns)
\item An igraph object
\item A statnet network object
\item A qgraph object
\item A tna object
\item An existing cograph_network object (returned as-is)
}}

\item{directed}{Logical. Force directed interpretation. NULL for auto-detect.}

\item{simplify}{Logical or character. If FALSE (default), every transition
from tna sequence data is a separate edge. If TRUE or a string
("sum", "mean", "max", "min"), duplicate edges are aggregated.}

\item{...}{Additional arguments (currently unused).}
}
\value{
A cograph_network object: a named list with components:
\describe{
\item{\code{nodes}}{Data frame with id, label, (x, y if layout applied)}
\item{\code{edges}}{Data frame with from, to, weight columns}
\item{\code{directed}}{Logical indicating if network is directed}
\item{\code{weights}}{Full n×n weight matrix (for to_matrix round-trip)}
\item{\code{data}}{Original estimation data (sequence matrix, edge list, etc.), or NULL}
\item{\code{meta}}{Consolidated metadata list with sub-fields:
\code{source} (input type string),
\code{layout} (layout info list or NULL),
\code{tna} (TNA metadata or NULL)}
\item{\code{node_groups}}{Optional node groupings data frame}
}

A \code{cograph_network} object. See \code{\link{as_cograph}}.
}
\description{
Creates a lightweight cograph_network object from various network inputs.
The resulting object is a named list with all data accessible via \code{$}.
}
\details{
The cograph_network format is designed to be:
\itemize{
\item Lean: Only essential data stored, computed values derived on demand
\item Modern: Uses named list elements instead of attributes for clean \code{$} access
\item Compatible: Works seamlessly with splot() and other cograph functions
}

Use getter functions for programmatic access:
\code{\link{get_nodes}}, \code{\link{get_edges}}, \code{\link{get_labels}},
\code{\link{n_nodes}}, \code{\link{n_edges}}

Use setter functions to modify:
\code{\link{set_nodes}}, \code{\link{set_edges}}, \code{\link{set_layout}}
}
\examples{
# From adjacency matrix
mat <- matrix(c(0, 1, 1, 1, 0, 1, 1, 1, 0), nrow = 3)
net <- as_cograph(mat)

# Direct $ access to core data
net$nodes      # nodes data frame
net$edges      # edges data frame
net$directed   # TRUE/FALSE

# Getter functions (recommended for programmatic use)
get_nodes(net)   # nodes data frame
get_edges(net)   # edges data frame (from, to, weight)
get_labels(net)  # character vector of labels
n_nodes(net)     # 3
n_edges(net)     # 3
cograph::is_directed(net) # FALSE (symmetric matrix)

# Setter functions
net <- set_nodes(net, data.frame(id = 1:3, label = c("A", "B", "C")))
net <- set_edges(net, data.frame(from = c(1,2), to = c(2,3), weight = c(0.5, 0.8)))
net <- set_layout(net, data.frame(x = c(0, 1, 0.5), y = c(0, 0, 1)))

# Plot it
splot(net)

# From igraph (if installed)
if (requireNamespace("igraph", quietly = TRUE)) {
  g <- igraph::make_ring(10)
  net <- as_cograph(g)
  splot(net)
}
mat <- matrix(c(0, 1, 1, 1, 0, 1, 1, 1, 0), nrow = 3)
net <- to_cograph(mat)
}
\seealso{
\code{\link{get_nodes}} to extract the nodes data frame,
\code{\link{get_edges}} to extract edges as a data frame,
\code{\link{n_nodes}} and \code{\link{n_edges}} for counts,
\code{\link{is_directed}} to check directedness,
\code{\link{splot}} for plotting
}
