class EAMotifsReal (EvolAlgorithm): def __init__(self, popsize, numits, noffspring, filename): self.motifs = MotifFinding() self.motifs.readFile(filename, "dna") indsize = self.motifs.motifSize * len(self.motifs.alphabet) EvolAlgorithm.__init__(self, popsize, numits, noffspring, indsize) def initPopul(self, indsize): maxvalue = self.motifs.seqSize(0) - self.motifs.motifSize self.popul = PopulReal(self.popsize, indsize, maxvalue, []) def vector_to_PWM(self, v): #v -> vetor de números reais self.pwm = createMatZeros(len(self.mtoifs.alphabet), self.motifs.motifSize) for i in range(0, len(v), self.motifs.alphabet): col_idx = i / len(self.motifs.alphabet) col = v[i : i + len(self.motifs.alphabet)] soma = sum(col) for j in range(len(self.motifs.alphabet)): self.pwm[j][col_idx] = col[j] / soma return pwm def evaluate(self, indivs): for i in range(len(indivs)): ind = indivs[i] sol = ind.getGenes() self.motifs.pwm = self.vector_to_PWM(sol) s = [] for seq in self.motifs.seqs: p = self.motifs.mostProbableSeq(seq) s.append(p) ## TPC - ussar score multiplicativo sem atualizar a PWM ## fit = self.motifs.score(sol) ind.setFitness(fit)
class EAMotifsReal (EvolAlgorithm): def __init__(self, popsize, numits, noffspring, filename): self.motifs = MotifFinding() self.motifs.readFile(filename, "dna") indsize = self.motifs.motifSize * len(self.motifs.alphabet) EvolAlgorithm.__init__(self, popsize, numits, noffspring, indsize) def initPopul(self, indsize): maxvalue = self.motifs.seqSize(0) - self.motifs.motifSize self.popul = PopulReal(self.popsize, indsize, 0, maxvalue, []) def vec_to_pwm(self,v): n_alph = len(self.motifs.alphabet) n_motif = self.motifs.motifSize pwm = createMatZeros(n_alph, n_motif) for i in range(0,len(v),n_alph): col_idx = int(i / n_alph) col = v[i:i+n_alph] soma = sum(col) for j in range(n_alph): pwm[j][col_idx] = col[j] / soma return pwm def probabSeq(self, seq): res = 1.0 for i in range(self.motifs.motifSize): lin = self.motifs.alphabet.index(seq[i]) res *= self.motifs.pwm[lin][i] return res def mostProbableSeq(self, seq): maximo = -1.0 maxind = -1 for k in range(len(seq)-self.motifs.motifSize): p = self.probabSeq(seq[k:k + self.motifs.motifSize]) if(p > maximo): maximo = p maxind = k return maxind def evaluate(self, indivs): for i in range(len(indivs)): ind = indivs[i] sol = ind.getGenes() pwm = self.vec_to_pwm(sol) mtf = MyMotifs(pwm=pwm, alphabet=self.motifs_finding.alphabet) s = [] for j in range(len(self.motifs_finding.seqs)): seq = self.motifs_finding.seqs[j].seq p = mtf.mostProbableSeq(seq) s.append(p) fit1 = self.motifs.scoreMult(s,self.motifs.pwm) # com scoreMult fit = self.motifs.score(s) ind.setFitness(fit) ind.setmultFitness(fit1)
class EAMotifsReal(EvolAlgorithm): def __init__(self, popsize, numits, noffspring, filename): self.motifs = MotifFinding() self.motifs.readFile(filename, 'dna') indsize = self.motifs.motifSize * len(self.motifs.alphabet) EvolAlgorithm.__init__(self, popsize, numits, noffspring, indsize) def initPopul(self, indsize): maxvalue = self.motifs.seqSize(0) - self.motifs.motifSize self.popul = PopulReal(self.popsize, indsize, ub=maxvalue, indivs=[]) def vec_to_pwm(self, v): pwm = createMatZeros(len(self.motifs.alphabet), self.motifs.motifSize) for i in range(0, len(v), len(self.motifs.alphabet)): col_idx = int(i / len(self.motifs.alphabet)) col = v[i:i + len(self.motifs.alphabet)] soma = sum(col) for j in range(len(self.motifs.alphabet)): pwm[i][col_idx] = col[j] / soma return pwm def evaluate(self, indivs): for i in range(len(indivs)): ind = indivs[i] sol = ind.getGenes() pwm = self.vec_to_pwm(sol) s = [] my_motif = MyMotifs(pwm, self.motifs.alphabet) for seq in self.motifs.seqs: p = my_motif.mostProbableSeq(seq) s.append(p) fit = self.motifs.scoreMult(sol, pwm) ind.setFitness(fit)
class EAMotifsReal(EvolAlgorithm): def __init__(self, popsize, numits, noffspring, filename): self.motifs = MotifFinding() self.motifs.readFile(filename, "dna") indsize = self.motifs.motifSize * len(self.motifs.alphabet) EvolAlgorithm.__init__(self, popsize, numits, noffspring, indsize) def initPopul(self, indsize): maxvalue = self.motifs.seqSize(0) - self.motifs.motifSize self.popul = PopulReal(self.popsize, indsize, maxvalue, []) def vec_to_pwm(self, v): n_alph = len(self.motifs.alphabet) n_motif = self.motifs.motifSize pwm = createMatZeros(len(n_alph), n_motif) for i in range(0, len(v), n_alph): # col_idx = i / n_alph col = v[i:i + n_alph] soma = sum(col) for j in range(n_alph): pwm[j][col_idx] = col[j] / soma #EXEMPLO: #[1,2,3,4,5,6,7,8,9,10,....] #A 1 #C 2 #T 3 #G 4 #A 1 2 3 4 #C def evaluate(self, indivs): for i in range(len(indivs)): ind = indivs[i] sol = ind.getGenes() #criar um MyMotif a partir da PWM pwm = self.vec_to_pwm(sol) mtf = MyMotifs(pwm=pwm, alphabet=self.motifs_finding.alphabet) s = [] for j in range(len(self.motifs_finding.seqs)): seq = self.motifs_finding.seqs[j].seq p = mtf.motifs.mostProbableSeq(seq) s.append(p) ## TPC - ussar score multiplicativo sem atualizar a PWM ## fit = self.motifs_finding.score(s) ind.setFitness(fit)
class EAMotifsInt(EvolAlgorithm): def __init__(self, popsize, numits, noffspring, filename): self.motifs = MotifFinding() self.motifs.readFile(filename, "dna") indsize = len(self.motifs) EvolAlgorithm.__init__(self, popsize, numits, noffspring, indsize) def initPopul(self, indsize): maxvalue = self.motifs.seqSize(0) - self.motifs.motifSize self.popul = PopulInt(self.popsize, indsize, maxvalue, []) def evaluate(self, indivs): for i in range(len(indivs)): ind = indivs[i] sol = ind.getGenes() fit = self.motifs.score(sol) ind.setFitness(fit)
class EAMotifsInt(EvolAlgorithm): def __init__(self, popsize, numits, noffspring, filename): self.motifs = MotifFinding() self.motifs.readFile(filename, "dna") indsize = len(self.motifs) EvolAlgorithm.__init__(self, popsize, numits, noffspring, indsize) def initPopul(self, indsize): maxvalue = self.motifs.seqSize(0) - self.motifs.motifSize self.popul = PopulInt(self.popsize, indsize, maxvalue, []) def evaluate(self, indivs): #mudar a funcao de avalicao -> usamos o score for i in range(len(indivs)): ind = indivs[i] #cada vetor de posicoes sol = ind.getGenes() fit = self.motifs.score( sol ) #avaliar o score que sera a fit para cada vetor de posicoes iniciais ind.setFitness(fit)
class EAMotifsInt(EvolAlgorithm): def __init__(self, popsize, numits, noffspring, filename): self.motifs = MotifFinding() self.motifs.readFile(filename, "dna") indsize = len( self.motifs) #numero de seqs a analisar aka numero de individuos EvolAlgorithm.__init__(self, popsize, numits, noffspring, indsize) def initPopul(self, indsize): maxvalue = self.motifs.seqSize( 0 ) - self.motifs.motifSize #upper bound é o indice maximo que o vetor das pos pode ter (tamanho da seq - tamanho do motif) self.popul = PopulInt(self.popsize, indsize, maxvalue, []) def evaluate(self, indivs): for i in range(len(indivs)): ind = indivs[i] sol = ind.getGenes() fit = self.motifs.score(sol) multifit = self.motifs.scoreMult(sol) ind.setFitness(fit) ind.setMultiFitness(multifit)