scona.scripts package¶
Submodules¶
scona.scripts.make_figures module¶
This code makes the figures for the manuscript “
-
scona.scripts.make_figures.
add_colorbar
(grid, big_fig, cmap_name, y_min=0, y_max=1, cbar_min=0, cbar_max=1, vert=False, label=None, show_ticks=True, pad=0)[source]¶ Add a colorbar to the big_fig in the location defined by grid
grid : grid spec location to add colormap big_fig : figure to which colorbar will be added cmap_name : name of the colormap x_min : the minimum value to plot this colorbar between x_max : the maximum value to plot this colorbar between cbar_min : minimum value for the colormap (default 0) cbar_max : maximum value for the colormap (default 1) vert : whether the colorbar should be vertical (default False) label : the label for the colorbar (default: None) ticks : whether to put the tick values on the colorbar (default: True) pad : how much to shift the colorbar label by (default: 0)
-
scona.scripts.make_figures.
add_four_hor_brains
(grid, f_list, big_fig, hor=True)[source]¶ Take the four pysurfer views (left lateral, left medial, right medial and right lateral) and arrange them in a row according to the grid positions given by grid
grid : the gridspec list of grid placements f_list : list of four file pysurfer image files big_fig : the figure to which you’re adding the images
# THIS WAS UPDATED TO INCLUDE PLOTTING IN A GRID # Should probably change the function name!
-
scona.scripts.make_figures.
add_wedge
(df, theta_dict, wedge_colors_list, wedge_measure='von_economo', ax=None)[source]¶
-
scona.scripts.make_figures.
calc_min_max
(x, pad=0.05)[source]¶ Find min and max values such that all the data lies within 90% of of the axis range
-
scona.scripts.make_figures.
candidate_histogram
(measure_dict, covars_name='none', measure='PLS1_SZ', figure_name=None, ax=None, figure=None)[source]¶
-
scona.scripts.make_figures.
corr_by_agebin
(measure_dict_dict, paper_dir, x_measure='Degree_CT_covar_ones_all_COST_10', y_measure='CT_all_slope_age', ax=None, fig=None, label=None)[source]¶
-
scona.scripts.make_figures.
create_violin_data
(measure_dict, mpm='MT', measure='all_slope_age', cmap='RdBu_r', cmap_min=- 7, cmap_max=7)[source]¶ A little function to create a the data frame list for the MT depth violin plots
- INPUTS:
measure_dict — dictionary containing measure values measure ——– one of ‘mean’
‘std’ ‘all_slope_age’ ‘all_slope_ct’
default = ‘all_slope_age’
- colormap ——- matplotlib colormap
default = ‘RdBu_r’
-
scona.scripts.make_figures.
create_violin_labels
()[source]¶ A little function to create a labels list for the MT depth violin plots
-
scona.scripts.make_figures.
degree_r_values
(graph_dict, y, covars_list=['ones'], measure='CT', group='all')[source]¶
-
scona.scripts.make_figures.
figure_1
(measure_dict, figures_dir, results_dir, data_dir, mpm='MT', covars_name='none')[source]¶
-
scona.scripts.make_figures.
figure_1_replication
(measure_dict_D, measure_dict_V, three_cohorts_dir)[source]¶
-
scona.scripts.make_figures.
figure_2
(measure_dict, figures_dir, results_dir, mpm='MT', covars_name='none')[source]¶
-
scona.scripts.make_figures.
figure_3
(measure_dict, figures_dir, results_dir, data_dir, mpm='MT', covars_name='none', enrich=True)[source]¶
-
scona.scripts.make_figures.
figure_4
(measure_dict, graph_dict, figures_dir, results_dir, mpm='MT', rich_club=False, covars_name='none')[source]¶
-
scona.scripts.make_figures.
figure_4_replication
(measure_dict_D, measure_dict_V, three_cohorts_dir)[source]¶
-
scona.scripts.make_figures.
format_p
(x)[source]¶ If p is less than 0.001 then return a string of <.001
-
scona.scripts.make_figures.
get_anatomical_layouts
(G, df)[source]¶ This code takes in a data frame that has x, y, z coordinates and integer node labels (0 to n-1) for n nodes and returns three dictionaries containing appropriate pairs of coordinates for sagittal, coronal and axial slices.
-
scona.scripts.make_figures.
get_min_max_values
(measure_dict, gene_indices=None)[source]¶ These are the appropriate min and max values for the discovery cohort
-
scona.scripts.make_figures.
get_von_economo_color_dict
(von_economo)[source]¶ Create a color dictionary for the von economo values you pass The color_list is hard coded at the moment… might change one day
-
scona.scripts.make_figures.
get_von_economo_shapes_dict
(von_economo)[source]¶ Create a dictionary containing a different marker shape for each of the the von economo values you pass The shape_list is hard coded at the moment… might change one day
-
scona.scripts.make_figures.
make_combo_hists
(measure_dict_dict, paper_dir, gene='SZ', mpm='MT', covars_name='none')[source]¶
-
scona.scripts.make_figures.
make_combo_matrix
(measure_dict_dict, paper_dir, mpm='MT', covars_name='none')[source]¶
-
scona.scripts.make_figures.
make_combo_scatter
(measure_dict_dict, paper_dir, mpm='MT', covars_name='none')[source]¶
-
scona.scripts.make_figures.
make_figures
(measure_dict, figures_dir, pysurfer_dir, data_dir, graph_dict)[source]¶
-
scona.scripts.make_figures.
mediation_figure
(measure_dict, figures_dir, covars_name='none', measure_name='MT_projfrac+030')[source]¶
-
scona.scripts.make_figures.
network_summary_fig
(corrmat_file, NodalMeasures_file, GlobalMeasures_file, RichClub_file, figures_dir)[source]¶
-
scona.scripts.make_figures.
old_figure_1
(graph_dict, figures_dir, sagittal_pos, axial_pos, measure_dict, n=10, covars_list=['ones'], group='all')[source]¶
-
scona.scripts.make_figures.
old_figure_2
(df_ct, df_mpm, measure_dict, figures_dir, results_dir, aparc_names, mpm='MT')[source]¶
-
scona.scripts.make_figures.
old_figure_3
(graph_dict, measure_dict, figures_dir, covars_list=['ones'], group='all', measure='CT')[source]¶
-
scona.scripts.make_figures.
plot_anatomical_network
(G, NodalMeasures_file, measure='module', orientation='sagittal', cmap_name='jet_r', continuous=False, vmax=None, vmin=None, sns_palette=None, edge_list=None, edge_color='k', edge_width=0.2, node_list=None, rc_node_list=[], node_shape='o', rc_node_shape='s', node_size=500, node_size_list=None, figure=None, ax=None)[source]¶ Plots each node in the graph in one of three orientations (sagittal, axial or coronal). The nodes are sorted according to the measure given (default value: module) and then plotted in that order.
-
scona.scripts.make_figures.
plot_circular_network
(G, measure_dict, sort_measure='module', wedge_measure='von_economo', sort_cmap_name='jet_r', wedge_cmap_name='von_economo', node_size=500, edge_list=None, edge_color='k', edge_width=0.2, figure=None, ax=None, show_wedge=False)[source]¶
-
scona.scripts.make_figures.
plot_degree_dist
(G, ER=True, ax=None, figure_name=None, x_max=200, y_max=0.1, color=0.12156862745098039, 0.4666666666666667, 0.7058823529411765)[source]¶ Make a pretty plot of the degree distribution along with the degree distibution of an Erdos Renyi random graph that has the same number of nodes and edges
-
scona.scripts.make_figures.
plot_network_measures
(measure_dict, ax=None, figure_name=None, y_max=2.5, y_min=- 0.5, color=0.12156862745098039, 0.4666666666666667, 0.7058823529411765)[source]¶ Create a plot of the network measures along with their random counterparts
-
scona.scripts.make_figures.
plot_rich_club
(rc, rc_rand, ax=None, figure_name=None, x_max=200, y_max=1.2, color=0.12156862745098039, 0.4666666666666667, 0.7058823529411765, norm=False)[source]¶ Make a pretty plot of the rich club values per degree along with the rich club values you’d expect by chance from a random network with preserved degree distribution
rc and rc_rand are calculated by the rich_club function that is saved within the networkx_functions.py file
-
scona.scripts.make_figures.
plot_sagittal_network
(G, G_edge, sagittal_pos, axial_pos, integer_adjust=3, fractional_adjust=2.5, cmap_name='jet', ax=None, figure_name=None)[source]¶
-
scona.scripts.make_figures.
pretty_scatter
(x, y, x_label='x', y_label='y', x_max=None, x_min=None, y_max=None, y_min=None, figure_name=None, ax=None, figure=None, color='k', marker_colors=None, marker_shapes=None, marker_size=100, marker='o', despine_right=True, y0_line=True, x0_line=False)[source]¶ This function creates a scatter plot with a regression line for the y variable against the degrees of graph G
-
scona.scripts.make_figures.
rescale
(fname, suff='png')[source]¶ Journals generally like to make life easier for reviewers by sending them a manuscript that is not going to crash their computers with its size, so we’re going to create a smaller version of the input figure (fname) that is 8 inches wide at 200 dpi. It will be saved out in whatever format specified by the suff parameter, and the name will be the same as the original but with _LowRes appended
-
scona.scripts.make_figures.
results_matrix
(measure_dict, covars_name='none', graph='CT_ALL_COVARS_ONES_COST_10', figure_name=None, ax=None, figure=None)[source]¶
-
scona.scripts.make_figures.
setup_color_list
(df, cmap_name='jet', sns_palette=None, measure='module', continuous=False, vmax=1, vmin=0)[source]¶ Use a colormap to set colors for each value in the sort_measure and return a list of colors for each node
-
scona.scripts.make_figures.
violin_add_laminae
(ax, vert=True, labels=True)[source]¶ Great big thank yous to Konrad Wagstyl for journeying to the actual library and reading an actual book to pull out these values from von Economo’s original work. I took these values from Konrad, averaged across regions to get an average thickness per region, added these together to get an average total thickness and divided each value by this total number to get the percentages.
I then scaled the percentages so they lay ontop of a scale from 0 - 10 corresponding to the 11 sample depths for the freesurfer analyses.
The variance around each value was reasonably small. Means:
0.9 1.6 4.6 5.7 7.6 11.0
- Standard deviations:
0.17 0.21 0.25 0.12 0.10 0.12
- Mean + 1 standard devation:
1.6 2.2 5.0 6.0 7.8 10.9
- Mean - 1 standard deviation:
2.0 2.6 5.5 6.3 8.0 11.1
-
scona.scripts.make_figures.
violin_mt_depths
(measure_dict, mpm='MT', measure='all_slope_age', cmap='PRGn', cmap_min=- 7, cmap_max=7, y_max=None, y_min=None, figure_name=None, ax=None, figure=None, y_label=None, vert=True, lam_labels=True, cbar=False, pad=30)[source]¶ - INPUTS:
data_dir ——— where the PARC_*_behavmerge.csv files are saved measure_dict vert ————- create vertical box plots (rather than horizontal)
-
scona.scripts.make_figures.
von_economo_boxes
(measure_dict, figures_dir, von_economo, measure='CT_all_mean', group_label='Cortical Laminar Pattern', y_label=None, y_min=1.5, y_max=4.0, figure_name=None, figure=None, ax=None, von_economo_colors=True, color_dict='muted', cmap_name=None, max_color=False, min_color=False, alpha=1.0)[source]¶
scona.scripts.useful_functions module¶
-
scona.scripts.useful_functions.
read_in_data
(data, names_file, covars_file=None, centroids_file=None, data_as_df=True)[source]¶ Read in data from file paths
- Parameters
data (
str
) – path to a csv file. Read in as apandas.DataFrame
unlessdata_as_df=False
names_file (
str
) – path to a text file containing names of brain regions. Read in as list.covars_file (
str
, optional) – a text file containing a list of covariates to correct for. Read in as list.centroids_file (
str
, optional) – a text file containing cartesian coordinates of brain regions. Should be aligned with names_file so that the ith line of centroids_file is the coordinates of the brain region named in the ith line of names_file. Read in as list.data_as_df (
bool
, optional) – If False, returns data usesnumpy.loadtext()
to import data asnumpy.ndarray
- Returns
data, names, covars, centroids
- Return type
pandas.DataFrame
, list, list or None, list or None
-
scona.scripts.useful_functions.
write_out_measures
(df, output_dir, name, first_columns=[])[source]¶ Write out a DataFrame as a csv
- Parameters
df (
pandas.DataFrame
) – A dataframe of measures to write outoutput_dir (
str
) – The output and filename to write out to. Creates output_dir if it does not existname (
str
) – The output and filename to write out to. Creates output_dir if it does not existfirst_columns (
list
, optional) – There may be columns you want to be saved on the left hand side of the csv for readability. Columns will go left to right in the order specified by first_columns, followed by any columns not in first_columns.
scona.scripts.visualisation_commands module¶
-
scona.scripts.visualisation_commands.
rescale
(fname, suff='png')[source]¶ Journals generally like to make life easier for reviewers by sending them a manuscript that is not going to crash their computers with its size, so we’re going to create a smaller version of the input figure (fname) that is 8 inches wide at 200 dpi. It will be saved out in whatever format specified by the suff parameter, and the name will be the same as the original but with _LowRes appended
-
scona.scripts.visualisation_commands.
view_corr_mat
(corr_mat, output_name, cmap_name='RdBu_r', cost=None, bin=False)[source]¶ This is a visualisation tool for correlation matrices
- Parameters
corr_mat (
str
orpandas.DataFrame
ornumpy.array
) –corr_mat could be:
a string object - Path to the File, containing the matrix;
Note
loading the corr_mat from file is only possible if all data values are float (or integers). Please do not include column or row labels in the file.or a pandas.DataFrame object to represent a correlation matrix;
or a numpy.array representing a correlation matrix;
output_name (
str
) – the name of the file you want to save your visualization of correlation matrix to in.cmap_name (
string
orColormap
, optional) – A Colormap instance or registered colormap name. The colormap maps scalar data to colors. It is ignored for RGB(A) data. Defaults to ‘RdBu_r’.
- Returns
- Return type
The visualization of the correlation matrix is saved in the file.