density2graph module

density2graph.add_Gaussian_noise(mrc, loc=0.0, scale=1.0)[source]

Adds Gaussian white noise to the data in an mrc file

ref: https://numpy.org/doc/stable/reference/random/generated/numpy.random.normal.html

Parameters:
  • mrc (mrcfile object) – mrc object to add noise to

  • loc (float, optional) – mean of Gaussian distribution. Defaults to 0.

  • scale (float, optional) – standard deviation of Gaussian distribution. Defaults to 1.

Returns:

data with noise added

Return type:

[numpy array]

density2graph.cluster_data(xyz_data, DBSCAN_epsilon, DBSCAN_min_samples)[source]

Clusters data using DBSCAN from sklearn

Parameters:
  • xyz_data ([numpy array]) – A[0] = [x0,y0,z0]

  • DBSCAN_epsilon ([float]) – DBSCAN epsilon value (in pixels)

  • DBSCAN_min_samples ([int]) – DBSCAN min_samples

Returns:

clustering results stored in an object

Return type:

[sklearn DBSCAN cluster object]

density2graph.create_and_save_graph(coarse_model, proximity_px, out_fname, save=True)[source]

creates a Networkx graph from the coarse grained model (cluster centroids) and saves it as a graph XML file (.gexf)

Parameters:
  • coarse_model ([numpy array]) – array of cluster centroids, A[0] = [centroid_x0, centroid_y0, centroid_z0]

  • proximity_px ([float]) – pairwise cutoff distance for assigning edges to nodes, in pixels.

  • out_fname ([string]) – filename for output

  • save ([boolean]) – flag to save file (True) or not (False)

Returns:

graph representation of coarse model (cluster centroids)

Return type:

[networkx graph object]

density2graph.get_cluster_centroids(xyz_data, model)[source]

Coarse grain density model using cluster centroids

Parameters:
  • xyz_data ([numpy array]) – A[0] = [x0,y0,z0]

  • model ([sklearn DBSCAN cluster object]) – clustering results stored in an object

Returns:

array of cluster centroids, A[0] = [centroid_x0, centroid_y0, centroid_z0]

Return type:

[numpy array]

density2graph.load_density_file(fname)[source]

load a .mrc file using the mrcfile package

Parameters:

fname ([str]) – filename / filepath

Returns:

MRC data

Return type:

[mrcfile object]

density2graph.main(args)[source]

Takes a 3D density (.mrc), applies threshold, coarse-grains data, and converts it into a graph network. Outputs a .png file of the coarse grained model, and a .gexf graph xml file.

Parameters:

args ([argument parser object]) –

  • args.fname: .mrc filename (white density w/ black background)

  • args.t: unormalized pixel intensity threshold level

  • args.eps: DBSCAN epsilon (inter cluster distance)

  • args.ms: DBSCAN min samples (minimum number of samples in cluster)

  • args.d_cut: pairwise distance cutoff for assigning edges to graph, in pixels

density2graph.normalize_and_threshold_data(mrc, t, noise_stdev=0.0, norm_T=False)[source]

normalizes threshold value and densities then applies a cutoff threshold

Parameters:
  • mrc ([mrcfile object]) – mrc data

  • t ([float]) – raw (unormalized) pixel intensity cutoff threshold

  • noise_stdev ([float]) – Standard deviation of Gaussian noise (mean=0) to add. Default is 0 (no noise added)

  • norm_T ([bool]) – threshold value is normalized (True) or not normalized (False). Default is False.

Returns:

array of x,y,z coordinates which are above the cutoff threshold. A[0] = [x0,y0,z0]

Return type:

[numpy array]

density2graph.plot_clustering_results(xyz_data, coarse_model, figsize=3)[source]

creates a 3D scatter plot containing both the xyz data and the cluster centroids.

Note: should rotate afterwards for better visualization.

Parameters:
  • xyz_data ([numpy array]) – A[0] = [x0,y0,z0]

  • coarse_model ([numpy array]) – array of cluster centroids, A[0] = [centroid_x0, centroid_y0, centroid_z0]

Returns:

3d scatter plot figure

Return type:

[matplotlib figure object]