Beispiel #1
0
def processing_pipeline(
    experiment: starfish.Experiment,
    fov_name: str,
    n_processes: Optional[int] = None
) -> Tuple[starfish.ImageStack, starfish.IntensityTable]:
    """Process a single field of view of an experiment

    Parameters
    ----------
    experiment : starfish.Experiment
        starfish experiment containing fields of view to analyze
    fov_name : str
        name of the field of view to process
    n_processes : int

    Returns
    -------
    starfish.IntensityTable :
        decoded IntensityTable containing spots matched to the genes they are hybridized against
    """

    print("Loading images...")
    primary_image = experiment[fov_name].get_image(FieldOfView.PRIMARY_IMAGES)
    all_intensities = list()
    codebook = experiment.codebook

    images = enumerate(experiment[fov_name].iterate_image_type(
        FieldOfView.PRIMARY_IMAGES))

    for image_number, primary_image in images:

        print(f"Filtering image {image_number}...")
        filter_kwargs = dict(in_place=True,
                             verbose=True,
                             n_processes=n_processes)
        print("Applying Clip...")
        clip1.run(primary_image, **filter_kwargs)
        print("Applying Bandpass...")
        bandpass.run(primary_image, **filter_kwargs)
        print("Applying Gaussian Low Pass...")
        glp.run(primary_image, **filter_kwargs)
        print("Applying Clip...")
        clip2.run(primary_image, **filter_kwargs)

        print("Calling spots...")
        spot_attributes = tlmpf.run(primary_image)
        all_intensities.append(spot_attributes)

    spot_attributes = IntensityTable.concatenate_intensity_tables(
        all_intensities)

    print("Decoding spots...")
    decoded = codebook.decode_per_round_max(spot_attributes)
    decoded = decoded[decoded["total_intensity"] > .025]

    print("Processing complete.")

    return primary_image, decoded
Beispiel #2
0
def test_take_max():
    """
    Create two overlapping IntensityTables with differing number of spots and verify that
    by concatenating them with the TAKE_MAX strategy we only include spots in the overlapping
    section from the IntensityTable that had the most.
    """
    it1 = create_intensity_table_with_coords(Area(min_x=0,
                                                  max_x=2,
                                                  min_y=0,
                                                  max_y=2),
                                             n_spots=10)
    it2 = create_intensity_table_with_coords(Area(min_x=1,
                                                  max_x=2,
                                                  min_y=1,
                                                  max_y=3),
                                             n_spots=20)

    concatenated = IntensityTable.concatenate_intensity_tables(
        [it1, it2], overlap_strategy=OverlapStrategy.TAKE_MAX)

    # The overlap section hits half of the spots from each intensity table, 5 from it1
    # and 10 from i21. It2 wins and the resulting concatenated table should have all the
    # spots from it2 (20) and 6 (one on the border) from it1 (6) for a total of 26 spots
    assert concatenated.sizes[Features.AXIS] == 26
Beispiel #3
0
import os, fnmatch
from starfish import IntensityTable

filenames = []
listOfFiles = os.listdir('.')
pattern = "*.nc"
for entry in listOfFiles:
    if fnmatch.fnmatch(entry, pattern):
        filenames.append(entry)

# load files into memory and concat them
decoded_intensity_tables = map(IntensityTable.open_netcdf, filenames)
merged_table = IntensityTable.concatenate_intensity_tables(
    decoded_intensity_tables)
merged_table.to_netcdf("merged_decoded_fovs.nc")