def overlay_anndatas(adata_spliced, adata_unspliced):
    """'Overlays' anndata objects by taking the intersection of the obs and var
    of each anndata.

    :param adata_spliced: an Anndata object
    :type adata_spliced: anndata.Anndata
    :param adata_unspliced: an Anndata object
    :type adata_unspliced: anndata.Anndata

    :return: a new Anndata object
    :rtype: anndata.Anndata
    """
    idx = adata_spliced.obs.index.intersection(adata_unspliced.obs.index)
    spliced_intersection = adata_spliced[idx]
    unspliced_intersection = adata_unspliced[idx]
    spliced_unspliced = spliced_intersection.copy()
    spliced_unspliced.layers['spliced'] = spliced_intersection.X
    spliced_unspliced.layers['unspliced'] = unspliced_intersection.X
    return spliced_unspliced
