//JAVA TO C# CONVERTER WARNING: 'final' parameters are not allowed in .NET: //ORIGINAL LINE: public final int getSize(final org.broadinstitute.variant.variantcontext.Genotype g) public int getSize(Genotype g) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int[] v = getValues(g); int[] v = getValues(g); return v == null ? 0 : v.Length; }
private void OnePointCrossover(Genotype parent1, Genotype parent2, ref Genotype offspring1, ref Genotype offspring2) { var genotypeParent1 = parent1.GetRawGenotype(); var genotypeParent2 = parent2.GetRawGenotype(); int crossoverPoint = genotypeParent1.Count; if (Random.Range(0.0f, 1.0f) < crossoverRate) { crossoverPoint = Random.Range(0, genotypeParent1.Count); List <float[]> genotypeA = new List <float[]>(); List <float[]> genotypeB = new List <float[]>(); for (int i = 0; i < genotypeParent1.Count; ++i) { if (i < crossoverPoint) { genotypeA.Add(genotypeParent1[i]); genotypeB.Add(genotypeParent2[i]); } else { genotypeA.Add(genotypeParent2[i]); genotypeB.Add(genotypeParent1[i]); } } offspring1.SetRawGenotype(genotypeA); offspring2.SetRawGenotype(genotypeB); } }
protected override Factory <EvolutionResult <DoubleGene, double> > Factory() { return(() => { var random = RandomRegistry.GetRandom(); return EvolutionResult.Of( random.NextBoolean() ? Optimize.Maximum : Optimize.Minimum, new Population <DoubleGene, double>(100) .Fill(() => Phenotype.Of( Genotype.Of(DoubleChromosome.Of(0, 1)), 1, a => a.Gene.Allele), 100 ), random.NextInt(1000), random.NextInt(1000), EvolutionDurations.Of( TimeSpan.FromMilliseconds(random.NextInt(1000000)), TimeSpan.FromMilliseconds(random.NextInt(1000000)), TimeSpan.FromMilliseconds(random.NextInt(1000000)), TimeSpan.FromMilliseconds(random.NextInt(1000000)), TimeSpan.FromMilliseconds(random.NextInt(1000000)), TimeSpan.FromMilliseconds(random.NextInt(1000000)), TimeSpan.FromMilliseconds(random.NextInt(1000000)) ), random.NextInt(100), random.NextInt(100), random.NextInt(100) ); }); }
/// <summary> /// Initialise new lifeform /// </summary> /// <param name="_genotype">The genotype to use</param> /// <param name="layerSizes">The layerSizes of the neural network</param> public LifeForm(Genotype _genotype, params uint[] layerSizes) { isAlive = false; GenoType = _genotype; NN = new NeuralNetwork(layerSizes); //Check for matching number of genes to weights if (NN.WeightCount != _genotype.GeneCount) { throw new ArgumentException("Lifeform(): Genotype gene count does not match the number of weights in neural network"); } IEnumerator <float> chromosome = _genotype.GetEnumerator(); //Assign chromosome to weights in neural network foreach (NeuralLayer layer in NN.Layers) { for (int x = 0; x < layer.Weights.GetLength(0); x++) //Neurons of current layer { for (int y = 0; y < layer.Weights.GetLength(1); y++) //Neurons of next layer { layer.Weights[x, y] = chromosome.Current; chromosome.MoveNext(); } } } }
/// <summary> /// Initialises a new agent from given genotype, constructing a new feedfoward neural network from /// the parameters of the genotype. /// </summary> /// <param name="genotype">The genotpye to initialise this agent from.</param> /// <param name="topology">The topology of the feedforward neural network to be constructed from given genotype.</param> public Agent(Genotype genotype, NeuralLayer.ActivationFunction defaultActivation, params uint[] topology) { IsAlive = false; this.Genotype = genotype; FNN = new NeuralNetwork(topology); foreach (NeuralLayer layer in FNN.Layers) { layer.NeuronActivationFunction = defaultActivation; } //Check if topology is valid if (FNN.WeightCount != genotype.ParameterCount) { throw new ArgumentException("The given genotype's parameter count must match the neural network topology's weight count."); } //Construct FNN from genotype IEnumerator <float> parameters = genotype.GetEnumerator(); foreach (NeuralLayer layer in FNN.Layers) //Loop over all layers { for (int i = 0; i < layer.Weights.GetLength(0); i++) //Loop over all nodes of current layer { for (int j = 0; j < layer.Weights.GetLength(1); j++) //Loop over all nodes of next layer { layer.Weights[i, j] = parameters.Current; parameters.MoveNext(); } } } }
public static void CompleteCrossover(Genotype parent1, Genotype parent2, float swapChance, out Genotype offspring1, out Genotype offspring2) { //Initialise new parameter vectors int parameterCount = parent1.ParameterCount; float[] off1Parameters = new float[parameterCount], off2Parameters = new float[parameterCount]; //Iterate over all parameters randomly swapping for (int i = 0; i < parameterCount; i++) { if (randomizer.Next() < swapChance) { //Swap parameters off1Parameters[i] = parent2[i]; off2Parameters[i] = parent1[i]; } else { //Don't swap parameters off1Parameters[i] = parent1[i]; off2Parameters[i] = parent2[i]; } } offspring1 = new Genotype(off1Parameters); offspring2 = new Genotype(off2Parameters); }
public void StreamWithInitialGenotypes() { var problem = Problem.Of( a => a, Codec.Of( () => Genotype.Of(IntegerChromosome.Of(0, 1000)), g => g.Gene.Allele ) ); const int genotypeCount = 10; const int max = 1000; var genotypes = IntRange.Of(1, genotypeCount) .Select(i => IntegerChromosome.Of(IntegerGene.Of(max, 0, max))) .Select(i => Genotype.Of(i)) .ToImmutableSeq(); var engine = Engine.Builder(problem).Build(); var result = engine.Stream(genotypes) .Take(1) .ToBestEvolutionResult(); long maxCount = result.GetPopulation().Count(pt => pt.GetFitness() == max); Assert.True(maxCount >= genotypeCount, $"{maxCount} >= {genotypeCount}"); }
public RecombinationOutput Recombine(Genotype a, Genotype b) { IList<Genotype> offsprings = new List<Genotype>(); int nbrChild = UnityEngine.Random.Range(minChild, maxChild); for (var i = 0; i < nbrChild; ++i) { Genotype g = new Genotype(); Extension e; // 50% chance to inherit the base extension from one of the parents. if (Probability.Test(0.5)) e = a.Root; else e = b.Root; g.Root = e.LocalClone(); recombinaison(g.Root, a.Root, b.Root); // Mutations if (Probability.Test(0.3)) { Mutation mutation = new Mutation(); mutation.AddGeneticModifier(new Blur(new Set(new[] { "root" }, Set.Mode.Blacklist), new Set(new[] { "scale" }), 0.1f)); //mutation.AddGeneticModifier(new Addition(new Set(new[] { "Motor" }, Set.Mode.Whitelist), new Set(new[] { "scale" }), 2)); g.Mutate(mutation); } offsprings.Add(g); } return new RecombinationOutput(offsprings); }
private void constructGenotype() { DefaultSEVA defaultGenes = new DefaultSEVA(); Genotype genotype = new Genotype(); var root = new Cylinder(defaultGenes); genotype.setRootElement(root); Sphere front = new Sphere(new DefaultSEVA("bob")); //front.setGeneticData("position",new Vector3(1, 0, 0)); front.setGeneticData("position", new WInt(25)); front.addExtension(new Square(defaultGenes)); Sphere back = new Sphere(new DefaultSEVA("a")); back.setGeneticData("Bienvenue à", new WString("GATTACA")); back.setGeneticData("position",new WVector3(-1, 0, 0)); Plate left = new Plate(new DefaultSEVA("a")); left.setGeneticData("position", new WVector3(0, 0, 1)); left.setGeneticData("rotation", new WVector3(1, 1, 0)); Plate right = new Plate(defaultGenes); right.setGeneticData("position", new WVector3(0, 0, -1)); right.setGeneticData("rotation", new WVector3(-1, -1, 0)); back.addExtension(right); back.addExtension(left); root.addExtension(front); root.addExtension(back); base.genotype = genotype; }
protected void Start() { genotype = new Genotype(Random.Range(-1, Int32.MaxValue)); fov = GetComponent <FieldOfView>(); myRigidbody = GetComponent <Rigidbody>(); agent = GetComponent <NavMeshAgent>(); viewCamera = Camera.main; if (GameManager.Instance.deathEnabled) { utilitySystem.SubscribeOnUrgeExceedLimit((() => { if (gameObject != null) { Die(); } })); } agent.speed = Random.Range(minSpeed, maxSpeed); male = (Random.value > 0.5f); DecodeGenotype(); }
private Genotype CrossPoint(Genotype parent1, Genotype parent2) { int[] childGenes = new int[rows]; for (int i = 25; i < 50; i++) { childGenes[i] = parent1.Genes[i]; } int position = 0; for (int i = 0; i < rows; i++) { Boolean found = false; for (int j = 23; j < 50; j++) { if (parent2.Genes[i] == childGenes[j]) { found = true; break; } } if (!found) { childGenes[position] = parent2.Genes[i]; position++; } } schedule.ChangeOrderAndUpdate(childGenes); return(new Genotype(childGenes, schedule.GetTotalCost())); }
public override Phenotype Develop(Genotype genotype) { BinaryGenotype binaryGenotype = (BinaryGenotype)genotype; ANNWeightPhenotype annWeightPhenotype = new ANNWeightPhenotype(); double max = Math.Pow(2, NumBitsPerWeight); double[] weights = new double[NumWeights]; int weight = 0; int weightIndex = 0; for (int i = 0; i < binaryGenotype.BitVector.Length; i++) { // Convert bits to an int weight += binaryGenotype.BitVector[i] << (i % NumBitsPerWeight); if (i % NumBitsPerWeight == NumBitsPerWeight - 1) { // Calculating a weight between 0 and 1 weights[weightIndex] = (double)(weight - max / 2) / max; weight = 0; weightIndex++; } } annWeightPhenotype.Weights = weights; return(annWeightPhenotype); }
protected string GetFrequencyString(IEnumerable <CalledAllele> variants, bool isReference, int totalDepth) { CalledAllele firstVariant = variants.First(); if (isReference) { if (firstVariant.TotalCoverage == 0) { return((0).ToString(FrequencySigFigFormat)); } return((1 - firstVariant.Frequency).ToString(FrequencySigFigFormat)); } Genotype gt = firstVariant.Genotype; if ((gt == Genotype.HeterozygousAlt1Alt2) || (gt == Genotype.Alt12LikeNoCall)) { if (SumMultipleVF) { return(variants.Select(v => ((double)v.AlleleSupport / (double)totalDepth)).Sum().ToString(FrequencySigFigFormat)); } // tjd + // commented out since we are currently just using one number to represent // VF, even for alt1, alt2 variants. // IE, SumMultipleVF is ucrrently never false. // //var altAllelesFrequencies = (variants.Select(v => ((double)v.AlleleSupport / (double)totalDepth).ToString(FrequencySigFigFormat))).ToList(); //return (string.Join(",", altAllelesFrequencies)); //tjd - } return((firstVariant.Frequency).ToString(FrequencySigFigFormat)); }
private static string GetAlleleCountString(IEnumerable <CalledAllele> variants, bool isReference, int totalDepth) { CalledAllele firstVariant = variants.First(); if (isReference) { return(firstVariant.AlleleSupport.ToString()); } Genotype gt = firstVariant.Genotype; if (gt == Genotype.HeterozygousAlt1Alt2 || gt == Genotype.Alt12LikeNoCall || gt == Genotype.Others) { List <string> altAllelesSupport = variants.Select(v => v.AlleleSupport.ToString()).ToList(); if (variants.Count() > 1) { return(string.Join(",", altAllelesSupport)); } var otherReads = totalDepth - firstVariant.AlleleSupport - firstVariant.ReferenceSupport; if (firstVariant.PhaseSetIndex == 1 || gt == Genotype.Others) { return(string.Format("{0},{1},{2}", firstVariant.ReferenceSupport, firstVariant.AlleleSupport, otherReads)); } return(string.Format("{0},{1},{2}", firstVariant.ReferenceSupport, otherReads, firstVariant.AlleleSupport)); } return(string.Format("{0},{1}", variants.First().ReferenceSupport, firstVariant.AlleleSupport)); }
private void ExecuteDiploidGenotypeTest( Genotype expectedGenotype, int expectedNumAllelesToPrune, List <float> refFrequencies, List <float> altFrequencies) { ExecuteDiploidGenotypeTest(expectedGenotype, expectedNumAllelesToPrune, refFrequencies, altFrequencies, new List <FilterType> { }, 1000); }
public void GetPloidyFromGenotypes_DotIsIgnored() { var genotypes = new[] { Genotype.GetGenotype("."), Genotype.GetGenotype("1|2"), Genotype.GetGenotype("0/2") }; var ploidy = AlleleBlock.GetMaxPloidy(genotypes); Assert.Equal(2, ploidy); }
//JAVA TO C# CONVERTER WARNING: 'final' parameters are not allowed in .NET: //ORIGINAL LINE: public final int getSize(final org.broadinstitute.variant.variantcontext.Genotype g) public int getSize(Genotype g) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int[] v = getValues(g); int[] v = getValues(g); return(v == null ? 0 : v.Length); }
private void ExecuteSomaticGenotypeTest(int totalCoverage, float refFrequency, bool isReference, Genotype expectedGenotype, List <FilterType> filters) { var variant = TestHelper.CreatePassingVariant(isReference); variant.Filters = filters; variant.TotalCoverage = totalCoverage; if (!isReference) { var refSupport = (int)(refFrequency * totalCoverage); variant.AlleleSupport = totalCoverage - refSupport; variant.ReferenceSupport = refSupport; } var GTC = new SomaticGenotypeCalculator(); GTC.MinDepthToGenotype = 30; var allelesToPrune = GTC.SetGenotypes(new List <CalledAllele> { variant }); Assert.Equal(0, allelesToPrune.Count); Assert.Equal(expectedGenotype, variant.Genotype); }
public void GenotypeFromCrossPlan(CrossPlan cp, Genotype gen) { if (gen != null) { gen.UpdateFromCrossPlan(cp); } }
public Variant(Interval parent, VariantContext variant, Chromosome chromosome) : base(parent, variant.Chr, "", "+", variant.Start, variant.End, null) { Chromosome = chromosome; VariantContext = variant; ReferenceAllele = variant.Reference; ReferenceAlleleString = variant.Reference.BaseString; Genotype = variant.Genotypes.First(); // assumes just one sample GenotypeType = Genotype.Type; ReadDepth = Genotype.DP; FirstAlleleDepth = Genotype.AD == null ? -1 : Genotype.AD[0]; SecondAlleleDepth = Genotype.AD == null ? -1 : Genotype.AD[1]; FirstAllele = Genotype.GetAllele(0); FirstAlleleString = FirstAllele.BaseString; SecondAllele = Genotype.GetAllele(1); SecondAlleleString = SecondAllele.BaseString; CalculateType(); if (variant.Attributes.TryGetValue("ANN", out object snpEffAnnotationObj)) { if (snpEffAnnotationObj as string[] != null) { SnpEffAnnotations = (snpEffAnnotationObj as string[]).Select(x => new SnpEffAnnotation(this, x)).ToList(); } if (snpEffAnnotationObj as string != null) { SnpEffAnnotations = new List <SnpEffAnnotation> { new SnpEffAnnotation(this, snpEffAnnotationObj as string) }; } } }
public double ExpectedOffspring_Tests(int doubleDominant, int dominantHetero, int dominantRecessive, int doubleHetero, int heteroRecessive, int doubleRecessive, Genotype genotype, float offspringPerPair) { var model = new ExpectedOffspringModel(doubleDominant, dominantHetero, dominantRecessive, doubleHetero, heteroRecessive, doubleRecessive); return(model.ExpectedOffspring(genotype, offspringPerPair)); }
/// <summary> /// Computes a genetic algorithm with given parameters /// </summary> /// <param name="wantedGenotype">The genotype to fit around</param> /// <param name="generations">Number of generations</param> /// <param name="populationSize">Size of a generation's population</param> /// <param name="tournaments">Number of tournaments in selection</param> /// <param name="rounds">Number of rounds in each tournament</param> /// <param name="mutationRate">Between 0 and 1, chance to mutate a gene</param> /// <returns>A genotype of the last generation's population</returns> public static Genotype Generate( Genotype wantedGenotype, int generations = 600, int populationSize = 300, int tournaments = 200, int rounds = 20, float mutationRate = 0.01f ) { Genotype[] population = GA.InitPopulation(populationSize, wantedGenotype.Length); int[] scores = GA.Evaluate(population, wantedGenotype); for (int g = 1; g < generations; g++) { population = GA.Selection(population, scores, tournaments, rounds); for (int n = tournaments; n < populationSize; n++) { population[n] = GA.Recombine( population[Random.Range(0, n)], population[Random.Range(0, n)] ); } for (int n = 0; n < populationSize; n++) { population[n] = GA.Mutation(population[n], mutationRate); } scores = GA.Evaluate(population, wantedGenotype); } return(GA.Selection(population, scores, 1, rounds)[0]); }
/// <summary> /// edge recombination operator (ER) /// Precondition: parent1 and parent2 contain the same alleles. /// Postcondition: child contains the same alleles as parent1. /// </summary> /// <param name="parent1"></param> /// <param name="parent2"></param> /// <returns></returns> public static Genotype EdgeRecombinationCrossover(Genotype parent1, Genotype parent2) { var count = parent1.Count; if (count <= 1) { return(parent1); } var neighbours = GetNeighbours(parent1, parent2); var previousAllele = parent1[0]; var child = new Genotype(count) { previousAllele }; while (child.Count < count) { DeleteNeighbour(neighbours, previousAllele); var insertAllele = FindNextAllele(neighbours, previousAllele); neighbours.Remove(previousAllele); child.Add(insertAllele); previousAllele = insertAllele; } return(child); }
public ActionResult Detail(int?filterId, string filter) { Genotype genotypeSearched = null; SelectionSummaryViewModel ssvm = null; int genusId = SessionManager.GetGenusId().Value; if (!filterId.HasValue && !filter.IsNullOrWhiteSpace()) { var genotypesResult = m_repo.GetGenotypes(filter, genusId, 2); if (genotypesResult.Count() == 1) { genotypeSearched = genotypesResult.First(); } } else if (filterId.HasValue) { genotypeSearched = m_repo.GetGenotype(filterId.Value); } if (genotypeSearched != null) { ssvm = s_repo.GetSelectionSummary(genotypeSearched.Id); } if (ssvm == null) { return(RedirectToAction("Index", new { filter = filter })); } ViewBag.GenusId = genusId; ViewBag.FlatTypes = new SelectList(m_repo.GetFlatTypes(), "Id", "Name"); return(View(ssvm)); }
public ActionResult CreateNote(Note note) { ActionResult result; if (note == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Genotype genotype = m_repo.GetGenotype(note.GenotypeId); if (genotype == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } if (ModelState.IsValid) { m_repo.SaveNote(note); result = PartialView("~/Areas/Accessions/Views/SelectionSummary/EditorTemplates/EditNote.cshtml", note); } else { result = PartialView("~/Areas/Accessions/Views/SelectionSummary/EditorTemplates/EditNewNote.cshtml", note); } return(result); }
public void TestGenerateGenericGenotypesForAGenotype() { var f = new GenoTypeTestFixture(); f.SetUp(); var expected = new List <Genotype>(); Genotype tDom = new Genotype("T", Dominance.Dominant, Dominance.Dominant); Genotype tHet = new Genotype("T", Dominance.Dominant, Dominance.Recessive); Genotype tRec = new Genotype("T", Dominance.Recessive, Dominance.Recessive); Genotype tHet2 = new Genotype("T", Dominance.Recessive, Dominance.Dominant); expected.Add(tHet); expected.Add(tDom); expected.Add(tRec); expected.Add(tHet2); Genotype tgenotype = new Genotype("T", Dominance.Recessive, Dominance.Recessive); List <Genotype> genericGenotypes = tgenotype.CreateGenericGenotypes(); Assert.AreEqual(expected[0].ToString(), genericGenotypes[0].ToString()); Assert.AreEqual(expected[1].ToString(), genericGenotypes[1].ToString()); Assert.AreEqual(expected[2].ToString(), genericGenotypes[2].ToString()); Assert.AreEqual(expected[3].ToString(), genericGenotypes[3].ToString()); }
/// <summary> /// Builds a pedigree tree for a Genotype. A Pedigree tree is a BST-like structure of parents for that genotype. /// </summary> /// <param name="id">The ID of the Genotype to build a Pedigree from.</param> /// <returns>The root node of the Pedigree Tree, or null if the ID doesn't find a match.</returns> public static TreeNode <Genotype> BuildPedigreeTree(this Genotype target, IPlantBreedingRepo repo) { if (target == null) { throw new ArgumentNullException("target"); } Genotype root = repo.GetGenotype(target.Id); Tuple <Genotype, Genotype> parents = repo.GetGenotypeParents(target); var node = new TreeNode <Genotype> { Data = root }; if (parents != null && parents.Item1 != null) { // Left side is always the male. node.Left = BuildPedigreeTree(parents.Item1, repo); } if (parents != null && parents.Item2 != null) { // Right side is always the female. node.Right = BuildPedigreeTree(parents.Item2, repo); } return(node); }
/// <summary> /// 完整的交叉 /// </summary> public static void CompleteCrossover(Genotype parent1, Genotype parent2, float swapChance, out Genotype offspring1, out Genotype offspring2) { //Initialise new parameter vectors //初始化新的参数矩阵 int parameterCount = parent1.ParameterCount; float[] off1Parameters = new float[parameterCount], off2Parameters = new float[parameterCount]; //Iterate over all parameters randomly swapping //遍历所有参数,随机交换 for (int i = 0; i < parameterCount; i++) { //如果生成的随机数小于交换参考值,则进行交换 if (randomizer.Next() < swapChance) { //Swap parameters off1Parameters[i] = parent2[i]; off2Parameters[i] = parent1[i]; } else { //不进行交换,直接遗传到子基因 //Don't swap parameters off1Parameters[i] = parent1[i]; off2Parameters[i] = parent2[i]; } } //根据新的参数矩阵生成新的基于型 offspring1 = new Genotype(off1Parameters); offspring2 = new Genotype(off2Parameters); }
public override Phenotype Develop(Genotype genotype) { IntGenotype intGenotype = (IntGenotype)genotype; TourPhenotype tourPhenotype = new TourPhenotype(); int max = intGenotype.Max; int[] tour = new int[max]; tourPhenotype.Tour = tour; // Fill in possible cities List <int> possibleCities = new List <int>(max); for (int i = 0; i < max; i++) { possibleCities.Add(i); } // Choose cities based on genotype int c; for (int i = 0; i < max; i++) { //c = intGenotype.List[i] % possibleCities.Count; //tour[i] = possibleCities[c]; //possibleCities.RemoveAt(c); tour[i] = intGenotype.List[i]; } return(tourPhenotype); }
public void GenotypeIsCreatedWithRightNumberOfValues() { // Use the Assert class to test conditions var genotype = new Genotype(10); Assert.AreEqual(10, genotype.Values.Length); }
public string MapGenotype(Genotype genotype) { switch (genotype) { case Genotype.HomozygousAlt: return("1/1"); case Genotype.HomozygousRef: return("0/0"); case Genotype.HeterozygousAltRef: return("0/1"); case Genotype.HeterozygousAlt1Alt2: return("1/2"); case Genotype.RefLikeNoCall: return("./."); case Genotype.AltLikeNoCall: return("./."); case Genotype.RefAndNoCall: return("0/."); case Genotype.AltAndNoCall: return("1/."); default: return("./."); } }
private void ValidateMapComponentGenotype(int mapComponentId, int?newGenotypeId) { MapComponent old = u_repo.GetMapComponent(mapComponentId); if (old == null) { throw new MapException(Properties.Settings.Default.ExceptionMapComponentInvalid); } Genotype newGenotype = null; if (newGenotypeId.HasValue) { newGenotype = u_repo.GetGenotype(newGenotypeId.Value); } //Genotype is empty and the old has a value if (newGenotype == null && old.GenotypeId.HasValue) { if (old.MapComponentYears.HasAny() && old.MapComponentYears.SelectMany(t => t.Answers).HasAny()) { throw new MapException(Properties.Settings.Default.ExceptionMapComponentYear); } } }
public AgentData(Genotype genotype, NeuralLayer.ActivationFunctionType activationFunctionType, bool useRNN, uint[] topology) { this.genotype = genotype; this.activationFunctionType = activationFunctionType; this.useRNN = useRNN; this.topology = topology; }
// This method calculates the fitness for a given genotype. private static java.lang.Double eval(Genotype gt) { double x = ((DoubleGene)gt.getGene()).doubleValue(); double y = Math.Cos(0.5 + Math.Sin(x)) * Math.Cos(x); return new java.lang.Double(y); }
public void shouldUseNextNumberFromNumberStreamAsCrossoverPoint() { Genotype<int> g1 = new Genotype<int> (12, 342, 34, 65); Genotype<int> g2 = new Genotype<int> (234, 9, 89734, 456); int crossoverPoint = 2; mockNumberStream.PushInt (crossoverPoint); IList<Genotype<int>> children = singlePointCrossover.Cross (g1, g2, mockNumberStream); }
public void crossingShouldProduceTwoChildren() { Genotype<int> g1 = new Genotype<int> (12, 342, 34, 65); Genotype<int> g2 = new Genotype<int> (234, 9, 89734, 456); mockNumberStream.PushInt (0); IList<Genotype<int>> children = singlePointCrossover.Cross (g1, g2, mockNumberStream); Assert.AreEqual (2, children.Count); }
// Calculate the path length of hte current genotype. public static double dist(Genotype gt) { // Convert the genotype to the traveling path int[] path = gt.getChromosome().toSeq().stream() .mapToInt(new ToIntFunctionImpl()) .toArray(); // Calculate the path distance. var dist = IntStream.__Methods.range(0, STOPS) .mapToDouble(new IntToDoubleFunctionImpl(path)) .sum(); return dist; }
public override int getValue(Genotype g) { return Math.Min(g.GQ, VCFConstants.MAX_GENOTYPE_QUAL); }
public abstract int getValue(Genotype g);
public override int[] getValues(Genotype g) { singleton[0] = getValue(g); return singleton[0] == -1 ? null : singleton; }
/// <summary> /// Create a new builder starting with the values in Genotype g </summary> /// <param name="g"> </param> public GenotypeBuilder(Genotype g):this() { copy(g); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Requires({"encodingType != null", "nValuesPerGenotype >= 0"}) public void addGenotype(final BCF2Encoder encoder, final org.broadinstitute.variant.variantcontext.VariantContext vc, final org.broadinstitute.variant.variantcontext.Genotype g) throws java.io.IOException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //JAVA TO C# CONVERTER WARNING: 'final' parameters are not allowed in .NET: public virtual void addGenotype(BCF2Encoder encoder, VariantContext vc, Genotype g) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final Object fieldValue = g.getExtendedAttribute(getField(), null); object fieldValue = g.getExtendedAttribute(Field, null); FieldEncoder.encodeValue(encoder, fieldValue, encodingType, nValuesPerGenotype); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Ensures({"result >= 0"}) protected int numElements(final org.broadinstitute.variant.variantcontext.VariantContext vc, final org.broadinstitute.variant.variantcontext.Genotype g) //JAVA TO C# CONVERTER WARNING: 'final' parameters are not allowed in .NET: protected internal virtual int numElements(VariantContext vc, Genotype g) { return FieldEncoder.numElements(vc, g.getExtendedAttribute(Field)); }
//JAVA TO C# CONVERTER WARNING: 'final' parameters are not allowed in .NET: //ORIGINAL LINE: protected int numElements(final org.broadinstitute.variant.variantcontext.VariantContext vc, final org.broadinstitute.variant.variantcontext.Genotype g) protected internal override int numElements(VariantContext vc, Genotype g) { return ige.getSize(g); }
//JAVA TO C# CONVERTER WARNING: 'final' parameters are not allowed in .NET: //ORIGINAL LINE: protected int numElements(final org.broadinstitute.variant.variantcontext.VariantContext vc, final org.broadinstitute.variant.variantcontext.Genotype g) protected internal override int numElements(VariantContext vc, Genotype g) { return FieldEncoder.numElements(vc, g.Filters); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void addGenotype(final BCF2Encoder encoder, final org.broadinstitute.variant.variantcontext.VariantContext vc, final org.broadinstitute.variant.variantcontext.Genotype g) throws java.io.IOException //JAVA TO C# CONVERTER WARNING: 'final' parameters are not allowed in .NET: public override void addGenotype(BCF2Encoder encoder, VariantContext vc, Genotype g) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int samplePloidy = g.getPloidy(); int samplePloidy = g.Ploidy; for (int i = 0; i < nValuesPerGenotype; i++) { if (i < samplePloidy) { // we encode the actual allele //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.broadinstitute.variant.variantcontext.Allele a = g.getAllele(i); Allele a = g.getAllele(i); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int offset = getAlleleOffset(a); int offset = getAlleleOffset(a); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int encoded = ((offset+1) << 1) | (g.isPhased() ? 0x01 : 0x00); int encoded = ((offset + 1) << 1) | (g.Phased ? 0x01 : 0x00); encoder.encodeRawBytes(encoded, encodingType); } else { // we need to pad with missing as we have ploidy < max for this sample encoder.encodeRawBytes(encodingType.MissingBytes, encodingType); } } }
public void Mutate(Genotype genotype, MutationResults results) { }
public void Add(Genotype genotype) { Genotypes.Add(genotype); }
public double getLog10GQ(Genotype genotype, IList<Allele> vcAlleles) { return getLog10GQ(genotype.Alleles,vcAlleles); }
public double getLog10GQ(Genotype genotype, VariantContext context) { return getLog10GQ(genotype,context.Alleles); }
public override int getValue(Genotype g) { return g.DP; }
/// <summary> /// Calculates the fitness for a given genotype. /// </summary> /// <param name="gt">Genotype of BitGene type in Java example</param> /// <returns></returns> private static Integer count(Genotype gt) { return new Integer(((BitChromosome)(gt.getChromosome())).bitCount()); }
public override int[] getValues(Genotype g) { return g.PL; }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void addGenotype(final BCF2Encoder encoder, final org.broadinstitute.variant.variantcontext.VariantContext vc, final org.broadinstitute.variant.variantcontext.Genotype g) throws java.io.IOException //JAVA TO C# CONVERTER WARNING: 'final' parameters are not allowed in .NET: public override void addGenotype(BCF2Encoder encoder, VariantContext vc, Genotype g) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final String fieldValue = g.getFilters(); string fieldValue = g.Filters; FieldEncoder.encodeValue(encoder, fieldValue, encodingType, nValuesPerGenotype); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void addGenotype(final BCF2Encoder encoder, final org.broadinstitute.variant.variantcontext.VariantContext vc, final org.broadinstitute.variant.variantcontext.Genotype g) throws java.io.IOException //JAVA TO C# CONVERTER WARNING: 'final' parameters are not allowed in .NET: public override void addGenotype(BCF2Encoder encoder, VariantContext vc, Genotype g) { FieldEncoder.encodeValue(encoder, ige.getValues(g), encodingType, nValuesPerGenotype); }
public abstract int[] getValues(Genotype g);
private void redrawAlleleAndGenotypeControls(int numDominant, int numRecessive) { StringBuilder sb; // Build a string out of the dominant allele symbols and display it sb = new StringBuilder($"{{ {_dominantAlleles[0].Symbol}"); for (int a = 1; a < numDominant; ++a) sb.Append($", {_dominantAlleles[a].Symbol}"); sb.Append(" }"); DominantSetLbl.Text = sb.ToString(); // Build a string out of the recessive allele symbols and display it sb = new StringBuilder($"{{ {_recessiveAlleles[0].Symbol}"); for (int a = 1; a < numRecessive; ++a) sb.Append($", {_recessiveAlleles[a].Symbol}"); sb.Append(" }"); RecessiveSetLbl.Text = sb.ToString(); // Clear old count controls HeteroGrpbox.Controls.Clear(); HomoGrpbox.Controls.Clear(); AlleleCheckPanel.Controls.Clear(); OutputChart.Series.Clear(); OutputDgv.Columns.Clear(); // Get all possible Alleles and associate them with Controls int numAlleles = numDominant + numRecessive; Allele[] everyAllele = _dominantAlleles.Take(numDominant).Union(_recessiveAlleles.Take(numRecessive)).ToArray(); ChartArea _alleleArea = OutputChart.ChartAreas[0]; _series = new Dictionary<Allele, Series>(numAlleles); _dgvColumns = new Dictionary<Allele, DataGridViewColumn>(numAlleles); OutputDgv.Columns.Add(GenerationCol); for (int a = 0; a < numAlleles; ++a) { Allele allele = everyAllele[a]; // Chart series Series s = new Series(allele.Symbol) { ChartArea = _alleleArea.Name, ChartType = SeriesChartType.Line, //MarkerStyle = MARKER_STYLES[a], }; _series.Add(allele, s); OutputChart.Series.Add(s); // DataGridViewColumns DataGridViewColumn col = new DataGridViewTextBoxColumn() { Name = $"AlleleFreqCol{a}", HeaderText = allele.Symbol, ReadOnly = true, SortMode = DataGridViewColumnSortMode.NotSortable, }; _dgvColumns.Add(everyAllele[a], col); OutputDgv.Columns.Add(col); // Checkboxes AlleleCheckPrefab prefab = new AlleleCheckPrefab(allele, _series[allele], _dgvColumns[allele], a); prefab.AddToContainer(AlleleCheckPanel); } // Define all possible Genotypes and give them a default initial count in the population _homoCounts = new GenotypeCount[numAlleles]; _heteroCounts = new GenotypeCount[numAlleles, numAlleles]; for (int ca = 0; ca < numAlleles; ++ca) { // ca = col allele // Homozygotes Genotype homoGenotype = new Genotype(everyAllele[ca]); GenotypeCount h**o = new GenotypeCount() { Genotype = homoGenotype, Count = DEFAULT_COUNT }; _homoCounts[ca] = h**o; GenotypeCountPrefab homoPrefab = new GenotypeCountPrefab(h**o, ca, 0); homoPrefab.AddToContainer(HomoGrpbox); // Heterozygotes for (int ra = ca + 1; ra < numAlleles; ++ra) { // ra = row allele Genotype heteroGenotype = new Genotype(everyAllele[ca], everyAllele[ra]); GenotypeCount hetero = new GenotypeCount() { Genotype = heteroGenotype, Count = DEFAULT_COUNT }; _heteroCounts[ra, ca] = hetero; GenotypeCountPrefab heteroPrefab = new GenotypeCountPrefab(hetero, ra, ca); heteroPrefab.AddToContainer(HeteroGrpbox); } } }
public int getSize(Genotype g) { int[] v = getValues(g); return v == null ? 0 : v.Length; }
private Genotype fullyDecodeGenotypes (Genotype g, VCFHeader header) { IDictionary<string, object> map = fullyDecodeAttributes (g.ExtendedAttributes, header, true); var g2 = new GenotypeBuilder (g); g2.AddAttributes (map); return g2.Make (); }
/// <summary> /// Copy all of the values for this builder from Genotype g /// </summary> /// <param name="g"></param> /// <returns></returns> /// TODO: Why have a copy on a builder? Either implement ICloneable or remove this old method. public GenotypeBuilder copy(Genotype g) { SampleName=g.SampleName; Alleles=g.Alleles.ToList(); Phased=g.Phased; GQ=g.GQ; DP=g.DP; AD=g.AD; PL=g.PL; Filter=g.Filters; AddAttributes(g.ExtendedAttributes); return this; }