コード例 #1
0
        /// <summary>
        /// Method for calculating and displaying
        /// </summary>
        /// <param name="orf"></param>
        /// <param name="amino"></param>
        private void CalculateAndDisplayORF(List <string> orf, List <string> amino)
        {
            Data = new DataTable();
            int columnIdx = 0;

            Data.Columns.Add(new DataColumn("CPB"));
            foreach (var k in ORF.aminoORFseq)
            {
                Data.Columns.Add(new DataColumn(columnIdx.ToString()));
                columnIdx++;
            }

            // CPBcalculator method initialization
            try
            {
                OriginalCPBscoreTextBox.Text = ORF.CPBcalculator(ORF.orfSeq).ToString();
                // datagrid filling
                ORF.aminoORFseq.Insert(0, "");
                ORF.orfSeq.Insert(0, OriginalCPBscoreTextBox.Text);
                Data.Rows.Add(ORF.aminoORFseq.ToArray());
                Data.Rows.Add(ORF.orfSeq.ToArray());
                ORF.aminoORFseq.RemoveAt(0);
                ORF.orfSeq.RemoveAt(0);
                OptimizationDataGrid.ItemsSource = Data.DefaultView;
                GeneticCode.UploadGeneticCode();
                ORF.aminoAcidCounts = ORF.aminoORFseq.GroupBy(i => i)
                                      .ToDictionary(i => i.Key, i => i.Count());
                NcScoreTextBox.Text = ORF.NcCalculator(ORF.orfSeq, ORF.aminoAcidCounts).ToString();
            }
            catch
            {
                string message = "Something went wrong. Please verify your FASTA file for incorrect codons or check your ranking.";
                ModernDialog.ShowMessage(message.ToString(), "Error", MessageBoxButton.OK);
            }
        }
コード例 #2
0
 public Zombie(GeneticCode code)
 {
     this.code = code;
     setFuel(200);
     addBehaviours();
     updateWeights();
 }
コード例 #3
0
ファイル: Creature.cs プロジェクト: Horonex/EcoSim
    public float[] Hear()
    {
        float[] output = new float[8 * 3];

        var sounds = SoundManager.instance.GetHearable(this);

        int i = 0;

        foreach (var item in sounds)
        {
            if (sounds.Count - i < 8)
            {
                i++;
                continue;
            }
            else
            {
                output[i]     = GetAngle(item.Value);
                output[i + 1] = GeneticCode.ToInt(item.Value.wave);
                output[i + 2] = item.Key;
                i++;
            }
        }

        return(output);
    }
コード例 #4
0
 protected NucleotideSequence(string sequence, AlphabetType alphabet, GeneticCode geneticCode = GeneticCode.Standard, IEnumerable <string> tags = null)
     : this(sequence, alphabet, geneticCode)
 {
     if (tags != null)
     {
         _tags = new HashSet <string>(tags);
     }
 }
コード例 #5
0
        public void Decoding_string_should_ignore_prefixed_operators()
        {
            Func<string, string> g = s => GenoTypes().Single(x => x.Value.Equals(s)).Key;
            Func<string> generateBits = () => string.Format("{0}{1}{2}{3}", g("/"), g("7"), g("+"), g("4"));

            var sut = new GeneticCode(new Random());

            Assert.Equal("7+4", sut.Decode(generateBits()));
        }
コード例 #6
0
 public GeneticCode[] MutateNumber(int times)
 {
     GeneticCode[] gCodes = new GeneticCode[times];
     gCodes[0] = this;
     for (int i = 1; i < times; i++)
     {
         gCodes[i] = new GeneticCode(gCodes[i - 1]);
     }
     return(gCodes);
 }
