Exemplo n.º 1
0
        protected int GetIndex(EditPeakScoringModelDlg editDlg, Type calcType)
        {
            var calculators = editDlg.PeakScoringModel.PeakFeatureCalculators;
            var calculator  = calculators.FirstOrDefault(calc => calc.GetType() == calcType);

            return(calculator != null?calculators.IndexOf(calculator) : -1);
        }
Exemplo n.º 2
0
        protected void VerifyScores(EditPeakScoringModelDlg editDlg,
                                    bool isPresent,
                                    Type[] scoreTypes)
        {
            List <double?> scores;

            VerifyScores(editDlg, isPresent, scoreTypes, out scores);
        }
Exemplo n.º 3
0
 protected void VerifyScores(EditPeakScoringModelDlg editDlg,
                             bool isPresent,
                             Type[] scoreTypes,
                             out List <double?> scores)
 {
     scores = new List <double?>();
     foreach (var scoreType in scoreTypes)
     {
         Assert.AreEqual(IsActiveCalculator(editDlg, scoreType), isPresent);
         scores.Add(ValueCalculator(editDlg, scoreType));
     }
 }
Exemplo n.º 4
0
        private void ValidateCoefficients(EditPeakScoringModelDlg editDlgFromSrm, int coeffIndex)
        {
            string coefficients = string.Join(@"|", GetCoefficientStrings(editDlgFromSrm));

            if (IsRecordMode)
            {
                Console.WriteLine(@"""{0}"", // Not L10N", coefficients);  // Not L10N
            }
            else
            {
                AssertEx.AreEqualLines(EXPECTED_COEFFICIENTS[coeffIndex], coefficients);
            }
        }
Exemplo n.º 5
0
 protected void VerifyScores(EditPeakScoringModelDlg editDlg,
                             bool isPresent,
                             Type[] scoreTypes,
                             out List <double?> scores)
 {
     scores = new List <double?>();
     foreach (var scoreType in scoreTypes)
     {
         Assert.AreEqual(IsActiveCalculator(editDlg, scoreType), isPresent,
                         string.Format("Score calculator type {0} unexpectedly {1}", scoreType, isPresent ? "disabled" : "enabled"));
         scores.Add(ValueCalculator(editDlg, scoreType));
     }
 }
Exemplo n.º 6
0
 private IEnumerable <string> GetCoefficientStrings(EditPeakScoringModelDlg editDlg)
 {
     for (int i = 0; i < editDlg.PeakCalculatorsGrid.Items.Count; i++)
     {
         double?weight = editDlg.PeakCalculatorsGrid.Items[i].Weight;
         if (weight.HasValue)
         {
             yield return(string.Format(CultureInfo.InvariantCulture, "{0:F04}", weight.Value));
         }
         else
         {
             yield return(" null ");  // To help values line up
         }
     }
 }
Exemplo n.º 7
0
        protected EditPeakScoringModelDlg.HistogramGroup GetHistogramForScoreIndex(EditPeakScoringModelDlg editDlg, int scoreIndex)
        {
            EditPeakScoringModelDlg.HistogramGroup scoreHistograms;
            EditPeakScoringModelDlg.HistogramGroup pValueHistograms;
            EditPeakScoringModelDlg.HistogramGroup qValueHistograms;
            PointPairList piZeroLine;

            editDlg.GetPoints(
                scoreIndex,
                out scoreHistograms,
                out pValueHistograms,
                out qValueHistograms,
                out piZeroLine);
            return(scoreHistograms);
        }
Exemplo n.º 8
0
 private void VerifyBias(EditPeakScoringModelDlg editDlg, string bias, bool isRecording = true)
 {
     if (IsRecordMode)
     {
         if (isRecording)
         {
             Console.WriteLine(@"""{0}"",", editDlg.PeakScoringModel.Parameters.Bias.ToString(CultureInfo.CurrentCulture));
         }
     }
     else
     {
         double biasNum;
         Assert.IsTrue(double.TryParse(bias, NumberStyles.Float, CultureInfo.InvariantCulture, out biasNum));
         Assert.AreEqual(editDlg.PeakScoringModel.Parameters.Bias, biasNum, 1e-5);
     }
 }
