Exemplo n.º 1
0
#Contiguous pixels that decode to the same gene are called as spots via connected components labeling. The minimum area of these spots are set by this parameter. The intuition is that pixel vectors, that pass the distance and magnitude thresholds, shold probably not be trusted as genes as the mRNA transcript would be too small for them to be real. This parameter can be set based on microscope resolution and signal amplification strategy.
#
#### Crop size
#The crop size crops the image by a number of pixels large enough to eliminate parts of the image that suffer from boundary effects from both signal aquisition (e.g., FOV overlap) and image processing. Here this value is 40.
#
#Given these three thresholds, for each pixel vector, the decoder picks the closest code (minimum distance) that satisfies each of the above thresholds, where the distance is calculated between the code and a normalized intensity vector and throws away subsequent spots that are too small.
# EPY: END markdown

# EPY: START code
# TODO this crop should be (x, y) = (40, 40) but it was getting eaten by kwargs
from starfish.spots import SpotFinder
psd = SpotFinder.PixelSpotDetector(codebook=experiment.codebook,
                                   metric='euclidean',
                                   distance_threshold=0.5176,
                                   magnitude_threshold=1.77e-5,
                                   min_area=2,
                                   max_area=np.inf,
                                   norm_order=2,
                                   crop_z=0,
                                   crop_y=0,
                                   crop_x=0)

initial_spot_intensities, prop_results = psd.run(scaled_image)

spot_intensities = initial_spot_intensities.loc[initial_spot_intensities[
    Features.PASSES_THRESHOLDS]]
# EPY: END code

# EPY: START markdown
### Compare to results from paper
#
#The below plot aggregates gene copy number across single cells in the field of view and compares the results to the published intensities in the MERFISH paper.
# EPY: END markdown

# EPY: START code
# how much magnitude should a barcode have for it to be considered by decoding? this was set by looking at
# the plot above
magnitude_threshold = 0.5
# how big do we expect our spots to me, min/max size. this was set to be equivalent to the parameters
# determined by the Zhang lab.
area_threshold = (5, 30)
# how close, in euclidean space, should the pixel barcode be to the nearest barcode it was called to?
# here, I set this to be a large number, so I can inspect the distribution of decoded distances below
distance_threshold = 3

psd = SpotFinder.PixelSpotDetector(codebook=exp.codebook,
                                   metric='euclidean',
                                   distance_threshold=distance_threshold,
                                   magnitude_threshold=magnitude_threshold,
                                   min_area=area_threshold[0],
                                   max_area=area_threshold[1])

initial_spot_intensities, results = psd.run(zero_norm_stack)
# EPY: END code

# EPY: START code
spots_df = initial_spot_intensities.to_features_dataframe()
spots_df['area'] = np.pi * spots_df['radius']**2
spots_df = spots_df.loc[spots_df[Features.PASSES_THRESHOLDS]]
spots_df.head()
# EPY: END code

# EPY: START markdown
#### QC Plots