Exemplo n.º 1
0
 private static int ComparePeptideTimes(GraphPointData p1, GraphPointData p2)
 {
     if (ReferenceEquals(p1.NodePep, p2.NodePep))
     {
         return(Peptide.CompareGroups(p1.NodeGroup, p2.NodeGroup));
     }
     return(Comparer.Default.Compare(p1.TimePepCharge, p2.TimePepCharge));
 }
Exemplo n.º 2
0
 private static int CompareGroupMassErrors(GraphPointData p1, GraphPointData p2)
 {
     return(Comparer.Default.Compare(p1.MassErrorGroup, p2.MassErrorGroup));
 }
Exemplo n.º 3
0
/*
 *          private static int ComparePeptideAreas(GraphPointData p1, GraphPointData p2)
 *          {
 *              if (ReferenceEquals(p2.NodePep, p1.NodePep))
 *                  return Peptide.CompareGroups(p2.NodeGroup, p1.NodeGroup);
 *              return Comparer.Default.Compare(p2.AreaPepCharge, p1.AreaPepCharge);
 *          }
 */

            private static int CompareGroupAreas(GraphPointData p1, GraphPointData p2)
            {
                return(Comparer.Default.Compare(p2.AreaGroup, p1.AreaGroup));
            }
Exemplo n.º 4
0
 private static int CompareGroupTimes(GraphPointData p1, GraphPointData p2)
 {
     return(Comparer.Default.Compare(p1.TimeGroup, p2.TimeGroup));
 }
