Пример #1
0
    def add_plate(self, plates, exp_dir):
        """
        add plate(s) from an experiment to the plate_store
        plates being a string or list of strings of the plate names.

        can only add plates from a single experiment directory

        if adding plates from multiple experiments, then use multiple add_plate
        methods

        Parameters:
        -----------
        plates : string or list of strings
            plate names of plates to be added
        exp_dir : string
            path to experiment directory that contains the plates
        """
        if isinstance(plates, str):
            full_path = exp_dir + plates
            img_files = filelist.files_from_plate(full_path)
            self.plate_store[plates] = [full_path, img_files]
        elif isinstance(plates, list):
            full_path = [exp_dir + i for i in plates]
            img_files = [
                filelist.files_from_plate(plate) for plate in full_path
            ]
            for idx, plate in enumerate(plates):
                self.plate_store[plate] = [full_path[idx], img_files[idx]]
        else:
            raise ValueError("plates has to be a string of a list of strings")
Пример #2
0
def test_files_from_plate_truncate():
    """files_from_plate with truncated file-paths"""
    plate_path = os.path.join(TEST_PATH, "test-plate-1")
    output = filelist.files_from_plate(plate_path,
        clean=True, truncate=True)
    for f in output:
        assert len(f.split(os.sep)) == 4
Пример #3
0
def test_files_from_plate():
    """see if we get image files from a plate directory"""
    plate_path = os.path.join(TEST_PATH, "test-plate-1")
    output = filelist.files_from_plate(plate_path,
        clean=True, truncate=False)
    assert len(output) > 0
    for f in output:
        assert f.endswith(".tif")
Пример #4
0
    def add_experiment(self, exp_dir):
        """
        add all plates in an experiment to the platestore

        Parameters:
        -----------
        exp_dir : string
            path to imageXpress experiment that contains plate sub-directories
        """
        self.exp_dir = exp_dir
        plate_names = os.listdir(exp_dir)
        plate_paths = filelist.paths_to_plates(exp_dir)
        img_files = [filelist.files_from_plate(p) for p in plate_paths]
        for idx, plate in enumerate(plate_names):
            self.plate_store[plate] = [plate_paths[idx], img_files[idx]]
Пример #5
0
def test_files_from_plate_clean_false():
    """files_from_plate with clean as false"""
    plate_path = os.path.join(TEST_PATH, "test-plate-1")
    output = filelist.files_from_plate(plate_path,
        clean=False, truncate=False)
    assert len(output) > 0
Пример #6
0
import os
import pandas as pd
from cptools2 import splitter
from cptools2 import filelist

# need to have an image list
CURRENT_PATH = os.path.dirname(__file__)
TEST_PATH = os.path.join(CURRENT_PATH, "example_dir")
TEST_PATH_PLATE_1 = os.path.join(TEST_PATH, "test-plate-1")
# just use a single plate
IMG_LIST = filelist.files_from_plate(TEST_PATH_PLATE_1)


def test_well_site_table():
    """job_splitter._well_site_table(img_list)"""
    output = splitter._well_site_table(IMG_LIST)
    assert isinstance(output, pd.DataFrame)
    # check the dataframe is the right size
    # should have a row per image in image list and 3 columns
    assert output.shape == (len(IMG_LIST), 3)
    # need to short as for some unknown reason the order is being mixed up
    # though doesn't matter as always use column names rather than index
    assert sorted(output.columns.tolist()) == sorted(
        ["img_paths", "Metadata_well", "Metadata_site"])


def test_group_images():
    """job_splitter._group_images(df_img)"""
    # create dataframe for _group_images
    df_img = splitter._well_site_table(IMG_LIST)
    output = splitter._group_images(df_img)