nico_annotations package

Subpackages

Submodules

nico_annotations.Annotations module

nico_annotations.Annotations.create_directory(outputFolder)[source]

Create an empty directory.

This function checks if a specified directory exists, and if not, it creates the directory.

Parameters

outputFolderstr

The path of the directory to be created.

Raises

OSError

If the directory cannot be created due to permission issues or other OS-related errors.

Notes

  • If the directory already exists, no action is taken.

  • This function ensures that the directory path is available for subsequent file operations.

Example

>>> create_directory('./new_out/')
nico_annotations.Annotations.delete_files(input)[source]

This function will delete the anchors file and temporary file generated during the annotations.

nico_annotations.Annotations.findSpatialCells(midzoneCells, mnn)[source]

Finds the anchored cells for each cell type.

This helper function is used in find_all_the_spatial_cells_mapped_to_single_cells to identify the spatial cells that are anchored to each single-cell RNA sequencing (scRNAseq) cell type.

Parameters

midzoneCellsnumpy.ndarray

An array of barcode IDs representing the single-cell RNA sequencing (scRNAseq) cells belonging to a specific cell type.

mnnnumpy.ndarray

A 2D array where each row represents a mutual nearest neighbor (MNN) pair. The first column contains spatial cell barcode IDs and the second column contains scRNAseq cell barcode IDs.

Returns

dict

A dictionary where keys are spatial cell barcode IDs and values are the counts of how many times each spatial cell is anchored to the scRNAseq cells.

nico_annotations.Annotations.find_all_the_spatial_cells_mapped_to_single_cells(sc_ctype_id, sc_clusters, mnn, sc_ctype_name)[source]

Maps spatial cells to single-cell RNA sequencing (scRNAseq) cell types.

This helper function is used in nico_based_annotation to find the mapping of cells between spatial and scRNAseq modalities. It identifies the spatial cells that correspond to specific scRNAseq cell types based on mutual nearest neighbor (MNN) pairs.

Parameters

sc_ctype_idnumpy.ndarray

An array of unique identifiers for each scRNAseq cell type.

sc_clustersnumpy.ndarray

A 2D array where each row contains a barcode ID and a cluster ID representing the clustering of scRNAseq cells.

mnnnumpy.ndarray

A 2D array where each row represents an MNN pair. The first column contains spatial cell barcode IDs and the second column contains scRNAseq cell barcode IDs.

sc_ctype_namelist of str

A list of names corresponding to each scRNAseq cell type ID.

Returns

dict

A dictionary where keys are spatial cell barcode IDs and values are lists containing the scRNAseq cell type names and their counts, with each spatial cell being mapped to the most frequent scRNAseq cell type if there are ties.

nico_annotations.Annotations.find_anchor_cells_between_ref_and_query(refpath='./inputRef/', quepath='./inputQuery/', output_annotation_dir=None, output_nico_dir=None, neigh=50, no_of_pc=50, minkowski_order=2)[source]

Finds all anchor cells between query and reference data.

This function reads the reference and query data from the specified directories, performs necessary preprocessing, and finds mutual nearest neighbors in the PCA space to map cell types between the two datasets.

Parameters

refpathstr, optional

Path to the directory containing reference scRNAseq data. This directory should contain: - ‘Original_counts.h5ad’ : The original count matrix in raw layer. - ‘sct_singleCell.h5ad’ : The scTransform-like normalized matrix. (default is ‘./inputRef/’)

quepathstr, optional

Path to the directory containing spatial transcriptomics query data. This directory should contain: - ‘sct_spatial.h5ad’ : The scTransform-like normalized matrix. (default is ‘./inputQuery/’)

output_annotation_dirstr, optional

Directory to save output annotations. If None, a default directory is used. (default is None)

output_nico_dirstr, optional

Directory to save output NICOLAE results. If None, ‘./nico_out/’ is used. (default is ‘./nico_out/annotations’)

neighint, optional

