Example #1
0
        private void buttonGenerateCommetParams_Click(object sender, EventArgs e)
        {
            cometParams cp = GetCometParamsFromScreen();

            try
            {
                CheckForConsistencyInForms(cp);
            }
            catch (Exception e3)
            {
                MessageBox.Show(e3.Message);
                return;
            }

            string cpf = GenerateTheSearchParamsString(cp);

            //Serialize it and check if it is different than the default parameters
            //If it is different, we ask the user if the default parameters should be updated
            string serializedCometParams = cp.SerializeToXML();

            if (!serializedCometParams.Equals(Properties.Settings.Default.SearchSettings))
            {
                if (MessageBox.Show("Update default search parameters ?", "Default parameters", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    Settings.Default.SearchSettings = serializedCometParams;
                    Settings.Default.Save();
                }
            }

            richTextBoxVerify.Text  = cpf;
            tabControl1.SelectedTab = tabPageVerify;
        }
Example #2
0
        public static List <SQTScan2> CallComet(cometParams cp, string searchFile)
        {
            FileInfo fi = new FileInfo(searchFile);

            string cpf = CometWrapper.GenerateTheSearchParamsString(cp);

            //Write the comet result to the directory
            StreamWriter sw = new StreamWriter(fi.DirectoryName + "/" + "comet.params");

            sw.WriteLine(cpf);
            sw.Close();

            string cometCall = CometWrapper.GetCometPath();

            CometWrapper.CallComet(fi, cometCall, cpf);

            string sqtFileTmp = fi.Name.Replace(fi.Extension, ".sqt");
            string sqtFile    = fi.Directory.FullName + "/" + sqtFileTmp;

            PatternTools.SQTParser2.SQTParser2 sqtParser = new SQTParser2();

            List <SQTScan2> theResult = sqtParser.Parse(sqtFile);

            int removedNoMatch = theResult.RemoveAll(a => a.Matches.Count == 0);

            return(theResult);
        }
Example #3
0
        private void CometWrapper_Load(object sender, EventArgs e)
        {
            comboBoxEnzyme.DataSource                 = enzymes;
            comboBoxEnzyme.SelectedIndex              = 1;
            comboBoxEnzymeSpecificity.SelectedIndex   = 0;
            comboBoxTheoreticalFragIons.SelectedIndex = 0;
            Control.CheckForIllegalCrossThreadCalls   = false;

            //Load Default search Parameters
            try
            {
                cometParams cp = new cometParams();

                StringReader s = new StringReader(Properties.Settings.Default.SearchSettings);

                XmlSerializer xmlSerializer = new XmlSerializer(cp.GetType());
                cp = (cometParams)xmlSerializer.Deserialize(s);

                //Now we need to update the screen
                UpdateScreenFromSerializedObject(cp);
            }
            catch (Exception e4)
            {
                MessageBox.Show("No default parameters have been set.\n" + e4.Message);
            }
        }
Example #4
0
        //--------------------------------------------------------


        private void CheckForConsistencyInForms(cometParams cp)
        {
            Console.WriteLine("Checking for consistency in forms.");

            if (!Directory.Exists(textBoxInput.Text))
            {
                throw new Exception("Please enter a valid input directory containing .RAW, .mgf, .ms2, or .mzML files");
            }

            List <string> searchDirs = GetDirectoriesWithRawOrMS2orMZMLorMGF();

            if (searchDirs.Count == 0)
            {
                throw new Exception("No .RAW, .mgf, .mzXML, .ms2, or mzML files found for searching.");
            }

            //Verify if we have a comet.params in all directories
            List <string> directories = GetDirectoriesWithRawOrMS2orMZMLorMGF();


            //Verify if we have a valid search sequence database
            if (!File.Exists(textBoxSequenceDatabase.Text))
            {
                throw new Exception("No sequence database file found.");
            }

            //Check if at least one ion type is selected
            if (checkBoxIon_B.Checked && checkBoxIon_X.Checked && checkBoxIonA.Checked && checkBoxIonC.Checked && checkBoxIonNL.Checked && checkBoxIonY.Checked && checkBoxIonZ.Checked)
            {
                throw new Exception("At lease one ion type must be selected");
            }

            if (numericUpDownClearMZMin.Value > numericUpDownClearMZMax.Value)
            {
                throw new Exception("Clear MZ Min value must be less than Clear MZ Max value.");
            }

            if (numericUpDownSearchMassMin.Value > numericUpDownSearchMassMax.Value)
            {
                throw new Exception("Search mass maximum must be greater than search mass min.");
            }

            if (cp.MyModificationItems.Count(a => a.isCTerm && !a.isDiff) > 1)
            {
                throw new Exception("Only one static C terminal modification is allowed");
            }

            if (cp.MyModificationItems.Count(a => a.isNTerm && !a.isDiff) > 1)
            {
                throw new Exception("Only one static N terminal modification is allowed");
            }
        }
Example #5
0
        //--------------------------------------------
        private cometParams GetCometParamsFromScreen()
        {
            cometParams cp = new cometParams();

            cp.SequenceDatabase = textBoxSequenceDatabase.Text;
            cp.IonsA            = checkBoxIonA.Checked;
            cp.IonsB            = checkBoxIon_B.Checked;
            cp.IonsC            = checkBoxIonC.Checked;
            cp.IonsX            = checkBoxIon_X.Checked;
            cp.IonsY            = checkBoxIonY.Checked;
            cp.IonsZ            = checkBoxIonZ.Checked;
            cp.IonsNL           = checkBoxIonNL.Checked;

            cp.PrecursorMassTolerance = (double)numericUpDownPrecursorMassTolerance.Value;
            cp.Enzyme               = comboBoxEnzyme.SelectedIndex;
            cp.EnzymeSpecificity    = comboBoxEnzymeSpecificity.SelectedIndex + 1;
            cp.MissedCleavages      = (int)numericUpDownAllowedMissedCleavages.Value;
            cp.FragmentBinTolerance = (double)numericUpDownFragmentBinTolerance.Value;
            cp.FragmentBinOffset    = (double)numericUpDownFragBinOffset.Value;

            if ((int)comboBoxTheoreticalFragIons.SelectedIndex == 0)
            {
                cp.TheoreticalFragIons = 1;
            }
            else
            {
                cp.TheoreticalFragIons = 0;
            }


            cp.MaxVariableModsPerPeptide = (int)numericUpDownMaxVariableModsPerPeptides.Value;

            cp.ClearMZRangeMin = (double)numericUpDownClearMZMin.Value;
            cp.ClearMZRangeMax = (double)numericUpDownClearMZMax.Value;

            cp.SearchMassRangeMin = (double)numericUpDownSearchMassMin.Value;
            cp.SearchMassRangeMax = (double)numericUpDownSearchMassMax.Value;

            cp.MyModificationItems = GetModsFromTable();

            return(cp);
        }
Example #6
0
        static void Main(string[] args)
        {
            int    minNoPeptides      = 2;
            double minAcceptableXCorr = 1.7;
            string sequenceDB         = @"C:\Users\pcarvalho\Desktop\XIC\BSA\PFUsmall.T-R";
            string massSpectraFile    = @"C:\Users\pcarvalho\Desktop\XIC\BSA\1\20111024_BSA_40fmol_01.RAW";


            CometWrapper.cometParams cp = new CometWrapper.cometParams();

            cp.ClearMZRangeMax = 0;
            cp.ClearMZRangeMin = 0;

            cp.Enzyme               = 1; //Trypsin
            cp.EnzymeSpecificity    = 2;
            cp.FragmentBinOffset    = 0.4;
            cp.FragmentBinTolerance = 1.0005;
            cp.IonsA  = false;
            cp.IonsB  = true;
            cp.IonsC  = false;
            cp.IonsNL = true;
            cp.IonsX  = false;
            cp.IonsY  = true;
            cp.IonsZ  = false;

            cp.MaxVariableModsPerPeptide = 3;
            cp.MissedCleavages           = 4;


            Modification m1 = new Modification("Carb", (decimal)57.02146, "C");

            //Modification m2 = new Modification("M", (decimal)15.9949, "M");
            //m2.isDiff = true;

            //For cross-linker dead end, include as a variable mod, and then as a variable mod for n-terminal

            cp.MyModificationItems = new List <CometWrapper.Modification>()
            {
                m1
            };

            cp.PrecursorMassTolerance = 40;
            cp.SearchMassRangeMax     = 5500;
            cp.SearchMassRangeMin     = 550;
            cp.SequenceDatabase       = sequenceDB;
            cp.TheoreticalFragIons    = 1;

            List <SQTScan2> myResults = CometWrapper.RemoteCall.CallComet(cp, massSpectraFile);



            int removedPrimary = myResults.RemoveAll(a => a.Matches[0].PrimaryScore < minAcceptableXCorr);

            var proteinIDs = (from result in myResults
                              from ID id in result.Matches[0].IDs
                              group id by id.Locus into myLocusGroups
                              select new { ID = myLocusGroups.Key, Count = myLocusGroups.Count() });

            List <string> peptides = (from result in myResults
                                      select result.Matches[0].PeptideSequence).Distinct().ToList();

            PatternTools.FastaParser.FastaFileParser ffp = new PatternTools.FastaParser.FastaFileParser();
            ffp.ParseFile(new StreamReader(cp.SequenceDatabase), true, PatternTools.FastaParser.DBTypes.IDSpaceDescription);

            List <FastaItem> myFasta = new List <FastaItem>();

            foreach (var prot in proteinIDs)
            {
                if (prot.Count >= minNoPeptides)
                {
                    myFasta.Add(ffp.MyItems.Find(a => a.SequenceIdentifier.Equals(prot.ID)));
                }
            }

            Console.WriteLine("Done");
        }
Example #7
0
        public static string GenerateTheSearchParamsString(cometParams cp)
        {
            string cpt = Properties.Settings.Default.CometParamsTemplate;

            cpt = cpt.Replace("[CLEARMZRANGEMAX]", cp.ClearMZRangeMax.ToString());
            cpt = cpt.Replace("[CLEARMZRANGEMIN]", cp.ClearMZRangeMin.ToString());

            cpt = cpt.Replace("[ENZYME]", cp.Enzyme.ToString());
            cpt = cpt.Replace("[SAMPLENZYME]", cp.Enzyme.ToString());

            cpt = cpt.Replace("[DIGESTIONSPECIFICITY]", cp.EnzymeSpecificity.ToString());
            cpt = cpt.Replace("[FRAGMENTBINOFFSET]", cp.FragmentBinOffset.ToString());
            cpt = cpt.Replace("[FRAGMENTBINTOLERANCE]", cp.FragmentBinTolerance.ToString());
            cpt = cpt.Replace("[A_ION]", BoolHelper(cp.IonsA));
            cpt = cpt.Replace("[B_ION]", BoolHelper(cp.IonsB));
            cpt = cpt.Replace("[C_ION]", BoolHelper(cp.IonsC));
            cpt = cpt.Replace("[NL_ION]", BoolHelper(cp.IonsNL));
            cpt = cpt.Replace("[X_ION]", BoolHelper(cp.IonsX));
            cpt = cpt.Replace("[Y_ION]", BoolHelper(cp.IonsY));
            cpt = cpt.Replace("[Z_ION]", BoolHelper(cp.IonsZ));
            cpt = cpt.Replace("[MAXVARIABLEMODSPERPEPTIDE]", cp.MaxVariableModsPerPeptide.ToString());
            cpt = cpt.Replace("[MISSEDCLEAVAGES]", cp.MissedCleavages.ToString());
            cpt = cpt.Replace("[PEPTIDEMASSTOLERANCE]", cp.PrecursorMassTolerance.ToString());
            cpt = cpt.Replace("[MASSRANGEMAX]", cp.SearchMassRangeMax.ToString());
            cpt = cpt.Replace("[MASSRANGEMIN]", cp.SearchMassRangeMin.ToString());
            cpt = cpt.Replace("[DBPATH]", cp.SequenceDatabase);
            cpt = cpt.Replace("[THEORETICALFRAGMENTIONS]", cp.TheoreticalFragIons.ToString());

            //Static mods for amino acids
            List <string> staticModKeys = new List <string>()
            {
                "[ADD_G]", "[ADD_A]", "[ADD_S]", "[ADD_P]", "[ADD_V]", "[ADD_T]",
                "[ADD_C]", "[ADD_L]", "[ADD_I]", "[ADD_N]", "[ADD_D]", "[ADD_Q]",
                "[ADD_K]", "[ADD_E]", "[ADD_M]", "[ADD_O]", "[ADD_H]", "[ADD_F]",
                "[ADD_R]", "[ADD_Y]", "[ADD_W]", "[ADD_B]", "[ADD_J]", "[ADD_U]",
                "[ADD_X]", "[ADD_Z]"
            };

            List <Modification> staticMod = cp.MyModificationItems.FindAll(a => !a.isDiff);

            foreach (string smod in staticModKeys)
            {
                string[] cols = Regex.Split(smod, "_");
                cols[1] = cols[1].Remove(1, 1);
                List <Modification> mods = staticMod.FindAll(a => a.Residues.Contains(cols[1]));

                foreach (Modification m in mods)
                {
                    cpt = cpt.Replace(smod, m.MassShift.ToString());
                }

                if (mods.Count == 0)
                {
                    cpt = cpt.Replace(smod, "0.0");
                }
            }

            //Variable mods for amino acids
            List <Modification> varMod = cp.MyModificationItems.FindAll(a => a.isDiff);

            for (int i = 0; i < 6; i++)
            {
                int j = i + 1;
                if (i < varMod.Count)
                {
                    string res = varMod[i].Residues;

                    if (varMod[i].isCTerm)
                    {
                        res += "c";
                    }

                    if (varMod[i].isNTerm)
                    {
                        res = "n" + res;
                    }

                    cpt = cpt.Replace("[VARMOD" + j + "]", varMod[i].MassShift + " " + res + " 0 4 -1 0 0");
                }
                else
                {
                    cpt = cpt.Replace("[VARMOD" + j + "]", "0.0 X 0 3 -1 0 0");
                }
            }

            //C static mod
            List <Modification> CstaticMod = cp.MyModificationItems.FindAll(a => !a.isDiff && a.isCTerm);

            if (CstaticMod.Count > 1)
            {
                throw new Exception("Only 1 C static mod is acceptable");
            }
            if (CstaticMod.Count == 1)
            {
                cpt = cpt.Replace("[FIXEDCTERMINUS]", CstaticMod[0].MassShift.ToString());
            }
            else
            {
                cpt = cpt.Replace("[FIXEDCTERMINUS]", "0.0");
            }

            //N static mod
            List <Modification> NstaticMod = cp.MyModificationItems.FindAll(a => !a.isDiff && a.isNTerm);

            if (NstaticMod.Count > 1)
            {
                throw new Exception("Only 1 N static mod is acceptable");
            }
            if (NstaticMod.Count == 1)
            {
                cpt = cpt.Replace("[FIXEDNTERMINUS]", NstaticMod[0].MassShift.ToString());
            }
            else
            {
                cpt = cpt.Replace("[FIXEDNTERMINUS]", "0.0");
            }

            return(cpt);
        }