예제 #1
0
        /// <summary>
        /// This function handle is called from both the fragmentladder and the dataview.
        /// This function handles the case when the user selects a peptide and scan number in dataview.
        /// </summary>
        /// <param name="ScanNumber">The scan number that relates to the experimental data.</param>
        /// <param name="Peptide">The peptide sequence.</param>
        public void HandleSelectScanAndPeptide(string ScanNumber, string Peptide)
        {
            DataLoaded = true;
            try
            {
                SpectrumLook.Views.FragmentLadderView.LadderInstanceBuilder ladderBuilder = new Views.FragmentLadderView.LadderInstanceBuilder();

                m_currentScanNumber = Convert.ToInt32(ScanNumber);
                m_currentPeptide    = Peptide;
                //use the builder director to crunch all the data
                List <Element> theoreticalList = m_builderDirector.BuildTheoryList(Peptide, m_isFragmentationModeETD, this.m_fragLadder.fragmentLadderOptions.modificationList);
                m_experimentalList = m_builderDirector.BuildActualList(Convert.ToInt32(ScanNumber), m_dataFileLocation);
                List <Element> comparedList = m_builderDirector.BuildComparedList(m_mainForm.m_currentOptions.toleranceValue, m_mainForm.m_currentOptions.lowerToleranceValue, m_experimentalList, PrecursorMZ, ref theoreticalList);

                //now give the data to the views to display
                //Send the FragmentLadder and the Plot the data to show
                if (m_ladderInstancesTable.ContainsKey(ScanNumber + Peptide))
                {
                    m_currentInstance = m_ladderInstancesTable[ScanNumber + Peptide][0];
                    m_fragLadder.generateLadderFromSelection(0.0, m_ladderInstancesTable[ScanNumber + Peptide]);
                }
                else
                {
                    List <LadderInstance> tempList     = new List <LadderInstance>();
                    LadderInstance        tempInstance = ladderBuilder.GenerateInstance(theoreticalList, Peptide, m_fragLadder.fragmentLadderOptions.modificationList);
                    tempInstance.scanAndPeptide = ScanNumber + "|" + Peptide;
                    tempList.Add(tempInstance);
                    m_ladderInstancesTable.Add(ScanNumber + Peptide, tempList);

                    m_currentInstance = m_ladderInstancesTable[ScanNumber + Peptide][0];
                    m_fragLadder.generateLadderFromSelection(0.0, m_ladderInstancesTable[ScanNumber + Peptide]);
                }
                m_plot.PlotData(comparedList, ScanNumber, Peptide);
                //m_experimentalList.Clear();
                //m_experimentalList = null;
            }
            catch (InvalidProgramException ex)
            {
                if (ex.Message.Contains("Invalid File Type"))
                {
                    MessageBox.Show("Invalid File Type for the Data file.  Only .mzXml, .mzData, and .raw types are allowed.", "File Type Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    throw ex;
                }
            }
        }
예제 #2
0
        /// <summary>
        /// This function handles recalculating all the ladder instances in the hashtable.
        /// This is normally called when the fragment ladder options change.
        /// </summary>
        public void HandleRecalculateAllInHashCode()
        {
            //Get all the Keys in the HashTable.
            string[] allKeyValues = m_ladderInstancesTable.Keys.ToArray();
            SpectrumLook.Views.FragmentLadderView.LadderInstanceBuilder ladderBuilder = new Views.FragmentLadderView.LadderInstanceBuilder();

            foreach (string currentKey in allKeyValues)
            {
                List <LadderInstance> currentLadderInstances = m_ladderInstancesTable[currentKey];
                m_ladderInstancesTable.Remove(currentKey);
                List <LadderInstance> newInstanceList = new List <LadderInstance>();
                foreach (LadderInstance currentInstance in currentLadderInstances)
                {
                    //Give Theoretical List the modified Peptide
                    //Assuming The Frag ladder will add the PeptideString of the modified thing.
                    List <Element> theoreticalList = m_builderDirector.BuildTheoryList(currentInstance.PeptideString, m_isFragmentationModeETD, this.m_fragLadder.fragmentLadderOptions.modificationList);
                    //Give experimental List the original Peptide.
                    //WARNING : ASSUMEING THE SCAN NUMBER KEY IS AN INTERGER
                    //THIS MAY NOT BE THE CASE IF PARSER CHANGES
                    List <Element> experimentalList = m_builderDirector.BuildActualList(int.Parse(currentInstance.scanNumberString), m_dataFileLocation);
                    //build the compared list
                    List <Element> comparedList = m_builderDirector.BuildComparedList(m_mainForm.m_currentOptions.toleranceValue, m_mainForm.m_currentOptions.lowerToleranceValue, experimentalList, PrecursorMZ, ref theoreticalList);

                    //Generate the Instance based on the builder.
                    LadderInstance newLadder = ladderBuilder.GenerateInstance(theoreticalList, currentInstance.PeptideString, m_fragLadder.fragmentLadderOptions.modificationList);

                    newLadder.scanAndPeptide = currentInstance.scanAndPeptide;

                    //Add to List
                    newInstanceList.Add(newLadder);
                }
                //Add List Of Instances to the HashTable.
                m_ladderInstancesTable.Add(currentKey, newInstanceList);
            }
            if (m_ladderInstancesTable.Count > 0)
            {
                m_currentInstance = m_ladderInstancesTable[m_currentScanNumber + m_currentPeptide][0];
                m_fragLadder.generateLadderFromSelection(0.0, m_ladderInstancesTable[m_currentScanNumber + m_currentPeptide]);
            }
        }
예제 #3
0
        /// <summary>
        /// This handle is called from the fragmentLadder.
        /// This is created for the purpose of adding a modified peptide to the current Instance List.
        /// </summary>
        /// <param name="Peptide">A peptide string.</param>
        public bool HandleInputPeptide(string Peptide)
        {
            if (m_currentScanNumber == 0)
            {
                MessageBox.Show(
                    "Please open a synopsis and data file and then load a scan from the data view to calculate: \"" +
                    Peptide + "\"");
                return(false);
            }

            if (Peptide.Length == 1)
            {
                MessageBox.Show("Invalid peptide string (single character.");
                return(false);
            }

            /*MG: Generating a regular expression string with the current modification
             * symbols to check if the peptide string from the user is a valid peptide string.
             * if its not, giving feedback to user and returning out*/
            string modList        = new string(m_fragLadder.fragmentLadderOptions.modificationList.Keys.ToArray());
            string escapedModList = "";

            // The manual way, based on a list of metacharacters that need to be escaped

            /*foreach (char c in modList)
             * {
             *  // Characters that must be escaped: \[^$.|?*+(){}
             *  if ("\\[^$.|?*+(){}".Contains(c))
             *  {
             *      escapedModList += "\\" + c;
             *  }
             *  else
             *  {
             *      escapedModList += c;
             *  }
             * }*/
            // The automatic way, using .NET
            escapedModList = System.Text.RegularExpressions.Regex.Escape(modList);

            // One or more characters, A-Z, which may be followed by a valid modification symbol, that does not end with a modification symbol be itself?
            // The escaping of all symbols is likely a problem.
            //string spattern = "^([A-Z]{1,}[" + escapedModList + "]{0,1})*[^" + escapedModList + "]$";
            // Match any set of one or more groups of "character a-z followed by 0-2 valid modification symbols"
            string spattern = "([A-Z][" + escapedModList + "]{0,5})+";

            // This test will always be evaluate to 'not false' whenever there are lowercase characters or symbols that are not in the modification list,
            // or if the peptide begins with a modification symbol.
            // TODO: can a peptide begin with a modification symbol? (Not with any software Matt Monroe has written/uses - put mod after first amino acid)
            if (!System.Text.RegularExpressions.Regex.IsMatch(Peptide, "^" + spattern + "$"))
            {
                // Get a string with all invalid characters
                string invalid = System.Text.RegularExpressions.Regex.Replace(Peptide, spattern, "");
                if (modList.Contains(Peptide[0]))
                {
                    MessageBox.Show("The peptide string cannot start with a modification.");
                    return(false);
                }
                if (System.Text.RegularExpressions.Regex.Replace(invalid, "[" + escapedModList + "]", "").Length == 0)
                {
                    MessageBox.Show("Invalid peptide string: Too many modifications on a single amino acid.");
                    return(false);
                }

                MessageBox.Show("Invalid characters in peptide string \"" + invalid + "\", please remove the characters or define them in options/fragment ladder");
                return(false);
            }

            // check to see if peptide exists in the ladder instances table and don't add a modification if it does
            bool is_same = false;

            foreach (var instance in m_ladderInstancesTable[m_currentScanNumber.ToString() + m_currentPeptide])
            {
                if (instance.PeptideString == Peptide)
                {
                    is_same = true;
                }
            }

            if (!is_same)
            {
                SpectrumLook.Views.FragmentLadderView.LadderInstanceBuilder ladderBuilder =
                    new Views.FragmentLadderView.LadderInstanceBuilder();

                //use the builder director to crunch all the data
                List <Element> theoreticalList = m_builderDirector.BuildTheoryList(Peptide, m_isFragmentationModeETD,
                                                                                   this.m_fragLadder.fragmentLadderOptions.modificationList);
                List <Element> comparedList =
                    m_builderDirector.BuildComparedList(m_mainForm.m_currentOptions.toleranceValue,
                                                        m_mainForm.m_currentOptions.lowerToleranceValue, m_experimentalList, PrecursorMZ, ref theoreticalList);

                //now give the data to the views to display
                //Send the FragmentLadder and the Plot the data to show
                if (m_ladderInstancesTable.ContainsKey(m_currentScanNumber.ToString() + m_currentPeptide))
                {
                    m_currentInstance = ladderBuilder.GenerateInstance(theoreticalList, Peptide,
                                                                       m_fragLadder.fragmentLadderOptions.modificationList);
                    m_currentInstance.scanAndPeptide = m_currentScanNumber.ToString() + "|" + Peptide;
                    m_ladderInstancesTable[m_currentScanNumber.ToString() + m_currentPeptide].Add(m_currentInstance);
                    m_currentInstance = m_ladderInstancesTable[m_currentScanNumber.ToString() + m_currentPeptide][0];
                    m_fragLadder.generateLadderFromSelection(0.0, m_ladderInstancesTable[m_currentScanNumber.ToString() + m_currentPeptide]);
                    m_plot.PlotData(comparedList, m_currentScanNumber.ToString(), Peptide);
                }
                else
                {
                    m_plot.PlotData(comparedList, m_currentScanNumber.ToString(), m_currentPeptide);
                }

                return(true);
            }

            return(false);
        }