spatial_network() Creates a network for a given
SpatialExperiment object (spe) based on the correlation of features. Will
return a fully connect graph
spatial_network(
spe,
assay_names,
feature_names = NULL,
query_feature = NULL,
target_features = list(),
method = "spearman"
)SpatialExperiment (SPE) object
Name of assay in the spe object that contains data to be plotted. If only one it will focus on features in the first assay. If more than one it will compute correlations across all features.
will describe which value to use for node names. IF missing will use rownames
A single feature to query for correlation. If there
are no target_features will build a network between this feature all other
nodes. If missing, correlation will be computed between all nodes in
target_features.
List of features to compute correlation across. If
query_feature is not NULL, will compute correlation only between these
features and the query_feature. Otherwise, it will compute correlation
between all features in this list. DEFAULT: all features in spe.
to use for correlation, default is spearman
a tidygraph object that can be used for plotting or analysis
Using the feature values, the algorithm computes the correlation
between them across space, filtes by lowest_thresh (in the interest of
compute time) and then selects the most correlated edges using the
top_edges parameter.
Only the largest connected component is plotted, but the entire
graph is returned as an tidygraph object.
data(pancMeta)
data(smallPancData)
data(protMeta)
img0.spe <- convert_to_spe(smallPancData$Image_0,
pancMeta,
protMeta,
feature_meta_colname = "pancProts",
image_files = system.file("extdata", "Image_0.png", package = "spammR"),
spatial_coords_colnames = c("x_pixels", "y_pixels"),
sample_id = "Image0",
image_ids = "with_grid"
)
#> Note: Only mapping metadata for 2986 features out of 3000 data points
#get 10 most variable features
vp <- sort(apply(assay(img0.spe),1,var),decreasing = TRUE)[1:10]
##now call the network
res <- spatial_network(img0.spe,'proteomics', target_features=names(vp))
#> Joining with `by = join_by(rowval)`