コード例 #7
0
ファイル: Reproduction.cs プロジェクト: gabesf/Simvolution
    private static GeneticCode DuplicateGeneticCode(GeneticCode oGeneticCode)
    {
        GeneticCode newGeneticCode     = new GeneticCode();
        float       mutationChance     = oGeneticCode.GetMutationChance();
        float       noise              = oGeneticCode.GetNoise();
        float       noiseChance        = oGeneticCode.GetNoiseChance();
        List <byte> newGeneticCodeList = new List <byte>();
        List <byte> oldGeneticCodeList = oGeneticCode.GetGeneticCodeList();

        //Debug.Log("Mutation Chance " + mutationChance);

        int randomInsert = Random.Range(0, oldGeneticCodeList.Count);
        //randomInsert = 1;

        //Debug.Log("Random Insert at = " + randomInsert);
        byte randomValue = (byte)(Random.Range(0, 255));

        randomValue = 10;
        //Debug.Log("Random Value = " + randomValue);


        for (int i = 0; i < oldGeneticCodeList.Count; i++)
        {
            bool addNoise = false;
            if (Random.Range(0f, 1f) > noiseChance)
            {
                addNoise = true;
            }

            if (Random.Range(0f, 1f) < mutationChance)
            {
                Debug.Log("Random Insertion @ " + i);
                newGeneticCodeList.Add((byte)(Random.Range(0, 255)));
                Debug.Log("Safely inserted");
            }

            byte byteToAdd = oldGeneticCodeList[i];

            if (addNoise)
            {
                //Debug.Log("Adding noise to " + byteToAdd);
                byteToAdd = (byte)(byteToAdd * Random.Range(-noise, +noise));
                //Debug.Log("Added noise : " + byteToAdd);
            }

            newGeneticCodeList.Add(oldGeneticCodeList[i]);
        }

        Debug.Log("Exited");
        newGeneticCode.SetGeneticCodeList(newGeneticCodeList);
        //newGeneticCodeList = new List<byte>();

        return(newGeneticCode);
    }
コード例 #8
0
 public static Population NewPopulation(float target, int size, Random randomness)
 {
     var decoder = new GeneticCode(randomness);
     return new Population(target,
         Enumerable.Range(0, size)
             .Select(id =>
                 Chromosome.New(target,
                     decoder)),
                 randomness,
                 bits => decoder.Decode(bits));
 }
コード例 #9
0
        protected NucleotideSequence(string sequence, AlphabetType alphabet, GeneticCode geneticCode)
        {
            NucleotideAlphabet = new NucleotideAlphabet(alphabet, geneticCode);
            ActiveAlphabet     = alphabet;
            GeneticCode        = geneticCode;
            var trimmedSequence = sequence.Trim();



            VerifyAndInitializeNucleotides(trimmedSequence);
            Sequence = trimmedSequence;
        }
コード例 #10
0
 public Human(GeneticCode code)
 {
     this.code            = code;
     type                 = HumanType.Child;
     firstUpdate          = true;
     secondsUntilMaturity = 5f + (Random.value * 10f);
     state                = HumanState.Idle;
     setFuel(200);
     addBehaviours();
     updateWeights();
     World.world.updateHumanState(getID());
 }
コード例 #11
0
ファイル: GameManager.cs プロジェクト: Horonex/EcoSim
    public void SpawnCreature(GeneticCode GCode)
    {
        if (creatures.Count < MaxCreature)
        {
            Creature newCreature = Instantiate(toInst);

            newCreature.Init(BrainMaker.OneSizeBrain(newCreature), GCode, new Vector2(0, 0), new Vector2(1, 0));


            creatures.Add(newCreature);
        }
    }
コード例 #12
0
 protected NucleotideSequence(string sequence, AlphabetType alphabet, GeneticCode geneticCode, Dictionary <Nucleotide, long> symbolCounts, IEnumerable <string> tags)
 {
     NucleotideAlphabet = new NucleotideAlphabet(alphabet, geneticCode);
     ActiveAlphabet     = alphabet;
     GeneticCode        = geneticCode;
     Sequence           = sequence;
     SymbolCounts       = symbolCounts;
     if (tags != null)
     {
         _tags = new HashSet <string>(tags);
     }
 }
コード例 #13
0
 public GeneticCode(GeneticCode parent)
 {
     genes = new List <Gene>();
     foreach (var g in parent.GetGenes())
     {
         foreach (var m in g.Mutate())
         {
             genes.Add(m);
         }
     }
     fillerCode = parent.MutateFiller();
     decoded    = true;
 }
コード例 #14
0
ファイル: Creature.cs プロジェクト: Horonex/EcoSim
    public void Init(Brain brain, GeneticCode GCode, Vector2 pos, Vector2 ang)
    {
        this.brain = brain;
        Genotype   = GCode;
        stats      = new Stats(new List <StatGene>());
        stomac     = new Stomac(this);
        stats      = new Stats(Genotype.GetGenes(), this);

        brain.owner = this;

        position    = pos;
        orientation = ang;
    }
