public override int LoadIndex(string FileName)
        {
            this.RawFileName = FileName;

            RawFile  = new MassSpecDataReader();
            MSReader = RawFile;
            MSReader.OpenDataFile(FileName);
            Spectra = (int)(MSReader.MSScanFileInformation.TotalScansPresent);

            bool PosMode = false, NegMode = false;

            if (Spectra <= 0)
            {
                return(0);
            }

            int i, LastFull = 0, Total = 0;

            //there will be fake [0] spectra with no data and fake last spectra with no data
            //it is made to make any chromatogram start and end with zero
            IndexDir   = new int[Spectra + 2];
            IndexRev   = new int[Spectra + 2];
            RawSpectra = new RawSpectrum[Spectra + 2];
            for (int j = 0; j <= Spectra + 1; j++)
            {
                RawSpectra[j] = new RawSpectrum();
            }
            TimeStamps = new double[Spectra + 2];
            TimeCoefs  = new double[Spectra + 2];

            LowRT  = 0.0;
            HighRT = 0.0;

            int Progress = 0;

            for (i = 1; i <= Spectra; i++)
            {
                if ((int)(100.0 * ((double)i / (double)Spectra)) > Progress)//report progress
                {
                    Progress = (int)(100.0 * ((double)i / (double)Spectra));
                    RepProgress?.Invoke(Progress);
                }

                IMSScanRecord ScanRecord = MSReader.GetScanRecord(i - 1);

                if (ScanRecord.MSScanType == MSScanType.Scan && ScanRecord.MSLevel == MSLevel.MS && ScanRecord.CollisionEnergy == 0.0)          //if spectra is a FULL MS

                {
                    PosMode |= ScanRecord.IonPolarity == IonPolarity.Positive;
                    NegMode |= ScanRecord.IonPolarity == IonPolarity.Negative;

                    RawSpectra[i].RT   = ScanRecord.RetentionTime;
                    TimeStamps[i]      = RawSpectra[i].RT - RawSpectra[LastFull].RT;
                    RawSpectra[i].Scan = i;

                    IndexDir[LastFull] = i;
                    IndexRev[i]        = LastFull;

                    LastFull = i;

                    Total++;
                }
            }
            IndexDir[LastFull]    = Spectra + 1;
            IndexDir[Spectra + 1] = -1;
            IndexRev[Spectra + 1] = LastFull;

            TotalRT          = RawSpectra[LastFull].RT;
            AverageTimeStamp = TotalRT / Total;

            //time interval bias coefficients
            for (i = IndexDir[0]; IndexDir[i] != -1; i = IndexDir[i])
            {
                TimeCoefs[i] = (TimeStamps[i] + TimeStamps[IndexDir[i]]) / (2.0 * AverageTimeStamp);
            }
            TimeCoefs[i] = 1.0;

            //Fake spectra number 0 has to have reasonable RT
            double FRT = RawSpectra[IndexDir[0]].RT;
            double SRT = RawSpectra[IndexDir[IndexDir[0]]].RT;

            RawSpectra[0].RT = Math.Max(0, FRT - (SRT - FRT));
            //Last spectra also has to have reasonable RT
            FRT = RawSpectra[LastFull].RT;
            SRT = RawSpectra[IndexRev[LastFull]].RT;
            RawSpectra[Spectra + 1].RT = FRT + (FRT - SRT);

            RawSpectra[0].Data           = new MZData[0];
            RawSpectra[Spectra + 1].Data = new MZData[0];

            PeakFilter = new MsdrPeakFilter();
            PeakFilter.AbsoluteThreshold = 5.0;

            if (PosMode && !NegMode)
            {
                Mode = 1;
            }
            if (!PosMode && NegMode)
            {
                Mode = -1;
            }

            return(Spectra);
        }
Example #2
0
        public static PeakList <Peak> GetPeakList(this IMsdrDataReader reader, double retentionTime, IMsdrPeakFilter peakFilter)
        {
            PeakList <Peak> result = new PeakList <Peak>();

            IBDASpecData s = reader.GetSpectrum(retentionTime, MSScanType.All, IonPolarity.Mixed, IonizationMode.Unspecified, peakFilter, true);

            for (int i = 0; i < s.XArray.Length; i++)
            {
                result.Add(new Peak(s.XArray[i], s.YArray[i]));
            }

            if (s.MZOfInterest.Length > 0)
            {
                result.PrecursorMZ = s.MZOfInterest[0].Start;
            }

            result.ScanTimes.Add(new ScanTime(0, retentionTime));

            return(result);
        }