public void Output(List<IonTypePeak> pkl, IonType ionType)
 {
   Console.WriteLine("Assert.AreEqual({0}, pkl.Count);", pkl.Count);
   for (int i = 0; i < pkl.Count; i++)
   {
     Console.WriteLine(MyConvert.Format("AssertPeak(pkl[{0}], IonType.{1}, {2}, {3:0.0000});", i, ionType.ToString(), i + 1, pkl[i].Mz));      
   }
 }
Esempio n. 2
0
        public FragmentIon(PepV01 peptide, IonType type, int offset, double mh)
        {
            _peptide = peptide;

            IType          = type;
            CleavageOffset = offset;
            MassH          = new TypedMass(mh, MassType.MonoisotopicMassH);

            // Derived values
            if (IsNTerminal())
            {
                Ordinal = offset + 1;
                AA      = peptide.Target.Sequence[offset];
            }
            else
            {
                Ordinal = _peptide.Length - offset - 1;
                AA      = peptide.Target.Sequence[offset + 1];
            }
        }
Esempio n. 3
0
        private static int InitialSize(IonType type)
        {
            switch (type)
            {
            case IonType.List:
                return(1);

            case IonType.Sexp:
                return(4);

            case IonType.Struct:
                return(5);

            case IonType.Datagram:
                return(3);

            default:
                return(4);
            }
        }
Esempio n. 4
0
        public void StepIn(IonType type)
        {
            if (!type.IsContainer())
            {
                throw new IonException($"Cannot step into {type}");
            }

            PrepareValue();
            //wrapup the current writes

            if (_containerStack.Count > 0)
            {
                var writeList = _dataBuffer.Wrapup();
                Debug.Assert(ReferenceEquals(writeList, _containerStack.Peek().Sequence));
            }

            var pushedContainer = _containerStack.PushContainer(type == IonType.Struct ? ContainerType.Struct : ContainerType.Sequence);

            _dataBuffer.StartStreak(pushedContainer.Sequence);
        }
Esempio n. 5
0
        public FragmentIon(PepV01 peptide, IonType type, int offset, double mh)
        {
            _peptide = peptide;

            IType          = type;
            CleavageOffset = offset;
            MassH          = mh;

            // Derived values
            if (IsNTerminal())
            {
                Ordinal = offset + 1;
                AA      = peptide.Sequence[offset];
            }
            else
            {
                Ordinal = _peptide.Length - offset - 1;
                AA      = peptide.Sequence[offset + 1];
            }
        }
Esempio n. 6
0
        public Transition(TransitionGroup group, IonType type, int?offset, int?massIndex, Adduct adduct, int?decoyMassShift, CustomMolecule customMolecule = null)
        {
            _group = group;

            IonType        = type;
            CleavageOffset = offset ?? 0;
            MassIndex      = massIndex ?? 0;
            Adduct         = adduct;
            DecoyMassShift = decoyMassShift;
            // Small molecule precursor transition should have same custom molecule as parent
            if (IsPrecursor(type) && group.IsCustomIon)
            {
                CustomIon = new CustomIon(group.CustomMolecule, adduct);
            }
            else if (customMolecule is CustomIon)
            {
                // As with reporter ions
                CustomIon = (CustomIon)customMolecule;
                Assume.IsTrue(Equals(adduct.AdductCharge, CustomIon.Adduct.AdductCharge));
                Adduct = CustomIon.Adduct; // Ion mass is part of formula, so use charge only adduct
            }
            else if (customMolecule != null)
            {
                CustomIon = new CustomIon(customMolecule, adduct);
            }
            // Derived values
            if (!IsCustom(type, group))
            {
                Peptide peptide = group.Peptide;
                Ordinal = OffsetToOrdinal(type, (int)offset, peptide.Length);
                AA      = (IsNTerminal()
                    ? peptide.Sequence[(int)offset]
                    : peptide.Sequence[(int)offset + 1]);
            }
            else
            {
                // caller may have passed in offset = group.Peptide.Length - 1, which for custom ions gives -1
                CleavageOffset = 0;
            }
            Validate();
        }
