Tip Tracking in PyHamilton

One really simple tool I like to use in PyHamilton is a tip tracking class. The idea is that unlike interacting with wells, you usually don’t care exactly which tips you’re picking up, you just need the right number of unused tips to execute a particular command.

With this in mind, we can write a class that serves us a list of tips that we can pick up to execute a command, and automatically updates the number of tips so that the next time we fetch tips, we fetch from an updated index.

class TipRack:
    This class automatically tracks the tips remaining in a 
    rack and lets the user fetch a specified number of tips
    def __init__(self, rack):
        The class is initialized by referencing a
        PyHamilton Tip96 or Tip384 object
        self.rack = rack
        self.starting_tips = rack._num_items
        self.remaining_tips = rack._num_items
    def get_tips(self, num_tips):
        This method fetches a specified number of tips
        and updates the object state to subtract those
        current_tip = self.starting_tips - self.remaining_tips
        tips_list = [(self.rack, tip) for tip in range(current_tip, current_tip + num_tips)]
        self.remaining_tips -= num_tips
        return tips_list
    def get_tips_seq(self, seq):
        num_tips = len([ch for ch in seq.aspirate if ch])
        tips = self.get_tips(num_tips)
        return tips

lmgr = LayoutManager('assets//deck.lay')
tips = lmgr.assign_unused_resource(ResourceType(Tip96, "drug_a_tips"))
tracked_tips = TipRack(tips)