示例#1
0
def replayPopFromText(param, pop, caracs):
    txtpop = []
    with open('replay.txt', 'r') as txt:
        for l in txt:
            txtpop.append(l)

    for i in range(len(txtpop)):
        if txtpop[i][:4] == 'nom:':

            ind = classes.indiv(param, caracs)
            ind.ADN.setNbNodeInt(int(txtpop[i].split()[13][:-1]))

            j = i + 1
            while txtpop[j] != '\n':

                g = classes.gene()

                g.inNode = int(txtpop[j].split()[0][:-1])
                g.outNode = int(txtpop[j].split()[1][:-1])
                g.weight = float(txtpop[j].split()[2][:-1])
                g.active = bool(txtpop[j].split()[3][:-1] == 'True')
                g.code = int(txtpop[j].split()[4])

                ind.ADN.addGene(g)

                ind.ADN.siInLibre[g.inNode] = False
                if g.outNode < ind.ADN.encOffset:
                    ind.ADN.siOutLibre[g.outNode] = False
                else:
                    ind.ADN.siEncrLibre[g.outNode] = False
                j += 1

            ind.nom = pop.getProchNom()
            pop.addIndiv(ind)
示例#2
0
def loadPopForAnalysis(param, pop, caracs):
    txtpop = []
    with open('population.txt', 'r') as txt:
        for l in txt:
            txtpop.append(l)

    for i in range(len(txtpop)):
        if txtpop[i][:4] == 'nom:':

            ind = classes.indiv(param, caracs)
            ind.nom = int(txtpop[i].split()[1][:-1])
            ind.espece = int(txtpop[i].split()[9][:-1])
            ind.score = float(txtpop[i].split()[15][:-1])
            ind.classement = int(txtpop[i].split()[17])

            j = i + 1
            while txtpop[j] != '\n':

                g = classes.gene()

                g.inNode = int(txtpop[j].split()[0][:-1])
                g.outNode = int(txtpop[j].split()[1][:-1])
                g.weight = float(txtpop[j].split()[2][:-1])
                g.active = bool(txtpop[j].split()[3][:-1] == 'True')
                g.code = int(txtpop[j].split()[4])

                ind.ADN.addGene(g)

                j += 1

            pop.addIndiv(ind)
示例#3
0
def creationNodeInt(param, pop, ind):
	
	nbConnexEligible = ind.ADN.compteGene()
	connexEligible = []
	for g in ind.ADN.seqGene:
		if g.weight == 0 or not g.active:
			nbConnexEligible -= 1
			connexEligible.append(0)
		else:
			connexEligible.append(1)
	
	if nbConnexEligible == 0:
		changementPoids(ind)
	else:
		rndGene = random.choices(ind.ADN.seqGene, connexEligible)[0]
		rndGene.active = False
		
		g1 = classes.gene()
		g1.inNode = rndGene.inNode
		g1.outNode = param['nbOutput'] + ind.ADN.nbNodeInt
		g1.weight = 1
		g1.active = True
		if pop.arbreGen[g1.inNode][g1.outNode] == 0:
			pop.setGeneCode(g1.inNode, g1.outNode)
		g1.code = pop.arbreGen[g1.inNode][g1.outNode]		
		
		g2 = classes.gene()
		g2.inNode = param['nbInput'] + ind.ADN.nbNodeInt
		g2.outNode = rndGene.outNode
		g2.weight = rndGene.weight
		g2.active = True
		if pop.arbreGen[g2.inNode][g2.outNode] == 0:
			pop.setGeneCode(g2.inNode, g2.outNode)
		g2.code = pop.arbreGen[g2.inNode][g2.outNode]
		
		ind.ADN.addGene(g1)
		ind.ADN.addGene(g2)
		ind.ADN.addNodeInt()

		oldEncr = rndGene.code + ind.ADN.encOffset
		if not ind.ADN.siEncrLibre[oldEncr]:
			newEncr = g2.code + ind.ADN.encOffset
			for g in ind.ADN.seqGene:
				if g.outNode == oldEncr:
					g.outNode = newEncr
			ind.ADN.siEncrLibre[oldEncr] = True
			ind.ADN.siEncrLibre[newEncr] = False
