Customized violin plot

This visualization function can be launched from class DigitalCellSorter. By default the function also exports a summary of the data.

From submodule VisualizationFunctions:

class VisualizationFunctions(dataName='dataName', saveDir='', matplotlibMode='Agg', safePlotting=True, verbose=1)[source]

Class of visualization functions for DigitalCellSorter

makeViolinPlot(*args, **kwargs)[source]

Exloratory analysis of the numeric values distributions using matplotlib violinplot.

Parameters:
df_sel: pandas.DataFrame
Table where rows are unique object identifiers, columns are [dimPanels, dimCategories, gene1, gene2, …]

Numeric columns should be without any missing values

genes: list

List of genes names to plot, these should be a (sub)set of the df_sel columns

dimPanels: str

Name of the categorical variable is for saparation into panels. Option ‘All’ can be used too

dimCategories: str

Name of the categorical variable is for saparation into categories within a panel. Option ‘All’ can be used too

panelWidth: float, Default 5

Width of a panel, including the tick labels

panelHeight: float, Default 5

Height of a panel, including the tick labels

title: str, Default ‘{name} {gene}’

Template for panel names

exportData: float, Default True

Whether to export data summary into an excel file

xlabel: str, Default ‘$log(count+1)$’

x-axis label

ylabel: str, Default ‘’

y-axis label

addPoints: boolean, Default True

Whehter to include scattered points on violins

linesColor: str, Default ‘black’

Line color

linesWidth: float, Default 1.0

Line width

cmap: matplotlib.colormap or callable, Default cm.jet

Colormap or its string name

fontsize: float, Default 10

Size of labels font

showMedians: boolean, Default True

Whehter to display median

showExtrema: boolean, Default True

Whehter to display max and min

excludeZeroValues: boolean, Default False

If True then zeros and missing values are not used in calculation of the probability densities

violinWidths: float, Default 0.85

Relative violin widths

violinAlpha: float, Default 0.7

Transparency of the violins

pointsColor: str, Default ‘black’

Color of the points

pointsSize: float, Default 1.0

Size of the points

pointsAlpha: float, Default 0.7

Transparency of the points

pointsPushBack: boolean, Default True

If False then points will be drawn in front of all other objects

sharex: boolean, Default True

Whehter to share x-axis

sharey: boolean, Default True

Whehter to share y-axis

dpi: float, Default 300

Resolution of the figure

extension: str, Default ‘png’

Format extension of the figure

Returns:

None

Usage:

DCS.makeViolinPlot(data, [‘Numeric 1’, ‘Numeric 2’], dimPanels=’Property A’, dimCategories=’Property B’)

Example with synthetic data:

data = pd.DataFrame({'Celltype': np.where((np.random.rand(1000)>0.7), 'Epithelial', 'Endothelial'),
                     'Condition': np.random.rand(1000)>0.3,
                     'Gene 1': np.log(np.random.rand(1000)*3 + 1),
                     'Gene 2': np.log(np.random.rand(1000)*1.5 + 1)})

DCS = DigitalCellSorter.DigitalCellSorter()
DCS.makeViolinPlot(data, ['Gene 1', 'Gene 2'],
                   dimPanels='Celltype', dimCategories='Condition',
                   title='{name}: {gene}', ylabel='Condition',
                   pointsSize=5, fontsize=12)

Example output:

Cannot load this figure