Esempio n. 7
0
        private (byte, byte[]) ScalarOrNullSplitParts(IonType type, SymbolToken?symbolToken, bool isNull, byte[] bytes)
        {
            int offset = this.GetLengthLength(bytes) + 1;

            if (type == IonType.Int && bytes.Length > offset)
            {
                // ignore sign byte prepended by BigInteger.toByteArray() when the magnitude
                // ends at byte boundary (the 'intLength512' test is an example of this)
                if ((bytes[offset] & 0xFF) == 0)
                {
                    offset++;
                }
            }

            // the representation is everything after TL (first byte) and length
            byte[] representation = bytes.Skip(offset).ToArray();
            byte   tq             = bytes[0];

            if (type == IonType.Symbol)
            {
                // symbols are serialized as strings; use the correct TQ:
                tq = 0x70;
                if (isNull)
                {
                    tq |= 0x0F;
                }
                else if (symbolToken != null && symbolToken.Value.Text == null && symbolToken.Value.Sid == 0)
                {
                    tq = 0x71;
                }
            }

            // not a bool, symbol, or null value
            if (type != IonType.Bool && type != IonType.Symbol && (tq & 0x0F) != 0x0F)
            {
                // zero - out the L nibble
                tq &= 0xF0;
            }

            return(tq, representation);
        }
Esempio n. 8
0
        public void CheckIonType(IonType type, bool check, bool visible)
        {
            var set = Settings.Default;

            switch (type)
            {
            case IonType.a: set.ShowAIons = aMenuItem.Checked = check; aMenuItem.Visible = visible; break;

            case IonType.b: set.ShowBIons = bMenuItem.Checked = check; bMenuItem.Visible = visible; break;

            case IonType.c: set.ShowCIons = cMenuItem.Checked = check; cMenuItem.Visible = visible; break;

            case IonType.x: set.ShowXIons = xMenuItem.Checked = check; xMenuItem.Visible = visible; break;

            case IonType.y: set.ShowYIons = yMenuItem.Checked = check; yMenuItem.Visible = visible; break;

            case IonType.z: set.ShowZIons = zMenuItem.Checked = check; zMenuItem.Visible = visible; break;

            case IonType.custom: set.ShowFragmentIons = fragmentsMenuItem.Checked = check; fragmentsMenuItem.Visible = visible; break;
            }
        }
Esempio n. 9
0
        public void StepIn(IonType type)
        {
            this.ThrowIfDisposed();
            if (!type.IsContainer())
            {
                throw new IonException($"Cannot step into {type}");
            }

            this.PrepareValue();

            // Wrapup the current writes
            if (this.containerStack.Count > 0)
            {
                var writeList = this.dataBuffer.Wrapup();
                Debug.Assert(ReferenceEquals(writeList, this.containerStack.Peek().Sequence), "writeList does not equal Sequence");
            }

            var pushedContainer = this.containerStack.PushContainer(this.GetContainerType(type));

            this.dataBuffer.StartStreak(pushedContainer.Sequence);
        }
Esempio n. 10
0
            public MockTranPeakData(double[] data,
                                    IonType ionType            = IonType.a,
                                    IsotopeLabelType labelType = null,
                                    int charge               = 2,
                                    double?massError         = null,
                                    double libIntensity      = 0,
                                    double?isotopeProportion = null)
            {
                if (labelType == null)
                {
                    labelType = IsotopeLabelType.light;
                }
                PeakData = new MockPeakData(data, massError) as TPeak;
                var peptide     = new Peptide(null, "AVVAVVA", null, null, 0);
                var tranGroup   = new TransitionGroup(peptide, null, charge, labelType);
                int offset      = ionType == IonType.precursor ? 6 : 0;
                var isotopeInfo = isotopeProportion == null ? null : new TransitionIsotopeDistInfo(1, (float)isotopeProportion);

                NodeTran = new TransitionDocNode(new Transition(tranGroup, ionType, offset, 0, charge, null),
                                                 null, 0, isotopeInfo, new TransitionLibInfo(1, (float)libIntensity));
            }
Esempio n. 11
0
 private bool ApplyRanking(RankParams rp, IonType type, int offset, TransitionLosses losses, Adduct adduct, bool filter,
                           int start, int end, double startMz, double ionMz)
 {
     // Avoid ranking precursor ions without losses, if the precursor isotopes will
     // not be taken from product ions
     if (!rp.excludePrecursorIsotopes || type != IonType.precursor || losses != null)
     {
         if (!filter || rp.tranSettings.Accept(rp.sequence, rp.precursorMz, type, offset, ionMz, start, end, startMz))
         {
             if (!rp.matchAll || (rp.minMz <= ionMz && ionMz <= rp.maxMz &&
                                  rp.rankTypes.Contains(type) &&
                                  (!rp.rankLimit.HasValue || rp.Ranked < rp.rankLimit) &&
                                  (rp.rankCharges.Contains(Math.Abs(adduct.AdductCharge)) || type == IonType.precursor))) // CONSIDER(bspratt) we may eventually want adduct-level control for small molecules, not just abs charge
             {
                 Rank = rp.RankNext();
                 return(true);
             }
         }
     }
     return(false);
 }
