def rna_folding(rna_data, policy, stochastically=True, render=False): np.random.seed(int.from_bytes(os.urandom(4), byteorder='little')) rna = RNA(rna_data['seq'], rna_data['pairs']) mcts = MCTS(policy, 2000, False, 10) min_energy = rna.energy() pred_energy, _, _ = mcts.evaluate_state(rna) if render: print(rna) while rna.action_space and pred_energy > 1: action, action_probs = mcts.get_action(rna, stochastically=stochastically, show_node=render) rna.move(action) mcts.update_with_action(action) energy = rna.energy() if energy < min_energy: min_energy = energy pred_energy, _, _ = mcts.evaluate_state(rna) if render: print("[*] RNA pair position: %s" % (action,)) print("[*] RNA secondary structure: %s" % ''.join(rna.sec)) print("[*] Predicted energy: %.2f" % pred_energy) print("[*] Current energy: %.2f" % energy) print("[*] Min energy: %.2f\n" % min_energy) print(rna) final_energy = rna.energy() rna_data['pred_sec'] = ''.join(rna.sec) rna_data['pred_pairs'] = rna.find_pairs return rna_data
def main(): problem_dataset_dir = os.path.join('Problems', 'Problem1') solution_dir = os.path.join("Problems", "Problem1Solution") data_reader = DataReader(problem_dataset_dir) training_data, testing_data = data_reader.get_data() codons_table = data_reader.get_rna_codon_table() for sample in training_data: rna_string = sample[0] output = sample[1] rna = RNA(rna_string) rna.set_codons_table(codons_table) amino_acid = rna.to_amino_acid() if amino_acid != output: raise Exception("Output not matched!\nExpecting: " + output + "\nFound: " + amino_acid) print("Passed training data..\n\n") writer = DataWriter(solution_dir) usage = Usage() for sample in testing_data: usage.start() rna_string = sample[0] rna = RNA(rna_string) rna.set_codons_table(codons_table) amino_acid = rna.to_amino_acid() usage.end() writer.write_data(rna_string, amino_acid, usage.get_execution_time(), usage.get_memory_usage()) print("RNA:\n" + rna_string) print("Protein:\n" + amino_acid) print("\n\nExecution Time: " + str(usage.get_execution_time()) + " s") print("Memory Usage: " + str(usage.get_memory_usage()) + " MB")
def setup(self): i = IndepVarComp() # variables i.add_output('in_design_tsr', desc='design tip speed ratio') i.add_output('in_tf', desc='scaling factor for laminate thickness') i.add_output('in_chord_coefficients', desc='coefficients of polynomial chord profile', shape=degree_bezier) i.add_output('in_twist_coefficients', desc='coefficients of polynomial twist profile', shape=degree_bezier) # parameters self.add_subsystem('dof', i, promotes=['*']) self.add_subsystem('rna', RNA(), promotes=['*']) self.add_subsystem('obj', ExecComp('f = -1 * cp / 0.4967')) #self.add_subsystem('obj', ExecComp('f = -1 * (cp/(rm)) / (0.4967/51092.66)', rm={'units' : 'kg'})) #self.add_subsystem('obj', ExecComp('f = -1 * (cp/(rm+hm+nm)) / (0.4967/217493.9)', rm={'units' : 'kg'}, hm={'units' : 'kg'}, nm={'units' : 'kg'})) #self.add_subsystem('obj', ExecComp('f = -1 * (cp/crt) / (0.4967/3202937.51)', crt={'units' : 'USD'})) self.add_subsystem('c1', ExecComp('tip = (y/5.6964)-1.0', tip={'units': 'm'}, y={'units': 'm'})) #, d={'units' : 'm'})) self.add_subsystem( 'c2', ExecComp('max_s = s/(450.0*10**6) - 1.0', s={'units': 'Pa'}, max_s={'units': 'Pa'})) self.connect('rotor_cp', 'obj.cp') #self.connect('rotor_mass', 'obj.rm') #self.connect('hub_system_mass', 'obj.hm') #self.connect('nacelle_mass', 'obj.nm') #self.connect('cost_rna_total', 'obj.crt') self.connect('tip_deflection', 'c1.y') self.connect('span_stress_max', 'c2.s')
def main(x, y, z, num_steps, u1, u2, u3, pwm_u1, pwm_u2, u1_t, u2_t, persistence, sequence): rna = RNA(x, y, z, sequence, persistence, pwm_u1, pwm_u2, u1_t, u2_t) i = 0 while i < num_steps: i += 1 rna.extend() rna.random_flight() u1.update() u2.update() u3.update() rna.bind_snorna(u1, u2) rna.release_snorna(u1, u2) splice = rna.bind_u3(u3) if splice: return i, splice return i, False
def get_dna_to_amino_acid_candidates(self, amino_acid): substring_length = len(amino_acid) * 3 rna = RNA() rna.set_codons_table(self.__codon_table) candidates = [] for i in range(0, len(self.__dna_string)): if i + substring_length > len(self.__dna_string): break candidate_substring = self.__dna_string[i:(i + substring_length)] rna_string = self.__dna_to_rna_string(candidate_substring) rna.set_rna_string(rna_string) current_amino_acid = rna.to_amino_acid() if current_amino_acid == amino_acid: candidates.append(candidate_substring) else: reversed_dna = self.__reverse_dna(candidate_substring) reversed_rna = self.__dna_to_rna_string(reversed_dna) rna.set_rna_string(reversed_rna) current_amino_acid = rna.to_amino_acid() if current_amino_acid == amino_acid: candidates.append(candidate_substring) continue complement_dna = self.__complement_dna(candidate_substring) complement_rna = self.__dna_to_rna_string(complement_dna) rna.set_rna_string(complement_rna) current_amino_acid = rna.to_amino_acid() if current_amino_acid == amino_acid: candidates.append(candidate_substring) continue reversed_complement_dna = self.__complement_dna( self.__reverse_dna(candidate_substring)) reversed_complement_rna = self.__dna_to_rna_string( reversed_complement_dna) rna.set_rna_string(reversed_complement_rna) current_amino_acid = rna.to_amino_acid() if current_amino_acid == amino_acid: candidates.append(candidate_substring) continue complement_reversed_dna = self.__reverse_dna( self.__complement_dna(candidate_substring)) complement_reversed_rna = self.__dna_to_rna_string( complement_reversed_dna) rna.set_rna_string(complement_reversed_rna) current_amino_acid = rna.to_amino_acid() if current_amino_acid == amino_acid: candidates.append(candidate_substring) continue return candidates
def get_dna_to_amino_acid_candidates(self, amino_acid): substring_length = len(amino_acid) * 3 rna = RNA() rna.set_codons_table(self.__codon_table) candidates = [] for i in range(0, len(self.__dna_string)): if i + substring_length > len(self.__dna_string): break candidate_substring = self.__dna_string[i:(i + substring_length)] rna_string = self.__dna_to_rna_string(candidate_substring) rna.set_rna_string(rna_string) current_amino_acid = rna.to_amino_acid() if current_amino_acid == amino_acid: candidates.append(candidate_substring) else: reversed_dna = self.__reverse_dna(candidate_substring) reversed_rna = self.__dna_to_rna_string(reversed_dna) rna.set_rna_string(reversed_rna) current_amino_acid = rna.to_amino_acid() if current_amino_acid == amino_acid: candidates.append(candidate_substring) continue complement_dna = self.__complement_dna(candidate_substring) complement_rna = self.__dna_to_rna_string(complement_dna) rna.set_rna_string(complement_rna) current_amino_acid = rna.to_amino_acid() if current_amino_acid == amino_acid: candidates.append(candidate_substring) continue reversed_complement_dna = self.__complement_dna(self.__reverse_dna(candidate_substring)) reversed_complement_rna = self.__dna_to_rna_string(reversed_complement_dna) rna.set_rna_string(reversed_complement_rna) current_amino_acid = rna.to_amino_acid() if current_amino_acid == amino_acid: candidates.append(candidate_substring) continue complement_reversed_dna = self.__reverse_dna(self.__complement_dna(candidate_substring)) complement_reversed_rna = self.__dna_to_rna_string(complement_reversed_dna) rna.set_rna_string(complement_reversed_rna) current_amino_acid = rna.to_amino_acid() if current_amino_acid == amino_acid: candidates.append(candidate_substring) continue return candidates
#entradas = [[0,0],[0,1],[1,0],[1,1]] #respostas_corretas = [0,0,0,1] #pesos = [0.0, 0.0] #taxa_aprendizagem = 0.1 #RNA.treinar(entradas, respostas_corretas, pesos, taxa_aprendizagem) porco = 0 cachorro = 1 entradas = [[1,1,0], [1,1,0], [1,1,0], [1,1,1], [0,1,1], [0,1,1]] respostas_corretas = [porco,porco,porco,cachorro,cachorro,cachorro] pesos = [0.0, 0.0, 0.0] taxa_aprendizagem = 0.1 pesos_ideal = RNA.treinar(entradas, respostas_corretas, pesos, taxa_aprendizagem) misterioso1 = [1,1,1] misterioso2 = [1,0,0] misterioso3 = [0,0,1] testes = [misterioso1, misterioso2, misterioso3] marcacoes_teste = [0,1,0] resultados = RNA.adivinhar(testes, pesos_ideal) for i in range(len(resultados)): if(resultados[i] == cachorro): print('estou chutando: cachorro') else: print('estou chutando: porco')