BrainNetworksInPython.scripts package

Submodules

BrainNetworksInPython.scripts.annotate_images_to_movie module

BrainNetworksInPython.scripts.call_pls module

BrainNetworksInPython.scripts.fill_measure_dict module

BrainNetworksInPython.scripts.make_corr_matrices module

BrainNetworksInPython.scripts.make_demo_table module

BrainNetworksInPython.scripts.make_demo_table.add_caption(latex_table, caption)[source]

Just add in a row on the second line down to include the caption (title) for this table

BrainNetworksInPython.scripts.make_demo_table.make_demo_table(data_dir, paper_dir)[source]

BrainNetworksInPython.scripts.make_figures module

BrainNetworksInPython.scripts.make_graphs module

BrainNetworksInPython.scripts.make_pysurfer_pictures module

BrainNetworksInPython.scripts.make_pysurfer_pictures.create_pysurfer_command(roi_file, scripts_dir, sub_data_dir, c='jet', l=None, u=None, t=-99, s='pial', cst='classic', center=False, c2=None, t2=None)[source]

Create a text string containing the appropriate options for the pysurfer command

BrainNetworksInPython.scripts.make_pysurfer_pictures.get_cmap_min_max_dict(measure_list)[source]
BrainNetworksInPython.scripts.make_pysurfer_pictures.make_pysurfer_figures(measure_dict, pysurfer_dir, sub_data_dir, scripts_dir, paper_dir, overwrite=False)[source]
BrainNetworksInPython.scripts.make_pysurfer_pictures.pysurfer_308_parcellation(aparc_names, paper_dir)[source]
BrainNetworksInPython.scripts.make_pysurfer_pictures.write_to_text(measure_dict, pysurfer_dir, measure_name, covars_name='none')[source]

mpm is the mpm measure you’re investigating (eg: MT)

For example:
write_to_text(measure_dict,
pysurfer_dir, ‘corr_age_coavars_site_c14’, ‘SlopeAge_at14_covars_site’)

BrainNetworksInPython.scripts.make_stats_tables module

BrainNetworksInPython.scripts.make_supplemental_figures module

BrainNetworksInPython.scripts.make_tables module

#================== Code to make tables for the NSPN Cortical Myelination paper

Created July 2015 by Kirstie Whitaker Contact: kw401@cam.ac.uk or www.github.com/KirstieJane #==================

BrainNetworksInPython.scripts.make_tables.add_caption(latex_table, caption)[source]

Just add in a row on the second line down to include the caption (title) for this table

BrainNetworksInPython.scripts.make_tables.adjust_header(latex_table, align_title_dict, multi_column_dict, top_title_dict, bottom_title_dict)[source]

Replace the standard header spacings to give two rows - the first being bold and containing some multicolumns and the second being in regular text

BrainNetworksInPython.scripts.make_tables.adjust_spacings(latex_table, col_list, align_col_dict)[source]

Replace the spacings for the main columns that are output on the top line of the latex table string with those in the align_col_dict

Return text that needs to go at the beginning and end of the latex file (the table string will go in between) This header and footer should be the same for every table

BrainNetworksInPython.scripts.make_tables.create_latex_tables(measure_dict, output_filename, covars_name='none', n=308, caption=False, sort_col='MT_projfrac+030_all_slope_age_m', ascending=False)[source]

The overall wrapper function

BrainNetworksInPython.scripts.make_tables.dict_to_df(table_dict, sort_col='MT_projfrac+030_all_slope_age', ascending=False)[source]

Put the table_dict into a data frame and sort by col

BrainNetworksInPython.scripts.make_tables.f_dp1_exp_0(x)[source]

Return as string wiht 1 decimal place

BrainNetworksInPython.scripts.make_tables.f_dp2_exp_0(x)[source]

Return as string wiht 2 decimal places

BrainNetworksInPython.scripts.make_tables.f_p(x)[source]

Return as string with 3 decimal places and no leading 0 unless smaller than 0.001 then return <.001

BrainNetworksInPython.scripts.make_tables.get_df_34(table_df)[source]
BrainNetworksInPython.scripts.make_tables.get_df_68(table_df)[source]
BrainNetworksInPython.scripts.make_tables.get_dicts(measure_dict, n=308, covars_name='none', graph='CT_ALL_COVARS_ONES_COST_10')[source]

Create a dict of dicts that contains all the parameters you want to set by hand. N represents the number of regions you want to access. It can be either 308 (all), 68 (collapsing within region), or 34 (collapsing within region and across hemisphere).

BrainNetworksInPython.scripts.make_tables.i(x)[source]

Return as string no decimal places

BrainNetworksInPython.scripts.make_tables.make_tables(measure_dict, tables_dir, cohort_name='Discovery')[source]

Make all the tables you could desire!

BrainNetworksInPython.scripts.make_tables.s(x)[source]

Simply return as a string

