def jsonEventAdd(self, jsonData): eventList = jsonData['eventList'] repeatEventList = jsonData['repeatEventList'] for eventSeq in eventList: eventType = eventSeq['eventType'] startXy = eventSeq['startXy'] endXy = eventSeq['endXy'] typoText = eventSeq['text'] url = eventSeq['url'] hotkey = eventSeq['command'] delay = eventSeq['delayTime'] actionType = eventSeq['actionType'] newSeq = sequence.sequence(startXy, eventType, endXy, typoText, url, hotkey, delay, actionType, self.pinList) self.eventManager.addEvent(newSeq, actionType) for repeatEventSeq in repeatEventList: eventType = repeatEventSeq['eventType'] startXy = repeatEventSeq['startXy'] endXy = repeatEventSeq['endXy'] typoText = repeatEventSeq['text'] url = repeatEventSeq['url'] hotkey = repeatEventSeq['command'] delay = repeatEventSeq['delayTime'] actionType = repeatEventSeq['actionType'] newSeq = sequence.sequence(startXy, eventType, endXy, typoText, url, hotkey, delay, actionType, self.pinList) self.eventManager.addEvent(newSeq, actionType)
def test_simpleDoubleException(self): """Simple string with two exceptions""" string = "A Z B A" self.assertEquals(sequence(string), "A Z B") string = "Z Y X C A" self.assertEquals(sequence(string), "Z Y")
def test_roster(self): """Examples given in "roster" email clarification""" string = "Abrahams, Adams, Bartholomew, Monroe, Windsor" self.assertEquals(sequence(string), string) string = "Abrahams, Adams, Monroe, Bartholomew, Windsor" self.assertEquals(sequence(string), string) string = "Abrahams, Monroe, Adams, Windsor, Bartholomew" self.assertEquals(sequence(string), "Abrahams, Monroe, Adams, Windsor,") string = "Abrahams, Bartholomew, Windsor, Adams, Monroe" self.assertEquals(sequence(string), string)
def eventAdd(self): # print('add click') eventType = self.inputTypeCombobox.currentText() startXy = self.startCoText.text() endXy = self.endCoText.text() typoText = self.typoText.text() url = self.browserText.text() hotkey = '' if eventType == '핫키': if self.copyRadio.isChecked(): hotkey = 'copy' elif self.pasteRadio.isChecked(): hotkey = 'paste' else: hotkey = 'close' delay = self.delayText.text() actionType = self.actionTypeCombobox.currentIndex() self.clearEventLayout() newSeq = sequence.sequence(startXy, eventType, endXy, typoText, url, hotkey, delay, actionType, self.pinList) self.eventManager.addEvent(newSeq, actionType) self.buildEventLayout()
def build_cmsDrivers(self): cds = [] for (stepindex, step) in enumerate(self.get_attribute('sequences')): stepcd = {} for key in step: seq = sequence(step[key]) cdarg = seq.build_cmsDriver() fragment = 'NameOfFragment' if self.get_attribute('root') == 1: fragment = 'step%d' % (stepindex + 1) if stepindex == 0: if self.get_attribute('input_dataset'): cdarg += " --filein dbs:%s" % self.get_attribute( 'input_dataset') else: cdarg += " --filein file:step%s.root" % (stepindex - 1) cdarg += " --fileout file:step%s.root" % stepindex if self.get_attribute('pileup_dataset_name') and not ( seq.get_attribute('pileup') in ['', 'NoPileUp']): cdarg += ' --pileup_input "dbs:%s" ' % ( self.get_attribute('pileup_dataset_name')) cd = 'cmsDriver.py %s %s' % (fragment, cdarg) if cd: stepcd[key] = cd cds.append(stepcd) return cds
def test_initial(self): """Initial example given in problem definition e-mail""" string = "Write a program that reports the longest sequence of words that appear " \ "in alphabetical order in a given input text, with at most one " \ "exception (break in ascending alphabetical order)." result = "a given input text, with at most one" self.assertEquals(sequence(string), result)
def build_cmsDrivers(self): cds = [] for (stepindex, step) in enumerate(self.get_attribute('sequences')): stepcd = {} for key in step: seq = sequence(step[key]) cdarg = seq.build_cmsDriver() fragment = 'NameOfFragment' if self.get_attribute('root') == 1: fragment = 'step%d' % (stepindex + 1) if stepindex == 0: if self.get_attribute('input_dataset'): cdarg += " --filein dbs:%s" % self.get_attribute('input_dataset') else: cdarg += " --filein file:step%s.root" % (stepindex - 1) cdarg += " --fileout file:step%s.root" % stepindex # the classic mixing identified by the presence of --pileup ; this is untouched if self.get_attribute('pileup_dataset_name') and not (seq.get_attribute('pileup') in ['', 'NoPileUp']): cdarg += ' --pileup_input "dbs:%s" ' % (self.get_attribute('pileup_dataset_name')) # the mixing using premixed events: absesence of --pileup and presence of datamix elif self.get_attribute('pileup_dataset_name') and (seq.get_attribute('pileup') in ['']) and (seq.get_attribute('datamix') in ['PreMix']): cdarg += ' --pileup_input "dbs:%s" ' % (self.get_attribute('pileup_dataset_name')) cd = 'cmsDriver.py %s %s' % (fragment, cdarg) if cd: stepcd[key] = cd cds.append(stepcd) return cds
def getSeqs(fn): s = [] with open(fn, 'r') as f: for line in f.readlines(): if '>' in line: continue s.append(line.strip()) return [sq.sequence(l) for l in s]
def add_sequence(self, seq_json={}, step=-1, name='default'): seq = sequence(json_input=seq_json) sequences = self.get_attribute('sequences') if step == -1: index = len(sequences) + 1 elif step <= len(sequences): index = step else: return sequences[index].update({name : seq.json()}) self.set_attribute('sequences', sequences)
def build_cmsDrivers(self): cds = [] for (stepindex,step) in enumerate(self.get_attribute('sequences')): stepcd = {} for key in step: cdarg = sequence(step[key]).build_cmsDriver() fragment='NameOfFragment' if self.get_attribute('root')==1: fragment='step%d'%(stepindex+1) cd='cmsDriver.py %s %s'%(fragment, cdarg) if cd: stepcd[key] = cd cds.append(stepcd) return cds
def add_sequence(self, seq_json=None, step=-1, name='default'): seq_json = seq_json if seq_json else {} seq = sequence(json_input=seq_json) sequences = self.get_attribute('sequences') if step == -1: index = len(sequences) + 1 elif step <= len(sequences): index = step else: return sequences[index].update({name: seq.json()}) self.set_attribute('sequences', sequences)
def guess_primes(pre, post): # TODO: support arbitrarily high primes # currently we only support a finite list of primes to keep it simple # def isPrime(n): # # note: this is really naiive prime checking for the sake of briefness. # if n in primes_set: return True # if n < 2: return False # for d in range(2, n): # if n%d == 0: # return False # return True # ensure all givent numbers are prime if not all( number in primes_set for number in (pre + post) ): return # guess the sequence of the indecies # TODO: binary search for efficiency indecies = ( [ primes.index(prime) for prime in pre ] + [ ... ] + [ primes.index(prime) for prime in post ] ) try: indexSequence = sequence.sequence(*indecies) # Yay recursion! except: return # our index sequence matches no pattern # def exponentialGenerator(): # current = start # while abs(current) <= abs(end) or not haveEnd: # yield current # current *= step def sequenceOfPrimesGenerator(): for index in indexSequence: yield primes[index] return sequenceOfPrimesGenerator()
def build_cmsDrivers(self): cds = [] for (stepindex,step) in enumerate(self.get_attribute('sequences')): stepcd = {} for key in step: seq=sequence(step[key]) cdarg = seq.build_cmsDriver() fragment='NameOfFragment' if self.get_attribute('root')==1: fragment='step%d'%(stepindex+1) if stepindex==0: if self.get_attribute('input_dataset'): cdarg+=" --filein dbs:%s"%self.get_attribute('input_dataset') else: cdarg+=" --filein file:step%s.root"%(stepindex-1) cdarg+=" --fileout file:step%s.root"%stepindex if self.get_attribute('pileup_dataset_name') and not (seq.get_attribute('pileup') in ['','NoPileUp']): cdarg+=' --pileup_input "dbs:%s" '%(self.get_attribute('pileup_dataset_name')) cd='cmsDriver.py %s %s'%(fragment, cdarg) if cd: stepcd[key] = cd cds.append(stepcd) return cds
from sequence import sequence 'hips', 'wrist', 'elbow', 'hand', 'arm' sequence([ [170, 90, 70, 100, 90], [150, 90, 110, 100, 130], [130, 90, 150, 100, 170], [110, 90, 110, 100, 130], [90, 90, 70, 100, 90], [70, 90, 30, 100, 50], [50, 90, 5, 100, 10], [30, 90, 30, 100, 50], [10, 90, 70, 100, 90], ])
def test_sequence(self): result = sequence.sequence(13) self.assertEqual(result, 10)
def test_multipleAlphabatizedEndWithException(self): """Multiple alphabatized substrings of different lengths, ending with an exception""" string = "A Z Y B C Z Y D E F Z Y G H I J K L M A" self.assertEquals(sequence(string), "G H I J K L M A")
def kunkel_full(protocol, params): growth_media = params["construct_setup"]['growth_media'] num_colonies = params["construct_setup"]['num_colonies'] ssDNA = params["construct_setup"]['ssDNA'] mutant_constructs = [] # make mutant objects for accessibility construct_collect = {} for csv_row in params["construct_setup"]['mutant_upload']: if csv_row["mutant_label"] not in construct_collect.keys(): construct_collect[csv_row["mutant_label"]] = [] construct_collect[csv_row["mutant_label"]].append( { "sequence": csv_row["sequence"], "purification": csv_row["purification"], "scale": csv_row["scale"], "oligo_label": csv_row["oligo_label"] }) else: construct_collect[csv_row["mutant_label"]].append( { "sequence": csv_row["sequence"], "purification": csv_row["purification"], "scale": csv_row["scale"], "oligo_label": csv_row["oligo_label"] } ) oligo_collect = {} for row in params["construct_setup"]["mutant_upload"]: if (row["sequence"] not in oligo_collect.keys() and row["oligo_label"] in protocol.refs.keys()): raise RuntimeError("You cannot specify two different " "oligos to be synthesized with the " "same name %s" % row['oligo_label']) elif row["sequence"] not in oligo_collect.keys(): oligo_collect[row["sequence"]] = { "sequence": row["sequence"], "purification": row["purification"], "scale": row["scale"], "destination": protocol.ref(row["oligo_label"], None, "micro-2.0", storage="cold_4").well(0) } for mut in construct_collect.keys(): mut_oligos = [o for o in construct_collect[mut]] mutant = Mutant(mut) for oligo in mut_oligos: mutant.add_oligos(oligo_collect[oligo["sequence"]]["destination"]) mutant_constructs.append(mutant) oligos_to_synthesize = [] for o in oligo_collect.keys(): scale_default(len(oligo_collect[o]["sequence"]), oligo_collect[o]["scale"], oligo_collect[o]["destination"].container.name) oligos_to_synthesize.append(oligo_collect[o]) protocol.oligosynthesize(oligos_to_synthesize) assemble_params = { 'ssDNA': ssDNA, 'constructs': [{ 'mutant_name': mu.name, 'oligos': mu.oligos} for mu in mutant_constructs], 'mutant_objs': mutant_constructs } annealing_plate = assemble(protocol, assemble_params) protocol.unseal(annealing_plate) transform_params = { 'num_colonies': num_colonies, 'growth_media': growth_media, 'constructs': [mu.anneal_well for mu in mutant_constructs], 'mutant_objs': mutant_constructs } growth_plate = transform(protocol, transform_params) seq_primers = [] for seq_primer in params["sequencing"]: if seq_primer["seq_choice"] != "No sequencing.": # make temp container with name of stock primer primer = protocol.ref(seq_primer["seq_choice"], None, "micro-1.5", discard=True).well(0) primer.set_name(seq_primer["seq_choice"]) primer_vol = "1:microliter" seq_primers.append(primer) sequence_params = { 'seq_set': [{ 'growth_wells': WellGroup([w for w in mu.growth_wells]), 'seq_primers': seq_primers} for mu in mutant_constructs] } if seq_primers: protocol.uncover(growth_plate) sequence(protocol, sequence_params) protocol.cover(growth_plate, lid="low_evaporation") if params["other_processing"]["other_processing"] != "No processing.": protocol.uncover(growth_plate) if params["other_processing"]["other_processing"] == "Miniprep": mini_samples = [] for mu in mutant_constructs: for w in mu.growth_wells: mini_samples.append({"sample": w, "name": w.name}) miniprep_params = { "type": "Miniprep", "media": growth_media, 'samples': mini_samples, "growth_plate": growth_plate } plasmidprep(protocol, miniprep_params) if params["other_processing"]["other_processing"] == "Return Colonies": return_plate = protocol.ref("return_plate_%s" % printdatetime(time=False), cont_type='96-pcr', storage='cold_4') for mut in mutant_constructs: for g_well in mut.growth_wells: protocol.transfer(g_well, return_plate.well(g_well.index), "30:microliter") return_plate.well(g_well.index).set_name(g_well.name) protocol.seal(return_plate) protocol.cover(growth_plate, lid="low_evaporation") if params["other_processing"]["other_processing"] == "Return Colonies Glycerol": return_plate = protocol.ref("return_plate_glycerol_%s" % printdatetime(time=False), cont_type='96-pcr', storage='cold_4') for mut in mutant_constructs: for g_well in mut.growth_wells: protocol.transfer(g_well, return_plate.well(g_well.index), "30:microliter") return_plate.well(g_well.index).set_name(g_well.name) for mut in mutant_constructs: for g_well in mut.growth_wells: protocol.provision("rs17rrhqpsxyh2", return_plate.well(g_well.index), "30:microliter") protocol.seal(return_plate) protocol.cover(growth_plate, lid="low_evaporation")
def test_singleException(self): """Single exception sequence""" string = "Z C B A" self.assertEquals(sequence(string), "Z C")
def test_equalString(self): """String with all equal elements""" string = "A A A A A A A A A A A A A" self.assertEquals(sequence(string), string)
def test_alphabatized(self): """Alphabatized string""" string = "A B C D E" self.assertEquals(sequence(string), string)
from sequence import sequence 'hips', 'wrist', 'elbow', 'hand', 'arm' sequence([ [170, 90, 70, 100, 90], [170, 140, 40, 90, 90], [170, 170, 20, 90, 90], [170, 175, 5, 90, 90], [170, 175, 5, 110, 90], [170, 165, 15, 110, 90], [170, 155, 25, 110, 90], [170, 145, 35, 110, 90], [170, 135, 45, 110, 90], [170, 125, 55, 110, 90], [170, 115, 65, 110, 90], [170, 105, 70, 110, 90], [170, 90, 70, 110, 90], [170, 80, 70, 110, 90], [170, 70, 70, 110, 90], [170, 90, 70, 100, 90], ])
class matchSeq: obj=sequence.sequence() col=obj.cols match = 2. mismatch = -2. gap = -2. s = { 'AA': match, 'AG': mismatch, 'AC': mismatch, 'AT': mismatch, 'GA': mismatch, 'GG': match, 'GC': mismatch, 'GT': mismatch, 'CA': mismatch, 'CG': mismatch, 'CC': match, 'CT': mismatch, 'TA': mismatch, 'TG': mismatch, 'TC': mismatch, 'TT': match, } for i in range(obj.rows): obj.a[i][0] = 0 for j in range(obj.cols): obj.a[0][j] = 0 for i in range(1, obj.rows): for j in range(1, obj.cols): choice1 = obj.a[i-1][j-1] + s[(obj.seq1[i-1] + obj.seq2[j-1])] choice2 = obj.a[i-1][j] + gap choice3 = obj.a[i][j-1] + gap obj.a[i][j] = max(choice1, choice2, choice3) aseq1 = '' aseq2 = '' # We reconstruct the alignment into aseq1 and aseq2, i = len(obj.seq1) j = len(obj.seq2) while i > 0 and j > 0: if i % 10 == 0: stderr.write('.') # by preforming a traceback of how the matrix was filled out above, # i.e. we find a shortest path from a[n,m] to a[0,0] score = obj.a[i][j] score_diag = obj.a[i-1][j-1] score_up = obj.a[i][j-1] score_left = obj.a[i-1][j] if score == score_diag + s[obj.seq1[i-1] + obj.seq2[j-1]]: aseq1 = obj.seq1[i-1] + aseq1 aseq2 = obj.seq2[j-1] + aseq2 i -= 1 j -= 1 elif score == score_left + gap: aseq1 = obj.seq1[i-1] + aseq1 aseq2 = '_' + aseq2 i -= 1 elif score == score_up + gap: aseq1 = '_' + aseq1 aseq2 = obj.seq2[j-1] + aseq2 j -= 1 else: # should never get here.. print ('ERROR') i = 0 j = 0 aseq1 = 'ERROR' aseq2 = 'ERROR' obj.seq1 = 'ERROR' obj.seq2 = 'ERROR' while i > 0: # If we hit j==0 before i==0 we keep going in i. aseq1 = obj.seq1[i-1] + aseq1 aseq2 = '_' + aseq2 i -= 1 while j > 0: # If we hit i==0 before i==0 we keep going in j. aseq1 = '_' + aseq1 aseq2 = obj.seq2[j-1] + aseq2 j -= 1
def gen(self): fh = open(self.package_name + ".sv", "w") fh.write(self.header.replace("file_name", self.package_name + ".sv")) fh.write("`ifndef _%s_\n" % (self.package_name.upper())) fh.write("`define _%s_\n" % (self.package_name.upper())) fh.write("\n") fh.write("package %s;\n" % (self.package_name)) fh.write(" import uvm_pkg::*;\n") fh.write("\n") fh.write(" `include \"%s.sv\"\n" % (self.defines_name)) fh.write(" `include \"%s.sv\"\n" % (self.config_name)) fh.write(" `include \"%s.sv\"\n" % (self.transaction_name)) fh.write(" `include \"%s.sv\"\n" % (self.config_name)) fh.write(" `include \"%s.sv\"\n" % (self.callback_name)) fh.write(" `include \"%s.sv\"\n" % (self.cov_callback_name)) fh.write(" `include \"%s.sv\"\n" % (self.master_driver_name)) fh.write(" `include \"%s.sv\"\n" % (self.master_sequencer_name)) fh.write(" `include \"%s.sv\"\n" % (self.master_sequence_name)) fh.write(" `include \"%s.sv\"\n" % (self.slave_driver_name)) fh.write(" `include \"%s.sv\"\n" % (self.slave_sequencer_name)) fh.write(" `include \"%s.sv\"\n" % (self.slave_sequence_name)) fh.write(" `include \"%s.sv\"\n" % (self.monitor_name)) fh.write(" `include \"%s.sv\"\n" % (self.master_agent_name)) fh.write(" `include \"%s.sv\"\n" % (self.slave_agent_name)) fh.write("\n") fh.write("endpackage: %s\n" % (self.package_name)) fh.write("\n") fh.write("`endif //_%s_\n" % (self.package_name.upper())) fh.close() #Generate agent components agent_defines = defines.defines(self.header, self.agent_setting) agent_defines.gen() agent_interface = interface.interface(self.header, self.agent_setting) agent_interface.gen() agent_cfg = cfg.cfg(self.header, self.agent_setting) agent_cfg.gen() agent_transaction = transaction.transaction(self.header, self.agent_setting) agent_transaction.gen() agent_sequencer = sequencer.sequencer(self.header, self.agent_setting) agent_sequencer.sequencer_gen() agent_sequence = sequence.sequence(self.header, self.agent_setting) agent_sequence.sequence_gen() agent_drv = driver.driver(self.header, self.agent_setting) agent_drv.master_driver_gen() agent_drv.slave_driver_gen() agent_mon = monitor.monitor(self.header, self.agent_setting) agent_mon.monitor_gen() agent_callback = callback.callback(self.header, self.agent_setting) agent_callback.callback_gen() agent_callback.cov_callback_gen() agent_agent = agent.agent(self.header, self.agent_setting) agent_agent.agent_gen()
def test_singleItem(self): """Single-item string""" string = "A" self.assertEquals(sequence(string), string)
def test_multipleAlphabatized(self): """Multiple alphabatized substrings of different lengths""" string = "A Z Y B C Z Y D E F Z Y G H I J K L M" self.assertEquals(sequence(string), "G H I J K L M")
from sequence import sequence 'hips', 'wrist', 'elbow', 'hand', 'arm' sequence([ [110, 90, 80, 90, 100], [110, 90, 80, 110, 100], [110, 90, 80, 90, 100], [110, 90, 80, 110, 100], [110, 90, 80, 90, 100], [110, 90, 80, 110, 100], [110, 90, 80, 90, 100], [110, 90, 80, 110, 100], [110, 90, 80, 90, 100], ])
def test_alphabatizedSingleException(self): """Alphabatized string with a single exception""" string = "A C B D E F G" self.assertEquals(sequence(string), string)
def test_endOfString(self): """Sequence occurs at end-of-string""" string = "Z Y X A B C" self.assertEquals(sequence(string), "A B C")
def test_mixedCase(self): """Mixed case""" string = "a B c D e F g" self.assertEquals(sequence(string), string)
def test_sequence_1(self): self.assertEqual( 17, sequence.sequence(15) )
def test_sequence_2(self): self.assertEqual( 1, sequence.sequence(2) )
from sequence import sequence from sortArray import sorting if __name__ == "__main__": cards_list = [5, 4, 0, 0 ,0 , 0, 6, 10, 22, 23, 24, 25, 26, 27, 28] cards_list_without_dublicates = [] for i in range(len(cards_list)): if cards_list[i] == 0: cards_list_without_dublicates.append(cards_list[i]) for i in cards_list: if i not in cards_list_without_dublicates: cards_list_without_dublicates.append(i) sorting(cards_list_without_dublicates) print(cards_list_without_dublicates) sequence(cards_list_without_dublicates)
def test_sequence_5(self): self.assertEqual( 17, sequence.sequence(602) )
from sequence import sequence 'hips', 'wrist', 'elbow', 'hand', 'arm' sequence([ [180, 90, 70, 100, 90], [180, 70, 90, 100, 70], [180, 50, 110, 100, 50], [180, 70, 90, 100, 70], [180, 90, 70, 100, 90], [180, 110, 50, 100, 110], [180, 130, 30, 100, 130], [180, 110, 50, 100, 110], [90, 90, 70, 100, 90], [0, 70, 90, 100, 70], [0, 50, 110, 100, 50], [0, 70, 90, 100, 70], [0, 90, 70, 100, 90], [0, 110, 50, 100, 110], [0, 130, 30, 100, 130], [0, 110, 50, 100, 110], [0, 90, 70, 100, 90], ])
def test_sequence_3(self): self.assertEqual( 118, sequence.sequence(97) )
def test_sequence_4(self): self.assertEqual( 92, sequence.sequence(91) )