Skip to content

spatial_pscore

Short Description

sm.pl.spatial_pscore: The function allows users to plot proximity volume and density scores. Run sm.tl.spatial_pscore before running this function.

Function

spatial_pscore(adata, label='spatial_pscore', plot_score='both', order_xaxis=None, color='grey', **kwargs)

Parameters:

Name Type Description Default
adata

AnnData object

required
label

string, optional
The label under which the data is saved. This is the same label parameter passed when running the sm.tl.spatial_pscore function.

'spatial_pscore'
plot_score

string, optional
Three option are available. A) Plot only the Proximity Density by passing in Proximity Density
B) Plot only the Proximity Volume by passing in Proximity Volume
C) Plot both side by side by passing both

'both'
order_xaxis

list, optional
If the user wants to re-order the x-axis, pass all the names in the x-axis in the desired order as a list. e.g. ['ROI2', 'ROI4', "ROI1"]

None
color

string, optional
Color of the bars.

'grey'
**kwargs

string
Other arguments that can be passed into sns.barplot

{}
1
2
3
    # Plot only `Proximity Volume` scores
    sm.pl.spatial_pscore (adata, color='Black', 
    plot_score='Proximity Volume', order_xaxis=['ROI2', 'ROI4', "ROI1"])
Source code in scimap/plotting/_spatial_pscore.py
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
def spatial_pscore (adata, label='spatial_pscore', plot_score='both', 
                    order_xaxis = None,
                    color='grey', **kwargs):
    """
Parameters:

    adata : AnnData object

    label : string, optional  
        The label under which the data is saved. This is the same `label` parameter 
        passed when running the `sm.tl.spatial_pscore` function.

    plot_score : string, optional  
        Three option are available. 
        A) Plot only the *Proximity Density* by passing in `Proximity Density`  
        B) Plot only the *Proximity Volume* by passing in `Proximity Volume`  
        C) Plot both side by side by passing `both`

    order_xaxis : list, optional  
        If the user wants to re-order the x-axis, pass all the names in the x-axis
        in the desired order as a list. e.g. ['ROI2', 'ROI4', "ROI1"] 

    color : string, optional  
        Color of the bars.

    **kwargs : string  
        Other arguments that can be passed into `sns.barplot`

Example:
```python
    # Plot only `Proximity Volume` scores
    sm.pl.spatial_pscore (adata, color='Black', 
    plot_score='Proximity Volume', order_xaxis=['ROI2', 'ROI4', "ROI1"])
```
    """


    # Isolate the data from anndata object
    data = adata.uns[label]

    # Order the x-axis if needed
    if order_xaxis is not None:
        data = data.reindex(order_xaxis)


    # Generate the x and y axis
    x  = data.index
    y_pd = data['Proximity Density'].values
    y_pv = data['Proximity Volume'].values

    # Plot what user requests
    if plot_score == 'Proximity Density':
        ax = sns.barplot(x=x, y=y_pd, color=color, **kwargs).set_title('Proximity Density')
        ax = plt.xticks(rotation=90)
        plt.tight_layout()
    if plot_score == 'Proximity Volume':
        ax = sns.barplot(x=x, y=y_pv, color=color, **kwargs).set_title('Proximity Volume')
        ax = plt.xticks(rotation=90)
        plt.tight_layout()
    if plot_score == 'both':
        fig, ax = plt.subplots(1,2)
        sns.barplot(x=x, y=y_pd, color=color, ax=ax[0], **kwargs).set_title('Proximity Density')
        ax[0].tick_params(axis='x', rotation=90)
        sns.barplot(x=x, y=y_pv, color=color, ax=ax[1], **kwargs).set_title('Proximity Volume')
        ax[1].tick_params(axis='x', rotation=90)
        plt.tight_layout()
        fig.show()