BrainNetworksInPython.scripts.make_tables.save_df_to_latex(latex_header, latex_footer, latex_table, output_filename)[source]

As it says on the tin, save the data frame to the filename

BrainNetworksInPython.scripts.old_make_figures module

This code makes the figures for the manuscript “

BrainNetworksInPython.scripts.old_make_figures.add_cells_picture(data_dir, big_fig, grid)[source]
BrainNetworksInPython.scripts.old_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)

BrainNetworksInPython.scripts.old_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!

BrainNetworksInPython.scripts.old_make_figures.add_wedge(df, theta_dict, wedge_colors_list, wedge_measure='von_economo', ax=None)[source]
BrainNetworksInPython.scripts.old_make_figures.all_mean_mt(measure_dict, figures_dir, mpm='MT')[source]
BrainNetworksInPython.scripts.old_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

BrainNetworksInPython.scripts.old_make_figures.candidate_histogram(measure_dict, covars_name='none', measure='PLS1_SZ', figure_name=None, ax=None, figure=None)[source]
BrainNetworksInPython.scripts.old_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]
BrainNetworksInPython.scripts.old_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’
BrainNetworksInPython.scripts.old_make_figures.create_violin_labels()[source]

A little function to create a labels list for the MT depth violin plots

BrainNetworksInPython.scripts.old_make_figures.degree_r_values(graph_dict, y, covars_list=['ones'], measure='CT', group='all')[source]
BrainNetworksInPython.scripts.old_make_figures.figs_for_talk(measure_dict, results_dir, talk_figs_dir)[source]
BrainNetworksInPython.scripts.old_make_figures.figure_1(measure_dict, figures_dir, results_dir, data_dir, mpm='MT', covars_name='none')[source]
BrainNetworksInPython.scripts.old_make_figures.figure_1_replication(measure_dict_D, measure_dict_V, three_cohorts_dir)[source]
BrainNetworksInPython.scripts.old_make_figures.figure_2(measure_dict, figures_dir, results_dir, mpm='MT', covars_name='none')[source]
BrainNetworksInPython.scripts.old_make_figures.figure_3(measure_dict, figures_dir, results_dir, data_dir, mpm='MT', covars_name='none', enrich=True)[source]
BrainNetworksInPython.scripts.old_make_figures.figure_4(measure_dict, graph_dict, figures_dir, results_dir, mpm='MT', rich_club=False, covars_name='none')[source]
BrainNetworksInPython.scripts.old_make_figures.figure_4_replication(measure_dict_D, measure_dict_V, three_cohorts_dir)[source]
BrainNetworksInPython.scripts.old_make_figures.format_p(x)[source]

If p is less than 0.001 then return a string of <.001

BrainNetworksInPython.scripts.old_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.

BrainNetworksInPython.scripts.old_make_figures.get_axis_label_dict()[source]
BrainNetworksInPython.scripts.old_make_figures.get_circular_layout(G, df)[source]
BrainNetworksInPython.scripts.old_make_figures.get_min_max_values(measure_dict, gene_indices=None)[source]

These are the appropriate min and max values for the discovery cohort

BrainNetworksInPython.scripts.old_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

BrainNetworksInPython.scripts.old_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

BrainNetworksInPython.scripts.old_make_figures.make_combo_figures(measure_dict_dict, paper_dir)[source]
BrainNetworksInPython.scripts.old_make_figures.make_combo_hists(measure_dict_dict, paper_dir, gene='SZ', mpm='MT', covars_name='none')[source]
BrainNetworksInPython.scripts.old_make_figures.make_combo_matrix(measure_dict_dict, paper_dir, mpm='MT', covars_name='none')[source]
BrainNetworksInPython.scripts.old_make_figures.make_combo_scatter(measure_dict_dict, paper_dir, mpm='MT', covars_name='none')[source]
BrainNetworksInPython.scripts.old_make_figures.make_figures(measure_dict, figures_dir, pysurfer_dir, data_dir, graph_dict)[source]
BrainNetworksInPython.scripts.old_make_figures.mediation_figure(measure_dict, figures_dir, covars_name='none', measure_name='MT_projfrac+030')[source]
BrainNetworksInPython.scripts.old_make_figures.mt_degree_network_fig(measure_dict, graph_dict, figures_dir)[source]
BrainNetworksInPython.scripts.old_make_figures.network_summary_fig(measure_dict, graph_dict, figures_dir)[source]
BrainNetworksInPython.scripts.old_make_figures.nodal_ct_mt(measure_dict, figures_dir, mpm='MT')[source]
BrainNetworksInPython.scripts.old_make_figures.old_figure_1(graph_dict, figures_dir, sagittal_pos, axial_pos, measure_dict, n=10, covars_list=['ones'], group='all')[source]
BrainNetworksInPython.scripts.old_make_figures.old_figure_2(df_ct, df_mpm, measure_dict, figures_dir, results_dir, aparc_names, mpm='MT')[source]
BrainNetworksInPython.scripts.old_make_figures.old_figure_3(graph_dict, measure_dict, figures_dir, covars_list=['ones'], group='all', measure='CT')[source]
BrainNetworksInPython.scripts.old_make_figures.parcellation_4horbrains(paper_dir)[source]
BrainNetworksInPython.scripts.old_make_figures.partial_volume_fig(measure_dict, figures_dir)[source]
BrainNetworksInPython.scripts.old_make_figures.plot_anatomical_network(G, measure_dict, centroids, measure='module', cost=10, covar='ONES', 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.

BrainNetworksInPython.scripts.old_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]
BrainNetworksInPython.scripts.old_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

