Exemplo n.º 1
0
        public static int[] ExtractMsm(string filename, IPeakList peakList, IRawFile rawFile, string msmName,
                                       string msmNameBinary, string msmNameIndex, int topx,
                                       double isotopeCorrelationThreshold, SilacType type, out long[] pointers)
        {
            StreamWriter sw              = new StreamWriter(msmName);
            BinaryWriter writer          = FileUtil.GetBinaryWriter(msmNameBinary);
            List <long>  filePointers    = new List <long>();
            List <int>   fileScanNumbers = new List <int>();
            long         filePos         = 0;

            for (int i = 0; i < rawFile.MS2Count; i++)
            {
                Spectrum s          = rawFile.GetMS2Spectrum(i);
                int      scanNumber = rawFile.GetScanNumberFromMs2Index(i);
                double   simpleMz   = rawFile.GetMS2MonoisotopicMz(i);
                if (double.IsNaN(simpleMz) || simpleMz < 1)
                {
                    simpleMz = peakList.GetMs2Mz(i);
                    if (double.IsNaN(simpleMz) || simpleMz < 1)
                    {
                        simpleMz = 1;
                    }
                }
                int    charge;
                double mz;
                double mass;
                GetPrecursorInfo(out charge, out mz, out mass, peakList, scanNumber, type, isotopeCorrelationThreshold, simpleMz);
                if (rawFile.GetMS2SignalType(i) != SignalType.Centroid)
                {
                    double[] specMasses;
                    float[]  specIntensities;
                    T01PeakDetection.DetectPeaks(s, false, 3, CentroidPosition.gaussian, out specMasses, out specIntensities);
                    s = new Spectrum(specMasses, specIntensities);
                }
                if (topx > 0)
                {
                    s = s.TopX(topx, 100);
                }
                int sn = rawFile.GetScanNumberFromMs2Index(i);
                if (s.Count == 0)
                {
                    continue;
                }
                StringBuilder sb = new StringBuilder();
                writer.Write(s.Count);
                for (int j = 0; j < s.Count; j++)
                {
                    sb.AppendFormat("{0:F3}\t{1:F2}\n", s.GetMass(j), s.GetIntensity(j));
                    writer.Write(s.GetMass(j));
                    writer.Write(1.0 * s.GetIntensity(j));
                }
                filePointers.Add(filePos);
                fileScanNumbers.Add(sn);
                filePos += 16 * s.Count + 4;
                sw.WriteLine("BEGIN IONS");
                sw.WriteLine("PEPMASS={0:F6}", mz);
                if (charge > 0)
                {
                    sw.WriteLine("CHARGE={0}+", charge);
                }
                else
                {
                    sw.WriteLine("CHARGE=2+ and 3+");
                }
                sw.WriteLine("TITLE=RawFile: {0} FinneganScanNumber: {1}", filename, sn);
                sw.Write(sb.ToString());
                sw.WriteLine("END IONS");
                sw.WriteLine();
            }
            writer.Close();
            sw.Close();
            pointers = filePointers.ToArray();
            return(fileScanNumbers.ToArray());
        }