def main(save_folder, spatial_adata):
    """Read out data for ST and scRNA-seq DGE Analysis and create UMAPs for Figure 3A/E and Suppl. Figures 3

    :return:
    """
    spatial_cluster_label = 'tissue_type'

    # load data
    cytokines, allinone, cytoresps_dict = gene_lists.get_publication_cyto_resps(
    )
    leukocyte_markers = gene_lists.leukocyte_markers()

    # remove all spots without a tissue label
    spatial_adata = spatial_adata[
        spatial_adata.obs[spatial_cluster_label] != 'Unknown']

    # 1. get observable for cytokine genes
    spatial_adata, obs_name = add_observables.convert_variable_to_observable(
        adata=spatial_adata,
        gene_names=cytokines,
        task='cell_gene',
        label='celltype',
        condition=None)

    spatial_adata, _ = add_observables.convert_variable_to_observable(
        adata=spatial_adata,
        gene_names=leukocyte_markers,
        task='cell_gene',
        label='celltype',
        condition=None)

    # # 2. Read out counts and metaData for DGE Analysis including double positive cytokine cells
    # 2.1 Read out only leukocytes spots by 'CD2', 'CD3D', 'CD3E', 'CD3G', 'CD247' and 'PTPRC' surface markers
    adata_leukocytes = get_celltypes_data(spatial_adata,
                                          genes=leukocyte_markers)

    # 2.2 Merge layers of epidermis and save it as epidermis and merge dermis depths and save it as dermis
    adata_leukocytes = get_tissueregions(adata=adata_leukocytes,
                                         tissue_label=spatial_cluster_label)

    # 3. Highlicht tissues epidermis and dermis + cytokines and for each single cytokine
    plot_tissueregions_cyto(adata=adata_leukocytes,
                            obs_name='cytokine_IL13',
                            title='Leukocytes_IL13',
                            save_folder=save_folder)
    plot_tissueregions_cyto(adata=adata_leukocytes,
                            obs_name='cytokine_IFNG',
                            title='Leukocytes_IFNG',
                            save_folder=save_folder)

    # 4. Read out all leukocyte positive spots
    include_cytokine_dp(adata=adata_leukocytes,
                        cytokines=cytokines,
                        save_folder=save_folder,
                        label=spatial_cluster_label,
                        key='ST',
                        paper_figure='3AC_Leukocytes')
def exclude_cytokine_dp(adata, cytoresps_dict):
    """Exclusively label double positive cells as double positive

    Parameters
    ----------
    adata : annData
    cytoresps_dict : dict

    Returns
    -------
    adata : annData
    obs_name : str

    """
    cytodict = gene_lists.cyto_asdict()
    # check if all genes are in adata
    cells = list(set(adata.var.index) & set(cytodict.keys()))
    remove_key = np.setdiff1d(list(cytoresps_dict.keys()), cells)
    if len(remove_key) > 0:
        cytodict.pop(remove_key[0], None)
    adata, obs_name = add_observables.convert_variable_to_observable(
        adata=adata,
        gene_names=cytodict,
        task='annotate_cells',
        label='cytokines',
        condition=[np.all, np.all, np.all])

    return adata, obs_name
def main(save_folder, spatial_adata):
    """Read out data for ST DGE Analysis and create UMAPs for Figure 3A

    :return:
    """
    spatial_cluster_label = 'tissue_type'

    # load data
    cytokines, allinone, cytoresps_dict = gene_lists.get_publication_cyto_resps(
    )

    # remove all spots without a tissue label
    spatial_adata = spatial_adata[
        spatial_adata.obs[spatial_cluster_label] != 'Unknown']

    # 1. get observable for cytokine genes
    spatial_adata, obs_name = add_observables.convert_variable_to_observable(
        adata=spatial_adata,
        gene_names=cytokines,
        task='cell_gene',
        label='celltype',
        condition=None)

    # 2. Highlight tissues epidermis and dermis + cytokines and for each single cytokine
    plot_tissuerlayers_cyto(adata=spatial_adata,
                            obs_name='cytokine_IL17A',
                            title='Wholedataset_IL17A',
                            save_folder=save_folder,
                            regions=spatial_cluster_label)
