Calculate a cosine similarity matrix for neuprint neurons

neuprint_cosine_matrix(
  ids,
  ...,
  threshold = 5,
  partners = c("outputs", "inputs"),
  group = FALSE,
  groupfun = NULL,
  details = NULL,
  conn = NULL
)

Arguments

ids

Passed to neuprint_ids

...

Optional filter expression defining which partners to include

threshold

An integer threshold (connections >= this will be returned)

partners

Whether to cluster based on connections to input or output partner neurons (default both).

group

Whether to group by cell type or another named column.

groupfun

A function which receives the metadata for all partner neurons and returns a single grouping vector (see the details section).

details

Optional character vector naming metadata columns to fetch for partner neurons.

conn

optional, a neuprintr connection object, which also specifies the neuPrint server. If NULL, the defaults set in your .Rprofile or .Renviron are used. See neuprint_login for details.

Value

matrix or list of two matrices (input and output)

Details

For most purposes you can use neuprint_cosine_plot directly, but it can sometimes be useful to use neuprint_cosine_matrix to have more control over how partner neurons are grouped (see e.g. groupfun) or which partner neurons are included in the results (.

The groupfun argument can be a powerful way to construct flexible grouping strategies for partner neurons. It was added in order to use information present in fields such as the group, serial or instance/name columns in the male VNC/CNS datasets. It will receive as input a dataframe and expects to receive a single vector of length matching the number of rows in the input dataframe. The input dataframe will contain the standard columns returned by neuprint_connection_table but you can request extra columns if necessary by naming them in the group argument.

Examples

# \donttest{
# NB the second (unnamed argument) filters the partner neurons
# so that only those with type containing the regular expression ORN are used
neuprint_cosine_matrix("/DA[1-3].*PN", grepl("ORN",type), partners='in')
#>            1734350788 1734350908 1765040289 5813039315 722817260 754534424
#> 1734350788  1.0000000  0.7911385  0.7838174  0.7508534 0.7478463 0.7899044
#> 1734350908  0.7911385  1.0000000  0.8131651  0.8421953 0.7844044 0.8548269
#> 1765040289  0.7838174  0.8131651  1.0000000  0.8310386 0.8299156 0.9000086
#> 5813039315  0.7508534  0.8421953  0.8310386  1.0000000 0.8099328 0.8491668
#> 722817260   0.7478463  0.7844044  0.8299156  0.8099328 1.0000000 0.8307328
#> 754534424   0.7899044  0.8548269  0.9000086  0.8491668 0.8307328 1.0000000
#> 754538881   0.7874977  0.7809437  0.8708951  0.8050826 0.8282373 0.8532473
#> 733316908   0.7594145  0.8497124  0.8137838  0.8343710 0.8326044 0.8468566
#> 1796817841  0.0000000  0.0000000  0.0000000  0.0000000 0.0000000 0.0000000
#> 1796818119  0.0000000  0.0000000  0.0000000  0.0000000 0.0000000 0.0000000
#> 1797505019  0.0000000  0.0000000  0.0000000  0.0000000 0.0000000 0.0000000
#> 1827516355  0.0000000  0.0000000  0.0000000  0.0000000 0.0000000 0.0000000
#> 818983130   0.0000000  0.0000000  0.0000000  0.0000000 0.0000000 0.0000000
#> 1702806746  0.0000000  0.0000000  0.0000000  0.0000000 0.0000000 0.0000000
#> 1702815630  0.0000000  0.0000000  0.0000000  0.0000000 0.0000000 0.0000000
#> 1703683361  0.0000000  0.0000000  0.0000000  0.0000000 0.0000000 0.0000000
#> 666135689   0.0000000  0.0000000  0.0000000  0.0000000 0.0000000 0.0000000
#>            754538881 733316908 1796817841 1796818119 1797505019 1827516355
#> 1734350788 0.7874977 0.7594145  0.0000000  0.0000000  0.0000000  0.0000000
#> 1734350908 0.7809437 0.8497124  0.0000000  0.0000000  0.0000000  0.0000000
#> 1765040289 0.8708951 0.8137838  0.0000000  0.0000000  0.0000000  0.0000000
#> 5813039315 0.8050826 0.8343710  0.0000000  0.0000000  0.0000000  0.0000000
#> 722817260  0.8282373 0.8326044  0.0000000  0.0000000  0.0000000  0.0000000
#> 754534424  0.8532473 0.8468566  0.0000000  0.0000000  0.0000000  0.0000000
#> 754538881  1.0000000 0.8238283  0.0000000  0.0000000  0.0000000  0.0000000
#> 733316908  0.8238283 1.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> 1796817841 0.0000000 0.0000000  1.0000000  0.4512069  0.3026890  0.3648613
#> 1796818119 0.0000000 0.0000000  0.4512069  1.0000000  0.5869982  0.7033427
#> 1797505019 0.0000000 0.0000000  0.3026890  0.5869982  1.0000000  0.6480365
#> 1827516355 0.0000000 0.0000000  0.3648613  0.7033427  0.6480365  1.0000000
#> 818983130  0.0000000 0.0000000  0.4413857  0.6897041  0.5350274  0.5396716
#> 1702806746 0.0000000 0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> 1702815630 0.0000000 0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> 1703683361 0.0000000 0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> 666135689  0.0000000 0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#>            818983130 1702806746 1702815630 1703683361 666135689
#> 1734350788 0.0000000  0.0000000  0.0000000  0.0000000 0.0000000
#> 1734350908 0.0000000  0.0000000  0.0000000  0.0000000 0.0000000
#> 1765040289 0.0000000  0.0000000  0.0000000  0.0000000 0.0000000
#> 5813039315 0.0000000  0.0000000  0.0000000  0.0000000 0.0000000
#> 722817260  0.0000000  0.0000000  0.0000000  0.0000000 0.0000000
#> 754534424  0.0000000  0.0000000  0.0000000  0.0000000 0.0000000
#> 754538881  0.0000000  0.0000000  0.0000000  0.0000000 0.0000000
#> 733316908  0.0000000  0.0000000  0.0000000  0.0000000 0.0000000
#> 1796817841 0.4413857  0.0000000  0.0000000  0.0000000 0.0000000
#> 1796818119 0.6897041  0.0000000  0.0000000  0.0000000 0.0000000
#> 1797505019 0.5350274  0.0000000  0.0000000  0.0000000 0.0000000
#> 1827516355 0.5396716  0.0000000  0.0000000  0.0000000 0.0000000
#> 818983130  1.0000000  0.0000000  0.0000000  0.0000000 0.0000000
#> 1702806746 0.0000000  1.0000000  0.9713775  0.3657420 0.3632341
#> 1702815630 0.0000000  0.9713775  1.0000000  0.3593996 0.3463019
#> 1703683361 0.0000000  0.3657420  0.3593996  1.0000000 0.9335473
#> 666135689  0.0000000  0.3632341  0.3463019  0.9335473 1.0000000
# }