コード例 #15
0
ファイル: GameManager.cs プロジェクト: Horonex/EcoSim
    public void SpawnCreature(Brain brain, GeneticCode GCode)
    {
        if (creatures.Count < MaxCreature)
        {
            Creature newCreature = Instantiate(toInst);

            newCreature.Init(brain, GCode, new Vector2(0, 0), new Vector2(1, 0));

            creatures.Add(newCreature);
        }

        //creatures.Add()
    }
コード例 #16
0
        public NucleotideAlphabet(AlphabetType nucleotideAlphabet, GeneticCode geneticCode)
        {
            if (nucleotideAlphabet == AlphabetType.ExtendedProtein || nucleotideAlphabet == AlphabetType.StandardProtein)
            {
                throw new ArgumentException(String.Format(AlphabetDataProvider.InvalidNucleotideAlphabet, nucleotideAlphabet));
            }

            GeneticCode        = geneticCode;
            AllowedSymbols     = AlphabetDataProvider.GetAllowedNucleotideSymbols(nucleotideAlphabet);
            ComplementTable    = AlphabetDataProvider.GetComplementTable(nucleotideAlphabet);
            TranscriptionTable = AlphabetDataProvider.GetTranscriptionTable(nucleotideAlphabet);
            TranslationTable   = AlphabetDataProvider.GetTranslationTable(geneticCode, nucleotideAlphabet);
            GcContentSymbols   = AlphabetDataProvider.GcContentSymbols(nucleotideAlphabet);
        }
コード例 #17
0
    public void spawnChild(uint motherID, Vector2 location, GeneticCode code)
    {
        Boid  mother = getBoid(motherID);
        float fuel   = mother.getFuel();

        mother.setFuel(fuel * 0.75f);
        Boid child = new Human(code);

        child.setPosition(location);
        child.setFuel(fuel * 0.5f);
        boidsToAdd.Add(child);

        humansAlive++;
    }
コード例 #18
0
 public GeneticCode(GeneticCode a, float mutationRate)
 {
     data = new List <float>();
     for (int i = 0; i < a.getLength(); i++)
     {
         if (Random.value < mutationRate)
         {
             data.Add(Random.value);
         }
         else
         {
             data.Add(a.getValue(i));
         }
     }
 }
コード例 #19
0
        public RnaSequence(string rawBasePairs, AlphabetType alphabet, GeneticCode geneticCode = GeneticCode.Standard, IEnumerable <string> tags = null)
            : base(rawBasePairs, alphabet, geneticCode, tags)
        {
            switch (alphabet)
            {
            case AlphabetType.AmbiguousRna:
                break;

            case AlphabetType.StrictRna:
                break;

            default:
                throw new ArgumentException(String.Format(InvalidAlphabetForSequenceType, alphabet, GetType()));
            }
        }
コード例 #20
0
        public ProteinAlphabet(AlphabetType proteinAlphabet, GeneticCode geneticCode = GeneticCode.Standard)
        {
            switch (proteinAlphabet)
            {
            case AlphabetType.ExtendedProtein:
                break;

            case AlphabetType.StandardProtein:
                break;

            default:
                throw new ArgumentException(String.Format(InvalidProteinAlphabet, proteinAlphabet));
            }
            _activeAlphabet = proteinAlphabet;
            _geneticCode    = geneticCode;
        }
コード例 #21
0
 public GeneticCode(GeneticCode a, GeneticCode b, float mutationRate)
 {
     data = new List <float>();
     if (a.getLength() == b.getLength())
     {
         for (int i = 0; i < a.getLength(); i++)
         {
             if (Random.value < mutationRate)
             {
                 data.Add(Random.value);
             }
             else
             {
                 data.Add((a.getValue(i) + b.getValue(i)) / 2.0f);
             }
         }
     }
 }
コード例 #22
0
ファイル: GameManager.cs プロジェクト: Horonex/EcoSim
    // Start is called before the first frame update
    void Start()
    {
        if (instance == null)
        {
            instance = this;
        }

        InitRdm();
        Gene.SetMutationConstants(duplication: dupRate, inversion: inverRate, supression: supRate, insertion: inserRate);

        creatures = new HashSet <Creature>();
        var fill = GeneticCode.GetNewFiller();

        SpawnCreature(new GeneticCode("HXHOOOOOHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh", fill));
        SpawnCreature(new GeneticCode("HXHVHHHxHXHOhhhxHXHOhhhxHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh", fill));


        Tick();
    }
