Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        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);
        }