stitching

Find or apply coordinates to stitch an image

pysmFISH.stitching_package.stitching.assess_performance(micData, alignment, joining, cov_signal, xcov_list, folder, use_IJ_corners=False)[source]

Assess the performance of the stitching

This functions writes its the result to a file in “folder”.

micData: object
MicroscopeData object. Contains coordinates of the tile corners as taken from the microscope and contains the tile set.
alignment: dict
Contains key ‘P’ with a 1D numpy array containing pairwise alignment y and x coordinates (and z-coordinates when applicable) for each neighbouring pair of tiles, array will be 2 * len(contig_typles) for 2D data or 3 * len(contig_typles) for 3D data. Also contains key ‘covs’ with a 1D numpy array containing covariance for each pairwise alignment in ‘P’, ‘covs’ will be len(contig_typles).
joining: dict
Contains keys corner_list and final_image_shape. Corner_list is a list of list, each list is a pair of a tile index (int) and it’s tile’s shifted coordinates in the final image (numpy array containing floats). Final_image_shape is a tuple of size 2 or 3 depending on the numer of dimensions and contains ints.
cov_signal: np.array
The covariance of each neighbouring tile pair in the part of the tiles that overlap in the final stitched signal image.
xcov_list: list
List of cross covariance of the overlap of the tiles in the final stitched image. As returned by tilejoining.assess_overlap.
folder: str
String representing a path. The folder where the performance report should be saved. Needs a trailing slash (‘/’).
use_IJ_corners: bool
If True compare our corners to Image J found in a file in folder, the file name should contain: TileConfiguration.
pysmFISH.stitching_package.stitching.get_pairwise_alignments(tiles, tile_file, contig_tuples, micData, nr_peaks=8, nr_slices=None, nr_dim=2)[source]

Calculate the pairwise transition

Calculates pairwise transition for each neighbouring pair of tiles. This functions is only used in the single core version of the code, not when using MPI.

tiles: list
List of references to the the tiles in the hdf5 file tile_file.
tile_file: pointer
HDF5 file handle. Reference to the opened file containing the tiles.
contig_tuples: list
List of tuples. Each tuple is a tile pair. Tuples contain two tile indexes denoting these tiles are contingent to each other.
micData: object
MicroscopeData object. Containing coordinates of the tile corners as taken from the microscope.
nr_peaks: int
Number of peaks to be extracted from the PCM (Default: 8)
nr_slices: int

Only applicable when running with 3D pictures and using ‘compres pic’ method in pairwisesingle.py. Determines the number of slices that are compressed together (compression in the z-direction). If None, all the slices are compressed

together. (Default: None)
nr_dim: int
If 3, the code will assume three dimensional data for the tile, where z is the first dimension and y and x the second and third. For any other value 2-dimensional data is assumed. (default: 2)
: dict
Contains key ‘P’ with a 1D numpy array containing pairwise alignment y and x coordinates (and z-coordinates when applicable) for each neighbouring pair of tiles, array will be 2 * len(contig_typles) for 2D data or 3 * len(contig_typles) for 3D data. Also contains key ‘covs’ with a 1D numpy array containing covariance for each pairwise alignment in ‘P’, ‘covs’ will be len(contig_typles).
pysmFISH.stitching_package.stitching.get_pairwise_input(ImageProperties, folder, tile_file, hyb_nr, gene='Nuclei', pre_proc_level='FilteredData', est_overlap=0.1, y_flip=False, nr_dim=2)[source]

Get the information necessary to do the pairwise allignment

Find the pairwise pars for an unknown stitching. Works best with a folder containing image with nuclei (DAPI staining)