Esempio n. 12
0
        /// <summary>
        /// Calculate the transition losses that apply to a transition with
        /// a specific type and cleavage offset for a single set of explicit losses.
        /// </summary>
        private static TransitionLosses CalcTransitionLosses(IonType type, int cleavageOffset,
                                                             MassType massType, IList <ExplicitLoss> losses)
        {
            List <TransitionLoss> listLosses = null;

            for (int i = 0; i < losses.Count; i++)
            {
                var loss = losses[i];
                switch (type)
                {
                case IonType.a:
                case IonType.b:
                case IonType.c:
                    if (loss.IndexAA > cleavageOffset)
                    {
                        continue;
                    }
                    break;

                case IonType.x:
                case IonType.y:
                case IonType.z:
                    if (loss.IndexAA <= cleavageOffset)
                    {
                        continue;
                    }
                    break;
                }
                if (listLosses == null)
                {
                    listLosses = new List <TransitionLoss>();
                }
                listLosses.Add(loss.TransitionLoss);
            }
            if (listLosses == null)
            {
                return(null);
            }
            return(new TransitionLosses(listLosses, massType));
        }
Esempio n. 13
0
        /// <summary>
        /// Partition data by ion type.
        /// Reduce the charge states to only one charge if <see cref="ShouldCombineChargeStates" /> is true.
        /// </summary>
        /// <param name="dataPoints">The data Points.</param>
        /// <param name="sequenceLength">The length of the sequence.</param>
        /// <returns>Peak data points partitioned by ion type.</returns>
        private Dictionary <IonType, PeakDataPoint[]> PartitionData(IEnumerable <PeakDataPoint> dataPoints, int sequenceLength)
        {
            var dataDict = new Dictionary <IonType, PeakDataPoint[]>();

            // partition data set by ion type
            foreach (var dataPoint in dataPoints)
            {
                var ionType = dataPoint.IonType;
                if (this.ShouldCombineChargeStates)
                {
                    ionType = new IonType(ionType.Name, ionType.OffsetComposition, 1, ionType.IsPrefixIon);
                }

                if (!dataDict.ContainsKey(ionType))
                {
                    dataDict.Add(ionType, new PeakDataPoint[sequenceLength]);
                }

                var points = dataDict[ionType];

                int index = dataPoint.Index - 1;

                if (!dataPoint.IonType.IsPrefixIon)
                {
                    index = sequenceLength - dataPoint.Index;
                }

                // If the ion type has multiple options, choose the best one.
                if (points[index] == null ||
                    double.IsNaN(points[index].Error) ||
                    (dataPoint.Y / Math.Abs(dataPoint.Error)) > (points[index].Y / Math.Abs(points[index].Error)))
                {
                    points[index] = dataPoint;
                }
            }

            return(dataDict);
        }
Esempio n. 14
0
        /// <summary>
        /// Calculate isotope ion labels for precursor.
        /// </summary>
        /// <param name="labelModifications">The heavy/light labels.</param>
        /// <returns>A list of precursor labeled ions.</returns>
        private ReactiveList <LabeledIonViewModel> GenerateIsotopePrecursorLabels(ReactiveList <SearchModification> labelModifications = null)
        {
            var ions = new ReactiveList <LabeledIonViewModel> {
                ChangeTrackingEnabled = true
            };

            if (this.SelectedPrSm.Sequence.Count == 0)
            {
                return(ions);
            }

            var sequence = this.SelectedPrSm.Sequence;

            if (labelModifications != null)
            {
                sequence = IonUtils.GetHeavySequence(sequence, labelModifications.ToArray());
            }

            #pragma warning disable 0618
            var precursorIonType = new IonType("Precursor", Composition.H2O, this.SelectedPrSm.Charge, false);
            #pragma warning restore 0618
            var composition         = sequence.Aggregate(Composition.Zero, (current, aa) => current + aa.Composition);
            var relativeIntensities = composition.GetIsotopomerEnvelope();
            var indices             = new List <int> {
                -1
            };
            for (int i = 0; i < relativeIntensities.Envelope.Length; i++)
            {
                if (relativeIntensities.Envelope[i] >= IcParameters.Instance.PrecursorRelativeIntensityThreshold ||
                    i == 0)
                {
                    indices.Add(i);
                }
            }

            ions.AddRange(indices.Select(index => new LabeledIonViewModel(composition, precursorIonType, false, this.lcms, null, false, index)));
            return(ions);
        }
