コード例 #1
0
        // Special implementation to be called by custom comparer
        public int CompareTo(
            OutData rhs,
            OutData.OutsComparer.ComparisonType which)
        {
            switch (which)
            {
            case OutData.OutsComparer.ComparisonType.Xcorr1:
                return(this.Xcorr1.CompareTo(rhs.Xcorr1));

            case OutData.OutsComparer.ComparisonType.XcorrRandomVSXcorr1:
                return(this.Xcorr1.CompareTo(rhs.XcorrRandom));

            case OutData.OutsComparer.ComparisonType.XcorrRandomVSXcorrRandom:
                return(this.XcorrRandom.CompareTo(rhs.XcorrRandom));

            case OutData.OutsComparer.ComparisonType.pRatio:
                return(this.pRatio.CompareTo(rhs.pRatio));

            case OutData.OutsComparer.ComparisonType.FDR:
                return(this.FDR.CompareTo(rhs.FDR));

            case OutData.OutsComparer.ComparisonType.RAWfile:
                return(this.RAWFile.CompareTo(rhs.RAWFile));

            case OutData.OutsComparer.ComparisonType.key:
            {
                int result = 0;
                result = this.RAWFile.CompareTo(rhs.RAWFile);
                if (result != 0)
                {
                    return(result);
                }
                result = this.FirstScan.CompareTo(rhs.FirstScan);
                if (result != 0)
                {
                    return(result);
                }
                result = this.Charge.CompareTo(rhs.Charge);
                if (result != 0)
                {
                    return(result);
                }
                return(result);
            }

            case OutData.OutsComparer.ComparisonType.RnkXc1:
                return(this.rnkXc1.CompareTo(rhs.rnkXc1));
            }
            return(0);
        }
コード例 #2
0
        public static ArrayList substituteExtension(ArrayList _identifications,
                                                    string _oldExtension,
                                                    string _newExtension)
        {
            ArrayList substituted = new ArrayList(_identifications.Count);

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

                currId.RAWFile = currId.RAWFile.Replace(_oldExtension, _newExtension);

                substituted.Add(currId);
            }



            return(substituted);
        }
コード例 #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);
        }
