def run(output_file): scipy.random.seed() gene_expression = start_transcribing(INI, "outputdir", tss, tts, prot, genome_size) fitness = get_fitness(gene_expression, expected_profile) with open(output_file, 'w') as f: f.write(str(fitness) + '\n')
def evol_main_loop(tss, tts, prot, genome_size, fitness, p_inversion, temperature, indel_size, expected_profile): # making backups for the current genome tss_backup = tss.copy() tts_backup = tts.copy() prot_backup = prot.copy() genome_size_backup = genome_size fitness_backup = fitness if np.random.rand( ) < p_inversion: # decide if there is an inversion or indel inversion(tss, tts, prot, genome_size) mutation_type = 1 else: genome_size = indel(tss, tts, prot, genome_size, indel_size) mutation_type = 2 #~ print(tss) #~ print(tts) #~ print(prot) #~ display_genome(tss,tts,prot,genome_size) gene_expression = sim.start_transcribing(INI_file, output_dir, tss, tts, prot, genome_size) fitness = get_fitness(gene_expression, expected_profile) # if the new fitness is lower than the previous one # and the random choice doesn't select the new genome # we go back to the backups if fitness < fitness_backup and np.random.rand() > np.exp( (fitness - fitness_backup) / temperature): tss = tss_backup tts = tts_backup prot = prot_backup genome_size = genome_size_backup fitness = fitness_backup mutation_type = 0 return (tss, tts, prot, genome_size, fitness, mutation_type)
def evol_master(arg): scipy.random.seed() fitness_file, p_inversion = arg # read the evolution parameters from the config file config = sim.read_config_file(INI_file) environment_file = config.get('EVOLUTION', 'environment') temperature = config.getfloat('EVOLUTION', 'temperature') temperature_rate = config.getfloat('EVOLUTION', 'temperature_rate') nbiter = config.getint('EVOLUTION', 'nbiter') #p_inversion = config.getfloat('EVOLUTION', 'p_inversion') indel_size = config.getint('EVOLUTION', 'indel_size') #fitness_file = config.get('EVOLUTION', 'output_file') pth = INI_file[:-10] expected_profile = pd.read_table(pth + environment_file, sep='\t', header=None)[1] tss, tts, prot, genome_size = sim.load_genome(INI_file) gene_expression = sim.start_transcribing(INI_file, output_dir, tss, tts, prot, genome_size) fitness = get_fitness(gene_expression, expected_profile) with open(fitness_file, 'w') as f: f.write("fitness\tgenome size\tmutation type\n") for it in range(nbiter): temperature *= temperature_rate tss, tts, prot, genome_size, fitness, mutation_type = evol_main_loop( tss, tts, prot, genome_size, fitness, p_inversion, temperature, indel_size, expected_profile) print("iteration : " + str(it) + "\tfitness : " + str(fitness)) # mutation_type is 0 if no changes occured 1 for inversion and 2 for indel with open(fitness_file, 'a') as f: f.write( str(fitness) + "\t" + str(genome_size) + "\t" + str(mutation_type) + "\n")
import sys import simulation as sim INI_file = sys.argv[1] output_dir = sys.argv[2] sim.start_transcribing(INI_file, output_dir)
import sys import simulation as sim INI_file = sys.argv[1] output_dir = sys.argv[2] (tss, tts, prot, genome_size) = sim.load_genome(INI_file) sim.start_transcribing(INI_file, output_dir, tss, tts, prot, genome_size)
def simulation(nb_simulations): #definition des listes de stockage de variations de fitness ancien_genome_optimal=[] variation_fitness=[] variation_nb_transcrits=[] liste_changement_position={} for simulation in range (nb_simulations): [position_gene,pos_barriere,taille_genome,rapport_mutation,nb_transcrits,pas_espace,taille_indel]=sim.start_transcribing(INI_file) fitness=calcul_fitness(fitness_optimal,nb_transcrits) print("on en est a la simulation ",simulation) #on calcule dans tous les cas un fitness de base if (simulation==0): liste_debut=[copy.deepcopy(position_gene) ,pos_barriere.copy(),taille_genome] variation_nb_transcrits.append(nb_transcrits) liste_changement_position["genome_originelle"]=position_gene ancien_genome_optimal=[position_gene,pos_barriere,taille_genome] elif application_monte_carlo(variation_fitness[-1],fitness): #la mutation apporte une amelioration de la fitness ou avec une certaine probabilite est conservee meme si deletere #on met alors a jour nos variables globales de variation de fitness cle="generation"+str(simulation) liste_changement_position[cle]=position_gene variation_nb_transcrits.append(nb_transcrits) ancien_genome_optimal=[position_gene,pos_barriere,taille_genome] else: #on est dans le cas ou il n'y a pas eu d'ameliorations de la fitness, dans ce cas, on revient a l'ancien genome le plus optimal fonction_modification_fichiers(INI_file,ancien_genome_optimal) variation_fitness.append(fitness) #On cree notre nouveau genome, qui sera eventuellement conserve #print("voila ce qu'on envoie a la mutation ",position_gene,pos_barriere,taille_genome,rapport_mut,pas_espace) new_genome=v2.create_new_genome(position_gene,pos_barriere,int(taille_genome+1),rapport_mutation,int(pas_espace),int(taille_indel)) #print( "nouveau genome apres mutation est ",new_genome, "\n\n") fonction_modification_fichiers(INI_file,new_genome) return variation_fitness
#############main function################# INI_file=sys.argv[1] #fixation par avance de certains parametres #on prend un seuil de 5% #recuperation fitness optimal fitness_optimal=recuperer_fitness_cible(INI_file) [position_gene,pos_barriere,taille_genome,rapport_mutation,nb_transcrits,pas_espace,taille_indel]=sim.start_transcribing(INI_file) liste_debut=[copy.deepcopy(position_gene) ,pos_barriere.copy(),taille_genome] nb_simulations=int(sys.argv[2]) test_parametres = {"['SIMULATION','RNAPS_NB']":[3,7],"['MUTATION','rapport_mutation_insert_invert']":[75,90],"['SIMULATION','GYRASE_CONC']":[0.2,0.9],"['MUTATION', 'taille_indel']":[1,5]} ''' test_parametres = {"['GLOBAL','DELTA_X']":[20], "['SIMULATION','SIM_TIME']":[1000], "['MUTATION','rapport_mutation_insert_invert']":[0.2],"['SIMULATION','GYRASE_CONC']":[0.1], "['MUTATION', 'taille_indel']":[1]} valeurs_initiales = {"['SIMULATION','RNAPS_NB']":4, "['MUTATION','rapport_mutation_insert_invert']":60,"['SIMULATION','GYRASE_CONC']":0.3,