Exemplo n.º 9
0
        /// <summary>
        ///  Is the specified calculator valid for this dataset (has no unknown values and not all the same value)?
        /// </summary>
        private bool IsValidCalculator(int calculatorIndex)
        {
            double maxValue = Double.MinValue;
            double minValue = Double.MaxValue;

            foreach (var peakTransitionGroupFeatures in _peakTransitionGroupFeaturesList.Features)
            {
                // Find the highest and second highest scores among the transitions in this group.
                foreach (var peakGroupFeatures in peakTransitionGroupFeatures.PeakGroupFeatures)
                {
                    double value = peakGroupFeatures.Features[calculatorIndex];
                    if (EditPeakScoringModelDlg.IsUnknown(value))
                    {
                        return(false);
                    }
                    maxValue = Math.Max(value, maxValue);
                    minValue = Math.Min(value, minValue);
                }
            }
            return(maxValue > minValue);
        }
Exemplo n.º 10
0
        protected double?ValueCalculator(EditPeakScoringModelDlg editDlg, Type calcType)
        {
            var index = GetIndex(editDlg, calcType);

            return(editDlg.PeakCalculatorsGrid.Items[index].Weight);
        }
Exemplo n.º 11
0
        protected bool IsActiveCalculator(EditPeakScoringModelDlg editDlg, Type calcType)
        {
            var index = GetIndex(editDlg, calcType);

            return(editDlg.PeakCalculatorsGrid.Items[index].IsEnabled);
        }
Exemplo n.º 12
0
        protected EditPeakScoringModelDlg.HistogramGroup GetHistogramForScore(EditPeakScoringModelDlg editDlg, Type scoreType)
        {
            int index = GetIndex(editDlg, scoreType);

            return(GetHistogramForScoreIndex(editDlg, index));
        }
Exemplo n.º 13
0
        private void VerifyCellValues(EditPeakScoringModelDlg editDlg, string expectedValueString, double sumWeights = 1.0, bool isRecording = true)
        {
            // Parse the expected values
            var expectedFields = expectedValueString.Split(new[] { '|', ';' });

            expectedFields = expectedFields.Take(expectedFields.Length - 1).ToArray();
            Assert.AreEqual(expectedFields.Length % 3, 0);
            int numRows = expectedFields.Length / 3;

            // Verify expected number of rows.
            Assert.AreEqual(editDlg.PeakCalculatorsGrid.RowCount, numRows);
            // Verify normalized weights add to 1
            double sumNormWeights = 0;
            var    readModeSb     = new StringBuilder();
            int    fieldNum       = 0;
            string expectedValue  = null;

            for (int row = 0; row < numRows; row++)
            {
                for (int col = 0; col < 4; col++)
                {
                    if (col != 1)
                    {
                        expectedValue = expectedFields[fieldNum++];
                    }

                    // Verify cell value.
                    var actualValue = editDlg.PeakCalculatorsGrid.GetCellValue(col, row);
                    if (IsRecordMode && isRecording)
                    {
                        if (col == 0)
                        {
                            readModeSb.Append(actualValue == null ? "" : actualValue + '|');
                        }
                        if (col == 2)
                        {
                            readModeSb.Append((string.IsNullOrEmpty(actualValue) ? "" : double.Parse(actualValue).ToString(editDlg.PeakCalculatorWeightFormat)) + '|');
                        }
                        if (col == 3)
                        {
                            readModeSb.Append((string.IsNullOrEmpty(actualValue) ? "" : double.Parse(actualValue).ToString(editDlg.PeakCalculatorPercentContributionFormat)) + ";");
                        }
                    }
                    if (col == 2 && !string.IsNullOrEmpty(actualValue))
                    {
                        actualValue = double.Parse(actualValue).ToString(editDlg.PeakCalculatorWeightFormat);
                    }
                    if (col == 3 && !string.IsNullOrEmpty(actualValue))
                    {
                        sumNormWeights += double.Parse(actualValue);
                        actualValue     = double.Parse(actualValue).ToString(editDlg.PeakCalculatorPercentContributionFormat);
                    }
                    if (!IsRecordMode && col != 1)
                    {
                        // Normalize decimal separator
                        if (actualValue != null)
                        {
                            actualValue = actualValue.Replace(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator,
                                                              CultureInfo.InvariantCulture.NumberFormat.NumberDecimalSeparator);
                        }
                        Assert.AreEqual(expectedValue, actualValue);
                    }
                }
            }
            if (IsRecordMode && isRecording)
            {
                Console.WriteLine(@"""{0}"",", readModeSb);
            }
            Assert.AreEqual(sumNormWeights, sumWeights, 0.005);
        }