raphael-group / paste2

Probabilistic Alignment of Spatial Transcriptomics Experiments v.2

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Code for LTARI

SiaGuo opened this issue · comments

Hi, it's a good work for 3D reconstruction. I noticed the usage of LTARI in your manuscript, but I fail to find it in your tutorial page or the source code. I wonder if you can provide a description of the usage so that I can evaluate the performance. Thanks.

Hi,

Thank you for your interest in paste2! Here is the implementation of LTARI I used in the paper:

import sklearn

def compute_alignment_ari(sliceA, sliceB, pi):
    mapped_clusters = []
    for j in range(pi.shape[1]):
        mapping = pi[:, j]
        if np.sum(mapping) > 0:
            i = np.argmax(mapping)
            mapped_clusters.append(sliceA.obs['annotation'][i])
        else:
            mapped_clusters.append("NULL")

    assert len(sliceB.obs['annotation']) == len(mapped_clusters)
    true_clusters_mapped_region = []
    mapped_clusters_mapped_region = []
    for i in range(len(sliceB.obs['annotation'])):
        if mapped_clusters[i] != "NULL":
            true_clusters_mapped_region.append(sliceB.obs['annotation'][i])
            mapped_clusters_mapped_region.append(mapped_clusters[i])

    ari = sklearn.metrics.adjusted_rand_score(true_clusters_mapped_region, mapped_clusters_mapped_region)
    return ari

sliceA, sliceB are AnnData objects and pi is the n*m alignment matrix. This code assumes the .obs['annotation'] field stores the cell type annotation and should be changed to the name you use to store the annotation in your dataset.

Let me know if there is any issue with it! Thank you.