def main(save_folder, adata):
    """Read out spots for DGE analysis and create UMAP of single cell RNA-seq data for Suppl. Figures 4B

    Parameters
    ----------
    save_folder : str
    adata : annData

    Returns
    -------

    """
    sc_cluster_obs = 'cluster_labels'

    # 1. load gene list
    cytokines, allinone, cytoresps_dict = gene_lists.get_publication_cyto_resps(
    )
    leukocyte_markers = gene_lists.leukocyte_markers()

    # 2. get observable for cytokine genes
    adata, obs_name = add_observables.convert_variable_to_observable(
        adata=adata,
        gene_names=cytokines,
        task='cell_gene',
        label='celltype',
        condition=None)

    # Only Leukocytes:
    # 3. Read out counts and metaData for DGE Analysis including double positive cytokine cells
    # 3.1 Read out only T-cell spots by CD2 surface markers
    adata_leukocytes = get_celltypes_data(adata, genes=leukocyte_markers)

    # 3.3 Read out all leukocyte cells
    include_cytokine_dp(adata=adata_leukocytes,
                        cytokines=cytokines,
                        save_folder=save_folder,
                        label=sc_cluster_obs,
                        key='SC_merged',
                        paper_figure='SC')

    # 3.4 Add IL17A label to adata
    adata_leukocytes = add_observables.add_columns_genes(
        adata=adata_leukocytes, genes='IL17A', label='IL17A')
    """ Figure 3D: Highlight IL-17A """
    plot_annotated_cells(adata=adata_leukocytes,
                         color='IL17A_label',
                         paper_figure='D',
                         save_folder=save_folder,
                         key='SC',
                         title='Leukocytes_IL17A',
                         xpos=0.02,
                         ypos=0.95)
def get_expression_values(adata, gene):
    """Add gene count, label and cluster annotation as column to annData

    Parameters
    ----------
    adata : annData
    gene : str or 'list' ['str']

    Returns
    -------

    """

    # Get observable for gene
    adata, obs_name = add_observables.convert_variable_to_observable(
        adata=adata, gene_names=gene, task='cell_gene', label='celltype', condition=None)

    return adata, obs_name
def main(save_folder, adata):
    """Read out spots for DGE analysis and create UMAP of single cell RNA-seq data for Suppl. Figures 4B

    Parameters
    ----------
    save_folder : str
    adata : annData

    Returns
    -------

    """
    sc_cluster_obs = 'cluster_labels'

    # 1. load gene list
    cytokines, allinone, cytoresps_dict = gene_lists.get_publication_cyto_resps()
    leukocyte_markers = gene_lists.leukocyte_markers()

    # 2. get observable for cytokine genes
    adata, obs_name = add_observables.convert_variable_to_observable(
        adata=adata, gene_names=cytokines, task='cell_gene', label='celltype', condition=None)

    # Only Leukocytes:
    # 3. Read out counts and metaData for DGE Analysis including double positive cytokine cells
    # 3.1 Read out only T-cell spots by CD2 surface markers
    adata_leukocytes = get_celltypes_data(adata, genes=leukocyte_markers)

    # 3.3 Read out all leukocyte cells
    include_cytokine_dp(adata=adata_leukocytes, cytokines=cytokines, save_folder=save_folder,
                        label=sc_cluster_obs, key='SC_merged', paper_figure='SC')
    # 3.3 Read out all leukocyte cells but exclude double positive cytokine cells
    adata_leukocytes, obs_name = exclude_cytokine_dp(adata=adata_leukocytes, cytoresps_dict=cytoresps_dict)

    # Plot cytokines and highlight double positive
    plot_annotated_cells(adata=adata_leukocytes, color='cytokines_others', paper_figure='',
                         save_folder=save_folder, key='SC', title="Leukocytes_IL17A_IFNG",
                         xpos=0.02, ypos=0.95, palette=["#ff7f00", "#377eb8", 'purple'])

    # Add cytokine label to adata and Plot: Highlight cytokines
    adata_leukocytes = add_observables.add_columns_genes(adata=adata_leukocytes, genes='IFNG', label='IFNG')

    """ Suppl. Figure 4B: Highlight IFN-g """
    plot_annotated_cells(adata=adata_leukocytes, color='IFNG_label', paper_figure='4B', save_folder=save_folder,
                         key='SC', title="Leukocyte_IFNG", xpos=0.02, ypos=0.95)