コード例 #23
0
ファイル: Creature.cs プロジェクト: Horonex/EcoSim
    public float[] Look()
    {
        float[] output = new float[8 * 3];


        int i = 0;

        foreach (var item in GetInRange(this, stats.vDistance, stats.vAngle))
        {
            if (i >= 8)
            {
                break;
            }
            output[i]     = GeneticCode.ToInt(item.Value.GetPheno());
            output[i + 1] = GetAngle(item.Value);
            output[i + 2] = GetDistance(item.Value);
            i++;
        }

        return(output);
    }
コード例 #24
0
    /// <summary>
    /// return percentage of similarity between 2 genomes.
    /// </summary>
    /// <param name="g1"></param>
    /// <param name="g2"></param>
    /// <returns></returns>
    static public float Compare(GeneticCode g1, GeneticCode g2)
    {
        if (!g1.decoded)
        {
            g1.Decode();
        }
        if (!g2.decoded)
        {
            g2.Decode();
        }
        int success = 0;
        int fail    = 0;

        CompareGenes(g1.genes, g2.genes, ref success, ref fail);

        CompareFiller(g1.fillerCode, g2.fillerCode, ref success, ref fail);

        //Debug.Log(success + "s");
        //Debug.Log(fail + "f");

        return((float)success / (float)(success + fail));
    }
コード例 #25
0
ファイル: StatGene.cs プロジェクト: Horonex/EcoSim
 void SetValue()
 {
     value = GeneticCode.ToInt(geneticString.Substring(TYPELENGTH + 2));
 }
コード例 #26
0
    void Start()
    {
        gameObject.AddComponent <MeshFilter>();
        currentStage = CurrentStage.expanding;

        //Debug.Log("Start being called");
        if (geneticCode == null)
        {
            //Debug.Log(gameObject.name + " is creating a genetic code!");
            geneticCode = new GeneticCode();
        }
        else
        {
            //Debug.Log(gameObject.name + " already have a genetic code!");
        }

        parts = new List <GameObject>();



        geneticCodeOperator         = new GeneticCodeOperator();
        geneticBuildingInstructions = new GeneticBuildingInstructions();

        #region neural network tests

        /*
         * neural = new NetworkModel();
         * neural.Layers.Add(new NeuralLayer(4, 1, "INPUT"));
         * neural.Layers.Add(new NeuralLayer(2, 1, "HIDDEN"));
         * neural.Layers.Add(new NeuralLayer(4, 2, "OUTPUT"));
         *
         * neural.Build();
         * //Debug.Log("----Before Training------------");
         * neural.Print();
         *
         * NeuralData X = new NeuralData(4);
         * X.Add(1, 1);
         * X.Add(1, 1);
         * X.Add(1, 0);
         * X.Add(1, 1);
         *
         * NeuralData Y = new NeuralData(4);
         * Y.Add(1);
         * Y.Add(1);
         * Y.Add(0);
         * Y.Add(0);
         *
         * neural.Train(X, Y, iterations: 10, learningRate: 0.1);
         * //List<double> outputs = neural.Process(X);
         *
         */
        #endregion

        //Debug.Log("----After Training------------");

        //for(int i = 0; i < outputs.Count; i++)
        //{
        //    Debug.Log($"Output{i} = {outputs[i]}");
        //}

        //neural.Print();

        //X.Add(2.0f);
        //X.Add(3.0f);

        //List<double> outputs = neural.Train(X);

        //Debug.Log("Output");
        //for (int i = 0; i < outputs.Count; i++)
        //{
        //    Debug.Log($"Out{i} = {outputs[i]}");
        //}


        List <byte> geneticCodeList = geneticCode.GetGeneticCodeList();

        geneticCodeOperator.ProcessGeneticCode(gameObject, ref geneticCodeList, geneticBuildingInstructions.GetBuildingInstructions());

        geneticCode.SetGeneticCodeList(geneticCodeList);

        //read geneticCode
        //operateGeneticCode
    }