folder: str
String representing the path of the folder containing the tile file and the yaml metadata file. Needs a trailing slash (‘/’).
tile_file: pointer
HDF5 file handle. Reference to the opened file containing the tiles.
hyb_nr: int
The number of the hybridization we are going to stitch. This will be used to navigate tile_file and find the correct tiles.
gene: str
The name of the gene we are going to stitch. This will be used to navigate tile_file and find the correct tiles. (Default: ‘Nuclei’)
pre_proc_level: str
The name of the pre processing group of the tiles we are going to stitch. This will be used to navigate tile_file and find the correct tiles. (Default: ‘Filtered’)
est_overlap: float
The fraction of two neighbours that should overlap, this is used to estimate the shape of the tile set and then overwritten by the actual average overlap according to the microscope coordinates. (default: 0.1)
y_flip: bool
The y_flip variable is designed for the cases where the microscope sequence is inverted in the y-direction. When set to True the y-coordinates will also be inverted before determining the tile set. (Default: False)
nr_dim: int
If 3, the code will assume three dimensional data for the tile, where z is the first dimension and y and x the second and third. For any other value 2-dimensional data is assumed. (Default: 2)
tiles: list
List of references to the the tiles in the hdf5 file tile_file.
contig_tuples: list
List of tuples. Each tuple is a tile pair. Tuples contain two tile indexes denoting these tiles are contingent to each other.
nr_pixels: int
Height and length of the tile in pixels, tile is assumed to be square.
z_count: int
The number of layers in one tile (size of the z-axis). Is 1 when nr_dim is not 3.
micData: object
MicroscopeData object. Contains coordinates of the tile corners as taken from the microscope.
pysmFISH.stitching_package.stitching.get_pairwise_input_npy(image_properties, converted_positions, hybridization, est_overlap, y_flip=False, nr_dim=2)[source]

Get the information necessary to do the pairwise allignment Modified version of the get_pairwise_input functions that work on .npy files and not on hdf5

Find the pairwise pairs for an unknown stitching.

image_properties: dict
Dictionary with the image details parsed from the Experimental_metadata.yaml file
converted_positions: dict
Dictionary with the coords of the images for all hybridization The coords are a list of floats
hybridization: str
Hybridization that will be processed (Ex. Hybridization2)
est_overlap: float
The fraction of two neighbours that should overlap, this is used to estimate the shape of the tile set and then overwritten by the actual average overlap according to the microscope coordinates. (default: 0.1)
y_flip: bool
The y_flip variable is designed for the cases where the microscope sequence is inverted in the y-direction. When set to True the y-coordinates will also be inverted before determining the tile set. (Default: False)
nr_dim: int
If 3, the code will assume three dimensional data for the tile, where z is the first dimension and y and x the second and third. For any other value 2-dimensional data is assumed. (Default: 2)
tiles: np.array
Array of int with the tiles number. -1 indicate an empty tile
contig_tuples: list
List of tuples. Each tuple is a tile pair. Tuples contain two tile indexes denoting these tiles are contingent to each other.
nr_pixels: int
Height and length of the tile in pixels, tile is assumed to be square.
z_count: int
The number of layers in one tile (size of the z-axis). Is 1 when nr_dim is not 3.
micData: object
MicroscopeData object. Contains coordinates of the tile corners as taken from the microscope.
pysmFISH.stitching_package.stitching.get_place_tile_input(folder, tiles, contig_tuples, micData, nr_pixels, z_count, alignment, data_name, nr_dim=2, save_alignment=True)[source]

Do the global alignment and get the shifted corner coordinates.

Calculates a shift in global coordinates for each tile (global alignment) and then applies these shifts to the corner coordinates of each tile and returns and saves these shifted corner coordinates.

This function produces a file with stitching data in folder called data_name, this file includes the corner coordinates which can be used to apply the stitching to another gene.

folder: str
String representing the path of the folder containing the tile file and the yaml metadata file. Needs a trailing slash (‘/’).
tiles: list
List of strings. List of references to the the tiles in the hdf5 file tile_file.
contig_tuples: list
List of tuples. Each tuple is a tile pair. Tuples contain two tile indexes denoting these tiles are contingent to each other.
micData: object
MicroscopeData object. Contains coordinates of the tile corners as taken from the microscope.
nr_pixels: int
Height and length of the tile in pixels, tile is assumed to be square.
z_count: int
The number of layers in one tile (size of the z-axis). Is 1 when nr_dim is not 3.
alignment: dict
Contains key ‘P’ with a 1D numpy array containing pairwise alignment y and x coordinates (and z-coordinates when applicable) for each neighbouring pair of tiles, array will be 2 * len(contig_typles) for 2D data or 3 * len(contig_typles) for 3D data. Also contains key ‘covs’ with a 1D numpy array containing covariance for each pairwise alignment in ‘P’, ‘covs’ will be len(contig_typles).
data_name: str
Name of the file containing the pickled stitching data.
nr_dim: int
If 3, the code will assume three dimensional data for the tile, where z is the first dimension and y and x the second and third. For any other value 2-dimensional data is assumed. (default: 2)
save_alignment: bool
When False only the stitching coordinates and microscope data will be saved. When True also the contigency tuples and pairwise alignment will be saved (this is necessary if we want to refine the stitching later). (Default: True)
joining: dict
Contains keys corner_list and final_image_shape. Corner_list is a list of list, each list is a pair of a tile index (int) and it’s tile’s shifted coordinates in the final image (numpy array containing floats). Final_image_shape is a tuple of size 2 or 3 depending on the numer of dimensions and contains ints.
pysmFISH.stitching_package.stitching.get_place_tile_input_apply(folder, tile_file, hyb_nr, data_name, gene='Nuclei', pre_proc_level='Filtered', nr_dim=2, check_pairwise=False)[source]