The number of K-nearest neighbors to find the anchor cells. (default is 50)

no_of_pcint, optional

The number of principal components used to transform the normalized expression matrix into PCA space. (default is 50)

minkowski_orderint, optional

The type of distance metric used: - 2 for Euclidean distance - 1 for Manhattan distance (default is 2)

Outputs

The function produces the mapping of cell type information between two modalities and saves the results in the specified output directory.

nico_annotations.Annotations.find_annotation_index(annot_cellname, sct_cellname)[source]

Helper function for find_common_MNN to find the correct cell name.

This function maps the indices of cell barcodes names to the corresponding indices in the anchored data.

Parameters

annot_cellnamelist or array-like

List or array of cell barcode names.

sct_cellnamelist or array-like

List or array of anchored cell barcode names.

Returns

indexlist

List of indices in sct_cellname that corresponds to the position of the cell barcode name in annot_cellname.

nico_annotations.Annotations.find_commnon_MNN(input)[source]

Helper function used in find_anchor_cells_between_ref_and_query to find the anchored cells between spatial and sequencing modalities using the mutual nearest neighbors (MNN) method in the PCA space.

This function reads MNN pairs from a provided file and processes the data to identify mutual nearest neighbors between spatial and single-cell datasets.

Parameters

inputobject

An object containing various attributes required for the function.

Returns

datanumpy.ndarray

After prunning the bad anchors it returen the good anchors.

nico_annotations.Annotations.find_index(sp_genename, sc_genename)[source]

Find the common gene space submatrix between two modalities.

This helper function is used within the find_anchor_cells_between_ref_and_query function to identify the indices of common genes between two lists of gene names corresponding to spatial and scRNAseq modalities.

Parameters

sp_genenamelist

A list of gene names from the spatial modality.

sc_genenamelist

A list of gene names from the scRNAseq modality.

Returns

list

A list of indices corresponding to the common genes found in both sp_genename and sc_genename.

Example

>>> sp_genes = ['gene1', 'gene2', 'gene3', 'gene4']
>>> sc_genes = ['gene3', 'gene4', 'gene5', 'gene6']
>>> index_sp,index_sc = find_index(sp_genes, sc_genes)
>>> print(index_sp)
[2, 3]
nico_annotations.Annotations.find_match_index_in_dist(t1, t2, s1, s2, index_1, index_2)[source]

Helper function used in find_mutual_nn to find the correct pairing of cell barcodes.

This function takes two lists of cell barcodes and their corresponding indices and returns the matched pair of distances for the specified indices.

Parameters

t1list or numpy.ndarray

A list or array containing the distances corresponding to the cell barcodes in s1.

t2list or numpy.ndarray

A list or array containing the distances corresponding to the cell barcodes in s2.

s1list or numpy.ndarray

A list or array containing the cell barcodes for the first set of distances.

s2list or numpy.ndarray

A list or array containing the cell barcodes for the second set of distances.

index_1int

The index of the cell barcode in s1 to be matched.

index_2int

The index of the cell barcode in s2 to be matched.

Returns

tuple

A tuple (p1, p2) where p1 is the distance from t1 corresponding to index_1 and p2 is the distance from t2 corresponding to index_2.

nico_annotations.Annotations.find_mutual_nn(minkowski_order, data1, data2, sp_barcode, sc_barcode, k1, k2)[source]

Helper function used in find_anchor_cells_between_ref_and_query to find mutual nearest neighbors using cKDTree.

This function finds mutual nearest neighbors (MNNs) between two datasets using the cKDTree algorithm. The mutual nearest neighbors are those pairs of points that are each other’s nearest neighbors.

Parameters

minkowski_orderint

The order of the Minkowski distance to use. For example, 2 is the Euclidean distance.

data1numpy.ndarray

The reference dataset, typically the spatial dataset.

data2numpy.ndarray

The query dataset, typically the sequencing dataset.

sp_barcodenumpy.ndarray

Array of barcodes for the spatial dataset.

