private void ms2mgf_TextChanged(object sender, EventArgs e)
        {
            firstTitle = Mgfutils.getFirstTitle(this.ms2mgf.Text.Trim());

            this.titleLbl.Text     = firstTitle;
            this.mgfParser.Enabled = true;
        }
        private void scanFieldsBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            ListBox.SelectedIndexCollection selection = this.scanFieldsBox.SelectedIndices;

            //scanField = new int[selection.Count];
            for (int i = 0; i < selection.Count; i++)
            {
                scanField = (int)selection[i];
            }

            this.scanNumberResTxt.Text = Mgfutils.getScanNumber(firstTitle, split_chars, scanField).ToString();
            locateMS2precMasses        = true;
        }
Exemple #3
0
        public static ArrayList getMHplusFromMgf(ArrayList identifications,
                                                 string mgffolder,
                                                 char[] split_chars,
                                                 int scanField)
        {
            string titleID    = "TITLE";
            string chargeID   = "CHARGE";
            string pepMassID  = "PEPMASS";
            float  protonMass = 1.007F;

            //Declaration of a comparer for OutData by key (RAWfilename, ScanNumber, charge)
            OutData.OutsComparer cmpKey = new OutData.OutsComparer();
            cmpKey.WhichComparison = OutData.OutsComparer.ComparisonType.key;

            //Sort up the identifications by the key comparer
            identifications.Sort(cmpKey);



            ArrayList identificationsWithMassCorrected = new ArrayList();

            FileInfo      file = new FileInfo(mgffolder);
            DirectoryInfo di   = new DirectoryInfo(mgffolder);

            FileInfo[] files = di.GetFiles("*.mgf");

            OutData firstId = (OutData)identifications[0];

            string       previousMgf = di.FullName + "\\" + firstId.RAWFile;
            StreamReader sr          = new StreamReader(previousMgf);


            string line = "";

            for (int i = 0; i < identifications.Count; i++)
            {
                OutData currId = (OutData)identifications[i];

                //Check wether we need to open a new file or not
                if (currId.RAWFile != previousMgf)
                {
                    sr.Close();
                    sr          = new StreamReader(di.FullName + "\\" + currId.RAWFile);
                    previousMgf = di.FullName + "\\" + currId.RAWFile;


                    //read the file, and locate the desired scannumber (MS2 previous to the id in MS3)
                    try
                    {
                        while (sr.Peek() != -1)
                        {
                            line = sr.ReadLine();
                            if (line.ToUpper().Contains(titleID))
                            {
                                //obtain the scannumber of the current spectrum
                                int tentativeScanNumberMS2 = Mgfutils.getScanNumber(line, split_chars, scanField);


                                //We need the PREVIOUS scannumber
                                int tentativeScanNumberMS3 = tentativeScanNumberMS2 + 1;

                                //get the charge of the spectrum
                                int charge = 0;
                                line = sr.ReadLine();
                                if (line.ToUpper().Contains(chargeID))
                                {
                                    string[] charge_sp = line.Split('=', '+');
                                    charge = int.Parse(charge_sp[1].Trim());
                                }

                                //is this spectrum in our list??
                                OutData spectrumToFind = new OutData(OutData.databases.Target, OutData.XCorrTypes.normalized);
                                spectrumToFind.RAWFile   = currId.RAWFile;
                                spectrumToFind.FirstScan = tentativeScanNumberMS3;
                                spectrumToFind.Charge    = currId.Charge;
                                int specFoundPos = identifications.BinarySearch(spectrumToFind, cmpKey);

                                if (specFoundPos > -1)
                                {
                                    bool massLocated = false;
                                    while (!massLocated)
                                    {
                                        line = sr.ReadLine();
                                        if (line.ToUpper().Contains(pepMassID))
                                        {
                                            massLocated = true;
                                            string[] pepMass_split      = line.Split('=');
                                            float    mz                 = float.Parse(pepMass_split[1]);
                                            OutData  spectrumToSwapMass = (OutData)identifications[specFoundPos];
                                            float    MHp                = mz * charge - (charge - 1) * protonMass;
                                            spectrumToSwapMass.MHp    = MHp;
                                            spectrumToSwapMass.Charge = (short)charge;

                                            identificationsWithMassCorrected.Add(spectrumToSwapMass);
                                            identifications.RemoveAt(specFoundPos);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    catch { }
                }
            }



            return(identificationsWithMassCorrected);
        }
Exemple #4
0
        public static void getMHplusFromMgf(string QuiXMLfile,
                                            string XMLschema,
                                            string mgffolder,
                                            char[] split_chars,
                                            int scanField,
                                            bool swapMgfRaw)
        {
            string titleID    = "TITLE";
            string chargeID   = "CHARGE";
            string pepMassID  = "PEPMASS";
            float  protonMass = 1.007F;

            //Open the QuiXML file created
            DataSet ds = new DataSet();

            ds.ReadXmlSchema(XMLschema);
            //ds.ReadXmlSchema(CSVtoQuiXML.Properties.Settings.Default.idSchema);
            ds.ReadXml(QuiXMLfile);

            DataView dv         = new DataView(ds.Tables["peptide_match"]);
            DataView dvFiltered = new DataView(ds.Tables["peptide_match"]);

            //sort the dataset by RAWfilename, ScanNumber, charge
            dv.Sort = "RawFileName, FirstScan, Charge";

            DataRowView firstId = dv[0];


            FileInfo      file = new FileInfo(mgffolder);
            DirectoryInfo di   = new DirectoryInfo(mgffolder);

            FileInfo[] files = di.GetFiles("*.mgf");

            string       previousMgf = di.FullName + "\\" + dv[0]["RawFileName"].ToString();
            StreamReader sr          = new StreamReader(previousMgf);


            string line = "";

            for (int i = 0; i < dv.Count; i++)
            {
                //Check wether we need to open a new file or not
                if (dv[i]["RawFileName"].ToString() != previousMgf)
                {
                    sr.Close();
                    sr          = new StreamReader(di.FullName + "\\" + dv[i]["RawFileName"].ToString());
                    previousMgf = di.FullName + "\\" + dv[i]["RawFileName"].ToString();


                    //read the file, and locate the desired scannumber (MS2 previous to the id in MS3)
                    try
                    {
                        while (sr.Peek() != -1)
                        {
                            line = sr.ReadLine();
                            if (line.ToUpper().Contains(titleID))
                            {
                                //obtain the scannumber of the current spectrum
                                int tentativeScanNumberMS2 = Mgfutils.getScanNumber(line, split_chars, scanField);


                                //We need the PREVIOUS scannumber
                                int tentativeScanNumberMS3 = tentativeScanNumberMS2 + 1;

                                //get the charge of the spectrum
                                int charge = 0;
                                line = sr.ReadLine();
                                if (line.ToUpper().Contains(chargeID))
                                {
                                    string[] charge_sp = line.Split('=', '+');
                                    charge = int.Parse(charge_sp[1].Trim());
                                }

                                //is this spectrum in our list??
                                dvFiltered.RowFilter = "rawfilename = '" + dv[i]["RawFileName"].ToString()
                                                       + "' and firstscan =" + dv[i]["FirstScan"].ToString()
                                                       + " and charge = " + dv[i]["Charge"].ToString();

                                if (dvFiltered.Count > 0)
                                {
                                    bool massLocated = false;
                                    while (!massLocated)
                                    {
                                        line = sr.ReadLine();
                                        if (line.ToUpper().Contains(pepMassID))
                                        {
                                            massLocated = true;
                                            string[] pepMass_split = line.Split('=');
                                            float    mz            = float.Parse(pepMass_split[1]);
                                            float    MHp           = mz * charge - (charge - 1) * protonMass;

                                            dvFiltered[0]["Charge"]        = charge;
                                            dvFiltered[0]["PrecursorMass"] = MHp;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    catch { }
                }
            }


            //swapping .mgf to .raw
            if (swapMgfRaw)
            {
                dv.RowFilter = "";
                dv.Sort      = "";
                for (int i = 0; i < dv.Count; i++)
                {
                    string strold = dv[i]["RawFileName"].ToString();
                    string strnew = strold.Replace(".mgf", ".RAW");
                    strnew = strnew.Replace(".MGF", ".RAW");
                    dv[i]["RawFileName"] = strnew;
                }
            }


            ds.WriteXml(QuiXMLfile);
        }