def score(self, design, params): score = 100 seq = design['sequence'] for i in range(0, len(seq)): # Pairs the same way in both states, avoiding double counting # by only looking at the opening bases if ((design['pairmap1'][i] == design['pairmap2'][i]) and (design['secstruct1'][i] == design['secstruct2'][i] == '(')): # Try swapping the sequence bp1 = design['pairmap1'][i] newSequence = (seq[:i] + seq[bp1] + seq[(i + 1):bp1] + seq[i] + seq[(bp1 + 1):]) # viennaconstraint includes the binding (On state) newSSb = inv_utils.fold(newSequence, False, design['viennaconstraint']) newSSnob = inv_utils.fold(newSequence) if newSSb != design['secstruct' + str(design['on_state'])]: score += params[0] if newSSnob != design['secstruct' + str(design['off_state'])]: score += params[1] return score
def score(self, design, params): score = 100 seq = design['sequence'] for i in range(0, len(seq)): # Pairs the same way in both states, avoiding double counting # by only looking at the opening bases if((design['pairmap1'][i] == design['pairmap2'][i]) and (design['secstruct1'][i] == design['secstruct2'][i] == '(')): # Try swapping the sequence bp1 = design['pairmap1'][i] newSequence = (seq[:i] + seq[bp1] + seq[(i+1):bp1] + seq[i] + seq[(bp1+1):]) # viennaconstraint includes the binding (On state) newSSb = inv_utils.fold( newSequence, False, design['viennaconstraint'] ) newSSnob = inv_utils.fold(newSequence) if newSSb != design['secstruct' + str(design['on_state'])]: score += params[0] if newSSnob != design['secstruct' + str(design['off_state'])]: score += params[1] return score
def post_solution(puzzle, title): sequence = puzzle.best_sequence fold = inv_utils.fold(sequence) design = eterna_utils.get_design_from_sequence(sequence, fold[0]) header = {'Content-Type': 'application/x-www-form-urlencoded'} login = { 'type': 'login', 'name': 'theeternabot', 'pass': '******', 'workbranch': 'main' } solution = { 'type': 'post_solution', 'puznid': puzzle.id, 'title': title, 'body': 'eternabot switch v1, score %s' % puzzle.best_design_score, 'sequence': sequence, 'energy': fold[1], 'gc': design['gc'], 'gu': design['gu'], 'ua': design['ua'], 'melt': design['meltpoint'], 'pointsrank': 'false', 'recommend-puzzle': 'true' } url = "http://jnicol.eternadev.org" #url = 'http://eterna.cmu.edu' loginurl = "%s/login/" % url posturl = "%s/post/" % url with requests.Session() as s: r = s.post(loginurl, data=login, headers=header) r = s.post(posturl, data=solution, headers=header) return
def solve(self, design): bases=inv_utils.BASES random.seed() elements = design['secstruct_elements'] target_pair = design['secstruct'] pair_map = design['pairmap'] length = len(target_pair) sequence = ['A']*length natural_pair = "" while(natural_pair != target_pair): for elem in elements: inv_utils.fill_gc(elem, pair_map , sequence, random) ret = inv_utils.fold(sequence) natural_pair = ret[0] return sequence
def get_sequence_info(self, sequence): """ get sequence information - native fold, bp distance, pairmap, design for a particular sequence """ native = [] native_pairmap = [] for i in range(self.n_targets): fold_sequence = self.get_fold_sequence(sequence, self.targets[i]) native.append(inv_utils.fold(fold_sequence)[0]) native_pairmap.append( eterna_utils.get_pairmap_from_secstruct(native[i])) bp_distance = self.score_secstructs(native) design_score = self.get_design_score(sequence, native) return [sequence, native, native_pairmap, bp_distance, design_score]
row_num += 1 print("Done parsing..") for design in designs: args = (design, ) ret = inv_utils.timeout(strategy.solve, args, timeout_duration=2, default=["AAAA"]) sequence = ret[0] t0 = ret[1] if (t0 != "timeout"): natural = inv_utils.fold(sequence)[0] target = design['secstruct'] if (natural == target): design['solve_time'] = t0 else: design['solve_time'] = "wrong solution" else: design['solve_time'] = t0 ## Output results f_output.write("<strong>Title : </strong>" + strategy.title_ + "<br/>") f_output.write("<strong>Author : </strong>" + strategy.author_ + "<br/>") f_output.write("\n\n\n") body_data = ""