示例#4
0
def creationConnexion(param, pop, ind, caracs):
	
	while True:
		inNode = ind.ADN.selectInActif()
		while True:
			outNode = ind.ADN.selectOutActif()
			if inNode < param['nbInput'] or outNode < param['nbOutput']\
				or inNode - param['nbInput'] != outNode - param['nbOutput']:
				break
		if not ind.ADN.tellSiGene(pop.arbreGen[inNode][outNode]):
			break
#prevents self-connexions and redundant genes
	
#	if inNode >= param['nbInput'] and outNode >= param['nbOutput']:
	if inNode >= param['nbInput']:
		if func.siCreationBoucle(param, ind, inNode, outNode, caracs):
			changementPoids(ind)
		else:
			g = classes.gene()
			
			g.inNode = inNode
			g.outNode = outNode
			g.weight = 0
			g.active = True
			if pop.arbreGen[g.inNode][g.outNode] == 0:
				pop.setGeneCode(g.inNode, g.outNode)
			g.code = pop.arbreGen[g.inNode][g.outNode]
			
			ind.ADN.addGene(g)
	else:
		g = classes.gene()
		
		g.inNode = inNode
		g.outNode = outNode
		g.weight = 0
		g.active = True
		if pop.arbreGen[g.inNode][g.outNode] == 0:
			pop.setGeneCode(g.inNode, g.outNode)
		g.code = pop.arbreGen[g.inNode][g.outNode]
			
		ind.ADN.addGene(g)
示例#5
0
def creationInput(pop, ind):
	g = classes.gene()
	
	g.inNode = ind.ADN.selectInLibre()
	g.outNode = ind.ADN.selectOutActif()
	g.weight = 0
	g.active = True
	if pop.arbreGen[g.inNode][g.outNode] == 0:
		pop.setGeneCode(g.inNode, g.outNode)
	g.code = pop.arbreGen[g.inNode][g.outNode]
	
	ind.ADN.addGene(g)
	ind.ADN.siInLibre[g.inNode] = False
示例#6
0
def siCreationBoucle(param, ind, inNode, outNode, caracs):
    mannequin = classes.indiv(param, caracs)
    for g in ind.ADN.seqGene:
        gmanq = classes.gene()
        g.copyTo(gmanq)
        mannequin.ADN.addGene(gmanq)

    gmanq = classes.gene()
    gmanq.inNode = inNode
    gmanq.outNode = outNode
    gmanq.active = True
    mannequin.ADN.addGene(gmanq)

    boolCreationBoucle = False

    for node in range(param['nbOutput']):
        boolCreationBoucle = boolCreationBoucle or\
         recSiBoucle(param, mannequin, node, 1)

    for encrNode in range(mannequin.ADN.encOffset, mannequin.maxOutputTotal):
        boolCreationBoucle = boolCreationBoucle or\
         recSiBoucle(param, mannequin, encrNode, 1)

    return boolCreationBoucle
示例#7
0
def creationOutput(param, pop, ind, caracs):
	inNode = ind.ADN.selectInActif()
	outNode = ind.ADN.selectOutLibre()
	
	if func.siCreationBoucle(param, ind, inNode, outNode, caracs):
		changementPoids(ind)
	else:
		g = classes.gene()
		
		g.inNode = inNode
		g.outNode = outNode
		g.weight = 0
		g.active = True
		if pop.arbreGen[g.inNode][g.outNode] == 0:
			pop.setGeneCode(g.inNode, g.outNode)
		g.code = pop.arbreGen[g.inNode][g.outNode]
		
		ind.ADN.addGene(g)
		ind.ADN.siOutLibre[g.outNode] = False
示例#8
0
def creationEncryption(param, pop, ind, caracs):
	
	inNode = ind.ADN.selectInActif()
	outNode = ind.ADN.selectEncryptionTarget().code + ind.ADN.encOffset
	
	if func.siCreationBoucle(param, ind, inNode, outNode, caracs):
		changementPoids(ind)
	else:
		g = classes.gene()
		
		g.inNode = inNode
		g.outNode = outNode
		g.weight = 0
		g.active = True
		if pop.arbreGen[g.inNode][g.outNode] == 0:
			pop.setGeneCode(g.inNode, g.outNode)
		g.code = pop.arbreGen[g.inNode][g.outNode]
		
		ind.ADN.addGene(g)
		ind.ADN.siEncrLibre[g.outNode] = False	
