Example #1
0
 public TransitionLossKey(TransitionGroupDocNode parent, TransitionDocNode transition, TransitionLosses losses)
 {
     Transition = transition.Transition;
     Losses = losses;
     if (Transition.IsCustom())
     {
         if (!string.IsNullOrEmpty(transition.PrimaryCustomIonEquivalenceKey))
             CustomIonEquivalenceTestValue = transition.PrimaryCustomIonEquivalenceKey;
         else if (!string.IsNullOrEmpty(transition.SecondaryCustomIonEquivalenceKey))
             CustomIonEquivalenceTestValue = transition.SecondaryCustomIonEquivalenceKey;
         else if (Transition.IsNonReporterCustomIon())
             CustomIonEquivalenceTestValue = "_mzSortIndex_" + parent.Children.IndexOf(transition); // Not L10N
         else
             CustomIonEquivalenceTestValue = null;
     }
     else
     {
        CustomIonEquivalenceTestValue = null;
     }
 }
Example #2
0
        public static int CalcProductCharge(double productPrecursorMass,
            int precursorCharge,
            double[,] productMasses,
            IList<IList<ExplicitLoss>> potentialLosses,
            double productMz,
            double tolerance,
            MassType massType,
            MassShiftType massShiftType,
            out IonType? ionType,
            out int? ordinal,
            out TransitionLosses losses,
            out int massShift)
        {
            // Get length of fragment ion mass array
            int len = productMasses.GetLength(1);

            // Check all possible ion types and offsets
            double minDelta = double.MaxValue, minDeltaNs = double.MaxValue;
            int bestCharge = 0, bestChargeNs = 0;
            IonType? bestIonType = null, bestIonTypeNs = null;
            int? bestOrdinal = null, bestOrdinalNs = null;
            TransitionLosses bestLosses = null, bestLossesNs = null;
            int bestMassShift = 0;

            // Check to see if it is the precursor
            foreach (var lossesTrial in TransitionGroup.CalcTransitionLosses(IonType.precursor, 0, massType, potentialLosses))
            {
                double productMass = productPrecursorMass - (lossesTrial != null ? lossesTrial.Mass : 0);
                int potentialMassShift;
                int nearestCharge;
                int? charge = CalcProductCharge(productMass, productMz, tolerance, false, precursorCharge,
                                               massShiftType, out potentialMassShift, out nearestCharge);
                if (charge.HasValue && charge.Value == precursorCharge)
                {
                    double potentialMz = SequenceMassCalc.GetMZ(productMass, charge.Value) + potentialMassShift;
                    double delta = Math.Abs(productMz - potentialMz);

                    if (potentialMassShift == 0 && minDeltaNs > delta)
                    {
                        bestChargeNs = charge.Value;
                        bestIonTypeNs = IonType.precursor;
                        bestOrdinalNs = len + 1;
                        bestLossesNs = lossesTrial;

                        minDeltaNs = delta;
                    }
                    else if (potentialMassShift != 0 && minDelta > delta)
                    {
                        bestCharge = charge.Value;
                        bestIonType = IonType.precursor;
                        bestOrdinal = len + 1;
                        bestLosses = lossesTrial;
                        bestMassShift = potentialMassShift;

                        minDelta = delta;
                    }
                }
            }

            foreach (IonType type in Transition.ALL_TYPES)
            {
                // Types have priorities.  If moving to a lower priority type, and there is already a
                // suitable answer stop looking.
                if ((type == Transition.ALL_TYPES[2] || type == Transition.ALL_TYPES[2]) &&
                        (MatchMz(minDelta, tolerance) || MatchMz(minDeltaNs, tolerance)))
                    break;

                for (int offset = 0; offset < len; offset++)
                {
                    foreach (var lossesTrial in TransitionGroup.CalcTransitionLosses(type, offset, massType, potentialLosses))
                    {
                        // Look for the closest match.
                        double productMass = productMasses[(int) type, offset];
                        if (lossesTrial != null)
                            productMass -= lossesTrial.Mass;
                        int potentialMassShift;
                        int nearestCharge;
                        int? chargeFound = CalcProductCharge(productMass, productMz, tolerance, false, precursorCharge,
                                                       massShiftType, out potentialMassShift, out nearestCharge);
                        if (chargeFound.HasValue)
                        {
                            int charge = chargeFound.Value;
                            double potentialMz = SequenceMassCalc.GetMZ(productMass, charge) + potentialMassShift;
                            double delta = Math.Abs(productMz - potentialMz);
                            if (potentialMassShift == 0 && minDeltaNs > delta)
                            {
                                bestChargeNs = charge;
                                bestIonTypeNs = type;
                                // The peptide length is 1 longer than the mass array
                                bestOrdinalNs = Transition.OffsetToOrdinal(type, offset, len + 1);
                                bestLossesNs = lossesTrial;

                                minDeltaNs = delta;
                            }
                            else if (potentialMassShift != 0 && minDelta > delta)
                            {
                                bestCharge = charge;
                                bestIonType = type;
                                // The peptide length is 1 longer than the mass array
                                bestOrdinal = Transition.OffsetToOrdinal(type, offset, len + 1);
                                bestLosses = lossesTrial;
                                bestMassShift = potentialMassShift;

                                minDelta = delta;
                            }
                        }
                    }
                }
            }

            // Pefer no-shift to shift, even if the shift value is closer
            if (MatchMz(minDelta, tolerance) && !MatchMz(minDeltaNs, tolerance))
            {
                ionType = bestIonType;
                ordinal = bestOrdinal;
                losses = bestLosses;
                massShift = bestMassShift;
                return bestCharge;
            }

            ionType = bestIonTypeNs;
            ordinal = bestOrdinalNs;
            losses = bestLossesNs;
            massShift = 0;
            return bestChargeNs;
        }