Exemplo n.º 5
0
            // ReSharper disable PossibleMultipleEnumeration
            protected GraphData(SrmDocument document, TransitionGroupDocNode selectedGroup, PeptideGroupDocNode selectedProtein,
                                int?iResult, DisplayTypeChrom displayType, GraphValues.IRetentionTimeTransformOp retentionTimeTransformOp,
                                PaneKey paneKey)
            {
                RetentionTimeTransformOp = retentionTimeTransformOp;
                // Determine the shortest possible unique ID for each peptide or molecule
                var sequences = new List <Tuple <string, bool> >();

                foreach (var nodePep in document.Molecules)
                {
                    sequences.Add(new Tuple <string, bool>(nodePep.ModifiedTarget.DisplayName, nodePep.IsProteomic));
                }
                var uniquePrefixGenerator = new UniquePrefixGenerator(sequences, 3);

                int pointListCount = 0;
                var dictTypeToSet  = new Dictionary <IsotopeLabelType, int>();

                bool onePointPerPeptide = PeptideOrder == SummaryPeptideOrder.document &&
                                          null != paneKey.IsotopeLabelType;
                // Figure out how many point lists to create
                bool displayTotals = (displayType == DisplayTypeChrom.total);

                if (displayTotals)
                {
                    foreach (var nodeGroup in document.MoleculeTransitionGroups)
                    {
                        if (!paneKey.IncludesTransitionGroup(nodeGroup))
                        {
                            continue;
                        }
                        IsotopeLabelType labelType = nodeGroup.TransitionGroup.LabelType;
                        if (!dictTypeToSet.ContainsKey(labelType))
                        {
                            dictTypeToSet.Add(labelType, pointListCount++);
                        }
                    }
                }
                else
                {
                    foreach (var nodeGroup in document.MoleculeTransitionGroups)
                    {
                        if (!paneKey.IncludesTransitionGroup(nodeGroup))
                        {
                            continue;
                        }
                        pointListCount = Math.Max(pointListCount, GraphChromatogram.GetDisplayTransitions(nodeGroup, displayType).Count());
                    }
                }

                // Build the list of points to show.
                var listPoints = new List <GraphPointData>();

                foreach (PeptideGroupDocNode nodeGroupPep in document.MoleculeGroups)
                {
                    if (AreaGraphController.AreaScope == AreaScope.protein)
                    {
                        if (!ReferenceEquals(nodeGroupPep, selectedProtein))
                        {
                            continue;
                        }
                    }
                    foreach (PeptideDocNode nodePep in nodeGroupPep.Children)
                    {
                        bool addBlankPoint = onePointPerPeptide &&
                                             !nodePep.TransitionGroups.Any(paneKey.IncludesTransitionGroup);
                        foreach (TransitionGroupDocNode nodeGroup in nodePep.Children)
                        {
                            var path = new IdentityPath(nodeGroupPep.PeptideGroup,
                                                        nodePep.Peptide, nodeGroup.TransitionGroup);
                            var graphPointData = new GraphPointData(nodePep, nodeGroup, path);
                            if (addBlankPoint || paneKey.IncludesTransitionGroup(nodeGroup))
                            {
                                listPoints.Add(graphPointData);
                            }
                            if (addBlankPoint)
                            {
                                break;
                            }
                        }
                    }
                }

                // Sort into correct order
                var peptideOrder = PeptideOrder;

                if (peptideOrder == SummaryPeptideOrder.time)
                {
                    if (displayTotals)
                    {
                        listPoints.Sort(ComparePeptideTimes);
                    }
                    else
                    {
                        listPoints.Sort(CompareGroupTimes);
                    }
                }
                else if (peptideOrder == SummaryPeptideOrder.area)
                {
                    listPoints.Sort(CompareGroupAreas);
                }
                else if (peptideOrder == SummaryPeptideOrder.mass_error)
                {
                    listPoints.Sort(CompareGroupMassErrors);
                }

                // Init calculated values
                var    pointPairLists = new List <PointPairList>();
                var    labels         = new List <string>();
                var    xscalePaths    = new List <IdentityPath>();
                double maxY           = 0;
                double minY           = double.MaxValue;
                int    selectedIndex  = -1;

                for (int i = 0; i < pointListCount; i++)
                {
                    pointPairLists.Add(new PointPairList());
                }

                // Calculate lists and values
                PeptideDocNode nodePepCurrent = null;
                int            chargeCount    = 0;
                var            chargeCurrent  = Adduct.EMPTY;

                foreach (var dataPoint in listPoints)
                {
                    var nodePep   = dataPoint.NodePep;
                    var nodeGroup = dataPoint.NodeGroup;
                    if (!ReferenceEquals(nodePep, nodePepCurrent))
                    {
                        nodePepCurrent = nodePep;

                        chargeCount   = GetChargeCount(nodePep);
                        chargeCurrent = Adduct.EMPTY;
                    }

                    bool addLabel = !displayTotals;
                    if (displayTotals && !Equals(nodeGroup.TransitionGroup.PrecursorAdduct, chargeCurrent))
                    {
                        LevelPointPairLists(pointPairLists);
                        addLabel = true;
                    }
                    chargeCurrent = nodeGroup.TransitionGroup.PrecursorAdduct;

                    var transitionGroup = nodeGroup.TransitionGroup;
                    int iGroup          = labels.Count;

                    if (addLabel)
                    {
                        string label = uniquePrefixGenerator.GetUniquePrefix(nodePep.ModifiedTarget.DisplayName, nodePep.IsProteomic) +
                                       (chargeCount > 1
                                            ? Transition.GetChargeIndicator(transitionGroup.PrecursorAdduct)
                                            : string.Empty);
                        if (!displayTotals && null == paneKey.IsotopeLabelType)
                        {
                            label += transitionGroup.LabelTypeText;
                        }
                        if (peptideOrder == SummaryPeptideOrder.time)
                        {
                            label += string.Format(@" ({0:F01})", displayTotals ?
                                                   dataPoint.TimePepCharge : dataPoint.TimeGroup);
                        }
                        labels.Add(label);
                        xscalePaths.Add(dataPoint.IdentityPath);
                    }

                    double groupMaxY = 0;
                    double groupMinY = double.MaxValue;

                    // ReSharper disable DoNotCallOverridableMethodsInConstructor
                    int?resultIndex = iResult.HasValue && iResult >= 0 ? iResult : null;
                    if (RTLinearRegressionGraphPane.ShowReplicate == ReplicateDisplay.best && nodePep != null)
                    {
                        resultIndex = null;
                        int iBest = nodePep.BestResult;
                        if (iBest != -1)
                        {
                            resultIndex = iBest;
                        }
                    }
                    if (displayTotals)
                    {
                        var labelType = nodeGroup.TransitionGroup.LabelType;
                        if (dictTypeToSet.ContainsKey(labelType))
                        {
                            if (paneKey.IncludesTransitionGroup(nodeGroup))
                            {
                                pointPairLists[dictTypeToSet[labelType]].Add(CreatePointPair(iGroup, nodeGroup,
                                                                                             ref groupMaxY, ref groupMinY,
                                                                                             resultIndex));
                            }
                            else
                            {
                                pointPairLists[dictTypeToSet[labelType]].Add(PointPairMissing(iGroup));
                            }
                        }
                    }
                    else
                    {
                        if (paneKey.IncludesTransitionGroup(nodeGroup))
                        {
                            var nodeTrans = GraphChromatogram.GetDisplayTransitions(nodeGroup, displayType).ToArray();
                            for (int i = 0; i < pointListCount; i++)
                            {
                                var pointPairList = pointPairLists[i];
                                pointPairList.Add(i >= nodeTrans.Length
                                                      ? CreatePointPairMissing(iGroup)
                                                      : CreatePointPair(iGroup, nodeTrans[i], ref groupMaxY,
                                                                        ref groupMinY,
                                                                        resultIndex));
                            }
                        }
                        else
                        {
                            for (int i = 0; i < pointListCount; i++)
                            {
                                pointPairLists[i].Add(CreatePointPairMissing(iGroup));
                            }
                        }
                    }
                    // ReSharper restore DoNotCallOverridableMethodsInConstructor

                    // Save the selected index and its y extent
                    if (ReferenceEquals(selectedGroup, nodeGroup))
                    {
                        selectedIndex = labels.Count - 1;
                        SelectedMaxY  = groupMaxY;
                        SelectedMinY  = groupMinY;
                    }
                    // If multiple groups in the selection, make sure y extent is max of them
                    else if (selectedIndex == labels.Count - 1)
                    {
                        SelectedMaxY = Math.Max(groupMaxY, SelectedMaxY);
                        SelectedMinY = Math.Min(groupMinY, SelectedMinY);
                    }
                    maxY = Math.Max(maxY, groupMaxY);
                    minY = Math.Min(minY, groupMinY);
                }

                PointPairLists = pointPairLists;
                Labels         = labels.ToArray();
                XScalePaths    = xscalePaths.ToArray();
                SelectedIndex  = selectedIndex;
                MaxY           = maxY;
                if (minY != double.MaxValue)
                {
                    MinY = minY;
                }
            }
 private static int ComparePeptideTimes(GraphPointData p1, GraphPointData p2)
 {
     if (ReferenceEquals(p1.NodePep, p2.NodePep))
         return Peptide.CompareGroups(p1.NodeGroup, p2.NodeGroup);
     return Comparer.Default.Compare(p1.TimePepCharge, p2.TimePepCharge);
 }
 private static int CompareGroupTimes(GraphPointData p1, GraphPointData p2)
 {
     return Comparer.Default.Compare(p1.TimeGroup, p2.TimeGroup);
 }
 /*
 private static int ComparePeptideAreas(GraphPointData p1, GraphPointData p2)
 {
     if (ReferenceEquals(p2.NodePep, p1.NodePep))
         return Peptide.CompareGroups(p2.NodeGroup, p1.NodeGroup);
     return Comparer.Default.Compare(p2.AreaPepCharge, p1.AreaPepCharge);
 }
 */
 private static int CompareGroupAreas(GraphPointData p1, GraphPointData p2)
 {
     return Comparer.Default.Compare(p2.AreaGroup, p1.AreaGroup);
 }
            protected GraphData(SrmDocument document, TransitionGroupDocNode selectedGroup, PeptideGroupDocNode selectedProtein, 
                int? iResult, DisplayTypeChrom displayType, GraphValues.IRetentionTimeTransformOp retentionTimeTransformOp,
                PaneKey paneKey)
            {
                RetentionTimeTransformOp = retentionTimeTransformOp;
                // Determine the shortest possible unique ID for each peptide or molecule
                var sequences = new List<Tuple<string, bool>>();
                foreach (var nodePep in document.Molecules)
                    sequences.Add(new Tuple<string, bool>(nodePep.RawTextId, nodePep.IsProteomic));
                var uniquePrefixGenerator = new UniquePrefixGenerator(sequences, 3);

                int pointListCount = 0;
                var dictTypeToSet = new Dictionary<IsotopeLabelType, int>();

                bool onePointPerPeptide = PeptideOrder == SummaryPeptideOrder.document &&
                                          null != paneKey.IsotopeLabelType;
                // Figure out how many point lists to create
                bool displayTotals = (displayType == DisplayTypeChrom.total);
                if (displayTotals)
                {
                    foreach (var nodeGroup in document.MoleculeTransitionGroups)
                    {
                        if (!paneKey.IncludesTransitionGroup(nodeGroup))
                        {
                            continue;
                        }
                        IsotopeLabelType labelType = nodeGroup.TransitionGroup.LabelType;
                        if (!dictTypeToSet.ContainsKey(labelType))
                            dictTypeToSet.Add(labelType, pointListCount++);
                    }
                }
                else
                {
                    foreach (var nodeGroup in document.MoleculeTransitionGroups)
                    {
                        if (!paneKey.IncludesTransitionGroup(nodeGroup))
                        {
                            continue;
                        }
                        pointListCount = Math.Max(pointListCount, GraphChromatogram.GetDisplayTransitions(nodeGroup, displayType).Count());
                    }
                }

                // Build the list of points to show.
                var listPoints = new List<GraphPointData>();
                foreach (PeptideGroupDocNode nodeGroupPep in document.MoleculeGroups)
                {
                    if (AreaGraphController.AreaScope == AreaScope.protein)
                    {
                        if (!ReferenceEquals(nodeGroupPep, selectedProtein))
                            continue;
                    }
                    foreach (PeptideDocNode nodePep in nodeGroupPep.Children)
                    {
                        bool addBlankPoint = onePointPerPeptide &&
                                             !nodePep.TransitionGroups.Any(paneKey.IncludesTransitionGroup);
                        foreach (TransitionGroupDocNode nodeGroup in nodePep.Children)
                        {
                            var path = new IdentityPath(nodeGroupPep.PeptideGroup,
                                                        nodePep.Peptide, nodeGroup.TransitionGroup);
                            var graphPointData = new GraphPointData(nodePep, nodeGroup, path);
                            if (addBlankPoint || paneKey.IncludesTransitionGroup(nodeGroup))
                            {
                                listPoints.Add(graphPointData);
                            }
                            if (addBlankPoint)
                            {
                                break;
                            }
                        }
                    }
                }

                // Sort into correct order
                var peptideOrder = PeptideOrder;
                if (peptideOrder == SummaryPeptideOrder.time)
                {
                    if (displayTotals)
                        listPoints.Sort(ComparePeptideTimes);
                    else
                        listPoints.Sort(CompareGroupTimes);
                }
                else if (peptideOrder == SummaryPeptideOrder.area)
                {
                    listPoints.Sort(CompareGroupAreas);
                }

                // Init calculated values
                var pointPairLists = new List<PointPairList>();
                var labels = new List<string>();
                var xscalePaths = new List<IdentityPath>();
                double maxY = 0;
                double minY = double.MaxValue;
                int selectedIndex = -1;

                for (int i = 0; i < pointListCount; i++)
                    pointPairLists.Add(new PointPairList());

                // Calculate lists and values
                PeptideDocNode nodePepCurrent = null;
                int chargeCount = 0, chargeCurrent = 0;
                foreach (var dataPoint in listPoints)
                {
                    var nodePep = dataPoint.NodePep;
                    var nodeGroup = dataPoint.NodeGroup;
                    if (!ReferenceEquals(nodePep, nodePepCurrent))
                    {
                        nodePepCurrent = nodePep;

                        chargeCount = GetChargeCount(nodePep);
                        chargeCurrent = 0;
                    }

                    bool addLabel = !displayTotals;
                    if (displayTotals && nodeGroup.TransitionGroup.PrecursorCharge != chargeCurrent)
                    {
                        LevelPointPairLists(pointPairLists);
                        addLabel = true;
                    }
                    chargeCurrent = nodeGroup.TransitionGroup.PrecursorCharge;

                    var transitionGroup = nodeGroup.TransitionGroup;
                    int iGroup = labels.Count;

                    if (addLabel)
                    {
                        string label = uniquePrefixGenerator.GetUniquePrefix(nodePep.RawTextId, nodePep.IsProteomic) +
                                       (chargeCount > 1
                                            ? Transition.GetChargeIndicator(transitionGroup.PrecursorCharge)
                                            : string.Empty);
                        if (!displayTotals && null == paneKey.IsotopeLabelType)
                            label += transitionGroup.LabelTypeText;
                        if (peptideOrder == SummaryPeptideOrder.time)
                        {
                            label += string.Format(" ({0:F01})", displayTotals ? // Not L10N
                                                                                   dataPoint.TimePepCharge : dataPoint.TimeGroup);
                        }
                        labels.Add(label);
                        xscalePaths.Add(dataPoint.IdentityPath);
                    }

                    double groupMaxY = 0;
                    double groupMinY = double.MaxValue;

                    // ReSharper disable DoNotCallOverridableMethodsInConstructor
                    int? resultIndex = iResult.HasValue && iResult >= 0 ? iResult : null;
                    if (RTLinearRegressionGraphPane.ShowReplicate == ReplicateDisplay.best && nodePep != null)
                    {
                        resultIndex = null;
                        int iBest = nodePep.BestResult;
                        if (iBest !=-1)
                            resultIndex = iBest;
                    }
                    if (displayTotals)
                    {
                        var labelType = nodeGroup.TransitionGroup.LabelType;
                        if (dictTypeToSet.ContainsKey(labelType))
                        {
                            if (paneKey.IncludesTransitionGroup(nodeGroup))
                            {
                                pointPairLists[dictTypeToSet[labelType]].Add(CreatePointPair(iGroup, nodeGroup,
                                                                                             ref groupMaxY, ref groupMinY,
                                                                                             resultIndex));
                            }
                            else
                            {
                                pointPairLists[dictTypeToSet[labelType]].Add(PointPairMissing(iGroup));
                            }
                        }
                    }
                    else
                    {
                        if (paneKey.IncludesTransitionGroup(nodeGroup))
                        {
                            var nodeTrans = GraphChromatogram.GetDisplayTransitions(nodeGroup, displayType).ToArray();
                            for (int i = 0; i < pointListCount; i++)
                            {
                                var pointPairList = pointPairLists[i];
                                pointPairList.Add(i >= nodeTrans.Length
                                                      ? CreatePointPairMissing(iGroup)
                                                      : CreatePointPair(iGroup, nodeTrans[i], ref groupMaxY,
                                                                        ref groupMinY,
                                                                        resultIndex));
                            }
                        }
                        else
                        {
                            for (int i = 0; i < pointListCount; i++)
                            {
                                pointPairLists[i].Add(CreatePointPairMissing(iGroup));
                            }
                        }
                    }
                    // ReSharper restore DoNotCallOverridableMethodsInConstructor

                    // Save the selected index and its y extent
                    if (ReferenceEquals(selectedGroup, nodeGroup))
                    {
                        selectedIndex = labels.Count - 1;
                        SelectedMaxY = groupMaxY;
                        SelectedMinY = groupMinY;
                    }
                        // If multiple groups in the selection, make sure y extent is max of them
                    else if (selectedIndex == labels.Count - 1)
                    {
                        SelectedMaxY = Math.Max(groupMaxY, SelectedMaxY);
                        SelectedMinY = Math.Min(groupMinY, SelectedMinY);
                    }
                    maxY = Math.Max(maxY, groupMaxY);
                    minY = Math.Min(minY, groupMinY);
                }

                PointPairLists = pointPairLists;
                Labels = labels.ToArray();
                XScalePaths = xscalePaths.ToArray();
                SelectedIndex = selectedIndex;
                MaxY = maxY;
                if (minY != double.MaxValue)
                    MinY = minY;
            }