示例#9
0
def creerPopulation(param, pop, caracs):
    for i in range(param['nbIndiv']):

        ind = classes.indiv(param, caracs)

        for connexion in range(param['connexInit']):

            g = classes.gene()

            unique = False
            while not unique:

                if connexion == 0:
                    inNode = 0
                else:
                    inNode = random.randrange(param['nbInput'])
                outNode = random.randrange(param['nbOutput'])

                if pop.arbreGen[inNode][outNode] == 0:
                    unique = True
                elif not ind.ADN.tellSiGene(pop.arbreGen[inNode][outNode]):
                    unique = True

            g.inNode = inNode
            g.outNode = outNode
            g.weight = random.uniform(-1, 1)
            g.active = True

            if pop.arbreGen[inNode][outNode] == 0:
                pop.setGeneCode(inNode, outNode)
            g.code = pop.arbreGen[inNode][outNode]

            ind.ADN.addGene(g)
            ind.ADN.siInLibre[inNode] = False
            ind.ADN.siOutLibre[outNode] = False

        ind.nom = pop.getProchNom()
        pop.addIndiv(ind)
示例#10
0
from classes import gene
from pyfaidx import Fasta
import os

APP_ROOT = os.path.dirname(os.path.abspath(__file__))

data = read_json_compressed()
a = data[1]
b = data[2]
name = a['name']
chrom = a['chrom']
start = a['start']
end = a['end']
ori = a['orientation']
exons = a['exons']
test_gene = gene(**a)
tg2 = gene(**b)
fasta_path = os.path.join(APP_ROOT, 'static', 'data', 'AT9.fa')
genome = Fasta(fasta_path)
tg2.get_sequence(genome)
print(name,start,end)
print(tg2.exon_list[0].start)

