<s> from __future__ import print_function <EOL> from . unit import Unit <EOL> from . util import quad_ind_to_num <EOL> import sys <EOL> if sys . version_info [ <NUM_LIT:0> ] >= <NUM_LIT:3> : <EOL> xrange = range <EOL> basestring = str <EOL> '''<STR_LIT>''' <EOL> class Well ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , container , index ) : <EOL> self . container = container <EOL> self . index = index <EOL> self . volume = None <EOL> self . name = None <EOL> self . properties = { } <EOL> def set_properties ( self , properties ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( properties , dict ) : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> if len ( self . properties . keys ( ) ) > <NUM_LIT:0> : <EOL> self . add_properties ( properties ) <EOL> else : <EOL> self . properties = properties <EOL> return self <EOL> def add_properties ( self , properties ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( properties , dict ) : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> for key , value in properties . items ( ) : <EOL> self . properties [ key ] = value <EOL> return self <EOL> def set_volume ( self , vol ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( vol , basestring ) and not isinstance ( vol , Unit ) : <EOL> raise TypeError ( "<STR_LIT>" % type ( vol ) ) <EOL> v = Unit . fromstring ( vol ) <EOL> if v > self . container . container_type . well_volume_ul : <EOL> raise ValueError ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> self . volume = v <EOL> return self <EOL> def set_name ( self , name ) : <EOL> """<STR_LIT>""" <EOL> self . name = name <EOL> return self <EOL> def humanize ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . container . humanize ( self . index ) <EOL> def __repr__ ( self ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT>" % ( str ( self . container ) , str ( self . index ) , <EOL> str ( self . volume ) ) <EOL> class WellGroup ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , wells ) : <EOL> if isinstance ( wells , Well ) : <EOL> wells = [ wells ] <EOL> elif isinstance ( wells , WellGroup ) : <EOL> wells = wells . wells <EOL> elif isinstance ( wells , list ) : <EOL> if not all ( isinstance ( well , Well ) for well in wells ) : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> else : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> self . wells = wells <EOL> def set_properties ( self , properties ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( properties , dict ) : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> for w in self . wells : <EOL> w . set_properties ( properties ) <EOL> return self <EOL> def set_volume ( self , vol ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( vol , ( Unit , basestring ) ) : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> for w in self . wells : <EOL> w . set_volume ( vol ) <EOL> return self <EOL> def indices ( self ) : <EOL> """<STR_LIT>""" <EOL> indices = [ ] <EOL> for w in self . wells : <EOL> assert w . container == self . wells [ <NUM_LIT:0> ] . container , "<STR_LIT>" <EOL> indices . append ( w . humanize ( ) ) <EOL> return indices <EOL> def append ( self , other ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( other , Well ) : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> else : <EOL> return self . wells . append ( other ) <EOL> def extend ( self , other ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( other , WellGroup ) : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> else : <EOL> return self . wells . extend ( other . wells ) <EOL> def __getitem__ ( self , key ) : <EOL> """<STR_LIT>""" <EOL> return self . wells [ key ] <EOL> def __len__ ( self ) : <EOL> """<STR_LIT>""" <EOL> return len ( self . wells ) <EOL> def __repr__ ( self ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT>" % ( str ( self . wells ) ) <EOL> def __add__ ( self , other ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( other , ( Well , WellGroup ) ) : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> if isinstance ( other , Well ) : <EOL> return WellGroup ( self . wells + [ other ] ) <EOL> else : <EOL> return WellGroup ( self . wells + other . wells ) <EOL> class Container ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , id , container_type , name = None , storage = None ) : <EOL> self . name = name <EOL> self . id = id <EOL> self . container_type = container_type <EOL> self . storage = storage <EOL> self . _wells = [ Well ( self , idx ) <EOL> for idx in xrange ( container_type . well_count ) ] <EOL> def well ( self , i ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( i , ( int , basestring ) ) : <EOL> raise TypeError ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> return self . _wells [ self . robotize ( i ) ] <EOL> def wells ( self , * args ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( args [ <NUM_LIT:0> ] , list ) : <EOL> wells = args [ <NUM_LIT:0> ] <EOL> else : <EOL> wells = [ args [ <NUM_LIT:0> ] ] <EOL> for a in args [ <NUM_LIT:1> : ] : <EOL> if isinstance ( a , list ) : <EOL> wells . extend ( a ) <EOL> else : <EOL> wells . extend ( [ a ] ) <EOL> for w in wells : <EOL> if not isinstance ( w , ( basestring , int , list ) ) : <EOL> raise TypeError ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> return WellGroup ( [ self . well ( w ) for w in wells ] ) <EOL> def robotize ( self , well_ref ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( well_ref , ( basestring , int , Well , list ) ) : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> return self . container_type . robotize ( well_ref ) <EOL> def humanize ( self , well_ref ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( well_ref , ( int , basestring , list ) ) : <EOL> raise TypeError ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> return self . container_type . humanize ( well_ref ) <EOL> def decompose ( self , well_ref ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( well_ref , ( int , basestring , Well ) ) : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> return self . container_type . decompose ( well_ref ) <EOL> def all_wells ( self , columnwise = False ) : <EOL> """<STR_LIT>""" <EOL> if columnwise : <EOL> num_cols = self . container_type . col_count <EOL> num_rows = self . container_type . well_count // num_cols <EOL> return WellGroup ( [ self . _wells [ row * num_cols + col ] <EOL> for col in xrange ( num_cols ) <EOL> for row in xrange ( num_rows ) ] ) <EOL> else : <EOL> return WellGroup ( self . _wells ) <EOL> def inner_wells ( self , columnwise = False ) : <EOL> """<STR_LIT>""" <EOL> num_cols = self . container_type . col_count <EOL> num_rows = self . container_type . row_count ( ) <EOL> inner_wells = [ ] <EOL> if columnwise : <EOL> for c in xrange ( <NUM_LIT:1> , num_cols - <NUM_LIT:1> ) : <EOL> wells = [ ] <EOL> for r in xrange ( <NUM_LIT:1> , num_rows - <NUM_LIT:1> ) : <EOL> wells . append ( ( r * num_cols ) + c ) <EOL> inner_wells . extend ( wells ) <EOL> else : <EOL> well = num_cols <EOL> for i in xrange ( <NUM_LIT:1> , num_rows - <NUM_LIT:1> ) : <EOL> inner_wells . extend ( xrange ( well + <NUM_LIT:1> , well + ( num_cols - <NUM_LIT:1> ) ) ) <EOL> well += num_cols <EOL> inner_wells = [ self . _wells [ x ] for x in inner_wells ] <EOL> return WellGroup ( inner_wells ) <EOL> def wells_from ( self , start , num , columnwise = False ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( start , ( basestring , int , Well ) ) : <EOL> raise TypeError ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> if not isinstance ( num , ( int ) ) : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> start = self . robotize ( start ) <EOL> if columnwise : <EOL> row , col = self . decompose ( start ) <EOL> num_rows = self . container_type . row_count ( ) <EOL> start = col * num_rows + row <EOL> return WellGroup ( self . all_wells ( columnwise ) . wells [ start : start + num ] ) <EOL> def quadrant ( self , quad ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( quad , str ) : <EOL> quad = quad_ind_to_num ( quad ) <EOL> allowed_layouts = { <NUM_LIT> : <NUM_LIT:12> , <NUM_LIT> : <NUM_LIT> } <EOL> n_wells = self . container_type . well_count <EOL> if ( n_wells not in allowed_layouts or <EOL> self . container_type . col_count != allowed_layouts [ n_wells ] ) : <EOL> raise ValueError ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> if n_wells == <NUM_LIT> : <EOL> if quad == <NUM_LIT:0> : <EOL> return WellGroup ( self . _wells ) <EOL> else : <EOL> raise ValueError ( <EOL> "<STR_LIT>" ) <EOL> if quad not in [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] : <EOL> raise ValueError ( <EOL> "<STR_LIT>" . format ( quad , str ( self . name ) ) ) <EOL> start_well = [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT> ] <EOL> wells = [ ] <EOL> for row_offset in xrange ( start_well [ quad ] , <NUM_LIT> , <NUM_LIT> ) : <EOL> for col_offset in xrange ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:2> ) : <EOL> wells . append ( row_offset + col_offset ) <EOL> return self . wells ( wells ) <EOL> def set_storage ( self , storage ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( storage , basestring ) : <EOL> raise TypeError ( "<STR_LIT>" <EOL> . format ( storage , type ( storage ) ) ) <EOL> self . storage = storage <EOL> return self <EOL> def discard ( self ) : <EOL> """<STR_LIT>""" <EOL> self . storage = None <EOL> return self <EOL> def __repr__ ( self ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT>" % ( str ( self . name ) ) </s>
