예제 #1
0
        /// <summary>
        /// Generate the annotation of a proteoform sequence as a substring of a protein sequence.
        /// </summary>
        /// <param name="sequence">The proteoform sequence.</param>
        /// <param name="proteinSequence">The protein sequence.</param>
        /// <param name="modLocations">The locations of modifications in the proteoform sequence.</param>
        private void GenerateAnnotation(Sequence sequence, Sequence proteinSequence, string modLocations)
        {
            var cleanSequenceStr   = sequence.Aggregate(string.Empty, (current, aa) => current + aa.Residue);
            var proteinSequenceStr = proteinSequence.Aggregate(string.Empty, (current, aa) => current + aa.Residue);

            var prevResidueIndex = -1;
            var nextResidueIndex = sequence.Count;

            var index = proteinSequenceStr.IndexOf(cleanSequenceStr, StringComparison.Ordinal);

            if (index >= 0)
            {
                if (index > 0)
                {
                    prevResidueIndex = index - 1;
                }

                if (index < proteinSequenceStr.Length - 1)
                {
                    nextResidueIndex = index + cleanSequenceStr.Length;
                }
            }

            var labelBuilder = new StringBuilder();

            if (prevResidueIndex >= 0)
            {
                labelBuilder.AppendFormat("{0}{1}.", proteinSequenceStr[prevResidueIndex], prevResidueIndex);
                PreSequence = proteinSequenceStr.Substring(0, prevResidueIndex + 1);
            }

            labelBuilder.AppendFormat("({0})", modLocations.Length == 0 ? (cleanSequenceStr.Length < 30 ? cleanSequenceStr : "...") : modLocations);

            if (nextResidueIndex < proteinSequenceStr.Length)
            {
                labelBuilder.AppendFormat(".{0}{1}", proteinSequenceStr[nextResidueIndex], nextResidueIndex);
                PostSequence = proteinSequenceStr.Substring(nextResidueIndex);
            }

            Annotation = labelBuilder.ToString();
        }
예제 #2
0
        /// <summary>
        /// Get precursor ion.
        /// </summary>
        /// <param name="sequence">Sequence for precursor ion.</param>
        /// <param name="charge">Charge state of precursor ion.</param>
        /// <returns>The precursor ion for the sequence and charge state..</returns>
        public static Ion GetPrecursorIon(Sequence sequence, int charge)
        {
            var composition = sequence.Aggregate(Composition.H2O, (current, aa) => current + aa.Composition);

            return(new Ion(composition, charge));
        }