monkeybread.stat.cell_contact
- monkeybread.stat.cell_contact(adata, groupby, group1, group2, actual_contact, contact_radius=None, perm_radius=100, n_perms=1000, split_groups=False, basis='spatial')
Calculates expected cell contact and p-value using a permutation test.
Test described in [F+22], consisting of position randomization within a radius. Instead of z-test, the p-value is derived from the number of permutations with higher count than observed in the data.
- Parameters
adata (
AnnData
) – Annotated data matrix.groupby (
str
) – A categorical column inadata.obs
to classify groups.group1 (
Union
[str
,List
[str
]]) – Either one group or a list of groups fromadata.obs[groupby]
.group2 (
Union
[str
,List
[str
]]) – Either one group or a list of groups fromadata.obs[groupby]
.actual_contact (
Dict
[str
,Set
[str
]]) – The actual cell contacts, as calculated bymonkeybread.calc.cell_contact()
.contact_radius (
Optional
[float
] (default:None
)) – The radius in which cells are considered touching. If not provided, will be calculated using half of the average radius of group1 + half of the average radius of group2. This requires width and height columns to be present inadata.obs
. Should be the same as used inmonkeybread.calc.cell_contact()
.perm_radius (
Optional
[float
] (default:100
)) – The radius within which to randomize location, in coordinate units.n_perms (
Optional
[int
] (default:1000
)) – The number of permutations to run.split_groups (
Optional
[bool
] (default:False
)) – Perform calculations using each possible pair from group1 and group2 instead of considering the groups as a whole.basis (
Optional
[str
] (default:'spatial'
)) – Coordinates inadata.obsm[X_{basis}]
to use. Defaults tospatial
.
- Return type
- Returns
If
split_groups = False
, a length-two tuple will be returned. The first element is an array containing the number of contacts observed for each permutation. The second element is a p_value comparing the expected contact to the actual contact. Ifsplit_groups = True
, a dataframe will be provided where each cell containsp_val
for that combination ofgroup1
(columns) andgroup2
(rows).