aspire.apple package¶
Submodules¶
aspire.apple.apple module¶
- class aspire.apple.apple.Apple(particle_size, output_dir='', min_particle_size=None, max_particle_size=None, query_image_size=None, minimum_overlap_amount=None, tau1=None, tau2=None, container_size=450, model='svm', model_opts=None, mrc_margin_left=99, mrc_margin_right=100, mrc_margin_top=99, mrc_margin_bottom=100, mrc_shrink_factor=2, mrc_gauss_filter_size=15, mrc_gauss_filter_sigma=0.5, response_thresh_norm_factor=20, conv_map_nthreads=4, n_processes=1)¶
Bases:
object
Instantiate an Apple instance with a given configuration.
Some discussion of parameters can be found in:
APPLE picker : Automatic particle picking, a low-effort cryo-EM framework. Heimowitz, Ayelet; Andén, Joakim; Singer, Amit. Journal of Structural Biology, Vol. 204, No. 2, 11.2018, p. 215-227.
- Parameters:
particle_size – Particle size (pixels) is required. Remaining parameters generally have defaults based on particle size.
min_particle_size
max_particle_size
query_image_size
minimum_overlap_amount
tau1 – SVM parameter
tau2 – SVM parameter
container_size – Defaults 450
output_dir – Optionally specify output_dir, defaults to local dir.
model – One of svm/gaussian_mixture/gaussian_naive_bayes/xgboost/thunder_svm
model_opts – Optional dictionary of svm model options. Defaults to None.
n_processes – Concurrent processes to spawn. May improve performance on very large machines. Otherwise use default of 1.
- particle_image(micro_img, particle_size, centers)¶
Return a numpy array representing the picked centers on a micrograph, suitable for rendering in a jupyter notebook or saving as a jpg etc.
- Parameters:
micro_img – The micrograph image as a numpy array
particle_size – Particle size of picked particles
centers – Picked centers for micrograph.
- Returns:
A numpy array with picked centers displayed as rectangles
- process_folder(folder, create_jpg=False)¶
- process_micrograph(filepath, create_jpg=False)¶
Process micrograph at filepath, returning (centers, particle_image).
- Parameters:
filepath – mrc filepath
create_jpg – Optionally writes JPG file identifying picked particles.
- Returns:
(centers, particle_image)
- process_micrograph_centers(filepath)¶
Process micrograph at filepath, returning centers.
- Parameters:
filepath – MRC filepath
- Returns:
centers
- process_micrograph_plots(filepath, centers, create_jpg=False)¶
Takes in centers, returns corresponding particle_image.
Optionally writes jpg to disk.
- Parameters:
filepath – mrc filepath
centers – Particle centers, typically from process_micrograph_centers.
create_jpg – Optionally writes JPG file with picked particles.
- Returns:
particle_image
- verify_input_values()¶
aspire.apple.helper module¶
- class aspire.apple.helper.PickerHelper¶
Bases:
object
- classmethod extract_query(img, block_size)¶
Extract all query images from the micrograph. windows are extracted with steps of size (block_size/2)
- Parameters:
img – Micrograph image.
block_size – Query images must be of size (block_size x block_size).
- Returns:
4D Matrix of query images.
- classmethod extract_references(img, query_size, container_size)¶
Chooses and extracts reference images from the micrograph.
- Parameters:
img – Micrograph image.
query_size – Reference images must be of the same size of query images, i.e. (query_size x query_size).
container_size – Containers are large regions used to select reference images. The size of each region is (container_size x container_size)
- Returns:
3D Matrix of reference images. windows[0] is the first reference window.
- classmethod extract_windows(img, block_size)¶
Extracts blocks of size (block_size x block_size) from the micrograph. Blocks are extracted with steps of size (block_size)
- Parameters:
img – Micrograph image.
block_size – required block size.
- Returns:
3D Matrix of blocks. For example, img[0] is the first block.
- classmethod gaussian_filter(size_filter, std)¶
Computes low-pass filter.
- Parameters:
size_filter – Size of filter (size_filter x size_filter).
std – sigma value in filter.
- classmethod get_training_set(micro_img, bw_mask_p, bw_mask_n, n)¶
Gets training set for the SVM classifier.
- Parameters:
micro_img – Micrograph image.
bw_mask_p – Binary image indicating regions from which to extract examples of particles.
bw_mask_n – Binary image indicating regions from which to extract examples of noise.
n – Size of training windows.
- Returns:
A matrix of features and a vector of labels for the SVM training.
- classmethod moments(img, query_size)¶
Calculates the mean and standard deviation for each window of size (query_size x query_size) in the micrograph.
- Parameters:
img – Micrograph image.
query_size – Size of windows for which to compute mean and std.
- Returns:
A matrix of mean intensity and a matrix of variance, each containing a single entry for each possible (query_size x query_size) window in the micrograph.
- classmethod reference_size(img, container_size)¶
aspire.apple.picking module¶
- class aspire.apple.picking.Picker(particle_size, max_size, min_size, query_size, tau1, tau2, moa, container_size, filename, output_directory, model='svm', model_opts=None, mrc_margin_left=99, mrc_margin_right=100, mrc_margin_top=99, mrc_margin_bottom=100, mrc_shrink_factor=2, mrc_gauss_filter_size=15, mrc_gauss_filter_sigma=0.5, response_thresh_norm_factor=20, conv_map_nthreads=4)¶
Bases:
object
This class does the actual picking with help from PickerHelper class.
- extract_particles(segmentation)¶
Saves particle centers into output .star file, after dismissing regions that are too big to contain a particle.
- Parameters:
segmentation – Segmentation of the micrograph into noise and particle projections.
- Returns:
centers
- get_maps(score, micro_img, particle_windows, non_noise_windows)¶
Gets maps of regions from which to extract particle training for the SVM classifier.
- Parameters:
score – Matrix containing a score for each query image.
micro_img – Micrograph image.
particle_windows – Number of windows that must contain a particle.
non_noise_windows – Number of windows that contain neither noise nor particles.
- Returns:
2-Tuple of particle and noise masks
- morphology_ops(segmentation)¶
Discards suspected artifacts from segmentation.
- Parameters:
segmentation – Segmentation of the micrograph into noise and particle projections.
- Returns:
Updated segmentation of the micrograph into noise and particle projections.
- query_score()¶
Calculates score for each query image.
Extracts query images and reference windows. Computes the cross-correlation between these windows, and applies a threshold to compute a score for each query image.
- Returns:
Matrix containing a score for each query image.
- read_micrograph()¶
Utility wrapper to read supported micrograph file extensions.
Applies binning and a low-pass filter.
- run_svm(score)¶
Trains and uses an SVM classifier.
Trains an SVM classifier to distinguish between noise and particle projections based on mean intensity and variance. Every possible window in the micrograph is then classified as either noise or particle.
This results in a segmentation of the micrograph.
- Parameters:
score – Matrix containing a score for each query image.
- Returns:
Segmentation of the micrograph into noise and particle projections.