Exemple #1
0
def _stringify_legacy_loc(loc: Union[OldWell, OldContainer,
                                     OldSlot, None]) -> str:
    def get_slot(location):
        trace = location.get_trace()
        for item in trace:
            if isinstance(item, OldSlot):
                return item

    type_to_text = {
        OldSlot: 'slot',
        OldContainer: 'container',
        OldWell: 'well',
    }

    # Coordinates only
    if loc is None:
        return '?'

    location = location_to_list(loc)
    multiple = len(location) > 1

    return '{object_text}{suffix} {first}{last} in "{slot_text}"'.format(
            object_text=type_to_text[type(location[0])],
            suffix='s' if multiple else '',
            first=location[0].get_name(),
            last='...'+location[-1].get_name() if multiple else '',
            slot_text=get_slot(location[0]).get_name()
        )
    def _stringify_legacy_loc(
            loc: Union[WellV1, Container, Slot, None]) -> str:
        # reworking of that found in commands.py in order to allow for subclasses
        def get_slot(location):
            trace = location.get_trace()
            for item in trace:
                if isinstance(item, Slot):
                    return item

        type_to_text = {Slot: 'slot', Container: 'container', WellV1: 'well'}

        # Coordinates only
        if loc is None:
            return '?'

        location = location_to_list(loc)
        multiple = len(location) > 1

        for cls, name in type_to_text.items():
            if isinstance(location[0], cls):
                text = name
                break
        else:
            text = 'unknown'

        return '{object_text}{suffix} {first}{last} in "{slot_text}"'.format(
            object_text=text,
            suffix='s' if multiple else '',
            first=location[0].get_name(),
            last='...' + location[-1].get_name() if multiple else '',
            slot_text=get_slot(location[0]).get_name())
Exemple #3
0
def _get_labware(command):  # noqa(C901)
    containers = []
    instruments = []
    modules = []
    interactions = []

    location = command.get('location')
    instrument = command.get('instrument')

    placeable = location
    if isinstance(location, Location):
        placeable = location.labware
    elif isinstance(location, tuple):
        placeable = location[0]

    maybe_module = _get_parent_module(placeable)
    modules.append(maybe_module)

    locations = command.get('locations')
    multiple_instruments = command.get('instruments')

    if location:
        if isinstance(location, (Placeable)) or type(location) == tuple:
            # type()== used here instead of isinstance because a specific
            # named tuple like location descends from tuple and therefore
            # passes the check
            containers.append(get_container(location))
        elif isinstance(location, (Location, labware.Well, labware.Labware)):
            containers.append(_get_new_labware(location))
        else:
            log.error(f'Cant handle location {location!r}')

    if locations:
        if is_new_loc(locations):
            list_of_locations = listify(locations)
            containers.extend(
                [_get_new_labware(loc) for loc in list_of_locations])
        else:
            list_of_locations = location_to_list(locations)
            containers.extend(
                [get_container(location) for location in list_of_locations])

    containers = [c for c in containers if c is not None]
    modules = [m for m in modules if m is not None]

    if instrument:
        instruments.append(instrument)
        interactions.extend([(instrument, container)
                             for container in containers])
    if multiple_instruments:
        for instr in multiple_instruments:
            instruments.append(instr)
            interactions.extend([(instr, container)
                                 for container in containers])

    return instruments, containers, modules, interactions
Exemple #4
0
def transfer(instrument, volume, source, dest):
    text = 'Transferring {volume} from {source} to {dest}'.format(
        volume=transform_volumes(volume),
        source=stringify_location(source),
        dest=stringify_location(dest))
    if is_new_loc(source):
        # Dest is assumed as new location too
        locations = [] + listify(source) + listify(dest)
    else:
        # incase either source or dest is list of tuple location
        # strip both down to simply lists of Placeables
        locations = [] + location_to_list(source) + location_to_list(dest)
    return make_command(name=command_types.TRANSFER,
                        payload={
                            'instrument': instrument,
                            'locations': locations,
                            'volume': volume,
                            'source': source,
                            'dest': dest,
                            'text': text
                        })