% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/subset-methods.R
\name{GraphExperiment-subset}
\alias{GraphExperiment-subset}
\alias{[,GraphExperiment,ANY,ANY,ANY-method}
\title{Subsetting \code{GraphExperiment} objects}
\arguments{
\item{x}{A \code{\link{GraphExperiment}} object.}

\item{i}{Numeric, row indices for subsetting.}

\item{j}{Numeric, column indices for subsetting.}
}
\value{
a \code{\link{GraphExperiment}} object.
}
\description{
The subsetting method for \code{\link{GraphExperiment}} objects ensures
that nodes from \code{igraph} objects are filtered to match rows and columns
with the remainder of the object.
}
\section{subset}{

\describe{
\item{\code{[}:}{ subsetting method}
}
}

\examples{
# Simulate elements of a GraphExperiment object
## Assays
gene_ids <- paste0("gene", seq_len(200))
cell_ids <- paste0("cell", seq_len(100))
mat <- matrix(rpois(20000, 5), ncol = 100, dimnames = list(gene_ids, cell_ids))

## rowGraph (with node attributes)
g <- graph_from_adjacency_matrix(cor(t(mat)), weighted = TRUE)
V(g)$degree <- igraph::strength(g)

## colGraph
g2 <- graph_from_adjacency_matrix(cor(mat), weighted = TRUE)

## rowData
rdata <- data.frame(
    row.names = gene_ids, 
    pathway = sample(c("P1", "P2"), size = length(gene_ids), replace = TRUE),
    coding = sample(c(TRUE, FALSE), size = length(gene_ids), replace = TRUE)
)

## colData
cdata <- data.frame(
    row.names = cell_ids, 
    celltype = sample(c("ct1", "ct2"), size = length(cell_ids), replace = TRUE)
)


# Create a GraphExperiment object
ge <- GraphExperiment(
    assays = list(counts = mat), 
    rowData = rdata,
    colData = cdata,
    rowGraphs = list(cor = g),
    colGraphs = list(cellcor = g2)
)
ge

# Subset object
ge[1:5, 1:5]
}