sc_barcodenumpy.ndarray

Array of barcodes for the single-cell dataset.

k1int

The number of nearest neighbors to query in the spatial dataset.

k2int

The number of nearest neighbors to query in the single-cell dataset.

Returns

numpy.ndarray

An array where each row represents a mutual nearest neighbor pair and their distances. The columns are: [sp_barcode of mutual_1, sc_barcode of mutual_2, distance in data1, distance in data2]

nico_annotations.Annotations.find_unmapped_cells_and_deg(deg, unique_mapped)[source]

Identifies unmapped non-anchored cells and their degrees.

This helper function is used in nico_based_annotation to find cells that have not been mapped and their corresponding degree values. It returns the cell names and their degree values sorted in descending order of degree.

Parameters

degdict

A dictionary where keys are cell node identifiers and values are their corresponding degrees (number of connections).

unique_mappeddict

A dictionary where keys are mapped cell node identifiers and values are their corresponding cell type names.

Returns

tupleA tuple containing two numpy arrays:
  • cellnamenumpy.ndarray

    An array of unmapped cell node identifiers sorted by their degree values in descending order.

  • degvaluenumpy.ndarray

    An array of degree values corresponding to the unmapped cell node identifiers, sorted in descending order.

nico_annotations.Annotations.nico_based_annotation(previous, ref_cluster_tag='cluster', across_spatial_clusters_dispersion_cutoff=0.15, guiding_spatial_cluster_resolution_tag='leiden0.5', number_of_iteration_to_perform_celltype_annotations=3, resolved_tie_issue_with_weighted_nearest_neighbor='No')[source]

This function performs NiCo-based annotation of spatial cell transcriptomes by using label transfer from scRNAseq data.

The function utilizes label transfer to annotate spatial transcriptomic data based on cell type information from scRNAseq data. It leverages anchored cells to iteratively annotate non-anchor cells. The annotations are either performed using a majority vote or a weighted vote based on distances in the transformed gene expression space.

The function starts by reading the output from find_anchor_cells_between_ref_and_query and annotates the spatial cells based on the provided parameters.

Parameters

previousobject

The output object from find_anchor_cells_between_ref_and_query containing necessary data for annotation.

ref_cluster_tagstr, optional

The slot in the reference anndata object file (‘Original_counts.h5ad’) where cell type information is stored <anndata>.obs[cluster]. (default is ‘cluster’)

across_spatial_clusters_dispersion_cutofffloat, optional

The cutoff used to remove noisy anchors. Anchored cells that belong to any guiding spatial cluster with a frequency lower than this cutoff will be discarded. (default is 0.15)

guiding_spatial_cluster_resolution_tagstr, optional

The guiding spatial Leiden cluster resolution (clustering of spatial data used for anchor pruning). The sct_spatial.h5ad file should have required resolution of Leiden clusterings such as 0.3, 0.4, 0.5, 0.6, 0.7 and 0.8 that can be stored in the anndata.obs slot with name ‘leiden0.3’, ‘leiden0.4’, ‘leiden0.5’, ‘leiden0.6’, ‘leiden0.7’ and ‘leiden0.8’. (default is ‘leiden0.5’)

number_of_iteration_to_perform_celltype_annotationsint, optional

The number of iterations to perform the cell type annotations. Higher numbers of iterations may annotate more cells but decrease confidence due to dilution of anchor information. (default is 3)

resolved_tie_issue_with_weighted_nearest_neighborstr, optional

Whether to resolve tie issues in cell type assignment with a weighted nearest neighbor approach: - ‘No’: Assigns ‘NM’ (not mapped) to non-anchor cells in case of a tie. - ‘Yes’: Utilizes the weighted average of cell type proportions for resolving ties, with weights inversely proportional to the distance. (default is ‘No’)

Outputs

For each iteration, the function generates the following files in the specified output directory: - _nico_annotation_cluster.csv: Contains the annotated cluster information. - _nico_annotation_ct_name.csv: Contains the cell type names associated with each cluster.

