Free cookie consent management tool by TermsFeed Policy Generator

Changeset 4639


Ignore:
Timestamp:
10/22/10 03:17:02 (14 years ago)
Author:
swagner
Message:

Worked on allele frequency analysis (#1234)

Location:
trunk/sources
Files:
1 added
3 edited
3 moved

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Analysis.Views/3.3/AlleleFrequencyCollectionView.Designer.cs

    r4638 r4639  
    2121
    2222namespace HeuristicLab.Analysis.Views {
    23   partial class AlleleFrequencyArrayView {
     23  partial class AlleleFrequencyCollectionView {
    2424    /// <summary>
    2525    /// Required designer variable.
     
    6161      chartArea1.AxisX.IntervalAutoMode = System.Windows.Forms.DataVisualization.Charting.IntervalAutoMode.VariableCount;
    6262      chartArea1.AxisX.LabelAutoFitStyle = ((System.Windows.Forms.DataVisualization.Charting.LabelAutoFitStyles)((System.Windows.Forms.DataVisualization.Charting.LabelAutoFitStyles.IncreaseFont | System.Windows.Forms.DataVisualization.Charting.LabelAutoFitStyles.DecreaseFont)));
    63       chartArea1.AxisX.LabelStyle.Angle = 90;
    6463      chartArea1.AxisX.Title = "Alleles";
    6564      chartArea1.AxisY.Maximum = 1D;
    6665      chartArea1.AxisY.Minimum = 0D;
    6766      chartArea1.AxisY.Title = "Relative Frequency";
    68       chartArea1.AxisY2.Title = "Average Solution Quality";
     67      chartArea1.AxisY2.Title = "Average Solution Quality / Average Impact";
    6968      chartArea1.CursorX.IsUserEnabled = true;
    7069      chartArea1.CursorX.IsUserSelectionEnabled = true;
     
    9089      this.chart.MouseMove += new System.Windows.Forms.MouseEventHandler(this.chart_MouseMove);
    9190      //
    92       // AlleleFrequencyArrayView
     91      // AlleleFrequencyCollectionView
    9392      //
    9493      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    9594      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    9695      this.Controls.Add(this.chart);
    97       this.Name = "AlleleFrequencyArrayView";
     96      this.Name = "AlleleFrequencyCollectionView";
    9897      this.Size = new System.Drawing.Size(498, 359);
    9998      ((System.ComponentModel.ISupportInitialize)(this.chart)).EndInit();
  • trunk/sources/HeuristicLab.Analysis.Views/3.3/AlleleFrequencyCollectionView.cs

    r4638 r4639  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324using System.Drawing;
     
    2930
    3031namespace HeuristicLab.Analysis.Views {
    31   [View("AlleleFrequencyArray View")]
    32   [Content(typeof(AlleleFrequencyArray), true)]
    33   public partial class AlleleFrequencyArrayView : ItemView {
     32  [View("AlleleFrequencyCollection View")]
     33  [Content(typeof(AlleleFrequencyCollection), true)]
     34  public partial class AlleleFrequencyCollectionView : ItemView {
    3435    private List<Series> invisibleSeries;
    3536
    36     public new AlleleFrequencyArray Content {
    37       get { return (AlleleFrequencyArray)base.Content; }
     37    public new AlleleFrequencyCollection Content {
     38      get { return (AlleleFrequencyCollection)base.Content; }
    3839      set { base.Content = value; }
    3940    }
    4041
    41     public AlleleFrequencyArrayView() {
     42    public AlleleFrequencyCollectionView() {
    4243      InitializeComponent();
    4344      invisibleSeries = new List<Series>();
     
    4950      if (Content == null) {
    5051        chart.Series.Clear();
    51         chart.DataSource = null;
    5252        invisibleSeries.Clear();
    5353      } else {
    5454        if (chart.Series.Count == 0) CreateSeries();
    55         chart.DataSource = Content.Select(x => new {
    56           Id = x.Id,
    57           BestKnownFrequency = x.ContainedInBestKnownSolution ? x.Frequency : 0,
    58           Frequency = !x.ContainedInBestKnownSolution ? x.Frequency : 0,
    59           Quality = x.AverageSolutionQuality,
    60           Impact = x.AverageImpact
    61         }).OrderBy(x => x.Impact).ToArray();
    6255        UpdateSeries();
    6356      }
     
    7164    protected virtual void CreateSeries() {
    7265      Series bestKnown = new Series("Alleles of Best Known Solution");
    73       bestKnown.ChartType = SeriesChartType.StackedColumn;
    74       bestKnown.XValueMember = "Id";
     66      bestKnown.ChartType = SeriesChartType.Column;
    7567      bestKnown.XValueType = ChartValueType.String;
    76       bestKnown.YValueMembers = "BestKnownFrequency";
    7768      bestKnown.YValueType = ChartValueType.Double;
    7869      bestKnown.YAxisType = AxisType.Primary;
    79       bestKnown.ToolTip = "X = #LABEL, Y = #VAL";
    8070      chart.Series.Add(bestKnown);
    8171
    8272      Series others = new Series("Other Alleles");
    83       others.ChartType = SeriesChartType.StackedColumn;
    84       others.XValueMember = "Id";
     73      others.ChartType = SeriesChartType.Column;
    8574      others.XValueType = ChartValueType.String;
    86       others.YValueMembers = "Frequency";
    8775      others.YValueType = ChartValueType.Double;
    8876      others.YAxisType = AxisType.Primary;
    89       others.ToolTip = "X = #LABEL, Y = #VAL";
    9077      chart.Series.Add(others);
     78      invisibleSeries.Add(others);
    9179
    9280      Series qualities = new Series("Average Solution Qualities");
    93       qualities.ChartType = SeriesChartType.FastLine;
    94       qualities.XValueMember = "Id";
     81      qualities.ChartType = SeriesChartType.FastPoint;
    9582      qualities.XValueType = ChartValueType.String;
    96       qualities.YValueMembers = "Quality";
    9783      qualities.YValueType = ChartValueType.Double;
    9884      qualities.YAxisType = AxisType.Secondary;
    99       qualities.ToolTip = "X = #LABEL, Y = #VAL";
     85      qualities.ToolTip = "#VAL";
    10086      chart.Series.Add(qualities);
    10187
    10288      Series impacts = new Series("Average Impact");
    103       impacts.ChartType = SeriesChartType.FastLine;
    104       impacts.XValueMember = "Id";
     89      impacts.ChartType = SeriesChartType.FastPoint;
    10590      impacts.XValueType = ChartValueType.String;
    106       impacts.YValueMembers = "Impact";
    10791      impacts.YValueType = ChartValueType.Double;
    10892      impacts.YAxisType = AxisType.Secondary;
    109       impacts.ToolTip = "X = #LABEL, Y = #VAL";
     93      impacts.ToolTip = "#VAL";
    11094      chart.Series.Add(impacts);
    11195    }
    11296
    11397    protected virtual void UpdateSeries() {
    114       chart.DataBind();
     98      int index = 1;
     99      Series bestKnown = chart.Series["Alleles of Best Known Solution"];
     100      Series others = chart.Series["Other Alleles"];
     101      Series qualities = chart.Series["Average Solution Qualities"];
     102      Series impacts = chart.Series["Average Impact"];
     103      bestKnown.Points.Clear();
     104      others.Points.Clear();
     105      qualities.Points.Clear();
     106      impacts.Points.Clear();
    115107
    116       if (invisibleSeries.Contains(chart.Series["Alleles of Best Known Solution"]))
    117         chart.Series["Alleles of Best Known Solution"].Points.Clear();
    118       chart.DataManipulator.Filter(CompareMethod.EqualTo, 0, chart.Series["Alleles of Best Known Solution"]);
     108      if (!invisibleSeries.Contains(bestKnown)) {
     109        foreach (AlleleFrequency af in Content.Where(x => x.ContainedInBestKnownSolution).OrderBy(x => x.AverageImpact)) {
     110          bestKnown.Points.Add(CreateFrequencyDataPoint(index, af));
     111          if (!invisibleSeries.Contains(qualities)) qualities.Points.AddXY(index, af.AverageSolutionQuality);
     112          if (!invisibleSeries.Contains(impacts)) impacts.Points.AddXY(index, af.AverageImpact);
     113          index++;
     114        }
     115      }
     116      if (!invisibleSeries.Contains(others)) {
     117        foreach (AlleleFrequency af in Content.Where(x => !x.ContainedInBestKnownSolution).OrderBy(x => x.AverageImpact)) {
     118          others.Points.Add(CreateFrequencyDataPoint(index, af));
     119          if (!invisibleSeries.Contains(qualities)) qualities.Points.AddXY(index, af.AverageSolutionQuality);
     120          if (!invisibleSeries.Contains(impacts)) impacts.Points.AddXY(index, af.AverageImpact);
     121          index++;
     122        }
     123      }
     124    }
    119125
    120       if (invisibleSeries.Contains(chart.Series["Other Alleles"]))
    121         chart.Series["Other Alleles"].Points.Clear();
    122       chart.DataManipulator.Filter(CompareMethod.EqualTo, 0, chart.Series["Other Alleles"]);
     126    protected virtual DataPoint CreateFrequencyDataPoint(int index, AlleleFrequency af) {
     127      string nl = Environment.NewLine;
    123128
    124       if (invisibleSeries.Contains(chart.Series["Average Solution Qualities"]))
    125         chart.Series["Average Solution Qualities"].Points.Clear();
    126       chart.DataManipulator.Filter(CompareMethod.EqualTo, 0, chart.Series["Average Solution Qualities"]);
    127 
    128       if (invisibleSeries.Contains(chart.Series["Average Impact"]))
    129         chart.Series["Average Impact"].Points.Clear();
    130       chart.DataManipulator.Filter(CompareMethod.EqualTo, 0, chart.Series["Average Impact"]);
     129      DataPoint p = new DataPoint(index, af.Frequency);
     130      p.AxisLabel = af.Id;
     131      p.ToolTip = string.Format("Id: {0}" + nl +
     132                                "Relative Frequency: {1}" + nl +
     133                                "Average Solution Quality: {2}" + nl +
     134                                "Average Impact: {3}" + nl +
     135                                "Contained in Best Known Solution: {4}" + nl +
     136                                "Contained in Best Solution: {5}",
     137                                af.Id, af.Frequency, af.AverageSolutionQuality, af.AverageImpact, af.ContainedInBestKnownSolution, af.ContainedInBestSolution);
     138      return p;
    131139    }
    132140
  • trunk/sources/HeuristicLab.Analysis.Views/3.3/HeuristicLab.Analysis.Views-3.3.csproj

    r4631 r4639  
    117117  <ItemGroup>
    118118    <None Include="HeuristicLabAnalysisViewsPlugin.cs.frame" />
    119     <Compile Include="AlleleFrequencyArrayView.cs">
    120       <SubType>UserControl</SubType>
    121     </Compile>
    122     <Compile Include="AlleleFrequencyArrayView.Designer.cs">
    123       <DependentUpon>AlleleFrequencyArrayView.cs</DependentUpon>
     119    <Compile Include="AlleleFrequencyCollectionView.cs" />
     120    <Compile Include="AlleleFrequencyCollectionView.Designer.cs">
     121      <DependentUpon>AlleleFrequencyCollectionView.cs</DependentUpon>
    124122    </Compile>
    125123    <Compile Include="HeuristicLabAnalysisViewsPlugin.cs" />
  • trunk/sources/HeuristicLab.Analysis/3.3/AlleleFrequencyAnalyzer.cs

    r4631 r4639  
    2020#endregion
    2121
     22using System.Collections.Generic;
    2223using System.Linq;
    2324using HeuristicLab.Core;
     
    7273    }
    7374
     75    private class AlleleFrequencyEqualityComparer : IEqualityComparer<AlleleFrequency> {
     76      public bool Equals(AlleleFrequency x, AlleleFrequency y) {
     77        return x.Id == y.Id;
     78      }
     79      public int GetHashCode(AlleleFrequency obj) {
     80        return obj.GetHashCode();
     81      }
     82    }
     83
    7484    public override IOperation Apply() {
    7585      int updateInterval = UpdateIntervalParameter.Value.Value;
     
    110120                                                          bestAlleles.Any(a => a.Id == x.Key)));
    111121
     122        // calculate dummy allele frequencies of alleles of best known solution which did not occur
     123        var bestKnownFrequencies = bestKnownAlleles.Select(x => new AlleleFrequency(x.Id, 0, x.Impact, 0, true, false)).Except(frequencies, new AlleleFrequencyEqualityComparer());
     124
    112125        // fetch results collection
    113126        ResultCollection results;
     
    120133
    121134        // store allele frequencies
    122         AlleleFrequencyArray frequenciesArray = new AlleleFrequencyArray(frequencies);
     135        AlleleFrequencyCollection frequenciesCollection = new AlleleFrequencyCollection(bestKnownFrequencies.Concat(frequencies));
    123136        if (!results.ContainsKey("Allele Frequencies"))
    124           results.Add(new Result("Allele Frequencies", frequenciesArray));
     137          results.Add(new Result("Allele Frequencies", frequenciesCollection));
    125138        else
    126           results["Allele Frequencies"].Value = frequenciesArray;
     139          results["Allele Frequencies"].Value = frequenciesCollection;
    127140
    128141        // store allele frequencies history
    129142        if (storeHistory) {
    130143          if (!results.ContainsKey("Allele Frequencies History")) {
    131             ItemCollection<AlleleFrequencyArray> history = new ItemCollection<AlleleFrequencyArray>();
    132             history.Add(frequenciesArray);
     144            AlleleFrequencyCollectionCollection history = new AlleleFrequencyCollectionCollection();
     145            history.Add(frequenciesCollection);
    133146            results.Add(new Result("Allele Frequencies History", history));
    134147          } else {
    135             ((ItemCollection<AlleleFrequencyArray>)results["Allele Frequencies History"].Value).Add(frequenciesArray);
     148            ((AlleleFrequencyCollectionCollection)results["Allele Frequencies History"].Value).Add(frequenciesCollection);
    136149          }
    137150        }
     
    146159          allelesTable = (DataTable)results["Alleles"].Value;
    147160        }
    148         allelesTable.Rows["Unique Alleles"].Values.Add(frequenciesArray.Length);
     161        allelesTable.Rows["Unique Alleles"].Values.Add(frequenciesCollection.Count);
    149162      }
    150163      return base.Apply();
  • trunk/sources/HeuristicLab.Analysis/3.3/AlleleFrequencyCollection.cs

    r4638 r4639  
    2626namespace HeuristicLab.Analysis {
    2727  /// <summary>
    28   /// Represents an array of allele frequencies.
     28  /// Represents a collection of allele frequencies.
    2929  /// </summary>
    30   [Item("AlleleFrequencyArray", "Represents an array of allele frequencies.")]
     30  [Item("AlleleFrequencyCollection", "Represents a collection of allele frequencies.")]
    3131  [StorableClass]
    32   public class AlleleFrequencyArray : ReadOnlyItemArray<AlleleFrequency> {
    33     public AlleleFrequencyArray() : base() { }
    34     public AlleleFrequencyArray(IEnumerable<AlleleFrequency> frequencies) : base(new ItemArray<AlleleFrequency>(frequencies)) { }
     32  public class AlleleFrequencyCollection : ReadOnlyItemCollection<AlleleFrequency> {
     33    public AlleleFrequencyCollection() : base() { }
     34    public AlleleFrequencyCollection(IEnumerable<AlleleFrequency> frequencies) : base(new ItemCollection<AlleleFrequency>(frequencies)) { }
    3535    [StorableConstructor]
    36     protected AlleleFrequencyArray(bool deserializing) : base(deserializing) { }
     36    protected AlleleFrequencyCollection(bool deserializing) : base(deserializing) { }
    3737  }
    3838}
  • trunk/sources/HeuristicLab.Analysis/3.3/HeuristicLab.Analysis-3.3.csproj

    r4623 r4639  
    110110  <ItemGroup>
    111111    <None Include="HeuristicLabAnalysisPlugin.cs.frame" />
     112    <Compile Include="AlleleFrequencyCollection.cs" />
    112113    <Compile Include="BestAverageWorstQualityAnalyzer.cs" />
    113114    <Compile Include="BestAverageWorstQualityCalculator.cs" />
     
    116117    <Compile Include="Allele.cs" />
    117118    <Compile Include="AlleleFrequency.cs" />
    118     <Compile Include="AlleleFrequencyArray.cs" />
     119    <Compile Include="AlleleFrequencyCollectionCollection.cs" />
    119120    <Compile Include="QualityAnalyzer.cs" />
    120121    <Compile Include="MinAverageMaxValueAnalyzer.cs" />
Note: See TracChangeset for help on using the changeset viewer.