SyConn API

syconn.brainqueries

syconn.brainqueries.analyze_dataset(wd)[source]

Analyze dataset, i.e. predict barrier, cell objects, calculate hull, map cell objects to tracings and predict synapses together with ultrastructure of cells to create connectivity matrix

Parameters:wd (str) – path to working directory
syconn.brainqueries.detect_similar_tracings(wd)[source]

Print similar skeleton file paths

Parameters:wd (str) – path to working directory
syconn.brainqueries.detect_synapses(wd, qsub_pe=None, qsub_queue=None)[source]
Detects contact sites between enriched tracings and writes contact site
summary and synapse summary to working directory.
Parameters:
  • wd (str Path to working directory) –
  • qsub_pe (str or None) – qsub parallel environment
  • qsub_queue (str or None) – qsub queue
syconn.brainqueries.enrich_tracings(anno_list, wd, map_objects=True, method='hull', radius=1200, thresh=2.2, filter_size=(2786, 1594, 250), create_hull=True, max_dist_mult=1.4, detect_outlier=True, dh=None, overwrite=False, nb_neighbors=20, nb_hull_vox=500, context_range=6000, neighbor_radius=220, nb_rays=20, nb_voting_neighbors=100, write_obj_voxel=True)[source]

Enriches a list of paths (to tracings) using dataset in working directory. Writes enriched tracings to ‘neuron’ folder in working directory, or, if specified, to DataHandler().data_path.

Parameters:
  • wd (str) – Path to working directory
  • anno_list (list) – paths to tracing .k.zip’s
  • map_objects (bool) – Map cell components to skeleton
  • method (str) – Either ‘kd’ for fix radius or ‘hull’/’supervoxel’ if membrane is available.
  • radius (int) – Radius in nm. Single integer if integer radius is for all objects the same. If list of three integer stick to ordering [mitos, vc, sj].
  • thresh (int) – Denotes the factor which is multiplied with the maximum membrane probability. The resulting value is used as threshold after which the membrane is assumed to be existant.
  • nb_rays (int) – Number of rays send at each skeleton node (multiplied by a factor of 5). Defines the angle between two rays (=360 / nb_rays) in the orthogonal plane.
  • neighbor_radius (int) – Radius of ball in which to look for supporting hull voxels. Used during outlier detection.
  • nb_neighbors (int) – minimum number of neighbors needed during outlier detection for a single hull point to survive.
  • filter_size (list, tuple of int) – minimum cell object sizes for each object (mitos, vesicle clouds, synaptic clefts)
  • nb_hull_vox (int) – Number of object hull voxels which are used to estimate spatial proximity to skeleton.
  • context_range (int) – Range of property features
  • nb_voting_neighbors (int) – Number votes of skeleton hull voxels (membrane representation) for object-mapping.
  • dh (DataHandler) – object containing SegmentationDataObjects mitos, vc, sj
  • create_hull (bool) – create skeleton membrane estimation
  • max_dist_mult (float) – Multiplier for radius to generate maximal distance of hull points to source node.
  • detect_outlier (bool) – Use outlier-detection if True
  • overwrite (bool) – Overwrite existing .k.zip’s of mapped skeletons
  • write_obj_voxel (bool) – write object voxel coordinates to .k.zip
syconn.brainqueries.enrich_tracings_all(wd, overwrite=False, qsub_pe=None, qsub_queue=None)[source]

Run :func: ‘enrich_tracings’ on available cluster nodes defined by somaqnodes or using multiprocessing.

Parameters:
  • wd (str) – Path to working directory
  • overwrite (bool) – enforce overwriting of existing files
  • qsub_pe (str or None) – qsub parallel environment
  • qsub_queue (str or None) – qsub queue
syconn.brainqueries.enrich_tracings_star(params)[source]
syconn.brainqueries.get_connectivity_list(wd)[source]

Find synapses between tracing pairs