The default output directory for these files is ./nico_out/annotations/.

Notes

  • The niche function uses the final iteration of the annotations for finding niche cell type interactions in the spatial_neighborhood_analysis.

nico_annotations.Annotations.plot_all_ct(CTname, PP, cellsinCT, ax, flag, cmap)[source]

Helper function used in visualize_umap_and_cell_coordinates_with_all_celltypes to plot all cell types together.

This function plots the locations of all cell types together on a single plot, with each cell type assigned a different color. Optionally, it can label each cell type with its index.

Parameters

CTnamelist of str

A list of cell type names to be plotted.

PPnumpy.ndarray

A 2D numpy array of shape (n_cells, 2) containing the coordinates of the cells.

cellsinCTlist of list of int

A list where each element is a list of indices corresponding to cells of a specific type.

axmatplotlib.axes.Axes

The axes object where the plot will be drawn.

flagbool

A flag indicating whether to label each cell type with its index on the plot.

cmapmatplotlib.colors.Colormap

The colormap used to assign colors to different cell types.

nico_annotations.Annotations.plot_specific_ct(CTname, PP, index, ax, cmap, ms, msna)[source]

Plots individual cell types for visualizing cell type annotations.

This helper function is used to visualize_umap_and_cell_coordinates_with_selected_celltypes by plotting the locations of cells belonging to specific cell types. Cells not belonging to any specified cell types are also plotted in a different color.

Parameters

CTnamelist of str

A list of cell type names to be plotted.

PPnumpy.ndarray

A 2D numpy array of shape (n_cells, 2) containing the coordinates of the cells.

indexlist of list of int

A list where each element is a list of indices corresponding to cells of a specific type.

axmatplotlib.axes.Axes

The axes object where the plot will be drawn.

cmapmatplotlib.colors.Colormap

The colormap used to assign colors to different cell types.

msint or float

The marker size for plotting the cells of specified types.

msnaint or float

The marker size for plotting the cells not belonging to any specified types.

Returns

None

This function does not return any value. It directly plots on the provided axes object.

nico_annotations.Annotations.read_dist_and_nodes_as_graph(knn_dist, knn_nodes)[source]

Reads edges information from k-nearest neighbors (KNN) data and converts it into a graph representation.

This helper function is used in the nico_based_annotation function to interpret the relationships between nodes (cells) based on their KNN distances. It constructs a graph G where nodes represent cells and edges represent the KNN relationships with associated distances as weights. Additionally, it calculates the degree of each node.

Parameters

knn_distarray-like

A 2D array where each row represents a node and contains the distances to its k-nearest neighbors.

knn_nodesarray-like

A 2D array where each row represents a node and contains the indices of its k-nearest neighbors.

Returns

degdict

A dictionary where keys are node indices and values are the degrees (number of edges) of the corresponding nodes.

Gnetworkx.Graph

A graph object where nodes represent cells and edges represent KNN relationships between cells.

weightsdict

