Plotting tools¶
Generate Heatmaps¶
- magine.plotting.heatmaps.cluster_distance_mat(dist_mat, names, figsize=(8, 8))[source]¶
Creates heatmap from distance matrix.
- Parameters
- dist_matnp.array
Distance matrix array.
- nameslist_like
Names of ticks for distance matrix
- figsizetuple
Size of figure, passed to matplotlib
- magine.plotting.heatmaps.heatmap_by_terms(data, term_labels, term_sets, colors=None, min_sig=None, convert_to_log=False, y_tick_labels='auto', columns='sample_id', index='identifier', values='fold_change', linewidths=0, cluster_row=False, cluster_col=False, div_colors=False, num_colors=21, figsize=None, annotate_sig=False, **kwargs)[source]¶
- Parameters
- datapd.DataFrame
- term_labelslist_like
List of labels for grouping
- term_setslist_like
List of list like that create the terms
- colorslist_like
Colors for plotting, if not provided it will be created
- min_sigint
Number of sign
- convert_to_logbool
- y_tick_labelslist_like
- columnsstr
Name of columns of df for pivotn
- indexstr
Name of index of df for pivot
- valuesstr
Name of values of df for pivot
- cluster_colbool
Cluster the data using searborn.clustermap
- cluster_rowbool
Cluster rows
- div_colorsbool
Use divergent colors for plotting
- figsizetuple
Size of figure, passed to matplotlib/seaborn
- num_colorsint
Number of colors for color bar
- annotate_sigbool
Add ‘*’ annotation to plot for significant changed terms
- linewidthsfloat or None
Add white line between plots
- min_sigint
Minimum number of significant ‘index’ across samples. Can be used to remove rows that are not significant across any sample.
- Returns
- plt.Figure
- magine.plotting.heatmaps.heatmap_from_array(data, convert_to_log=False, y_tick_labels='auto', cluster_row=False, cluster_col=False, columns='sample_id', index='term_name', values='combined_score', div_colors=False, num_colors=7, figsize=(6, 4), sort_row=None, annotate_sig=False, rank_index=None, linewidths=0.0, cluster_by_set=False, min_sig=0)[source]¶
- Parameters
- datamagine.data.base.BaseData
- convert_to_logbool
Convert fold_change column to log2 scale
- y_tick_labelslist_like
- columnsstr
Name of columns of df for pivot
- indexstr
Name of index of df for pivot
- valuesstr
Name of values of df for pivot
- cluster_colbool
Cluster the data using searborn.clustermap
- cluster_rowbool
Cluster the data using searborn.clustermap
- div_colorsbool
Use divergent colors for plotting
- figsizetuple
Size of figure, passed to matplotlib/seaborn
- sort_rowstr
Sort rows by (‘index’, ‘mean’, max’)
- num_colorsint
Number of colors for color bar
- annotate_sigbool
Add ‘*’ annotation to plot for significant changed terms
- linewidthsfloat or None
Add white line between plots
- cluster_by_set: bool
Cluster by gene set column. Only works for enrichment_array
- min_sigint
Minimum number of significant ‘index’ across samples. Can be used to remove rows that are not significant across any sample.
- rank_index: bool
Rank rows by index. Deprecated , plus use sort_row arg instead.
- Returns
- ——-
- plt.Figure
magine.plotting.species_plotting module¶
- magine.plotting.species_plotting.plot_dataframe(exp_data, html_filename, out_dir='proteins', plot_type='plotly', run_parallel=False)[source]¶
Creates
- Parameters
- exp_datamagine.BaseData.
- html_filenamestr
- out_dir: str, path
Directory that will contain all proteins
- plot_typestr
plotly or matplotlib output
- run_parallelbool
create plots in parallel
- Returns
- ——-
- magine.plotting.species_plotting.plot_genes_by_ont(data, list_of_terms, save_name, out_dir=None, exp_data=None, run_parallel=False, plot_type='plotly')[source]¶
Creates a figure for each GO term in data
BaseData should be a result of running calculate_enrichment. This function creates a plot of all proteins per term if a term is significant and the number of the reference set is larger than 5 and the total number of species measured is less than 100.
- Parameters
- datapandas.DataFrame
previously ran enrichment analysis
- list_of_termslist_list
- save_namestr
name to save file
- out_dirstr
output path for file
- exp_datamagine.ExperimentalData
data to plot
- run_parallelbool
To run in parallel using pathos.multiprocessing
- plot_typestr
plotly or matplotlib
- Returns
- out_arraydict
dict where keys are pointers to figure locations
- magine.plotting.species_plotting.plot_species(df, species_list=None, save_name='test', out_dir=None, title=None, plot_type='plotly', image_format='pdf', close_plots=False)[source]¶
- Parameters
- df: pandas.DataFrame
magine formatted dataframe
- species_list: list
List of genes to be plotter
- save_name: str
Filename to be saved as
- out_dir: str
Path for output to be saved
- title: str
Title of plot, useful when list of genes corresponds to a GO term
- plot_typestr
Use plotly to generate html output or matplotlib to generate pdf
- image_formatstr
pdf or png, only used if plot_type=”matplotlib”
- close_plotsbool
Close plot after making, use when creating lots of plots in parallel.
- magine.plotting.species_plotting.write_table_to_html(data, save_name='index', out_dir=None, run_parallel=False, exp_data=None, plot_type='matplotlib')[source]¶
Creates a html table of plots of genes for each ontology term.
- Parameters
- datamagine.enrichment.enrichment_result.EnrichmentResult
- save_namestr
name of html output file
- out_dirstr, optional
output path for all plots
- run_parallelbool
Create plots in parallel
- exp_datamagine.data.ExperimentalData
- plot_typestr {‘matplotlib’, ‘plotly’}
magine.plotting.venn_diagram_maker module¶
- magine.plotting.venn_diagram_maker.create_venn2(list1, list2, label1, label2, save_name=None, title=None, image_format='png', ax=None)[source]¶
Creates a venn digram containing for 2 lists
- Parameters
- list1list_like
- list2list_like
- label1str
- label2str
- save_namestr
- titlestr
- image_formatstr, optional
default png
- axmatplotlib.axes
- magine.plotting.venn_diagram_maker.create_venn3(list1, list2, list3, label1, label2, label3, save_name=None, image_format='png', title=None, ax=None, colors=('g', 'r', 'b'))[source]¶
Creates a venn digram containing for 3 lists
- Parameters
- list1list_like
- list2list_like
- list3list_like
- label1str
- label2str
- label3str
- save_namestr
- image_formatstr
default png
- title: str
- axmatplotlib.axes
magine.plotting.volcano_plots module¶
- magine.plotting.volcano_plots.add_volcano_plot(fig_axis, section_0, section_1, section_2)[source]¶
Adds a volcano plot to a fig axis
- Parameters
- fig_axisplt.Figure.axes
- section_0pd.DataFrame
- section_1pd.DataFrame
- section_2pd.DataFrame
- magine.plotting.volcano_plots.create_mask(data, use_sig=True, p_value=0.1, fold_change_cutoff=1.5)[source]¶
Creates a mask for volcano plots.
# Visual example of volcano plot # section 0 are significant criteria
# 0 # 1 # 0 # # # # # ################################# # # # # # 2 # 2 # 2 # # # # # #################################
- Parameters
- datapd.DataFrame
- use_sigbool
- p_valuefloat
p_value threshold
- fold_change_cutofffloat
fold change threshold
- magine.plotting.volcano_plots.save_plot(fig, save_name, out_dir=None, image_type='png')[source]¶
Saves fig
- Parameters
- figplt.Figure
Figure to be saved
- save_namestr
output file name
- out_dirstr, optional
output path
- image_typestr, optional
output type of file, {“png”, “pdf”, etc..}
- magine.plotting.volcano_plots.volcano_plot(data, save_name=None, out_dir=None, sig_column=False, p_value=0.1, fold_change_cutoff=1.5, x_range=None, y_range=None)[source]¶
Create a volcano plot of data
Creates a volcano plot of data type provided
- Parameters
- datapandas.DataFrame
data to create volcano plots from
- save_name: str
name to save figure
- out_dir: str, directory
Location to save figure
- sig_column: bool, optional
If to use significant flags of data
- p_value: float, optional
Criteria for significant
- fold_change_cutoff: float, optional
Criteria for significant
- y_range: array_like
upper and lower bounds of plot in y direction
- x_range: array_like
upper and lower bounds of plot in x direction