コード例 #4
0
        //public static void test()
        //{

        //    string[] txtFiles = new string[1];

        //    txtFiles[0] = "I:\\wrk\\iTRAQ_estadistica\\samples\\datos_abian\\Salida_Peptidos_Filtrados.txt";
        //    OutData.databases whichDB = OutData.databases.Target;

        //    ArrayList testing = readTXT(txtFiles, whichDB);


        //}

        public static ArrayList readTXT(string[] txtFiles,
                                        string[] readingOrder,
                                        OutData.databases whichDB)
        {
            ArrayList outsList = new ArrayList();

            //FormHeaderSelection frmHeader = new FormHeaderSelection();

            //frmHeader.Show();

            foreach (string file in txtFiles)
            {
                try
                {
                    StreamReader sr   = new StreamReader(File.OpenRead(file));
                    ArrayList    myAL = new ArrayList();

                    try
                    {
                        while (sr.Peek() != -1) //equivalente a feof en C
                        {
                            myAL.Add(sr.ReadLine());
                        }
                    }
                    catch
                    {
                        //Console.WriteLine(" Parse error: " + e);
                    }

                    //int r = myAL.Count;

                    //object ob = (object)myAL[0];
                    //myAL.Remove(ob);


                    foreach (object o in myAL)
                    {
                        try
                        {
                            OutData sd                    = new OutData(whichDB, OutData.XCorrTypes.regular);
                            int     RAWFilePos            = findInArray(readingOrder, "*RAW file name");
                            int     FirstScanPos          = findInArray(readingOrder, "*FirstScan [- LastScan]");
                            int     LastScanPos           = findInArray(readingOrder, "LastScan");
                            int     ProteinDescriptionPos = findInArray(readingOrder, "*Protein description");
                            int     MHpPos                = findInArray(readingOrder, "MH+");
                            int     deltaMPos             = findInArray(readingOrder, "DeltaM");
                            int     ChargePos             = findInArray(readingOrder, "*Charge");
                            int     SequencePos           = findInArray(readingOrder, "*Sequence");
                            int     PpepPos               = findInArray(readingOrder, "P (pep)");
                            int     Xcorr1Pos             = findInArray(readingOrder, "Xcorr1");
                            //int Xcorr2Pos = findInArray(readingOrder, "Xcorr2");
                            int DeltaCnPos  = findInArray(readingOrder, "DeltaCn");
                            int SpPos       = findInArray(readingOrder, "Sp");
                            int SpRankPos   = findInArray(readingOrder, "Sp Rank");
                            int ionsPos     = findInArray(readingOrder, "Ions");
                            int XcTeoricPos = findInArray(readingOrder, "XcTeoric");
                            int ScorePos    = findInArray(readingOrder, "Score");

                            sd.FileName = file;

                            string[] str;

                            str = Regex.Split(o.ToString(), "\t");


                            sd.RAWFile = str[RAWFilePos];

                            string[] scans = Regex.Split(str[FirstScanPos], "-");
                            sd.FirstScan = int.Parse(scans[0]);
                            if (scans.Length > 1)
                            {
                                sd.LastScan = int.Parse(scans[scans.Length - 1]);
                            }
                            else
                            {
                                sd.LastScan = sd.FirstScan;
                            }

                            // If there is a specific column for the LastScan, then it is overwritten in next file
                            if (LastScanPos != -1)
                            {
                                sd.LastScan = int.Parse(str[LastScanPos]);
                            }

                            sd.ProteinDescription = str[ProteinDescriptionPos];

                            if (MHpPos != -1)
                            {
                                sd.MHp = float.Parse(str[MHpPos]);
                            }
                            sd.PrecursorMass = float.Parse(str[MHpPos]);
                            if (deltaMPos != -1)
                            {
                                sd.deltaM = float.Parse(str[deltaMPos]);
                            }

                            sd.Charge = short.Parse(str[ChargePos]);

                            // Sequence is written only if selected
                            if (SequencePos != -1)
                            {
                                sd.Sequence = str[SequencePos];
                            }

                            if (PpepPos != -1)
                            {
                                sd.Ppep = float.Parse(str[PpepPos]);
                            }

                            if (Xcorr1Pos != -1)
                            {
                                sd.Xcorr1 = float.Parse(str[Xcorr1Pos]);
                            }

                            if (DeltaCnPos != -1)
                            {
                                sd.DeltaCn     = float.Parse(str[DeltaCnPos]);
                                sd.Xcorr2      = sd.Xcorr1Search * (1 - sd.DeltaCn);
                                sd.XcorrRandom = sd.Xcorr2;
                            }

                            if (SpPos != -1)
                            {
                                sd.Sp = float.Parse(str[SpPos]);
                            }

                            if (SpRankPos != -1)
                            {
                                sd.SpRank = short.Parse(str[SpRankPos]);
                            }

                            if (ionsPos != -1)
                            {
                                string[] ions = str[ionsPos].Split('/');
                                sd.IonsMatched = short.Parse(ions[0]);
                                if (ions.Length > 1)
                                {
                                    sd.IonsCompared = short.Parse(ions[ions.Length - 1]);
                                }
                            }

                            if (ScorePos != -1)
                            {
                                sd.Score = double.Parse(str[ScorePos]);
                            }

                            if (XcTeoricPos != -1)
                            {
                                sd.XcTeoric = float.Parse(str[XcTeoricPos]);
                            }


                            // Here to implement redundances
                            //int numOfReds = 3;
                            //Redundance[] allReds = new Redundance[numOfReds];

                            //Redundance myRed = new Redundance();
                            //allReds[0].FASTAIndex = 12345;
                            //allReds[0].FASTAProteinDescription = "la proteina que le falta al Marco";

                            //sd.Redundances = (Redundance[]) allReds.Clone();

                            outsList.Add(sd);
                        }
                        catch { }
                    }


                    sr.Close();
                }
                catch
                {
                }
            }

            return(outsList);
        }
コード例 #5
0
        public int CompareTo(Object rhs)
        {
            OutData r = (OutData)rhs;

            return(this.Xcorr1.CompareTo(r.Xcorr1));
        }