Get the data needed to apply stitching to another gene

folder: str
String representing the path of the folder containing the tile file, the stitching data file the yaml metadata file. Needs a trailing slash (‘/’).
tile_file: pointer
HDF5 file handle. Reference to the opened file containing the tiles.
hyb_nr: int
The number of the hybridization we are going to stitch. This will be used to navigate tile_file and find the correct tiles.
data_name: str
Name of the file containing the pickled stitching data.
gene: str
The name of the gene we are going to stitch. This will be used to navigate tile_file and find the correct tiles. (Default: ‘Nuclei’)
pre_proc_level: str
The name of the pre processing group of the tiles we are going to stitch. This will be used to navigate tile_file and find the correct tiles. (Default: ‘Filtered’)
nr_dim: int
If 3, the code will assume three dimensional data for the tile, where z is the first dimension and y and x the second and third. For any other value 2-dimensional data is assumed. (Default: 2)
check_pairwise: bool
If True the contig_tuples array is assumed to be in the pickled data file and will be returned. (Default: False)
joining: dict
Taken from the stitching data file. Contains keys corner_list and final_image_shape. Corner_list is a list of list, each list is a pair of an image number (int) and it’s coordinates (numpy array containing floats). Final_image_shape is a tuple of size 2 or 3 depending on the numer of dimensions and contains ints.
tiles: list
List of references to the the tiles in the hdf5 file tile_file.
nr_pixels: int
Height and length of the tile in pixels, tile is assumed to be square.
z_count: int
The number of layers in one tile (size of the z-axis). Is 1 when nr_dim is not 3.
micData: object
MicroscopeData object. Taken from the pickled stitching data. Contains coordinates of the tile corners as taken from the microscope.
contig_tuples: list
Only returned if check_pairwise == True. list of tuples. Taken from the pickled stitching data. Each tuple is a tile pair. Tuples contain two tile indexes denoting these tiles are contingent to each other.
pysmFISH.stitching_package.stitching.get_place_tile_input_apply_npy(hyb_dir, stitched_reference_files_dir, data_name, image_properties, nr_dim=2)[source]

Modified version of the get_place_tile_input_apply Get the data needed to apply stitching to another gene

hyb_dir: str
String representing the path of the folder containing the tile file, the stitching data file the yaml metadata file.
stitched_reference_files_dir: str
String representing the path of the folder containing the registered data.
data_name: str
Name of the file containing the pickled stitching data.
image_properties: dict
Dictionary with the image details parsed from the Experimental_metadata.yaml file
nr_dim: int
If 3, the code will assume three dimensional data for the tile, where z is the first dimension and y and x the second and third. For any other value 2-dimensional data is assumed. (Default: 2)
joining: dict
Taken from the stitching data file. Contains keys corner_list and final_image_shape. Corner_list is a list of list, each list is a pair of an image number (int) and it’s coordinates (numpy array containing floats). Final_image_shape is a tuple of size 2 or 3 depending on the numer of dimensions and contains ints.
tiles: list
List of strings. List of references to the the tiles in the hdf5 file tile_file.
nr_pixels: int
Height and length of the tile in pixels, tile is assumed to be square.
z_count: int
The number of layers in one tile (size of the z-axis). Is 1 when nr_dim is not 3.
micData: object
MicroscopeData object. Taken from the pickled stitching data. Contains coordinates of the tile corners as taken from the microscope.
pysmFISH.stitching_package.stitching.get_refine_pairwise_input(folder, tile_file, hyb_nr, data_name, gene='Nuclei', pre_proc_level='Filtered', nr_dim=2)[source]

