AtlasMapper
hnoca.map.mapper.AtlasMapper(ref_model)
A class to map a query dataset to a reference dataset using scPoli, scVI or scANVI models.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ref_model |
Union[SCANVI, SCVI, scPoli]
|
The reference model to map the query dataset to. |
required |
map_query(query_adata, retrain='partial', labeled_indices=None, **kwargs)
Map a query dataset to the reference dataset
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query_adata |
AnnData
|
The query dataset to map to the reference dataset |
required |
retrain |
Literal['partial', 'full', 'none']
|
Whether to retrain the query model.
|
'partial'
|
labeled_indices |
Optional[ndarray]
|
The indices of labeled cells in the query dataset. This is only used for scPoli models. |
None
|
**kwargs |
Additional keyword arguments to pass to the training function |
{}
|
compute_wknn(ref_adata=None, k=100, query2ref=True, ref2query=False, ref_rep_key='X_latent', query_rep_key='X_latent', weighting_scheme='jaccard_square', top_n=None)
Compute the weighted k-nearest neighbors graph between the reference and query datasets
Parameters:
Name | Type | Description | Default |
---|---|---|---|
k |
int
|
Number of neighbors per cell |
100
|
query2ref |
bool
|
Consider query-to-ref neighbors |
True
|
ref2query |
bool
|
Consider ref-to-query neighbors |
False
|
weighting_scheme |
Literal['n', 'top_n', 'jaccard', 'jaccard_square', 'gaussian', 'dist']
|
How to weight edges in the ref-query neighbor graph |
'jaccard_square'
|
top_n |
Optional[int]
|
The number of top neighbors to consider |
None
|
get_presence_scores(split_by=None, random_walk=True, alpha=0.1, n_rounds=100, log=True)
Estimate the presence score of the query dataset
Parameters:
Name | Type | Description | Default |
---|---|---|---|
split_by |
str
|
The column in the query dataset to split by |
None
|
random_walk |
bool
|
Whether to use random walk to estimate presence score |
True
|
alpha |
float
|
The heat diffusion parameter for the random walk |
0.1
|
n_rounds |
int
|
The number of rounds for the random walk |
100
|
log |
bool
|
Whether to log the presence score |
True
|
Returns:
Type | Description |
---|---|
dict
|
A dictionary with the presence scores |
transfer_labels(label_key)
Transfer labels from the reference dataset to the query dataset
Parameters:
Name | Type | Description | Default |
---|---|---|---|
label_key |
str
|
str The column in the reference dataset to transfer |
required |
Returns:
Type | Description |
---|---|
dict
|
A dictionary with the transfer scores |
get_matched_expression(rescale_factor=1)
Get the expression of reference cells matched to query cells. This can be used for quantitative comparisons like DE analysis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rescale_factor |
int
|
str Factor to rescale the log-normalized counts |
1
|
Returns:
Type | Description |
---|---|
AnnData
|
An AnnData object with the matched expression |
save(output_dir)
Save the mapper object to disk
Parameters:
Name | Type | Description | Default |
---|---|---|---|
output_dir |
str
|
str The directory to save the mapper object |
required |
load(input_dir)
classmethod
Load the mapper object from disk
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_dir |
str
|
str The directory to load the mapper object |
required |