@Override public WaveletChromatid clone() { try { final WaveletChromatid copy = (WaveletChromatid) super.clone(); copy.centromerePosition = this.centromerePosition; copy.mutability = this.mutability; copy.sequencedGenes = new ArrayList<AbstractWaveletGene>(); copy.promoters = new ArrayList<PromoterGene>(); copy.localSignalGenes = new ArrayList<SignalGene>(); copy.externalSignalGenes = new ArrayList<ExternalSignalGene>(); for (AbstractWaveletGene currentGene : this.sequencedGenes) copy.sequencedGenes.add(currentGene.clone()); for (PromoterGene currentGene : this.promoters) copy.promoters.add(currentGene.clone()); for (SignalGene currentGene : this.localSignalGenes) copy.localSignalGenes.add(currentGene.clone()); for (ExternalSignalGene currentGene : this.externalSignalGenes) copy.externalSignalGenes.add(currentGene.clone()); return copy; } catch (CloneNotSupportedException caught) { LOGGER.error("CloneNotSupportedException caught but not expected!", caught); throw new UnexpectedDannError("CloneNotSupportedException caught but not expected", caught); } }
public void mutate(final Set<AbstractKey> keyPool) { // there is a chance we will remove a signal gene from the chromatid if (Mutations.mutationEvent(mutability)) if (this.localSignalGenes.size() > 0) this.sequencedGenes.remove( this.localSignalGenes.remove( Mutations.getRandom().nextInt(this.localSignalGenes.size()))); // there is a chance we will add a new gene to the chromatid if (Mutations.mutationEvent(mutability) && getGenes().size() < max) { // generate the new receptorKey used in the new gene ReceptorKey newReceptorKey = new ReceptorKey(randomKey(keyPool)); // mutate new receptorKey before using it while (Mutations.mutationEvent(this.mutability)) newReceptorKey = newReceptorKey.mutate(mutability); // create a new gene using the new receptor AbstractWaveletGene newGene; final SignalKey newSignalKey = new SignalKey(randomKey(keyPool)); switch (RANDOM.nextInt(3)) { case 0: final MutableInteger initialDistance = (new MutableInteger(0)).mutate(mutability); newGene = new PromoterGene(newReceptorKey, initialDistance.intValue()); this.promoters.add((PromoterGene) newGene); break; case 1: newGene = new SignalGene(newReceptorKey, newSignalKey); this.localSignalGenes.add((SignalGene) newGene); break; default: newGene = new ExternalSignalGene(newReceptorKey, newSignalKey, RANDOM.nextBoolean()); this.externalSignalGenes.add((ExternalSignalGene) newGene); } // add the new gene to the sequence. there is an equal chance the // gene will be added to the head and tail if (RANDOM.nextBoolean()) this.sequencedGenes.add(0, newGene); else this.sequencedGenes.add(newGene); } // mutate each gene (the gene itself will handle if it actually mutates) for (AbstractWaveletGene currentGene : this.sequencedGenes) currentGene.mutate(keyPool); // mutate the mutability factor. if (Mutations.mutationEvent(mutability)) this.mutability = Mutations.mutabilityMutation(this.mutability); }
public WaveletChromatid(WaveletChromatid copy) { this.centromerePosition = copy.centromerePosition; this.mutability = copy.mutability; this.sequencedGenes = new ArrayList<AbstractWaveletGene>(); this.promoters = new ArrayList<PromoterGene>(); this.localSignalGenes = new ArrayList<SignalGene>(); this.externalSignalGenes = new ArrayList<ExternalSignalGene>(); for (AbstractWaveletGene currentGene : copy.sequencedGenes) this.sequencedGenes.add(currentGene.clone()); for (PromoterGene currentGene : copy.promoters) this.promoters.add(currentGene.clone()); for (SignalGene currentGene : copy.localSignalGenes) this.localSignalGenes.add(currentGene.clone()); for (ExternalSignalGene currentGene : copy.externalSignalGenes) this.externalSignalGenes.add(currentGene.clone()); }
public boolean bind(final SignalKeyConcentration concentration, final boolean isExternal) { boolean bound = false; for (AbstractWaveletGene gene : this.sequencedGenes) if (gene.bind(concentration, isExternal)) bound = true; return bound; }
public void preTick() { for (AbstractWaveletGene gene : this.sequencedGenes) gene.preTick(); }
public Set<AbstractKey> getKeys() { final HashSet<AbstractKey> allKeys = new HashSet<AbstractKey>(); for (AbstractWaveletGene gene : this.sequencedGenes) allKeys.addAll(gene.getKeys()); return Collections.unmodifiableSet(allKeys); }