R/hemibrain_adjacency.R
grouped_adjacency.Rd
Create a summary adjacency matrix in which input and/or output neurons are coalesced (by summation) into a smaller number of rows/columns. This can be used as a preprocessing step to present a simple representation of the connectivity between a larger number of cells in a heatmap.
grouped_adjacency( inputids = NULL, outputids = NULL, ingroup = c("type", "name", "cellBodyFiber"), outgroup = c("type", "name", "cellBodyFiber"), threshold = c(1, 0), scale = c("none", "col", "row"), ... )
inputids | Either the bodyids of the input neurons OR an adjacency matrix |
---|---|
outputids | bodyids of the output neurons. Not required if
|
ingroup, outgroup | grouping variables used to coalesce related neurons.
The default values match against dynamically fetched neuprint metadata
columns for the neurons specified by |
threshold | Remove (groups of) neurons that make fewer connections than this. If you provide a length two vector the first threshold will be an absolute value applied before scaling, while the second will be a fractional value applied after scaling. |
scale | Whether to scale the rows or columns so that they sum to 1.
Default is |
... | Additional arguments passed to
|
named numeric matrix with rows for input groups and columns for output groups.
The default value of threshold is c(1, 0)
. When
scale=F
this will not apply a threshold. When scale=T
this
will apply a threshold of 1 to the raw counts before scaling to ensure that
only valid output will be returned.
Grouping. There are 3 ways to specify ingroup
, outgroup
grouping variable:
by a string chosen from c("type", "name", "cellBodyFiber")
which specifies a neuprint field; this is retrieved dynamically for the body ids specified by inputids
, outputids
.
by a factor or numeric vector specifying groups. If the elements in this vector are named, then the groups
by a function that maps body ids to numeric/factor groups that are then handled like the previous option.
neuprint_get_adjacency_matrix
# \donttest{ # Default: search by type and group by type # NB first search is by regex # do not group input neurons but leave one row for each neuron da2pnkc=grouped_adjacency("/.*DA2.*PN.*", 'KC', ingroup = NULL) heatmap(da2pnkc)# alternatively, if you want to play around with different arguments, # you can get the raw adjacency matrix and then group that in different # ways if (FALSE) { pnkc.raw=neuprint_get_adjacency_matrix(inputids = class2ids("PN"), outputids = 'KC') pnkc.bytype=grouped_adjacency(pnkc.raw, ingroup = "type", outgroup = "type") heatmap(pnkc.bytype) # slightly finer groups heatmap(grouped_adjacency(pnkc.raw, ingroup = "type", outgroup = "name")) # add a threshold to remove neurons that make very few connections heatmap(grouped_adjacency(pnkc.raw, ingroup = "type", outgroup = "name", threshold=50)) # Trying scaling to see relative input onto different groups # of Kenyon cell target neurons. col=> heatmap(grouped_adjacency(pnkc.raw, ingroup = "type", outgroup = "name", scale='col', threshold = c(1,0.01))) } # }