Esempio n. 15
0
            public MockTranPeakData(double[] data,
                                    IonType ionType            = IonType.a,
                                    IsotopeLabelType labelType = null,
                                    int?charge               = null,
                                    double?massError         = null,
                                    double libIntensity      = 0,
                                    double?isotopeProportion = null)
            {
                if (labelType == null)
                {
                    labelType = IsotopeLabelType.light;
                }
                PeakData = new MockPeakData(data, massError) as TPeak;
                var peptide = new Peptide(null, "AVVAVVA", null, null, 0);

                charge = charge ?? 2;
                var tranGroup   = new TransitionGroup(peptide, Adduct.FromChargeProtonated(charge), labelType);
                int offset      = ionType == IonType.precursor ? 6 : 0;
                var isotopeInfo = isotopeProportion == null ? null : new TransitionIsotopeDistInfo(1, (float)isotopeProportion);

                NodeTran = new TransitionDocNode(new Transition(tranGroup, ionType, offset, 0, Adduct.FromChargeProtonated(charge), null),
                                                 null, TypedMass.ZERO_MONO_MASSH, new TransitionDocNode.TransitionQuantInfo(isotopeInfo, new TransitionLibInfo(1, (float)libIntensity), true));
            }
Esempio n. 16
0
        /// <summary>
        /// Get XICs for the ion.
        /// </summary>
        /// <param name="pointsToSmooth">Smoothing window width. </param>
        /// <param name="o">Object required for the cache.</param>
        /// <returns>The XICs for this ion</returns>
        private IList <XicDataPoint> GetXic(int pointsToSmooth, object o)
        {
            if (this.xic == null)
            {
                this.xic = this.GetXic();
            }

            var     x       = this.xic;
            IonType ionType = null;

            if (this.IsFragmentIon)
            {
                ionType = this.IonType;
            }

            // smooth
            if (pointsToSmooth > 2)
            {
                var smoother = new SavitzkyGolaySmoother(pointsToSmooth, 2);
                x = IonUtils.SmoothXic(smoother, x);
            }

            return(x.Where((t, i) => i <= 1 || i >= x.Count - 1 ||
                           !this.xic[i - 1].Intensity.Equals(t.Intensity) ||
                           !this.xic[i + 1].Intensity.Equals(t.Intensity))
                   .Select(
                       t => new XicDataPoint(
                           this.Lcms.GetElutionTime(t.ScanNum),
                           t.ScanNum,
                           t.Intensity,
                           this.Index,
                           this.Label)
            {
                IonType = ionType
            }).ToList());
        }
Esempio n. 17
0
 public static string GetLocalizedString(this IonType val)
 {
     return(LOCALIZED_VALUES[(int)val + 2]); // To include precursor and custom
 }
Esempio n. 18
0
 public static bool IsPeptideFragment(IonType type)
 {
     return(type >= IonType.a);
 }
Esempio n. 19
0
 public bool IsMatch(string sequence, IonType ionType, int cleavageOffset)
 {
     if (!IsFragment)
         return false;
     int ordinal = Transition.OffsetToOrdinal(ionType, cleavageOffset, sequence.Length);
     if (ordinal < MinFragmentLength)
         return false;
     char aaN = Transition.GetFragmentNTermAA(sequence, cleavageOffset);
     char aaC = Transition.GetFragmentCTermAA(sequence, cleavageOffset);
     // Make sure the specified amino acid is in the fragment set for this ion
     char aa = (IsNTerm() ? aaN : aaC);
     if (Fragment.IndexOf(aa) == -1)
         return false;
     // Make suer the adjacent amino acid is not in the restricted set for this ion
     aa = (IsNTerm() ? aaC : aaN);
     if (Restrict != null && Restrict.IndexOf(aa) != -1)
         return false;
     return true;
 }