Get the data needed to refine stitching with another gene

folder: str
String representing the path of the folder containing the tile file, the stitching data file the yaml metadata file. Needs a trailing slash (‘/’).
tile_file: pointer
HDF5 file handle. Reference to the opened file containing the tiles.
hyb_nr: int
The number of the hybridization we are going to stitch. This will be used to navigate tile_file and find the correct tiles.
data_name: str
Name of the file containing the pickled stitching data.
gene: str
The name of the gene we are going to stitch. This will be used to navigate tile_file and find the correct tiles. (Default: ‘Nuclei’)
pre_proc_level: str
The name of the pre processing group of the tiles we are going to stitch. This will be used to navigate tile_file and find the correct tiles. (Default: ‘Filtered’)
nr_dim: int
If 3, the code will assume three dimensional data for the tile, where z is the first dimension and y and x the second and third. For any other value 2-dimensional data is assumed. (Default: 2)
tiles: list
List of references to the the tiles in the hdf5 file tile_file.
contig_tuples: list
List of tuples. Each tuple is a tile pair. Tuples contain two tile indexes denoting these tiles are contingent to each other.
nr_pixels: int
Height and length of the tile in pixels, tile is assumed to be square.
z_count: int
The number of layers in one tile (size of the z-axis). Is 1 when nr_dim is not 3.
micData: object
MicroscopeData object. Contains coordinates of the tile corners as taken from the microscope.
pysmFISH.stitching_package.stitching.plot_final_image(im_file_name, joining, hyb_nr=1, gene='Nuclei', fig_name='final image', shrink_image=False, block=True)[source]

Displays the high quality final image in a plot window.

Takes a lot of working memory for full sized images. When plt_available is false this function does nothing and returns None.

im_file_name: str
Filename of the hdf5 file, containing the final image.
fig_name: str
Name of the plotting window (default: “final image”).
shrink_image: bool
Turn on shrink_image to reduce display quality and memory usage. (Default: False)
block: bool
Plot blocks the running program untill the plotting window is closed if true. Turn off block to make the code continue untill the next call of plt.show(block=True) before displaying the image. (default: True)
pysmFISH.stitching_package.stitching.refine_pairwise_alignments(tiles, tile_file, contig_tuples, alignment_old, micData=None, nr_peaks=8, nr_dim=2)[source]

Calculate the pairwise transition

Calculates pairwise transition for each neighbouring pair of tiles.

tiles: np.array
Array of tiles, a tile should be a 2d np.array representing a picture
contig_tuples: list
List of tuples denoting which tiles are contingent to each other.
micData: object
MicroscopeData object containing coordinates (default None)
nr_peaks: int
nr of peaks to be extracted from the PCM (default 8)
nr_dim: int
If 3, the code will assume three dimensional data for the tile, where z is the first dimension and y and x the second and third. For any other value 2-dimensional data is assumed. (default: 2)
: dict
Contains key ‘P’ with a 1D numpy array containing pairwise alignment y and x coordinates (and z-coordinates when applicable) for each neighbouring pair of tiles, array will be 2 * len(contig_typles) for 2D data or 3 * len(contig_typles) for 3D data. Also contains key ‘covs’ with a 1D numpy array containing covariance for each pairwise alignment in ‘P’, ‘covs’ will be len(contig_typles).
pysmFISH.stitching_package.stitching.save_as_tiff(data_file, hyb_nr, gene, location_image, pre_proc_level='StitchedImage', mode='both')[source]

Save the results as a tiff image for visual inspection.

data_file: pointer
HDF5 file handle. HDF5 file containing the final image.
gene: str
The name of the gene we stitched. This will be used to navigate data_file and find the correct final picture.
hyb_nr: int
The number of the hybridization we have stitched.This will be used to navigate data_file and find the correct final picture.
location_image: str
Full path to the file where the tiff file will be saved (extension not necessary).
pre_proc_level: str
The name of the pre processing group of the tiles we are going to stitch. Normally this will be ‘StitchedImage’, but when the final image is found in another datagroup it may be changed. This will be used to navigate data_file and find the correct final image. (Default: ‘StitchedImage’)
mode: str
Mode determines what color, quality and how many images are saved. Possible values for mode: save_ubyte, save_float, save_rgb. If another or no value is given the image is saved as is and a as a low quality copy (pixel depth 8 bits) (Default: ‘both’)