Parameters:wd (str) – path to working directory
Returns:descending array of synapse (axo-dendritic, if count is zero, axo-axonic touches arepresent) number between corresponding tracing pairs (tuple of ids)
Return type:np.array (n, 1), np.array (n x 2)
syconn.brainqueries.remap_tracings(wd, mapped_skel_paths, dh=None, method='hull', radius=1200, thresh=2.2, filter_size=(2786, 1594, 250), max_dist_mult=1.4, nb_neighbors=20, nb_hull_vox=500, neighbor_radius=220, nb_rays=20, nb_voting_neighbors=100, output_dir=None, write_obj_voxel=True, mito_min_votes=235, vc_min_votes=191, sj_min_votes=346, recalc_prop_only=True, context_range=6000)[source]

Remaps objects to skeleton without recalculating the hull.

Parameters:
  • wd (str) – Path to working directory
  • mapped_skel_paths (list of str) – Paths to tracings
  • dh (DataHandler) – object containing SegmentationDataObjects mitos, vc, sj
  • output_dir (str) – path to output dir. If none, use given path
  • write_obj_voxel (bool) – write object voxel to k.zip
  • sj_min_votes (int) – Best F2 score found by eval
  • mito_min_votes (int) – Best F1 score found by eval
  • vc_min_votes (int) – Best F2 score found by eval
  • method (str) – Either ‘kd’ for fix radius or ‘hull’/’supervoxel’ if membrane is available.
  • radius (int) – Radius in nm. Single integer if integer radius is for all objects the same. If list of three integer stick to ordering [mitos, vc, sj].
  • thresh (float) – Denotes the factor which is multiplied with the maximum membrane probability. The resulting value is used as threshold after which the membrane is assumed to be existant.
  • nb_rays (int) – Number of rays send at each skeleton node (multiplied by a factor of 5). Defines the angle between two rays (=360 / nb_rays) in the orthogonal plane.
  • neighbor_radius (int) – Radius of ball in which to look for supporting hull voxels. Used during outlier detection.
  • nb_neighbors (int) – minimum number of neighbors needed during outlier detection for a single hull point to survive.
  • filter_size (List of integer) – for each object [mitos, vc, sj]
  • nb_hull_vox (int) – Number of object hull voxels which are used to estimate spatial proximity to skeleton.
  • context_range (int) – Range of property features
  • nb_voting_neighbors (int) – Number votes of skeleton hull voxels (membrane representation) for object-mapping.
  • max_dist_mult (float) – Multiplier for radius to generate maximal distance of hull points to source node.
  • output_dir – Path to output directory, if None dh._data_path will be used.
  • recalc_prop_only (bool) – Recalculate only features and prediction of properties (axoness, spiness)
  • write_obj_voxel – write object voxel coordinates to kzip
syconn.brainqueries.remap_tracings_all(wd, dest_dir=None, recalc_prop_only=False, method='hull', context_range=6000, qsub_pe=None, qsub_queue=None)[source]

Run remap_tracings on available cluster nodes defined by somaqnodes or using single node multiprocessing.

Parameters:
  • wd (str) – Path to working directory, which contains skeleton nml / kzip files in
  • dest_dir (str) – Directory path to store mapped skeletons
  • recalc_prop_only (bool) – Recalculate properties (spiness, axoness) only, without calculating hull
  • method (str) – Method for object mapping procedure
  • context_range (int) – Context range for property features
  • qsub_pe (str or None) – qsub parallel environment
  • qsub_queue (str or None) – qsub queue
syconn.brainqueries.remap_tracings_star(params)[source]

Helper function for multiprocessed remap_tracings.

syconn.conmatrix

syconn.conmatrix.class_ranges(pred_arr)[source]

Helper function to get extent of cell types in sorted prediction

Parameters:pred_arr (np.array) – sorted array of cell type predictions
Returns:indices of changing cell type labels in pred_arr
Return type:np.array
syconn.conmatrix.diverge_map(low=(0.9372549019607843, 0.2549019607843137, 0.19607843137254902), high=(0.15294117647058825, 0.7215686274509804, 0.5803921568627451))[source]

