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); } } }
// CONSTRUCTORS public GenotypeCountPrefab(GenotypeCount data, int row, int col) { _dataBS = new BindingSource(data, null); build(row, col); }