A dictionary where keys are edge identifiers (formatted as ‘node1#node2’) and values are the distances between the nodes.

Notes

The function assumes that the first element in each row of knn_nodes is the node itself, and subsequent elements are its nearest neighbors.

nico_annotations.Annotations.remove_extra_character_from_name(name)[source]

Remove special characters from cell type names to avoid errors while saving figures.

This function replaces certain special characters in the input name with underscores or other appropriate characters to ensure the name is safe for use as a filename.

Parameters

namestr

The original cell type name that may contain special characters.

Returns

str

The modified cell type name with special characters removed or replaced.

Example

>>> name = 'T-cell (CD4+)/CD8+'
>>> clean_name = remove_extra_character_from_name(name)
>>> print(clean_name)
'T-cell_CD4p_CD8p'

Notes

The following replacements are made:

  • ‘/’ is replaced with ‘_’

  • ‘ ‘ (space) is replaced with ‘_’

  • ‘”’ (double quote) is removed

  • “’” (single quote) is removed

  • ‘)’ is removed

  • ‘(’ is removed

  • ‘+’ is replaced with ‘p’

  • ‘-’ is replaced with ‘n’

  • ‘.’ (dot) is removed

These substitutions help in creating filenames that do not contain characters that might be problematic for file systems or software.

nico_annotations.Annotations.resolved_confused_and_unmapped_mapping_of_cells_with_majority_vote(confused, G, all_mapped, unique_mapped, sp_leiden_barcode2cluid)[source]

Annotates confused anchored and non-anchored spatial cells using a majority vote scheme across the neighbors.

This helper function is used in nico_based_annotation to resolve the mapping of spatial cells that are either confused or not anchored by utilizing the majority vote of their neighbors’ annotations.

Parameters

confusedlist

List of spatial cell identifiers that are confused and need to be resolved.

Gnetworkx.Graph

Graph where nodes represent cells and edges represent connections between cells.

all_mappeddict

Dictionary where keys are cell identifiers and values are their mapped cell types.

unique_mappeddict

Dictionary to be updated where keys are cell identifiers and values are their resolved mapped cell types.

sp_leiden_barcode2cluiddict

Dictionary mapping cell identifiers to their cluster IDs based on Leiden clustering.

Returns

dict

Updated unique_mapped dictionary with resolved cell type annotations for the confused and unmapped cells.

nico_annotations.Annotations.resolved_confused_and_unmapped_mapping_of_cells_with_weighted_average_of_inverse_distance_in_neighbors(confused, G, weights, all_mapped, unique_mapped, sp_leiden_barcode2cluid_resolution_wise)[source]

Annotates confused and unmapped spatial cells using a weighted average score from their neighbors.

This helper function is used in nico_based_annotation to resolve the mapping of spatial cells that are either confused or not anchored by utilizing the weighted average of the inverse distance to their neighbors.

Parameters

confusedlist

List of spatial cell identifiers that are confused and need to be resolved.

Gnetworkx.Graph

Graph where nodes represent cells and edges represent connections between cells.

weightsdict

A dictionary where keys are edge identifiers (formatted as ‘node1#node2’) and values are the corresponding weights (inverse of distances).

all_mappeddict

Dictionary where keys are cell identifiers and values are their mapped cell types.

unique_mappeddict

Dictionary to be updated where keys are cell identifiers and values are their resolved mapped cell types.

sp_leiden_barcode2cluid_resolution_wisedict

Dictionary mapping cell identifiers to their cluster IDs based on Leiden clustering resolution.

Returns

dict

Updated unique_mapped dictionary with resolved cell type annotations for the confused and unmapped cells.

nico_annotations.Annotations.return_singlecells(cluster_data, midzone)[source]

Finds the scRNAseq cells belonging to a specific cell type.

This helper function is used in find_all_the_spatial_cells_mapped_to_single_cells to identify the single-cell RNA sequencing (scRNAseq) cells that belong to a specified cell type (midzone).

Parameters

cluster_datanumpy.ndarray

A 2D array where the first column contains barcode IDs and the second column contains cluster IDs.

midzoneint or str

The cluster ID representing the specific cell type of interest.

Returns

numpy.ndarray

An array of unique barcode IDs corresponding to the cells that belong to the specified cell type (midzone).

nico_annotations.Annotations.save_annotations_in_spatial_object(inputdict, anndata_object_name='nico_celltype_annotation.h5ad')[source]

Save NiCo cell type cluster annotations in the AnnData object.

This function takes a dictionary containing the necessary data and saves the cell type cluster annotations into the .obs[‘nico_ct’] slot of an AnnData object. The updated AnnData object is then saved to a specified file.

Inputs:

inputdictdict

A dictionary containing the cell type annotations related objects.

anndata_object_namestr, optional

Name of the AnnData file to save the annotated data. Default is ‘nico_celltype_annotation.h5ad’.

Outputs:

The function saves the annotated AnnData object in the specified directory (‘./nico_out/’) with the given file name.

nico_annotations.Annotations.sct_return_sc_sp_in_shared_common_PC_space(ad_sp1, ad_sc1, no_of_pc, method)[source]

Helper function used in find_anchor_cells_between_ref_and_query to transform the common gene expression data into PCA space.

This function scales the data, performs PCA on single-cell data, and then projects both spatial and single-cell data into the shared PCA space. The projections are normalized by z-scores.

Parameters

ad_sp1AnnData

AnnData object containing the spatial gene expression data.

ad_sc1AnnData

AnnData object containing the sequencing gene expression data.

no_of_pcint

Number of principal components to compute.

methodstr

Method used for scaling and PCA.

Returns

transfer_sp_comnumpy.ndarray

The spatial data projected into the shared PCA space.

transfer_sc_comnumpy.ndarray

The single-cell data projected into the shared PCA space.

sp_barcodenumpy.ndarray

Barcodes of the spatial data.

sc_barcodenumpy.ndarray

Barcodes of the single-cell data.

nico_annotations.Annotations.visualize_spatial_anchored_cell_mapped_to_scRNAseq(input, saveas='pdf', transparent_mode=False, showit=True, figsize=(12, 10))[source]

Visualizes the anchored cells mapping between spatial and sequencing modalities.

This function generates a heatmap to visualize the mapping of anchored cells between spatial Leiden clusters and scRNAseq clusters.

Parameters

inputobject,

An object containing various attributes required for the function. Specifically, it must contain: - visualize_anchors : tuple A tuple containing the matrix of anchored cells, and the cluster names for spatial and scRNAseq data. Example: (matrix, spatial_cluster_names, scrnaseq_cluster_names) - KNN : int The number of nearest neighbors used in the mutual nearest neighbors (MNN) analysis. - output_annot : str The path where the output figure will be saved.

saveasstr, optional

The format to save the figure, either ‘pdf’ or ‘png’ (default is ‘pdf’).

transparent_modebool, optional

Whether the background of the figure should be transparent (default is False).

showitbool, optional

Whether to display the figure immediately (default is True). If False, the figure is closed after saving.

figsizetuple, optional

The size of the figure (default is (12,10)).

Outputs

The figure is saved at the location specified by “nico_out/annotations/”.

nico_annotations.Annotations.visualize_umap_and_cell_coordinates_with_all_celltypes(output_annotation_dir=None, output_nico_dir=None, anndata_object_name='nico_celltype_annotation.h5ad', spatial_cluster_tag='nico_ct', spatial_coordinate_tag='spatial', umap_tag='X_umap', number_of_iteration_to_perform_celltype_annotations=3, cmap=<matplotlib.colors.LinearSegmentedColormap object>, saveas='pdf', transparent_mode=False, showit=True, figsize=(15, 6))[source]

Visualize UMAP and spatial coordinates with all cell types annotated in a single plot.

This function generates visualizations for UMAP projections and spatial coordinates of cells, annotated by cell types. It saves the figures to specified directories and supports customization of various visualization parameters.

Parameters:

output_annotation_dirstr, optional

Directory to save the annotation figures. Default is ‘./nico_out/annotations/’.

output_nico_dirstr, optional

Base directory for nico output files. Default is ‘./nico_out/’.

anndata_object_namestr, optional

Name of the AnnData object file containing cell type annotations. Default is ‘nico_celltype_annotation.h5ad’.

spatial_cluster_tagstr, optional

Key in AnnData object for spatial cluster annotations slot. Default is ‘nico_ct’.

spatial_coordinate_tagstr, optional

Key in AnnData object for spatial coordinates slot. Default is ‘spatial’.

umap_tagstr, optional

Key in AnnData object for UMAP embeddings slot. Default is ‘X_umap’.

number_of_iteration_to_perform_celltype_annotationsint, optional

Number of iterations performed for cell type annotations. Default is 3.

cmapmatplotlib.colors.Colormap, optional

Colormap used to color the cell types. Default is ‘jet’.

saveasstr, optional

Format to save the figures (‘pdf’ or ‘png’). Default is ‘pdf’.

transparent_modebool, optional

If True, sets the background color of the figures to transparent. Default is False.

showitbool, optional

If True, displays the figures. Default is True.

figsizetuple, optional

Dimensions of the figure size. Default is (15, 6).

Outputs:

Saves annotation figures to the following path ‘./nico_out/annotations/’

nico_annotations.Annotations.visualize_umap_and_cell_coordinates_with_selected_celltypes(output_annotation_dir=None, output_nico_dir=None, anndata_object_name='nico_celltype_annotation.h5ad', spatial_cluster_tag='nico_ct', spatial_coordinate_tag='spatial', umap_tag='X_umap', number_of_iteration_to_perform_celltype_annotations=3, choose_celltypes=[], msna=0.1, ms=0.5, showit=True, cmap=<matplotlib.colors.LinearSegmentedColormap object>, saveas='pdf', transparent_mode=False, figsize=(8, 3.5))[source]

Visualize UMAP and cell coordinates with selected cell types.

This function visualizes the UMAP embedding and cell coordinates for selected cell types from spatial transcriptomics data.

Inputs:

output_annotation_dirstr, optional

Directory path to save the annotation figures. Default is None, which uses ‘./nico_out/annotations/’.

output_nico_dirstr, optional

Directory path for NiCo outputs. Default is None, which uses ‘./nico_out/’.

anndata_object_namestr, optional

Name of the AnnData file containing cell type annotations. Default is ‘nico_celltype_annotation.h5ad’.

spatial_cluster_tagstr, optional

Slot for spatial cluster annotations in the AnnData object. Default is ‘nico_ct’.

spatial_coordinate_tagstr, optional

Slot for spatial coordinates in the AnnData object. Default is ‘spatial’.

umap_tagstr, optional

Slot for UMAP embeddings in the AnnData object. Default is ‘X_umap’.

number_of_iteration_to_perform_celltype_annotationsint, optional

Number of iterations for performing cell type annotations. Default is 3.

choose_celltypeslist, optional

List of cell types to visualize. Default is an empty list, which shows annotations for all cell types.

msnafloat, optional

Marker size for non-selected (NA) cell types. Default is 0.1.

msfloat, optional

Marker size for selected cell types. Default is 0.5.

showitbool, optional

Whether to display the figures. Default is True.

cmapColormap, optional

Colormap used to color the cell types. Default is plt.cm.get_cmap(‘jet’).

saveasstr, optional

Format to save the figures (‘pdf’ or ‘png’). Default is ‘pdf’.

transparent_modebool, optional

Whether to use a transparent background for the figures. Default is False.

figsizetuple, optional

Dimension of the figure size. Default is (8, 3.5).

Outputs:

The function saves individual cell type annotation figures in the specified directory.

Notes:

  • Ensure that the input AnnData object contains the required tags for UMAP, spatial coordinates, and cell type annotations.

  • The function will save the annotation figures in the specified directory.

nico_annotations.Annotations.write_annotation(deg_annot_cluster_fname, deg_annot_ct_fname, unique_mapped, cellname)[source]

Generates CSV files for each iteration’s annotation clusters and cell type names.

This helper function is used in nico_based_annotation to create two CSV files: one for the cluster annotation and one for the cell type names with their frequencies.

Parameters

deg_annot_cluster_fnamestr

The filename for the CSV file that will contain the cluster annotations.

deg_annot_ct_fnamestr

The filename for the CSV file that will contain the cell type names and their frequencies.

unique_mappeddict

A dictionary where keys are cell barcodes and values are their corresponding cell type names.

cellnamenumpy.ndarray

An array of cell barcode IDs.

Returns

numpy.ndarray

An array of cell type names corresponding to each cell barcode ID in the cellname array.

Module contents