Esempio n. 20
0
            private bool MatchNext(RankParams rp, IonType type, int offset, TransitionLosses losses, Adduct adduct, string fragmentName, int len, bool filter, int end, int start, double startMz)
            {
                bool isFragment = !Transition.IsPrecursor(type);
                var  ionMass    = isFragment ? rp.massesMatch[type, offset] : rp.massPreMatch;

                if (losses != null)
                {
                    ionMass -= losses.Mass;
                }
                double ionMz = SequenceMassCalc.GetMZ(ionMass, adduct);

                // Unless trying to match everything, stop looking outside the instrument range
                if (!rp.matchAll && !rp.HasLosses && ionMz > rp.maxMz)
                {
                    return(false);
                }
                // Check filter properties, if apropriate
                if ((rp.matchAll || ionMz >= rp.minMz) && Math.Abs(ionMz - ObservedMz) < rp.tolerance)
                {
                    // Make sure each m/z value is only used for the most intense peak
                    // that is within the tolerance range.
                    if (rp.IsSeen(ionMz))
                    {
                        return(true); // Keep looking
                    }
                    rp.Seen(ionMz);

                    int ordinal = Transition.OffsetToOrdinal(type, offset, len + 1);
                    // If this m/z aready matched a different ion, just remember the second ion.
                    var predictedMass = isFragment ? rp.massesPredict[type, offset] : rp.massPrePredict;
                    if (losses != null)
                    {
                        predictedMass -= losses.Mass;
                    }
                    double predictedMz = SequenceMassCalc.GetMZ(predictedMass, adduct);
                    if (MatchedIons != null)
                    {
                        // If first type was excluded from causing a ranking, but second does, then make it the first
                        // Otherwise, this can cause very mysterious failures to rank transitions that appear in the
                        // document.
                        var match = new MatchedFragmentIon(type, ordinal, adduct, fragmentName, losses, predictedMz);
                        if (Rank == 0 && ApplyRanking(rp, type, offset, losses, adduct, filter, start, end, startMz, ionMz))
                        {
                            MatchedIons.Insert(0, match);
                        }
                        else
                        {
                            MatchedIons.Add(match);
                        }
                        if (MatchedIons.Count < RankParams.MAX_MATCH)
                        {
                            return(true);
                        }

                        rp.matched = true;
                        return(false);
                    }

                    // Avoid using the same predicted m/z on two different peaks
                    if (predictedMz == ionMz || !rp.IsSeen(predictedMz))
                    {
                        rp.Seen(predictedMz);

                        ApplyRanking(rp, type, offset, losses, adduct, filter, start, end, startMz, ionMz);

                        MatchedIons = new List <MatchedFragmentIon> {
                            new MatchedFragmentIon(type, ordinal, adduct, fragmentName, losses, predictedMz)
                        };
                        rp.matched = !rp.matchAll;
                        return(rp.matchAll);
                    }
                }
                // Stop looking once the mass has been passed, unless there are losses to consider
                if (rp.HasLosses)
                {
                    return(true);
                }
                return(ionMz <= ObservedMz);
            }
Esempio n. 21
0
        private void ReadNullType(bool trailingWhitespace)
        {
            var kwt = trailingWhitespace ? TextConstants.KeywordNone : this.scanner.PeekNullTypeSymbol();

            switch (kwt)
            {
            case TextConstants.KeywordNull:
                this.valueType = IonType.Null;
                break;

            case TextConstants.KeywordBool:
                this.valueType = IonType.Bool;
                break;

            case TextConstants.KeywordInt:
                this.valueType = IonType.Int;
                break;

            case TextConstants.KeywordFloat:
                this.valueType = IonType.Float;
                break;

            case TextConstants.KeywordDecimal:
                this.valueType = IonType.Decimal;
                break;

            case TextConstants.KeywordTimestamp:
                this.valueType = IonType.Timestamp;
                break;

            case TextConstants.KeywordSymbol:
                this.valueType = IonType.Symbol;
                break;

            case TextConstants.KeywordString:
                this.valueType = IonType.String;
                break;

            case TextConstants.KeywordBlob:
                this.valueType = IonType.Blob;
                break;

            case TextConstants.KeywordClob:
                this.valueType = IonType.Clob;
                break;

            case TextConstants.KeywordList:
                this.valueType = IonType.List;
                break;

            case TextConstants.KeywordSexp:
                this.valueType = IonType.Sexp;
                break;

            case TextConstants.KeywordStruct:
                this.valueType = IonType.Struct;
                break;

            case TextConstants.KeywordNone:
                this.valueType = IonType.Null;
                break;     // this happens when there isn't a '.' otherwise peek

            // throws the error or returns none
            default:
                throw new IonException($"invalid keyword id ({kwt}) encountered while parsing a null");
            }

            // at this point we've consumed a dot '.' and it's preceding
            // whitespace
            // clear_value();
            this.valueVariant.SetNull(this.valueType);
        }
Esempio n. 22
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;
        }
Esempio n. 23
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;
 }
Esempio n. 24
0
 public static bool IsCustom(IonType type, TransitionGroup parent)
 {
     return type == IonType.custom || (type == IonType.precursor && parent.IsCustomIon);
 }
