def resizeSelection(self, delta, useUndoStack=True): """ Moves the selected idxs by delta by first iterating over all strands to calculate new idxs (method will return if snap-to behavior would create illegal state), then applying a resize command to each strand. """ resizeList = [] # calculate new idxs for strandSetDict in self._selectionDict.itervalues(): for strand, selected in strandSetDict.iteritems(): part = strand.virtualHelix().part() idxL, idxH = strand.idxs() newL, newH = strand.idxs() deltaL = deltaH = delta # process xovers to get revised delta if selected[0] and strand.connectionLow(): newL = part.xoverSnapTo(strand, idxL, delta) if newL == None: return deltaH = newL-idxL if selected[1] and strand.connectionHigh(): newH = part.xoverSnapTo(strand, idxH, delta) if newH == None: return deltaL = newH-idxH # process endpoints if selected[0] and not strand.connectionLow(): newL = idxL + deltaL if selected[1] and not strand.connectionHigh(): newH = idxH + deltaH if newL > newH: # check for illegal state return resizeList.append((strand, newL, newH)) # end for # end for # execute the resize commands if useUndoStack: self.undoStack().beginMacro("Resize Selection") for strand, idxL, idxH in resizeList: Strand.resize(strand, (idxL, idxH), useUndoStack) if useUndoStack: self.undoStack().endMacro()
def sortedSelectedStrands(self, strandSet): # outList = self._selectionDict[strandSet].keys() # outList.sort(key=Strand.lowIdx) outList = self._selectionDict[strandSet].items() getLowIdx = lambda x: Strand.lowIdx(itemgetter(0)(x)) outList.sort(key=getLowIdx) return outList
def sequence(self): temp = self.strand5p() if not temp: return None if temp.sequence(): return ''.join([Strand.sequence(strand) \ for strand in self.strand5p().generator3pStrand()]) else: return None
def __init__(self): self.led_on = False self.connected = False self.pattern = None self.color_spectrum = None self.error = False self.errormsg = None self.aws_access_key_id = None self.aws_secret_access_key = None self.aws_default_region = None self.aws_kinesis_stream_name = None self.device_state = {} if config.device_type == 'strand': self.strand = Strand() elif config.device_type == 'cam': self.cam = Cam() elif config.device_type == 'flame': self.flame = Flame()
def sequence(self): temp = self.strand5p() if not temp: return None if temp.sequence(): return ''.join([Strand.sequence(strand) \ for strand in self.strand5p().generator3pStrand()]) else: return None
def prepend5p(self, strand: Strand): '''Append a :class:`Strand` to the 3 prime end of the oligo ''' old_strand5p: Strand = self.strand5p assert(old_strand5p.strand5p is None) old_strand5p.strand5p = strand self.strand5p = strand strand.strand3p = old_strand5p # end def # end class
def prepend5p(self, strand: Strand): '''Append a :class:`Strand` to the 3 prime end of the oligo ''' old_strand5p: Strand = self.strand5p assert (old_strand5p.strand5p is None) old_strand5p.strand5p = strand self.strand5p = strand strand.strand3p = old_strand5p # end def # end class
def sequenceExport(self): vhNum5p = self.strand5p().virtualHelix().number() idx5p = self.strand5p().idx5Prime() seq = '' if self.isLoop(): print "A loop exists" raise Exception for strand in self.strand5p().generator3pStrand(): seq = seq + Strand.sequence(strand, forExport=True) if strand.connection3p() == None: # last strand in the oligo vhNum3p = strand.virtualHelix().number() idx3p = strand.idx3Prime() output = "%d[%d],%d[%d],%s,%s,%s\n" % \ (vhNum5p, idx5p, vhNum3p, idx3p, seq, len(seq), self._color) return output
def sequenceExport(self): vhNum5p = self.strand5p().virtualHelix().number() idx5p = self.strand5p().idx5Prime() seq = '' if self.isLoop(): # print "A loop exists" raise Exception for strand in self.strand5p().generator3pStrand(): seq = seq + Strand.sequence(strand, forExport=True) if strand.connection3p() == None: # last strand in the oligo vhNum3p = strand.virtualHelix().number() idx3p = strand.idx3Prime() output = "%d[%d],%d[%d],%s,%s,%s\n" % \ (vhNum5p, idx5p, vhNum3p, idx3p, seq, len(seq), self._color) return output
def __init__(self, *args, **kargs): """ Initialization: Keyword Arguments: sequence [type=str] -- Flat sequence to use for this complex. structure [type=str] -- Flat structure to use for this complex. name [type=str] -- Name of the complex. If None (the default), it is automatically generated with the form 'automatic' + a unique integer. boltzmann_sample [type=bool] -- Whether we should boltzmann sample this complex. You must include both of the required keyword arguments to create a Complex with the new style init, or pass it the old style arguments used in `old_init`. """ if len(args) == 4 or len(args) == 5: self.old_init(*args, **kargs) return elif 'sequence' in kargs and 'structure' in kargs: self.strand_list = [ Strand(sequence=i) for i in kargs['sequence'].split("+") ] self._fixed_structure = str(kargs['structure']) elif 'strands' in kargs and 'structure' in kargs: self.strand_list = kargs['strands'] self._init_parse_structure(str(kargs['structure'])) self.id = Complex.unique_id self.name = kargs.get('name') or "automatic" + str(Complex.unique_id) # note: Boltzmann sampling is somewhat confusing if you pass a # structure that is anything other than all "."'s. So maybe we # should check for that. self.boltzmann_sample = kargs.get('boltzmann_sample', False) self._last_boltzmann_structure = False self._boltzmann_sizehint = 1 self._boltzmann_queue = [] # Adjust here for default Boltzmann Parameters. 'None' in this case means to not pass that parameter and let the sample binary use its default. Substrate defaults to DNA. self._dangles = None self._substrate_type = None self._temperature = None # Taken to be 1, unless it is EXPLICITLY stated otherwise! self.boltzmann_supersample = 1 Complex.unique_id += 1
def __add__(self, other): if isinstance(other, Domain): return Strand(domains=[self, other]) else: return NotImplemented
def __init__(self, seq: str = None): self.seq: str = seq strand: Strand = None if seq is not None: strand = Strand(seq, self) self.strand5p: Strand = strand
class Device(object): """Represents the state of a single device.""" def __init__(self): self.led_on = False self.connected = False self.pattern = None self.color_spectrum = None self.error = False self.errormsg = None self.aws_access_key_id = None self.aws_secret_access_key = None self.aws_default_region = None self.aws_kinesis_stream_name = None self.device_state = {} if config.device_type == 'strand': self.strand = Strand() elif config.device_type == 'cam': self.cam = Cam() elif config.device_type == 'flame': self.flame = Flame() def get_status(self): logging.debug('Refreshing device status...') if config.device_type == 'flame': try: self.flame.update() except Exception as e: logging.error(f"Device state update exception {e}") self.device_state = { 'on': self.flame.on, 'error': self.flame.error } def update(self, updated_config): logging.debug(f"Updating device config: {updated_config}") if config.device_type == 'strand': # Check on/off if updated_config['on'] is False: self.off() else: try: self.strand.set(updated_config) except Exception as e: logging.error(e) elif config.device_type == 'cam': try: self.cam.set(updated_config) except Exception as e: logging.error(e) elif config.device_type == 'flame': try: self.flame.set(updated_config) except Exception as e: logging.error(e) def off(self): logging.debug('Turning all LEDs off...') self.strand.off() @staticmethod def parse_config(config_json): updated_config = json.loads(config_json) if config.device_type == 'strand': led_state = updated_config['on'] brightness = updated_config['brightness'] color_spectrum = updated_config['color']['spectrumRGB'] mode = updated_config['currentModeSettings']['pattern'] if color_spectrum > 0: # Because we can have both mode and color set, a color of 0 indicates mode should be used. color_spectrum = color_spectrum mode = None else: mode = mode color_spectrum = None config_result = { 'on': led_state, 'brightness': brightness, 'color_spectrum': color_spectrum, 'mode': mode } elif config.device_type == 'cam': stream_duration = updated_config['streamDuration'] aws_access_key_id = updated_config['AWSAccessKeyID'] aws_secret_access_key = updated_config['AWSSecretAccessKey'] aws_default_region = updated_config['AWSDefaultRegion'] aws_kinesis_stream_name = updated_config['AWSKinesisStreamName'] logging.debug( f"Stream launch request for {stream_duration} seconds. AWS_ACCESS_KEY: {aws_access_key_id}, KinesisStream: {aws_kinesis_stream_name}" ) config_result = { 'on': True, 'streamDuration': stream_duration, 'aws_access_key_id': aws_access_key_id, 'aws_secret_access_key': aws_secret_access_key, 'aws_default_region': aws_default_region, 'aws_kinesis_stream_name': aws_kinesis_stream_name } elif config.device_type == 'flame': flame_state = updated_config['on'] config_result = {'on': flame_state} logging.debug(f"Device Configuration: {config_result}") return config_result