Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/12/12 16:18:04 (12 years ago)
Author:
swagner
Message:

Worked on AlleleFrequencyAnalyzer (#1893)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Analysis/3.3/AlleleFrequencyAnalysis/AlleleFrequencyAnalyzer.cs

    r8283 r8289  
    170170        }
    171171
    172         // calculate scatter plot of contained relevant alleles and relative quality
    173         double avgContainedReleventAlleles = 0;
     172        // store allele frequencies
     173        AlleleFrequencyCollection frequenciesCollection = new AlleleFrequencyCollection(frequencies);
     174        if (!results.ContainsKey("Allele Frequencies"))
     175          results.Add(new Result("Allele Frequencies", frequenciesCollection));
     176        else
     177          results["Allele Frequencies"].Value = frequenciesCollection;
     178
     179        // store allele frequencies history
     180        if (storeHistory) {
     181          if (!results.ContainsKey("Allele Frequencies History")) {
     182            AlleleFrequencyCollectionHistory history = new AlleleFrequencyCollectionHistory();
     183            history.Add(frequenciesCollection);
     184            results.Add(new Result("Allele Frequencies History", history));
     185          } else {
     186            ((AlleleFrequencyCollectionHistory)results["Allele Frequencies History"].Value).Add(frequenciesCollection);
     187          }
     188        }
     189
     190        // store alleles data table
     191        DataTable allelesTable;
     192        if (!results.ContainsKey("Alleles")) {
     193          allelesTable = new DataTable("Alleles");
     194          allelesTable.VisualProperties.XAxisTitle = "Iteration";
     195          allelesTable.VisualProperties.YAxisTitle = "Number of Alleles";
     196          allelesTable.VisualProperties.SecondYAxisTitle = "Number of Alleles";
     197
     198          allelesTable.Rows.Add(new DataRow("Unique Alleles"));
     199          allelesTable.Rows["Unique Alleles"].VisualProperties.StartIndexZero = true;
     200
     201          allelesTable.Rows.Add(new DataRow("Unique Alleles of Best Known Solution", null));
     202          allelesTable.Rows["Unique Alleles of Best Known Solution"].VisualProperties.SecondYAxis = true;
     203          allelesTable.Rows["Unique Alleles of Best Known Solution"].VisualProperties.StartIndexZero = true;
     204
     205          allelesTable.Rows.Add(new DataRow("Fixed Alleles", null));
     206          allelesTable.Rows["Fixed Alleles"].VisualProperties.SecondYAxis = true;
     207          allelesTable.Rows["Fixed Alleles"].VisualProperties.StartIndexZero = true;
     208
     209          allelesTable.Rows.Add(new DataRow("Fixed Alleles of Best Known Solution", null));
     210          allelesTable.Rows["Fixed Alleles of Best Known Solution"].VisualProperties.SecondYAxis = true;
     211          allelesTable.Rows["Fixed Alleles of Best Known Solution"].VisualProperties.StartIndexZero = true;
     212
     213          allelesTable.Rows.Add(new DataRow("Lost Alleles of Best Known Solution", null));
     214          allelesTable.Rows["Lost Alleles of Best Known Solution"].VisualProperties.SecondYAxis = true;
     215          allelesTable.Rows["Lost Alleles of Best Known Solution"].VisualProperties.StartIndexZero = true;
     216
     217          results.Add(new Result("Alleles", allelesTable));
     218        } else {
     219          allelesTable = (DataTable)results["Alleles"].Value;
     220        }
     221
     222        int fixedAllelesCount = frequenciesCollection.Where(x => x.Frequency == 1).Count();
     223        var relevantAlleles = frequenciesCollection.Where(x => x.ContainedInBestKnownSolution);
     224        int relevantAllelesCount = relevantAlleles.Count();
     225        int fixedRelevantAllelesCount = relevantAlleles.Where(x => x.Frequency == 1).Count();
     226        int lostRelevantAllelesCount = relevantAlleles.Where(x => x.Frequency == 0).Count();
     227        int uniqueRelevantAllelesCount = relevantAllelesCount - lostRelevantAllelesCount;
     228        allelesTable.Rows["Unique Alleles"].Values.Add(frequenciesCollection.Count);
     229        allelesTable.Rows["Unique Alleles of Best Known Solution"].Values.Add(uniqueRelevantAllelesCount);
     230        allelesTable.Rows["Fixed Alleles"].Values.Add(fixedAllelesCount);
     231        allelesTable.Rows["Fixed Alleles of Best Known Solution"].Values.Add(fixedRelevantAllelesCount);
     232        allelesTable.Rows["Lost Alleles of Best Known Solution"].Values.Add(lostRelevantAllelesCount);
     233
     234        // store alleles values
     235        if (!results.ContainsKey("Unique Alleles"))
     236          results.Add(new Result("Unique Alleles", new DoubleValue(frequenciesCollection.Count)));
     237        else
     238          ((DoubleValue)results["Unique Alleles"].Value).Value = frequenciesCollection.Count;
     239
     240        if (!results.ContainsKey("Unique Alleles of Best Known Solution"))
     241          results.Add(new Result("Unique Alleles of Best Known Solution", new DoubleValue(uniqueRelevantAllelesCount)));
     242        else
     243          ((DoubleValue)results["Unique Alleles of Best Known Solution"].Value).Value = uniqueRelevantAllelesCount;
     244
     245        if (!results.ContainsKey("Fixed Alleles"))
     246          results.Add(new Result("Fixed Alleles", new DoubleValue(fixedAllelesCount)));
     247        else
     248          ((DoubleValue)results["Fixed Alleles"].Value).Value = fixedAllelesCount;
     249
     250        if (!results.ContainsKey("Fixed Alleles of Best Known Solution"))
     251          results.Add(new Result("Fixed Alleles of Best Known Solution", new DoubleValue(fixedRelevantAllelesCount)));
     252        else
     253          ((DoubleValue)results["Fixed Alleles of Best Known Solution"].Value).Value = fixedRelevantAllelesCount;
     254
     255        if (!results.ContainsKey("Lost Alleles of Best Known Solution"))
     256          results.Add(new Result("Lost Alleles of Best Known Solution", new DoubleValue(lostRelevantAllelesCount)));
     257        else
     258          ((DoubleValue)results["Lost Alleles of Best Known Solution"].Value).Value = lostRelevantAllelesCount;
     259
     260        // calculate contained alleles of best known solution and relative quality
    174261        if (bestKnownAlleles != null) {
    175262          double qualityRange = Math.Abs(qualities.Max() - qualities.Min());
    176263          var points = solutions.Select((s, index) => new Point2D<double>(CalculateAlleles(s).Intersect(bestKnownAlleles, new AlleleIdEqualityComparer()).Count(),
    177264                                                                          Math.Abs(qualities[index] - qualities[bestIndex]) / qualityRange));
    178           avgContainedReleventAlleles = points.Select(x => x.X).Average();
     265          var avgContainedReleventAlleles = points.Select(x => x.X).Average();
     266
    179267          var plot = new ScatterPlot("Contained Alleles of Best Known Solution and Relative Solution Qualtiy", null);
    180268          plot.VisualProperties.XAxisTitle = "Contained Alleles of Best Known Solution";
     
    203291            ((ScatterPlotHistory)results["Scatter Plot History"].Value).Add(plot);
    204292          }
    205         }
    206 
    207         // store allele frequencies
    208         AlleleFrequencyCollection frequenciesCollection = new AlleleFrequencyCollection(frequencies);
    209         if (!results.ContainsKey("Allele Frequencies"))
    210           results.Add(new Result("Allele Frequencies", frequenciesCollection));
    211         else
    212           results["Allele Frequencies"].Value = frequenciesCollection;
    213 
    214         // store allele frequencies history
    215         if (storeHistory) {
    216           if (!results.ContainsKey("Allele Frequencies History")) {
    217             AlleleFrequencyCollectionHistory history = new AlleleFrequencyCollectionHistory();
    218             history.Add(frequenciesCollection);
    219             results.Add(new Result("Allele Frequencies History", history));
    220           } else {
    221             ((AlleleFrequencyCollectionHistory)results["Allele Frequencies History"].Value).Add(frequenciesCollection);
     293
     294          if (!allelesTable.Rows.ContainsKey("Average Contained Alleles of Best Known Solution")) {
     295            allelesTable.Rows.Add(new DataRow("Average Contained Alleles of Best Known Solution", null));
     296            allelesTable.Rows["Average Contained Alleles of Best Known Solution"].VisualProperties.SecondYAxis = true;
     297            allelesTable.Rows["Average Contained Alleles of Best Known Solution"].VisualProperties.StartIndexZero = true;
    222298          }
    223         }
    224 
    225         // store alleles data table
    226         DataTable allelesTable;
    227         if (!results.ContainsKey("Alleles")) {
    228           allelesTable = new DataTable("Alleles");
    229           allelesTable.VisualProperties.XAxisTitle = "Iteration";
    230           allelesTable.VisualProperties.YAxisTitle = "Number of Alleles";
    231           allelesTable.VisualProperties.SecondYAxisTitle = "Number of Alleles";
    232 
    233           allelesTable.Rows.Add(new DataRow("Unique Alleles"));
    234           allelesTable.Rows["Unique Alleles"].VisualProperties.StartIndexZero = true;
    235 
    236           allelesTable.Rows.Add(new DataRow("Unique Alleles of Best Known Solution", null));
    237           allelesTable.Rows["Unique Alleles of Best Known Solution"].VisualProperties.SecondYAxis = true;
    238           allelesTable.Rows["Unique Alleles of Best Known Solution"].VisualProperties.StartIndexZero = true;
    239 
    240           allelesTable.Rows.Add(new DataRow("Fixed Alleles", null));
    241           allelesTable.Rows["Fixed Alleles"].VisualProperties.SecondYAxis = true;
    242           allelesTable.Rows["Fixed Alleles"].VisualProperties.StartIndexZero = true;
    243 
    244           allelesTable.Rows.Add(new DataRow("Fixed Alleles of Best Known Solution", null));
    245           allelesTable.Rows["Fixed Alleles of Best Known Solution"].VisualProperties.SecondYAxis = true;
    246           allelesTable.Rows["Fixed Alleles of Best Known Solution"].VisualProperties.StartIndexZero = true;
    247 
    248           allelesTable.Rows.Add(new DataRow("Lost Alleles of Best Known Solution", null));
    249           allelesTable.Rows["Lost Alleles of Best Known Solution"].VisualProperties.SecondYAxis = true;
    250           allelesTable.Rows["Lost Alleles of Best Known Solution"].VisualProperties.StartIndexZero = true;
    251 
    252           allelesTable.Rows.Add(new DataRow("Average Contained Alleles of Best Known Solution", null));
    253           allelesTable.Rows["Average Contained Alleles of Best Known Solution"].VisualProperties.SecondYAxis = true;
    254           allelesTable.Rows["Average Contained Alleles of Best Known Solution"].VisualProperties.StartIndexZero = true;
    255 
    256           results.Add(new Result("Alleles", allelesTable));
    257         } else {
    258           allelesTable = (DataTable)results["Alleles"].Value;
    259         }
    260 
    261         int fixedAllelesCount = frequenciesCollection.Where(x => x.Frequency == 1).Count();
    262         var relevantAlleles = frequenciesCollection.Where(x => x.ContainedInBestKnownSolution);
    263         int relevantAllelesCount = relevantAlleles.Count();
    264         int fixedRelevantAllelesCount = relevantAlleles.Where(x => x.Frequency == 1).Count();
    265         int lostRelevantAllelesCount = relevantAlleles.Where(x => x.Frequency == 0).Count();
    266         int uniqueRelevantAllelesCount = relevantAllelesCount - lostRelevantAllelesCount;
    267         allelesTable.Rows["Unique Alleles"].Values.Add(frequenciesCollection.Count);
    268         allelesTable.Rows["Unique Alleles of Best Known Solution"].Values.Add(uniqueRelevantAllelesCount);
    269         allelesTable.Rows["Fixed Alleles"].Values.Add(fixedAllelesCount);
    270         allelesTable.Rows["Fixed Alleles of Best Known Solution"].Values.Add(fixedRelevantAllelesCount);
    271         allelesTable.Rows["Lost Alleles of Best Known Solution"].Values.Add(lostRelevantAllelesCount);
    272         allelesTable.Rows["Average Contained Alleles of Best Known Solution"].Values.Add(avgContainedReleventAlleles);
    273 
    274         // store alleles values
    275         if (!results.ContainsKey("Unique Alleles"))
    276           results.Add(new Result("Unique Alleles", new DoubleValue(frequenciesCollection.Count)));
    277         else
    278           ((DoubleValue)results["Unique Alleles"].Value).Value = frequenciesCollection.Count;
    279 
    280         if (!results.ContainsKey("Unique Alleles of Best Known Solution"))
    281           results.Add(new Result("Unique Alleles of Best Known Solution", new DoubleValue(uniqueRelevantAllelesCount)));
    282         else
    283           ((DoubleValue)results["Unique Alleles of Best Known Solution"].Value).Value = uniqueRelevantAllelesCount;
    284 
    285         if (!results.ContainsKey("Fixed Alleles"))
    286           results.Add(new Result("Fixed Alleles", new DoubleValue(fixedAllelesCount)));
    287         else
    288           ((DoubleValue)results["Fixed Alleles"].Value).Value = fixedAllelesCount;
    289 
    290         if (!results.ContainsKey("Fixed Alleles of Best Known Solution"))
    291           results.Add(new Result("Fixed Alleles of Best Known Solution", new DoubleValue(fixedRelevantAllelesCount)));
    292         else
    293           ((DoubleValue)results["Fixed Alleles of Best Known Solution"].Value).Value = fixedRelevantAllelesCount;
    294 
    295         if (!results.ContainsKey("Lost Alleles of Best Known Solution"))
    296           results.Add(new Result("Lost Alleles of Best Known Solution", new DoubleValue(lostRelevantAllelesCount)));
    297         else
    298           ((DoubleValue)results["Lost Alleles of Best Known Solution"].Value).Value = lostRelevantAllelesCount;
     299          allelesTable.Rows["Average Contained Alleles of Best Known Solution"].Values.Add(avgContainedReleventAlleles);
     300
     301          if (!results.ContainsKey("Average Contained Alleles of Best Known Solution"))
     302            results.Add(new Result("Average Contained Alleles of Best Known Solution", new DoubleValue(avgContainedReleventAlleles)));
     303          else
     304            ((DoubleValue)results["Average Contained Alleles of Best Known Solution"].Value).Value = avgContainedReleventAlleles;
     305        }
    299306      }
    300307      return base.Apply();
Note: See TracChangeset for help on using the changeset viewer.