BrainNetworksInPython.scripts.old_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

BrainNetworksInPython.scripts.old_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

BrainNetworksInPython.scripts.old_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]
BrainNetworksInPython.scripts.old_make_figures.prepare_violin_movie(fig, ax)[source]
BrainNetworksInPython.scripts.old_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

BrainNetworksInPython.scripts.old_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

BrainNetworksInPython.scripts.old_make_figures.results_matrix(measure_dict, covars_name='none', graph='CT_ALL_COVARS_ONES_COST_10', figure_name=None, ax=None, figure=None)[source]
BrainNetworksInPython.scripts.old_make_figures.rich_edges_nodes(G, thresh=75)[source]
BrainNetworksInPython.scripts.old_make_figures.set_conn_types(G, G_edge=None, thresh=75)[source]
BrainNetworksInPython.scripts.old_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

BrainNetworksInPython.scripts.old_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
BrainNetworksInPython.scripts.old_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)
BrainNetworksInPython.scripts.old_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]
BrainNetworksInPython.scripts.old_make_figures.von_economo_scatter(measure_dict, figures_dir, von_economo, measure='CT_all_mean', x_label='x', y_label='y', x_min=1.5, x_max=4.0, y_min=0.8, y_max=1.2, figure_name=None, figure=None, ax=None)[source]
BrainNetworksInPython.scripts.old_make_figures.xyz_vs_measures(measure_dict, figures_dir, mpm='MT', covars_name='none')[source]

BrainNetworksInPython.scripts.permutation_testing module

BrainNetworksInPython.scripts.pysurfer_plot_500parcellation_surface_values module

BrainNetworksInPython.scripts.read_fsaverage_info module

BrainNetworksInPython.scripts.read_fsaverage_info.get_centroids(filename)[source]

Load the x, y, z coordinates of the cortical and subcortical parcellation regions, remove the first 41 entries which correspond to the subcortical regions, and return the values as a numpy array, and the axial, sagittal, and coronal positions as dictionaries

BrainNetworksInPython.scripts.read_fsaverage_info.get_labels(filename, convert_to_float=False)[source]

Load each line in the filename, where each line represents one of the cortical and subcortical regions in the 308 parcellation, remove the first 41 entries which correspond to the subcortical regions and return the names as a list.

If convert_to_float=True then convert the values in the list to floats otherwise leave as strings.

BrainNetworksInPython.scripts.read_fsaverage_info.read_fsaverage_info(fsaverage_dir)[source]

Get all the info you need from the study fsaverage directory which contains the names of the 308 regions, the location of each region’s center of mass, the assignment of each region to the appropriate von economo cortical type and and the assignment of each region to a lobe label.

BrainNetworksInPython.scripts.report_stats_tables module

BrainNetworksInPython.scripts.stats_functions module

BrainNetworksInPython.scripts.stats_functions.partial_r(x, y, covars)[source]
BrainNetworksInPython.scripts.stats_functions.residuals(x, y)[source]

Return residuals of least squares solution to y = AB where A =[[x 1]]. Uses numpy.linalg.lstsq to find B

BrainNetworksInPython.scripts.stats_functions.variance_partition(x1, x2, y)[source]

Describe the independent and shared explanatory variance of two (possibly correlated) variables on the dependent variable (y)

BrainNetworksInPython.scripts.useful_functions module

BrainNetworksInPython.scripts.useful_functions.read_in_data(regional_measures_file, names_file, covars_file=None, names_308_style=True)[source]
Read in the data from the three input files:
  • regional_measures_file
  • names_file
  • covars_file

If the names are in 308 style then drop the first 41 entries from the names and covars files.

BrainNetworksInPython.scripts.useful_functions.read_in_df(data_file, aparc_names)[source]

A very useful command for NSPN behavmerge data frames Beware though - this is quite specific and there are a few versions floating around! Be careful

BrainNetworksInPython.scripts.useful_functions.residuals(x, y)[source]

A useful little function that correlates x and y together to give their residual values. These can then be used to calculate partial correlation values

BrainNetworksInPython.scripts.visualisation_commands module

BrainNetworksInPython.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

BrainNetworksInPython.scripts.visualisation_commands.view_corr_mat(corr_mat_file, output_name, cmap_name='RdBu_r', cost=None, bin=False)[source]

Module contents