Example #3
0
 public static double CalcMass(double massH, TransitionLosses losses)
 {
     return massH - (losses != null ? losses.Mass : 0);
 }
Example #4
0
 /// <summary>
 /// In the case of small molecule transitions specified by mass only, position within 
 /// the parent's list of transitions is the only meaningful key.  So we need to know our parent.
 /// </summary>
 public TransitionLossEquivalentKey(TransitionGroupDocNode parent, TransitionDocNode transition, TransitionLosses losses)
 {
     Key = new TransitionEquivalentKey(parent, transition);
     Losses = losses;
 }
Example #5
0
 /// <summary>
 /// From a transition loss perspective, losses with equall masses
 /// are equal.  It is not necessary to compare the exact losses.
 /// </summary>
 public bool Equals(TransitionLosses other)
 {
     if (ReferenceEquals(null, other)) return false;
     if (ReferenceEquals(this, other)) return true;
     return other.Mass == Mass;
 }
Example #6
0
 private string GetLabel(IonType type, int ordinal, TransitionLosses losses, int charge, double mz, int rank, bool showMz)
 {
     var label = new StringBuilder(type.GetLocalizedString());
     if (!Transition.IsPrecursor(type))
         label.Append(ordinal.ToString(LocalizationHelper.CurrentCulture));
     if (losses != null)
     {
         label.Append(" -"); // Not L10N
         label.Append(Math.Round(losses.Mass, 1));
     }
     string chargeIndicator = (charge == 1 ? string.Empty : Transition.GetChargeIndicator(charge));
     label.Append(chargeIndicator);
     if (showMz)
         label.Append(string.Format(" = {0:F01}", mz)); // Not L10N
     if (rank > 0 && ShowRanks)
         label.Append(TextUtil.SEPARATOR_SPACE).Append(string.Format("({0})",string.Format(Resources.AbstractSpectrumGraphItem_GetLabel_rank__0__, rank))); // Not L10N
     return label.ToString();
 }
Example #7
0
 public TransitionKey(TransitionKey key, IsotopeLabelType labelType)
 {
     _ionType = key._ionType;
     _customIonEquivalenceTestValue = key._customIonEquivalenceTestValue;
     _ionOrdinal = key._ionOrdinal;
     _massIndex = key._massIndex;
     _decoyMassShift = key._decoyMassShift;
     _charge = key._charge;
     _precursorCharge = key._precursorCharge;
     _losses = key._losses;
     _labelType = labelType;
 }
Example #8
0
 public TransitionKey(TransitionGroupDocNode nodeGroup, TransitionLossKey tranLossKey, IsotopeLabelType labelType)
 {
     var transition = tranLossKey.Transition;
     _ionType = transition.IonType;
     _customIonEquivalenceTestValue = tranLossKey.CustomIonEquivalenceTestValue;
     _ionOrdinal = transition.Ordinal;
     _massIndex = transition.MassIndex;
     _decoyMassShift = transition.DecoyMassShift;
     _charge = transition.Charge;
     _precursorCharge = nodeGroup.TransitionGroup.PrecursorCharge;
     _losses = tranLossKey.Losses;
     _labelType = labelType;
 }
Example #9
0
 public ProductExp(int productCharge, IonType ionType, int fragmentOrdinal, TransitionLosses losses, int massShift)
 {
     Charge = productCharge;
     IonType = ionType;
     FragmentOrdinal = fragmentOrdinal;
     Losses = losses;
     MassShift = null;
     if (massShift != 0)
         MassShift = massShift;
 }