Esempio n. 25
0
 public static bool IsCTerminal(IonType type)
 {
     return type == IonType.x || type == IonType.y || type == IonType.z;
 }
Esempio n. 26
0
        public Transition(TransitionGroup group, IonType type, int? offset, int? massIndex, int charge, int? decoyMassShift, CustomIon customIon = null)
        {
            _group = group;

            IonType = type;
            CleavageOffset = offset ?? 0;
            MassIndex = massIndex ?? 0;
            Charge = charge;
            DecoyMassShift = decoyMassShift;
            // Small molecule precursor transition should have same custom ion as parent
            if (IsPrecursor(type) && group.IsCustomIon)
                CustomIon = group.CustomIon;
            else
                CustomIon = customIon;
            // Derived values
            if (!IsCustom(type, group))
            {
                Peptide peptide = group.Peptide;
                Ordinal = OffsetToOrdinal(type, (int)offset, peptide.Length);
                AA = (IsNTerminal()
                    ? peptide.Sequence[(int)offset]
                    : peptide.Sequence[(int)offset + 1]);
            }
            else
            {
                // caller may have passed in offset = group.Peptide.Length - 1, which for custom ions gives -1
                CleavageOffset = 0;
            }
            Validate();
        }
Esempio n. 27
0
 public Transition(TransitionGroup group, int charge, int? massIndex, CustomIon customIon, IonType type=IonType.custom)
     : this(group, type, null, massIndex, charge, null, customIon)
 {
 }
Esempio n. 28
0
 public Transition(TransitionGroup group, IonType type, int offset, int massIndex, int charge)
     : this(group, type, offset, massIndex, charge, null)
 {
 }
Esempio n. 29
0
 private bool IsVisibleIon(IonType type, int ordinal, int charge)
 {
     // Show precursor ions when they are supposed to be shown, regardless of charge
     return ordinal > 0 && ShowTypes.Contains(type) && (type == IonType.precursor || ShowCharges.Contains(charge));
 }
Esempio n. 30
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();
 }
Esempio n. 31
0
        private double GetTermMass(IonType type, ExplicitSequenceMods mods)
        {
            var modMasses = GetModMasses(mods);

            switch (type)
            {
                case IonType.a: return _massDiffA + modMasses._massModCleaveN;
                case IonType.b: return _massDiffB + modMasses._massModCleaveN;
                case IonType.c: return _massDiffC + modMasses._massModCleaveN;
                case IonType.x: return _massDiffX + modMasses._massModCleaveC;
                case IonType.y: return _massDiffY + modMasses._massModCleaveC;
                case IonType.z: return _massDiffZ + modMasses._massModCleaveC;
                default:
                    throw new ArgumentException("Invalid ion type"); // Not L10N
            }
        }
 public override void StepIn(IonType type)
 {
     // TODO implement top-level symbol table
     _userWriter.StepIn(type);
 }
Esempio n. 33
0
 private void CheckIonType(IonType type, bool check)
 {
     var set = Settings.Default;
     switch (type)
     {
         case IonType.a: set.ShowAIons = aMenuItem.Checked = check; break;
         case IonType.b: set.ShowBIons = bMenuItem.Checked = check; break;
         case IonType.c: set.ShowCIons = cMenuItem.Checked = check; break;
         case IonType.x: set.ShowXIons = xMenuItem.Checked = check; break;
         case IonType.y: set.ShowYIons = yMenuItem.Checked = check; break;
         case IonType.z: set.ShowZIons = zMenuItem.Checked = check; break;
     }
 }
Esempio n. 34
0
 public static bool IsCTerminal(IonType type)
 {
     return type == IonType.X || type == IonType.Y || type == IonType.Z;
 }
        private static CellDesc CreateIon(IonType type, int ordinal, double massH, int charge,
            IEnumerable<DocNode> choices, ICollection<DocNode> chosen, Transition tranSelected,
            RenderTools rt)
        {
            double mz = SequenceMassCalc.GetMZ(massH, charge);
            CellDesc cell = CreateData(string.Format("{0:F02}", mz), rt); // Not L10N

            foreach (TransitionDocNode nodeTran in choices)
            {
                Transition tran = nodeTran.Transition;
                if (tran.IonType == type &&
                    tran.Ordinal == ordinal &&
                    tran.Charge == charge)
                {
                    cell.Font = rt.FontBold;
                    if (Equals(tran, tranSelected))
                    {
                        cell.Brush = rt.BrushSelected; // Stop after selected
                        break;
                    }
                    if (!chosen.Contains(nodeTran))
                        cell.Brush = rt.BrushChoice;  // Keep looking
                    else
                    {
                        cell.Brush = rt.BrushChosen;  // Stop after chosen
                        break;
                    }
                }
            }

            return cell;
        }