Low and high are colors that will be used for the two ends of the spectrum. they can be either color strings or rgb color tuples

syconn.conmatrix.get_cell_majority_synsign(avg_wiring)[source]

Calculates majority synaptic sign of rows in average wiring

Parameters:avg_wiring (np.array) – averaged wiring
Returns:majority vote of synapse sign (row wise)
Return type:np.array of int
syconn.conmatrix.get_cum_pos(den_ranges, ax_ranges, den_pos, ax_pos)[source]

Calculates the position of synapse in average matrix, i.e. which sector it belongs to.

syconn.conmatrix.make_colormap(seq)[source]

Return a LinearSegmentedColormap seq: a sequence of floats and RGB-tuples. The floats should be increasing and in the interval (0,1).

syconn.conmatrix.plot_wiring(wiring, den_borders, ax_borders, max_val, confidence_lvl, binary, wd, big_entries=True, add_fname='', maj_vote=())[source]

Plot type sorted connectivity matrix and save to figures folder in working directory

Parameters:
  • wiring (np.array) – symmetric 2D array of size #cells x #cells
  • den_borders
  • type boarders on post synaptic site (cell) –
  • ax_borders – cell type boarders on pre synaptic site
  • max_val (float) – maximum cumulated contact area shown in plot
  • confidence_lvl (float) – minimum probability of cell type prediction to keep cell
  • binary (bool) – if True existence of synapse is weighted by 1, else 0
  • add_fname (str) – supplement of image file
  • maj_vote (tuple) –
  • big_entries (bool) – artificially increase pixel size from 1 to 3 for better visualization
syconn.conmatrix.plot_wiring_cs(wiring, den_borders, ax_borders, confidence_lvl, binary, wd, add_fname='_CS')[source]

Same as plot_wiring, but using all contact sites

syconn.conmatrix.plot_wiring_cum(wiring, den_borders, ax_borders, confidence_lvl, max_val, binary, wd, add_fname='', maj_vote=())[source]

Plot wiring diagram on celltype-to-celltype level, e.g. connectivity between EA and MSN

syconn.conmatrix.plot_wiring_cum_cs(wiring, den_borders, ax_borders, confidence_lvl, binary, wd, add_fname='')[source]

Same as plot wiring, but using all contact sites

syconn.conmatrix.type_sorted_wiring(wd, confidence_lvl=0.3, binary=False, max_syn_size=0.4, syn_only=True, big_entries=True)[source]

Calculate wiring of consensus skeletons sorted by predicted cell type classification and axoness prediction

Parameters:
  • wd (str) –
  • confidence_lvl (float) – minimum probability of cell type prediction to keep cell
  • binary (bool) – if True existence of synapse is weighted by 1, else 0
  • max_syn_size (float) – maximum cumulated synapse size shown in plot
  • syn_only (bool) – take only contact sites with synapse classification result of 1 into account
  • big_entries (bool) – artificially increase pixel size from 1 to 3 for better visualization
syconn.conmatrix.type_sorted_wiring_cs(wd, confidence_lvl=0.3, binary=False, max_syn_size=0.4)[source]

Same as type_sorted_wiring but for all contact sites (synapse classification 0 and 1)

syconn.contactsites

syconn.contactsites.calc_cs_node(args)[source]

Helper function. Calculates three nodes for given contantct site annotation containing center of cs and the nearest skeleton nodes. The skeleton nodes containg the property axoness, radius and skel_ID. The center contains all above information.

Parameters:args (list) – Filepath to AnnotationObject containing one CS list to store number of processed cs and queue
Returns:
  • list of SkeletonNodes
  • Three nodes (nodes of adjacent skeletons and center node of CS)
syconn.contactsites.collect_contact_sites(cs_dir, only_sj=False)[source]

