示例#1
0
        public void TestSimpleAdjustPValues()
        {
            var input    = new[] { .005, .02, .25 };
            var expected = new[] { .015, .030, .250 };
            var actual   = PValues.AdjustPValues(input);

            CollectionAssert.AreEqual(expected, actual);
        }
示例#2
0
        private void UpdateResults()
        {
            var results = GroupComparisonModel.Results;
            var rows    = new List <FoldChangeRow>();

            if (null != results)
            {
                Dictionary <int, double> criticalValuesByDegreesOfFreedom = new Dictionary <int, double>();
                var groupComparisonDef = results.GroupComparer.ComparisonDef;
                var adjustedPValues    = PValues.AdjustPValues(results.ResultRows.Select(
                                                                   row => row.LinearFitResult.PValue)).ToArray();
                for (int iRow = 0; iRow < results.ResultRows.Count; iRow++)
                {
                    var resultRow = results.ResultRows[iRow];
                    var protein   = new Protein(_skylineDataSchema, new IdentityPath(resultRow.Selector.Protein.Id));
                    Model.Databinding.Entities.Peptide peptide = null;
                    if (null != resultRow.Selector.Peptide)
                    {
                        peptide = new Model.Databinding.Entities.Peptide(_skylineDataSchema,
                                                                         new IdentityPath(protein.IdentityPath, resultRow.Selector.Peptide.Id));
                    }
                    double criticalValue;
                    if (!criticalValuesByDegreesOfFreedom.TryGetValue(resultRow.LinearFitResult.DegreesOfFreedom,
                                                                      out criticalValue))
                    {
                        criticalValue = FoldChangeResult.GetCriticalValue(groupComparisonDef.ConfidenceLevel,
                                                                          resultRow.LinearFitResult.DegreesOfFreedom);
                        criticalValuesByDegreesOfFreedom.Add(resultRow.LinearFitResult.DegreesOfFreedom, criticalValue);
                    }
                    FoldChangeResult foldChangeResult = new FoldChangeResult(groupComparisonDef.ConfidenceLevel,
                                                                             adjustedPValues[iRow], resultRow.LinearFitResult, criticalValue);
                    rows.Add(new FoldChangeRow(protein, peptide, resultRow.Selector.LabelType,
                                               resultRow.Selector.MsLevel, resultRow.Selector.GroupIdentifier, resultRow.ReplicateCount, foldChangeResult));
                }
            }
            var defaultViewSpec = GetDefaultViewSpec(rows);

            if (!Equals(defaultViewSpec, ViewContext.BuiltInViews.First()))
            {
                var viewInfo = new ViewInfo(_skylineDataSchema, typeof(FoldChangeRow), defaultViewSpec).ChangeViewGroup(ViewGroup.BUILT_IN);
                ViewContext.SetRowSources(new[]
                {
                    new RowSourceInfo(new StaticRowSource(rows), viewInfo)
                });
                if (null != _bindingListSource.ViewSpec && _bindingListSource.ViewSpec.Name == defaultViewSpec.Name &&
                    !_bindingListSource.ViewSpec.Equals(defaultViewSpec))
                {
                    _bindingListSource.SetView(viewInfo, new StaticRowSource(rows));
                }
            }
            _bindingListSource.RowSource = new StaticRowSource(rows);
        }