Esempio n. 36
0
        public static int OrdinalToOffset(IonType type, int ordinal, int len)
        {
            if (IsNTerminal(type))
                return ordinal - 1;

            return len - ordinal - 1;
        }
        /// <summary>
        /// 根据给定参数获取相应的b/y系列理论中性丢失离子列表
        /// </summary>
        /// <param name="theoreticalPeaks"></param>
        /// <param name="ionType"></param>
        /// <param name="charge"></param>
        /// <param name="phosphoAminoacidsMap"></param>
        /// <param name="canLossWater"></param>
        /// <param name="canLossAmmonia"></param>
        /// <returns></returns>
        public List <MatchedPeak> GetPhosphoNeutralLossPeaks(List <MatchedPeak> theoreticalPeaks, IonType ionType, int charge, Dictionary <int, string> phosphoAminoacidsMap, bool[] canLossWater, bool[] canLossAmmonia)
        {
            List <MatchedPeak> result = new List <MatchedPeak>();

            for (int i = 0; i < theoreticalPeaks.Count; i++)
            {
                string phosphoAminoacids = phosphoAminoacidsMap[i];

                if (phosphoAminoacids == null || phosphoAminoacids.Length == 0)
                {
                    continue;
                }

                List <INeutralLossType> nlCandidates = GetPhosphoNeutralLossTypes(phosphoAminoacids, canLossWater[i], canLossAmmonia[i]);

                result.AddRange(GetNeutralLossPeaks(ionType, theoreticalPeaks[i], nlCandidates, (m => m.IsPhosphoNeutralLossType())));
            }

            return(result);
        }
Esempio n. 38
0
 public static bool IsCTerminal(IonType type)
 {
     return(type == IonType.x || type == IonType.y || type == IonType.z);
 }
Esempio n. 39
0
 public static bool IsNTerminal(IonType type)
 {
     return type == IonType.a || type == IonType.b || type == IonType.c || type == IonType.precursor;
 }
Esempio n. 40
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;
 }
 public override void WriteNull(IonType type)
 {
     _userWriter.WriteNull(type);
 }
Esempio n. 42
0
 public static bool IsPrecursor(IonType type)
 {
     return type == IonType.precursor;
 }
Esempio n. 43
0
        public FragmentIon(PepV01 peptide, IonType type, int offset, double mh)
        {
            _peptide = peptide;

            IType = type;
            CleavageOffset = offset;
            MassH = mh;

            // Derived values
            if (IsNTerminal())
            {
                Ordinal = offset + 1;
                AA = peptide.Sequence[offset];
            }
            else
            {
                Ordinal = _peptide.Length - offset - 1;
                AA = peptide.Sequence[offset + 1];
            }
        }
Esempio n. 44
0
 public static int OffsetToOrdinal(IonType type, int offset, int len)
 {
     if (IsNTerminal(type))
         return offset + 1;
     else
         return len - offset - 1;
 }
Esempio n. 45
0
 public static bool IsNTerminal(IonType type)
 {
     return type == IonType.A || type == IonType.B || type == IonType.C;
 }
Esempio n. 46
0
 public static IonType GetEnum(string enumValue, IonType defaultValue)
 {
     return Helpers.EnumFromLocalizedString(enumValue, LOCALIZED_VALUES, defaultValue);
 }
Esempio n. 47
0
 public static bool IsNTerminal(IonType type)
 {
     return(type == IonType.a || type == IonType.b || type == IonType.c || type == IonType.precursor);
 }
Esempio n. 48
0
 public Transition(TransitionGroup group, Adduct charge, int?massIndex, CustomMolecule customMolecule, IonType type = IonType.custom)
     : this(group, type, null, massIndex, charge, null, customMolecule)
 {
 }
Esempio n. 49
0
 public static bool IsPrecursor(IonType type)
 {
     return(type == IonType.precursor);
 }
Esempio n. 50
0
 public static IonType GetEnum(string enumValue, IonType defaultValue)
 {
     return(Helpers.EnumFromLocalizedString(enumValue, LOCALIZED_VALUES, defaultValue));
 }
Esempio n. 51
0
 public static bool IsCustom(IonType type, TransitionGroup parent)
 {
     return(type == IonType.custom || (type == IonType.precursor && parent.IsCustomIon));
 }