Collect contact site nodes and corresponding features of all contact sites.

Parameters:
  • cs_dir (str) – Path to contact site directory
  • only_sj (bool) – If only synapse candidates are to be saved
  • cs_dir – path to contact site directory
  • only_sj
Returns:

CS nodes (n x 3), synapse feature (n x #feat)

Return type:

list of SkeletonNodes, np.array

syconn.contactsites.conn_dict_wrapper(wd, all=False)[source]

Wrapper function to write connectivity dictionary to working directory

syconn.contactsites.convert_to_standard_cs_name(name)[source]

Convert to all possible contact site key combinations

Parameters:name (str) – Contact site key
Returns:possible key variations
Return type:list of str
syconn.contactsites.create_synapse_skeleton(wd)[source]
syconn.contactsites.get_number_cs_details(cs_path)[source]

Prints number of synapse candidates and number of contact sites

Parameters:cs_path (str) –
syconn.contactsites.get_spine_dict(spine_node, max_dist=100)[source]

Gather spine information from spine endnote

Parameters:
  • spine_node (SkeletonNode) – Node containing spine information
  • max_dist (float) – Maximum distance from spine head to endpoint in nm
Returns:

Spine properties ‘head_diameter’ and ‘branch_dist’ and ‘head_proba’

Return type:

dict

syconn.contactsites.get_spine_summary(syn_nodes, cs_dir)[source]

Write out dictionary containing spines (dictionaries) with contact site name and spine number as key. The spine dictionary contains three values ‘head_diameter’, ‘branch_dist’ and head_proba

Parameters:
  • syn_nodes (list of SkeletonNodes) –
  • cs_dir (str) – path to contact site data
syconn.contactsites.syn_type_majority_vote(wd, suffix='')[source]

Majority vote of synapse type

Returns:
Return type:int, int
syconn.contactsites.synapse_matrix(wd, type_threshold=0.225, suffix='', exclude_dendrodendro=True)[source]
Parameters:
  • wd (str) –
  • type_threshold (float) –
  • suffix (str) –
  • exclude_dendrodendro (bool) –
syconn.contactsites.update_axoness_dict(cs_dir, syn_only=True)[source]

Update axoness dictionary with current data pulled from ‘neurons/’ folder

Parameters:
  • cs_dir (str) – path to contact site data
  • syn_only (bool) – if only synapses are to be saved.
Returns:

updated axoness dictionary

Return type:

dict

syconn.contactsites.update_property_dict(cs_dir)[source]

Update property dictionary

Parameters:cs_dir (str) –
Returns:update property dictionary
Return type:dict
syconn.contactsites.update_single_cs_axoness(params)[source]

Get axoness of adjacent tracings of contact site

Find nearest tracing node to representative coordinate of contact site of touching tracings.

Parameters:params (tuple (numpy.array, str)) – Representative coordinate and contact site key
Returns:contact site key, dictionary of skeleton axoness
Return type:str, dict
syconn.contactsites.update_single_cs_properties(params)[source]

Helper function of update_property_dict

syconn.contactsites.write_axoness_dicts(cs_dir)[source]

Write axoness dictionaries to working directory

Parameters:cs_dir (str) –
syconn.contactsites.write_cs_summary(cs_nodes, cs_feats, cs_dir, supp='', syn_only=True)[source]

Writes contact site summary of all contact sites without sampling

Parameters:
  • cs_nodes (lsit of SkeletonNodes) – contact site nodes
  • cs_feats (np.array) – synapse features of contact sites
  • cs_dir (str) – path to contact site directory
  • supp (str) – supplement for resulting file
  • syn_only (bool) – if only synapses are to be saved.
syconn.contactsites.write_property_dict(cs_dir)[source]

Write property dictionary to working directory

Parameters:cs_dir (str) –
syconn.contactsites.write_summaries(wd)[source]

Write information about contact sites and synapses, axoness and connectivity.

Parameters:wd (str) – Path to working directory of SyConn