示例#7
0
def main(save_folder, pp_adata, cluster_algorithm):
    """
    1. scRNAseq data set
    Read ou pre-processed Count matrix and apply Leiden clustering with resolution r = 0.1 for scRNAseq data set
    Annotate clusters manually

    2. ST data set
    Visualise count matrix with tissue types

    :return:
    """

    # 1. load gene list
    cytokines, allinone, cytoresps_dict = gene_lists.get_publication_cyto_resps(
    )

    # 2. Get observable for cytokine genes
    pp_adata, _ = add_observables.convert_variable_to_observable(
        adata=pp_adata,
        gene_names=cytokines,
        task='cell_gene',
        label='celltype',
        condition=None)

    # 3. Apply cluster algorithm
    pp_adata, key = apply_clusteralgo(adata=pp_adata,
                                      algorithm=cluster_algorithm,
                                      resolution=0.1)

    # 4. Annotate clusters with expert opinion - before the best resolution r=0.1 was identified
    pp_adata = annotate_cluster(adata=pp_adata,
                                cluster_algorithm=cluster_algorithm,
                                resolution=0.1)

    # 5. Plot UMAP scRNAseq data
    visualise_clusters(adata=pp_adata,
                       save_folder=save_folder,
                       key='cluster_labels',
                       title="SC")
def main(save_folder, spatial_adata):
    """
    Read out data for ST and scRNA-seq DGE Analysis and create UMAPs for Figure 3A/E and Suppl. Figures 3

    :return:
    """
    spatial_cluster_label = 'tissue_type'

    # 1. load gene lists
    cytokines, allinone, cytoresps_dict = gene_lists.get_publication_cyto_resps(
    )
    leukocyte_markers = gene_lists.leukocyte_markers()

    # 2. remove all spots without a tissue label
    spatial_adata = spatial_adata[
        spatial_adata.obs[spatial_cluster_label] != 'Unknown']

    # 3. get observable for cytokine genes and leukocyte markers
    spatial_adata, obs_name = add_observables.convert_variable_to_observable(
        adata=spatial_adata,
        gene_names=cytokines,
        task='cell_gene',
        label='celltype',
        condition=None)

    spatial_adata, obs_name = add_observables.convert_variable_to_observable(
        adata=spatial_adata,
        gene_names=leukocyte_markers,
        task='cell_gene',
        label='celltype',
        condition=None)

    # 4. Read out only leukocytes spots by 'CD2', 'CD3D', 'CD3E', 'CD3G', 'CD247' and 'PTPRC' surface markers
    adata_leukocytes = get_celltypes_data(spatial_adata,
                                          genes=leukocyte_markers)

    # 5. add observable healthy_disease
    spatial_adata = add_observables.add_disease_healthy_obs(spatial_adata)

    # keys: 'patient', 'biopsy_type', 'disease', 'tissue_type'
    # Suppl Figure 2A
    visualise_clusters(adata=spatial_adata,
                       save_folder=save_folder,
                       key='healthy_disease',
                       title="Diagnoses")
    # Suppl. Figure 2C
    visualise_clusters(adata=adata_leukocytes,
                       save_folder=save_folder,
                       key='tissue_type',
                       title="Leukocytes_tissuelayers")

    # 5. Read out spots which either have IL17A, IL13 or INFG genes
    adata_leukocytes, obs_name = exclude_cytokine_dp(
        adata=adata_leukocytes, cytoresps_dict=cytoresps_dict)

    # 6. Merge layers of epidermis and save it as epidermis and merge dermis depths and save it as dermis
    adata_leukocytes = get_tissueregions(adata=adata_leukocytes,
                                         tissue_label=spatial_cluster_label)

    # Suppl. Figure 2B
    plot_tissueregions_cyto(adata=adata_leukocytes,
                            obs_name=obs_name,
                            title='Leukocytes_Cytokines',
                            save_folder=save_folder,
                            gene_colors=[
                                "#ff7f00", "#e41a1c", 'darkgoldenrod',
                                'purple', "#377eb8", 'deeppink'
                            ])