Ejemplo n.º 1
0
    def test_read_tracker_panel_with_empty_cells(self):
        self.write_csv_string(self.tracker_multi_csv_with_empty_cells)

        loaded = panels.read_csv(self.filename)

        pd.testing.assert_frame_equal(loaded, self.expected_df)
Ejemplo n.º 2
0
def create_mibitiffs(input_folder,
                     run_path,
                     point,
                     panel_path,
                     slide,
                     size,
                     run_label=None,
                     instrument=None,
                     tissue=None,
                     aperture=None,
                     out=None):
    """Combines single-channel TIFFs into a MIBItiff.

    The input TIFFs are not assumed to have any MIBI metadata. If they do, it
    is suggested to use the simpler :meth:`~merge_mibitiffs` instead.

    Args:
        input_folder: Path to a folder containing single-channel TIFFs.
        run_path: Path to a run xml.
        point: Point name of the image, e.g. Point1 or Point2. This should match
            the name of folder generated for the raw data as it is listed in the
            run xml file.
        panel_path: Path to a panel CSV.
        slide: The slide ID.
        size: The size of the FOV in microns, i.e. 500.
        run_label: Optional custom run label for the combined TIFF. If uploading
            the output to MIBItracker, the run label set here must match the
            label of the MIBItracker run. Defaults to the name of the run xml.
        instrument: Optionally, the instrument ID.
        tissue: Optionally, the name of tissue.
        aperture: Optionally, the name of the aperture or imaging preset.
        out: Optionally, a path to a location for saving the combined TIFF. If
           not specified, defaults to 'combined.tiff' inside the input folder.
        run_label: Optionally, a custom run label for the `run` property of the
            image.
    """
    panel_df = panels.read_csv(panel_path)
    panel_name, _ = os.path.splitext(os.path.basename(panel_path))
    tiff_files = os.listdir(input_folder)

    fovs, calibration = runs.parse_xml(run_path)
    point_number = int(point[5:])
    try:
        fov = fovs[point_number - 1]  # point number is 1-based, not 0-based
    except IndexError:
        raise IndexError('{} not found in run xml.'.format(point))
    if fov['date']:
        run_date = datetime.datetime.strptime(fov['date'],
                                              '%Y-%m-%dT%H:%M:%S').date()
    else:
        run_date = datetime.datetime.now().date()

    image_data = []
    for i in panel_df.index:
        tiff_path = os.path.join(
            input_folder,
            _match_target_filename(tiff_files, panel_df['Target'][i]))
        data = _load_single_channel(tiff_path)
        image_data.append(data)

    image_data = np.stack(image_data, axis=2)

    image = mi.MibiImage(image_data,
                         list(zip(panel_df['Mass'], panel_df['Target'])))

    image.size = int(size)
    image.coordinates = (fov['coordinates'])
    image.filename = fov['run']
    image.run = run_label if run_label else fov['run']
    image.version = tiff.SOFTWARE_VERSION
    image.instrument = instrument
    image.slide = slide
    image.dwell = fov['dwell']
    image.scans = fov['scans']
    image.aperture = aperture
    image.point_name = fov['point_name']
    image.folder = fov['folder']
    image.tissue = tissue
    image.panel = panel_name
    image.date = run_date
    image.mass_offset = calibration['MassOffset']
    image.mass_gain = calibration['MassGain']
    image.time_resolution = calibration['TimeResolution']

    if out is None:
        out = os.path.join(input_folder, 'combined.tiff')

    tiff.write(out, image, multichannel=True)
Ejemplo n.º 3
0
    def test_read_tracker_panel(self):
        self.write_csv_string(self.tracker_csv)

        loaded = panels.read_csv(self.filename)

        pd.testing.assert_frame_equal(loaded, self.expected_df)