Example #1
0
def project_structure(conn, timestamp, image_fixture):
    """
    Project              Dataset           Image
    -------              -------           -----
    proj   ---->    ds    ---->            im0

    Screen        Plate         Well          Image
    ------        -----         ----          -----
    screen ---->  plate ---->   well   ----->  im1
    """

    proj_name = "proj_" + timestamp
    proj_id = ezomero.post_project(conn, proj_name)

    ds_name = "ds_" + timestamp
    ds_id = ezomero.post_dataset(conn, ds_name, project_id=proj_id)

    im_name = 'im_' + timestamp
    im_id = ezomero.post_image(conn, image_fixture, im_name, dataset_id=ds_id)

    update_service = conn.getUpdateService()

    # Create Screen
    screen_name = "screen_" + timestamp
    screen = ScreenWrapper(conn, ScreenI())
    screen.setName(screen_name)
    screen.save()
    screen_id = screen.getId()

    # Create Plate
    plate_name = "plate_" + timestamp
    plate = PlateWrapper(conn, PlateI())
    plate.setName(plate_name)
    plate.save()
    plate_id = plate.getId()
    link = ScreenPlateLinkI()
    link.setParent(ScreenI(screen_id, False))
    link.setChild(PlateI(plate_id, False))
    update_service.saveObject(link)

    # Create Well
    well = WellI()
    well.setPlate(PlateI(plate_id, False))
    well.setColumn(rint(1))
    well.setRow(rint(1))
    well.setPlate(PlateI(plate_id, False))

    # Create Well Sample with Image
    ws = WellSampleI()
    im_id1 = ezomero.post_image(conn, image_fixture, "well image")
    ws.setImage(ImageI(im_id1, False))
    well.addWellSample(ws)
    well_obj = update_service.saveAndReturnObject(well)
    well_id = well_obj.getId().getValue()

    return ({
        'proj': proj_id,
        'ds': ds_id,
        'im': im_id,
        'screen': screen_id,
        'plate': plate_id,
        'well': well_id,
        'im1': im_id1
    })