"""
LOCUS       Example                   24 bp    DNA              UNK 01-JAN-1980
DEFINITION  An example GenBank file generated by BioPython
ACCESSION   123456789
VERSION     123456789
KEYWORDS    .
SOURCE      .
  ORGANISM  .
示例#11
0
def creerPopulationAvecCouches(param, pop, caracs):
    for i in range(param['nbIndiv']):
        ind = classes.indiv(param, caracs)

        for transverse in range(param['transversesInit']):

            unique = False
            while not unique:

                if transverse == 0:
                    inNode = 0
                else:
                    inNode = random.randrange(param['nbInput'])
                outNode = random.randrange(param['nbOutput'])

                if pop.arbreGen[inNode][outNode] == 0:
                    unique = True
                elif not ind.ADN.tellSiGene(pop.arbreGen[inNode][outNode]):
                    unique = True

            for couche in range(param['couchesInit']):
                g = classes.gene()
                g.inNode = inNode
                g.outNode = param['nbOutput'] + ind.ADN.nbNodeInt
                g.weight = random.uniform(-1, 1)
                g.active = True

                if pop.arbreGen[g.inNode][g.outNode] == 0:
                    pop.setGeneCode(g.inNode, g.outNode)
                g.code = pop.arbreGen[g.inNode][g.outNode]

                ind.ADN.addGene(g)

                inNode = param['nbInput'] + ind.ADN.nbNodeInt
                ind.ADN.addNodeInt()

            g = classes.gene()
            g.inNode = inNode
            g.outNode = outNode
            g.weight = random.uniform(-1, 1)
            g.active = True

            if pop.arbreGen[g.inNode][g.outNode] == 0:
                pop.setGeneCode(g.inNode, g.outNode)
            g.code = pop.arbreGen[g.inNode][g.outNode]

            ind.ADN.addGene(g)

            ind.ADN.siInLibre[inNode] = False
            ind.ADN.siOutLibre[outNode] = False

        for nvlInput in range(param['inputSupInit']):
            mutation.creationInput(pop, ind)
            ind.ADN.seqGene[ind.ADN.compteGene() - 1].weight = random.uniform(
                -1, 1)

        for connexion in range(param['connexInit']):
            mutation.creationConnexion(param, pop, ind, caracs)
            ind.ADN.seqGene[ind.ADN.compteGene() - 1].weight = random.uniform(
                -1, 1)

        for encryption in range(param['encrInit']):
            mutation.creationEncryption(param, pop, ind, caracs)
            ind.ADN.seqGene[ind.ADN.compteGene() - 1].weight = random.uniform(
                -1, 1)

        for connexion in range(param['connexInit']):
            mutation.creationConnexion(param, pop, ind, caracs)
            ind.ADN.seqGene[ind.ADN.compteGene() - 1].weight = random.uniform(
                -1, 1)

        print(i)
        #for g in ind.ADN.seqGene:
        #	print(str(g.inNode) + '; ' + str(g.outNode) + '; ' + str(g.weight) + '; ' + str(g.active) + '; ' + str(g.code))

        ind.nom = pop.getProchNom()
        pop.addIndiv(ind)
示例#12
0
def seedPopFromCore(param, pop, caracs):
    txtpop = []
    with open('core.txt', 'r') as txt:
        for l in txt:
            txtpop.append(l)

    for i in range(len(txtpop)):
        if txtpop[i][:4] == 'nom:':

            ind = classes.indiv(param, caracs)
            ind.ADN.setNbNodeInt(int(txtpop[i].split()[13][:-1]))

            j = i + 1
            while txtpop[j] != '\n':

                g = classes.gene()

                g.inNode = int(txtpop[j].split()[0][:-1])
                g.outNode = int(txtpop[j].split()[1][:-1])
                g.weight = float(txtpop[j].split()[2][:-1])
                g.active = bool(txtpop[j].split()[3][:-1] == 'True')
                g.code = int(txtpop[j].split()[4])

                if pop.arbreGen[g.inNode][g.outNode] == 0:
                    pop.arbreGen[g.inNode][g.outNode] = g.code
                    if g.code > pop.prochCode:
                        pop.prochCode = g.code

                ind.ADN.addGene(g)

                ind.ADN.siInLibre[g.inNode] = False
                if g.outNode < ind.ADN.encOffset:
                    ind.ADN.siOutLibre[g.outNode] = False
                else:
                    ind.ADN.siEncrLibre[g.outNode] = False

                j += 1

            ind.nom = pop.getProchNom()
            pop.addIndiv(ind)

    for i in range(param['nbIndiv'] - 1):

        clone = classes.indiv(param, caracs)
        clone.ADN.setNbNodeInt(ind.ADN.nbNodeInt)

        for g0 in ind.ADN.seqGene:

            g = classes.gene()
            g0.copyTo(g)
            clone.ADN.addGene(g)

            clone.ADN.siInLibre[g.inNode] = False
            if g.outNode < clone.ADN.encOffset:
                clone.ADN.siOutLibre[g.outNode] = False
            else:
                clone.ADN.siEncrLibre[g.outNode] = False

        for nvlInput in range(param['inputSupInit']):
            mutation.creationInput(pop, clone)
        for nvlOutput in range(param['outputSupInit']):
            mutation.creationOutput(param, pop, clone, caracs)
        for connexion in range(param['connexInit']):
            mutation.creationConnexion(param, pop, clone, caracs)
        for encryption in range(param['encrInit']):
            mutation.creationEncryption(param, pop, clone, caracs)
        for chgtPoids in range(param['chgtPoidsInit']):
            mutation.changementPoids(clone)

        clone.nom = pop.getProchNom()
        pop.addIndiv(clone)
        print(clone.nom)
示例#13
0
def reproduction(param, pop, caracs):
    for ind in pop.indiv:
        if ind.classement > param['nbSurv']:
            ind.reset(param)

    for parent1 in pop.indiv:
        if parent1.classement != 0:
            parent2 = random.choices(pop.indiv, parent1.ptsMemeEspece)[0]

            for enfant in pop.indiv:
                if enfant.nom == 0:
                    break

            for g in parent1.ADN.seqGene:
                genf = classes.gene()
                if parent2.ADN.tellSiGene(g.code):
                    if random.randrange(2):
                        g.copyTo(genf)
                    else:
                        parent2.ADN.findGene(g.code).copyTo(genf)
                else:
                    g.copyTo(genf)
                enfant.ADN.addGene(genf)

            for g in parent2.ADN.seqGene:
                if not enfant.ADN.tellSiGene(g.code):
                    genf = classes.gene()
                    g.copyTo(genf)
                    enfant.ADN.addGene(genf)

            if func.siCreationBoucleChezEnfant(param, enfant, caracs):
                enfant.reset(param)
                parent2 = parent1
                for g in parent1.ADN.seqGene:
                    genf = classes.gene()
                    g.copyTo(genf)
                    enfant.ADN.addGene(genf)

            enfant.ADN.setNbNodeInt\
             (max(parent1.ADN.nbNodeInt, parent2.ADN.nbNodeInt))
            for g in enfant.ADN.seqGene:
                enfant.ADN.siInLibre[g.inNode] = False
                if g.outNode < enfant.ADN.encOffset:
                    enfant.ADN.siOutLibre[g.outNode] = False
                else:
                    enfant.ADN.siEncrLibre[g.outNode] = False

            enfant.nom = pop.getProchNom()
            enfant.parent1 = parent1.nom
            enfant.parent2 = parent2.nom
            if parent1.nom == parent2.nom:
                parent1.descendants += 1
            else:
                parent1.descendants += 1
                parent2.descendants += 1

    for regen in pop.indiv:
        if regen.nom == 0:
            regen.nom = pop.getProchNom()

            for transverse in range(param['transversesInit']):
                unique = False
                while not unique:
                    if transverse == 0:
                        inNode = 0
                    else:
                        inNode = random.randrange(param['nbInput'])
                    outNode = random.randrange(param['nbOutput'])

                    if not ind.ADN.tellSiGene(pop.arbreGen[inNode][outNode]):
                        unique = True

                for couche in range(param['couchesInit']):
                    g = classes.gene()
                    g.inNode = inNode
                    g.outNode = param['nbOutput'] + regen.ADN.nbNodeInt
                    g.weight = random.uniform(-1, 1)
                    g.active = True

                    if pop.arbreGen[g.inNode][g.outNode] == 0:
                        pop.setGeneCode(g.inNode, g.outNode)
                    g.code = pop.arbreGen[g.inNode][g.outNode]

                    regen.ADN.addGene(g)
                    inNode = param['nbInput'] + regen.ADN.nbNodeInt
                    regen.ADN.addNodeInt()

                g = classes.gene()
                g.inNode = inNode
                g.outNode = outNode
                g.weight = random.uniform(-1, 1)
                g.active = True

                if pop.arbreGen[g.inNode][g.outNode] == 0:
                    pop.setGeneCode(g.inNode, g.outNode)
                g.code = pop.arbreGen[g.inNode][g.outNode]

                regen.ADN.addGene(g)
                regen.ADN.siInLibre[inNode] = False
                regen.ADN.siOutLibre[outNode] = False

            for nvlInput in range(param['inputSupInit']):
                mutation.creationInput(pop, regen)
                regen.ADN.seqGene[regen.ADN.compteGene() -
                                  1].weight = random.uniform(-1, 1)

            for connexion in range(param['connexInit']):
                mutation.creationConnexion(param, pop, regen, caracs)
                regen.ADN.seqGene[regen.ADN.compteGene() -
                                  1].weight = random.uniform(-1, 1)

            for encryption in range(param['encrInit']):
                mutation.creationEncryption(param, pop, regen, caracs)
                regen.ADN.seqGene[regen.ADN.compteGene() -
                                  1].weight = random.uniform(-1, 1)

            for connexion in range(param['connexInit']):
                mutation.creationConnexion(param, pop, regen, caracs)
                regen.ADN.seqGene[regen.ADN.compteGene() -
                                  1].weight = random.uniform(-1, 1)
示例#14
0
from classes import gene
from pyfaidx import Fasta
import os

APP_ROOT = os.path.dirname(os.path.abspath(__file__))

data = read_json_compressed()
a = data[1]
b = data[2]
name = a['name']
chrom = a['chrom']
start = a['start']
end = a['end']
ori = a['orientation']
exons = a['exons']
test_gene = gene(**a)
tg2 = gene(**b)
fasta_path = os.path.join(APP_ROOT, 'static', 'data', 'AT9.fa')
genome = Fasta(fasta_path)
tg2.get_sequence(genome)
print(name, start, end)
print(tg2.exon_list[0].start)
"""
LOCUS       Example                   24 bp    DNA              UNK 01-JAN-1980
DEFINITION  An example GenBank file generated by BioPython
ACCESSION   123456789
VERSION     123456789
KEYWORDS    .
SOURCE      .
  ORGANISM  .
            .