コード例 #27
0
 public void SetGeneticCode(GeneticCode _geneticCode)
 {
     geneticCode = _geneticCode;
 }
コード例 #28
0
    public override void update(float deltaTime, List <Boid> neighbors, List <Boid> touching)
    {
        HumanType  initialType  = type;
        HumanState initialState = state;
        bool       seesZombie   = false;

        for (int i = 0; i < neighbors.Count; i++)
        {
            if (neighbors[i].getFaction() == "Zombie")
            {
                state      = HumanState.Hunted;
                seesZombie = true;
            }
        }
        if (seesZombie == false)
        {
            state = HumanState.Idle;
        }
        for (int i = 0; i < touching.Count; i++)
        {
            if (touching[i].getFaction() == "Food")
            {
                addFuel(touching[i].getFuel());
                World.world.removeFood(touching[i].getID());
            }
            else if (type == HumanType.Female && touching[i].getFaction() == "Male")
            {
                //Become pregnant
                type              = HumanType.PregnantFemale;
                childCode         = new GeneticCode(touching[i].getGeneticCode(), code, 0.05f);
                secondsUntilBirth = 7f;
            }
        }

        if (getFuel() < 0)
        {
            World.world.killHuman(getID());
            return;
        }
        else if (getFuel() < 50)
        {
            state = HumanState.Hungry;
        }

        if (type == HumanType.PregnantFemale)
        {
            secondsUntilBirth -= deltaTime;
            if (secondsUntilBirth < 0)
            {
                //Give birth
                World.world.spawnChild(getID(), getPosition(), childCode);
                type = HumanType.Female;
            }
        }
        else if (type == HumanType.Child)
        {
            secondsUntilMaturity -= deltaTime;
            if (secondsUntilMaturity < 0)
            {
                //Become an adult
                if (Random.value < 0.5f)
                {
                    type = HumanType.Male;
                }
                else
                {
                    type = HumanType.Female;
                }
            }
        }

        secondsAlive += deltaTime;

        if (firstUpdate || initialState != state || initialType != type)
        {
            firstUpdate = false;
            updateWeights();
            World.world.updateHumanState(getID());
        }
        return;
    }
コード例 #29
0
 internal RnaSequence(string safeSequence, AlphabetType alphabet, GeneticCode geneticCode, Dictionary <Nucleotide, long> symbolCounts, IEnumerable <string> tags = null)
     : base(safeSequence, alphabet, geneticCode, symbolCounts, tags)
 {
 }
コード例 #30
0
ファイル: StatGene.cs プロジェクト: Horonex/EcoSim
        public override void Express(Creature owner)
        {
            int value = GeneticCode.ToInt(geneticString.Substring(4));

            switch (geneticString.Substring(2, 2))
            {
            default:
            {
                break;
            }

            case "HH":
            {
                break;
            }

            case "HV":
            {
                owner.stats.size += value;
                break;
            }

            case "HO":
            {
                owner.stats.speed += value;
                break;
            }

            case "HX":
            {
                owner.stats.GestationTime += value;
                break;
            }

            case "VH":
            {
                owner.stats.GestationMaturity += value;
                break;
            }

            case "VV":
            {
                owner.stats.strength += value;
                break;
            }

            case "VO":
            {
                //owner.stats
                break;
            }

            case "VX":
            {
                //owner.stats
                break;
            }

            case "OH":
            {
                //owner.stats
                break;
            }

            case "OV":
            {
                //owner.stats
                break;
            }

            case "OO":
            {
                //owner.stats
                break;
            }

            case "OX":
            {
                //owner.stats
                break;
            }

            case "XH":
            {
                //owner.stats
                break;
            }

            case "XV":
            {
                //owner.stats
                break;
            }

            case "XO":
            {
                //owner.stats
                break;
            }

            case "XX":
            {
                //owner.stats
                break;
            }
            }
        }
コード例 #31
0
ファイル: StatGene.cs プロジェクト: Horonex/EcoSim
 void SetType()
 {
     type = (StatType)GeneticCode.ToInt(geneticString.Substring(0, TYPELENGTH));
 }
コード例 #32
0
 //Contructor for the brain.
 public Brain(Citizen _body, GeneticCode DNA)
 {
     body        = _body;
     geneticCode = DNA;
     location    = body.GetLocation();
 }