Esempio n. 52
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;
 }
Esempio n. 53
0
 public Transition(TransitionGroup group, IonType type, int offset, int massIndex, Adduct charge)
     : this(group, type, offset, massIndex, charge, null)
 {
 }
Esempio n. 54
0
        private double GetFragmentMass(string seq,
                                       IonType type,
                                       int ordinal,
                                       int? decoyMassShift,
                                       int massIndex,
                                       IsotopeDistInfo isotopeDists,
                                       ExplicitSequenceMods mods)
        {
            if (Transition.IsPrecursor(type))
            {
                if (isotopeDists != null)
                {
                    int i = isotopeDists.MassIndexToPeakIndex(massIndex);
                    if (0 > i || i >= isotopeDists.CountPeaks)
                    {
                        throw new IndexOutOfRangeException(
                            string.Format(Resources.SequenceMassCalc_GetFragmentMass_Precursor_isotope__0__is_outside_the_isotope_distribution__1__to__2__,
                                          GetMassIDescripion(massIndex), isotopeDists.PeakIndexToMassIndex(0),
                                          isotopeDists.PeakIndexToMassIndex(isotopeDists.CountPeaks - 1)));
                    }
                    return isotopeDists.GetMassI(massIndex, decoyMassShift);
                }
                return GetPrecursorMass(seq, mods);                
            }

            int len = seq.Length - 1;

            bool nterm = Transition.IsNTerminal(type);
            double mass = GetTermMass(nterm ? IonType.b : IonType.y, mods) + BioMassCalc.MassProton;

            int iA = (nterm ? 0 : len);
            int inc = (nterm ? 1 : -1);

            var modMasses = GetModMasses(mods);

            mass += (nterm ? modMasses._aminoNTermModMasses[seq[iA]] : modMasses._aminoCTermModMasses[seq[iA]]);

            for (int i = 0; i < ordinal; i++)
            {
                char aa = seq[iA];
                mass += _aminoMasses[aa] + modMasses._aminoModMasses[aa];
                if (mods != null && iA < mods.ModMasses.Count)
                    mass += mods.ModMasses[iA];
                iA += inc;
            }

            mass += GetTermDeltaMass(type);    // Exactly match GetFragmentIonMasses()

            return mass;
        }
Esempio n. 55
0
 private double GetTermDeltaMass(IonType type)
 {
     switch (type)
     {
         case IonType.a: return _massDiffA - _massDiffB;
         case IonType.b: return 0;
         case IonType.c: return _massDiffC - _massDiffB;
         case IonType.x: return _massDiffX - _massDiffY;
         case IonType.y: return 0;
         case IonType.z: return _massDiffZ - _massDiffY;
         default:
             throw new ArgumentException("Invalid ion type"); // Not L10N
     }
 }
Esempio n. 56
0
 public static IEnumerable<double> GetFragmentMasses(IonType type, double[,] masses)
 {
     int col = (int) type;
     int len = masses.GetLength(1);
     if (Transition.IsNTerminal(type))
     {
         for (int i = 0; i < len; i++)
             yield return masses[col, i];
     }
     else
     {
         for (int i = len - 1; i >= 0; i--)
             yield return masses[col, i];
     }
 }
Esempio n. 57
0
        public static ModifiedSequence GetFragmentSequence(ModifiedSequence modifiedSequence, IonType ionType,
                                                           int ordinal)
        {
            string unmodifiedSequence = modifiedSequence.GetUnmodifiedSequence();

            switch (ionType)
            {
            case IonType.a:
            case IonType.b:
            case IonType.c:
                return(new ModifiedSequence(unmodifiedSequence.Substring(0, ordinal),
                                            modifiedSequence.GetModifications().Where(mod => mod.IndexAA < ordinal),
                                            MassType.Monoisotopic));
            }

            int    offset           = unmodifiedSequence.Length - ordinal;
            string fragmentSequence = unmodifiedSequence.Substring(offset);
            var    newModifications = modifiedSequence.GetModifications()
                                      .Where(mod => mod.IndexAA >= offset)
                                      .Select(mod => mod.ChangeIndexAa(mod.IndexAA - offset));

            return(new ModifiedSequence(fragmentSequence, newModifications, MassType.Monoisotopic));
        }
 public void AssertPeak(IonTypePeak peak, IonType ionType, int ionIndex, double mz)
 {
   Assert.AreEqual(ionType, peak.PeakType);
   Assert.AreEqual(ionIndex, peak.PeakIndex);
   Assert.AreEqual(mz, peak.Mz, 0.0001);
 }