示例#3
0
        public void TestAdjustListOfPValues()
        {
            var input = new[]
            {
                0, 7.2867665485711353e-01, 1.1395351451692903e-04, 0, 0,
                0, 0, 5.7295134488581922e-03, 3.6202576492172511e-08, 0,
                6.6968629752750530e-08, 0, 0, 0, 0,
                0, 0, 0, 0, 0,
                2.6345568091021576e-01, 0, 1.1774885228897247e-02, 2.0858033300541479e-08, 0,
                0, 2.3421400293432981e-05, 0, 0, 0,
                0, 3.3684388611732174e-10, 0, 2.0239094797527057e-01, 0,
                7.9936057773011271e-15, 4.4724224323999806e-12, 0, 0, 4.0897231039323190e-01,
                0, 7.5570363823769249e-03, 0, 4.2761477929438962e-01, 4.5888446988493703e-02,
                9.7037489155127332e-11, 2.0262598487530425e-05, 0
            };
            var expected = new[]
            {
                0, 7.2867665485711353e-01, 1.4025047940545112e-04, 0, 0,
                0, 0, 6.8754161386298304e-03, 4.9649247760693727e-08, 0,
                8.9291506337000698e-08, 0, 0, 0, 0,
                0, 0, 0, 0, 0,
                2.8101939297089679e-01, 0, 1.3457011690168282e-02, 2.9446635247823267e-08, 0,
                0, 2.9584926686441660e-05, 0, 0, 0,
                0, 4.8995474344337708e-10, 0, 2.2079012506393153e-01, 0,
                1.2789769243681804e-14, 6.9250411856515830e-12, 0, 0, 4.2675371519293764e-01,
                0, 8.8472621061973754e-03, 0, 4.3671296608788723e-01, 5.1224312917388319e-02,
                1.4555623373269100e-10, 2.6286614254093528e-05, 0,
            };
            var actual = PValues.AdjustPValues(input);

            for (int i = 0; i < expected.Length; i++)
            {
                if (expected[i] == 0)
                {
                    Assert.AreEqual(expected[i], actual[i]);
                }
                else
                {
                    Assert.AreEqual(expected[i], actual[i], expected[i] / 1E8);
                }
            }
        }
        public GroupComparisonRefinementData(SrmDocument document, double adjustedPValCutoff,
                                             double foldChangeCutoff, int?msLevel, List <GroupComparisonDef> groupComparisonDefs,
                                             SrmSettingsChangeMonitor progressMonitor)
        {
            _progressMonitor    = progressMonitor;
            _foldChangeCutoff   = foldChangeCutoff;
            _adjustedPValCutoff = adjustedPValCutoff;
            if (msLevel.HasValue)
            {
                _msLevel = msLevel.Value;
            }
            else
            {
                _msLevel = document.PeptideTransitions.Any(t => !t.IsMs1) ? 2 : 1;
            }
            Data = new List <List <GroupComparisonRow> >();

            foreach (var groupComparisonDef in groupComparisonDefs)
            {
                var groupComparer = new GroupComparer(groupComparisonDef, document, _qrFactorizationCache);
                var results       = GroupComparisonModel.ComputeResults(groupComparer, document, null, null, progressMonitor);


                var adjustedPValues = PValues.AdjustPValues(results.Select(
                                                                row => row.LinearFitResult.PValue)).ToArray();

                var foldChangeList = new List <GroupComparisonRow>();
                for (int iRow = 0; iRow < results.Count; iRow++)
                {
                    var resultRow = results[iRow];
                    FoldChangeResult foldChangeResult = new FoldChangeResult(groupComparisonDef.ConfidenceLevel,
                                                                             adjustedPValues[iRow], resultRow.LinearFitResult, double.NaN);
                    foldChangeList.Add(new GroupComparisonRow(resultRow.Selector.Protein, resultRow.Selector.Peptide,
                                                              resultRow.Selector.MsLevel,
                                                              foldChangeResult));
                }

                Data.Add(foldChangeList);
            }
        }
        private void UpdateResults()
        {
            var results = GroupComparisonModel.Results;
            var rows    = new List <FoldChangeRow>();

            if (null != results)
            {
                var controlGroupIdentifier =
                    GroupComparisonModel.GroupComparisonDef.GetControlGroupIdentifier(_skylineDataSchema.Document
                                                                                      .Settings);
                Dictionary <int, double> criticalValuesByDegreesOfFreedom = new Dictionary <int, double>();
                var groupComparisonDef = results.GroupComparer.ComparisonDef;
                var adjustedPValues    = PValues.AdjustPValues(results.ResultRows.Select(
                                                                   row => row.LinearFitResult.PValue)).ToArray();
                for (int iRow = 0; iRow < results.ResultRows.Count; iRow++)
                {
                    var resultRow = results.ResultRows[iRow];
                    var protein   = new Protein(_skylineDataSchema, new IdentityPath(resultRow.Selector.Protein.Id));
                    Model.Databinding.Entities.Peptide peptide = null;
                    if (null != resultRow.Selector.Peptide)
                    {
                        peptide = new Model.Databinding.Entities.Peptide(_skylineDataSchema,
                                                                         new IdentityPath(protein.IdentityPath, resultRow.Selector.Peptide.Id));
                    }
                    double criticalValue;
                    if (!criticalValuesByDegreesOfFreedom.TryGetValue(resultRow.LinearFitResult.DegreesOfFreedom,
                                                                      out criticalValue))
                    {
                        criticalValue = FoldChangeResult.GetCriticalValue(groupComparisonDef.ConfidenceLevel,
                                                                          resultRow.LinearFitResult.DegreesOfFreedom);
                        criticalValuesByDegreesOfFreedom.Add(resultRow.LinearFitResult.DegreesOfFreedom, criticalValue);
                    }
                    FoldChangeResult foldChangeResult = new FoldChangeResult(groupComparisonDef.ConfidenceLevel,
                                                                             adjustedPValues[iRow], resultRow.LinearFitResult, criticalValue);
                    var runAbundances = new Dictionary <Replicate, ReplicateRow>();

                    foreach (var runAbundance in resultRow.RunAbundances)
                    {
                        Replicate replicate = new Replicate(_skylineDataSchema, runAbundance.ReplicateIndex);
                        runAbundances.Add(replicate, new ReplicateRow(replicate, runAbundance.Control ?
                                                                      controlGroupIdentifier : resultRow.Selector.GroupIdentifier
                                                                      , runAbundance.BioReplicate, Math.Pow(2, runAbundance.Log2Abundance)));
                    }
                    rows.Add(new FoldChangeRow(protein, peptide, resultRow.Selector.LabelType,
                                               resultRow.Selector.MsLevel, resultRow.Selector.GroupIdentifier, resultRow.ReplicateCount, foldChangeResult, runAbundances));
                }
            }

            var detailRows = new List <FoldChangeDetailRow>();

            foreach (var grouping in rows.ToLookup(row =>
                                                   Tuple.Create(row.Protein, row.Peptide, row.IsotopeLabelType, row.MsLevel)))
            {
                var foldChangeResults = grouping.ToDictionary(row => row.Group, row => row.FoldChangeResult);
                var runAbundances     = new Dictionary <Replicate, ReplicateRow>();
                foreach (var abundance in grouping.SelectMany(row => row.ReplicateAbundances))
                {
                    runAbundances[abundance.Key] = abundance.Value;
                }
                detailRows.Add(new FoldChangeDetailRow(grouping.Key.Item1, grouping.Key.Item2, grouping.Key.Item3, grouping.Key.Item4, foldChangeResults, runAbundances));
            }
            var defaultViewSpec   = GetDefaultViewSpec(rows);
            var clusteredViewSpec = GetClusteredViewSpec(defaultViewSpec);

            var rowSourceInfos = new List <RowSourceInfo>()
            {
                new RowSourceInfo(new StaticRowSource(rows),
                                  new ViewInfo(_skylineDataSchema, typeof(FoldChangeRow), defaultViewSpec).ChangeViewGroup(ViewGroup.BUILT_IN)),
                new RowSourceInfo(new StaticRowSource(detailRows),
                                  new ViewInfo(_skylineDataSchema, typeof(FoldChangeDetailRow), clusteredViewSpec).ChangeViewGroup(ViewGroup.BUILT_IN))
            };

            SetRowSourceInfos(rowSourceInfos);
        }