예제 #1
0
        public MSScan GetAllPeaks()
        {
            _Scan = new MSScan(0);
            int LineNumber = 0;
            StreamReader sr = new StreamReader(_filepath);
            string tmp;
            double floatout = -0.0f, mz, intensity;
            try
            {
                do
                {
                    tmp = sr.ReadLine();
                    LineNumber++;
                    if (double.TryParse(tmp.Split('\t')[0], out floatout))
                    {
                        mz = Convert.ToDouble(tmp.Split('\t')[0]);
                        intensity = Convert.ToDouble(tmp.Split('\t')[1]);
                        _Scan.AddPoint(new MSPoint(mz, intensity));
                    }

                } while (!sr.EndOfStream);

                if (_Scan.MSPointList.Count == 0)
                {
                    throw new Exception("Reading Peak in txt format error on Line:"+ LineNumber+"!! Please Check input File");
                }
                _Scan.ConvertHashTableToList();
                return _Scan;
            }
            catch
            {

                throw new Exception("Reading Peak in txt format error!! Please Check input File");
            }
            finally
            {
                sr.Close();
            }
        }
예제 #2
0
파일: Program.cs 프로젝트: chpaul/COL_Lib
 private static string SendScanViaNamedPipe(MSScan argMSScan)
 {
     System.Runtime.Serialization.IFormatter f = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
     MemoryStream memStream = new MemoryStream();
     f.Serialize(memStream, argMSScan);
     byte[] WriteBuffer = memStream.ToArray();
     string  responseMsg="";
     CSNamedPipe.NativeNamedPipeClient.Run(@"\\.\pipe\MSScan", WriteBuffer, out responseMsg);
     return responseMsg;
 }
예제 #3
0
파일: Program.cs 프로젝트: chpaul/COL_Lib
        private static MSScan GetScanFromFile(int argScanNo, double argSingleToNoise, double argPeakBackground, double argPeptideBackground, short argMaxCharge, GlypID.Readers.clsRawData Raw)
        {
            float[] _cidMzs = null;
            float[] _cidIntensities = null;
            GlypID.Peaks.clsPeak[] _cidPeaks = new GlypID.Peaks.clsPeak[1];
            GlypID.Peaks.clsPeak[] _parentPeaks = new GlypID.Peaks.clsPeak[1];

            GlypID.HornTransform.clsHornTransform mobjTransform = new GlypID.HornTransform.clsHornTransform();
            GlypID.HornTransform.clsHornTransformParameters mobjTransformParameters = new GlypID.HornTransform.clsHornTransformParameters() ;
            GlypID.HornTransform.clsHornTransformResults[] _transformResult;

            GlypID.Peaks.clsPeakProcessor cidPeakProcessor = new GlypID.Peaks.clsPeakProcessor();
            GlypID.Peaks.clsPeakProcessorParameters cidPeakParameters = new GlypID.Peaks.clsPeakProcessorParameters();

            GlypID.Peaks.clsPeakProcessor parentPeakProcessor = new GlypID.Peaks.clsPeakProcessor() ;
            GlypID.Peaks.clsPeakProcessorParameters parentPeakParameters = new GlypID.Peaks.clsPeakProcessorParameters();

            //Start Read Scan
            MSScan scan = new MSScan(argScanNo);

            Raw.GetSpectrum(argScanNo, ref _cidMzs, ref  _cidIntensities);
            scan.MsLevel = Raw.GetMSLevel(Convert.ToInt32(argScanNo));

            double min_peptide_intensity = 0;
            scan.Time = Raw.GetScanTime(scan.ScanNo);
            scan.ScanHeader = Raw.GetScanDescription(scan.ScanNo);
            if (scan.MsLevel != 1)
            {
                float[] _parentRawMzs = null;
                float[] _parentRawIntensitys = null;

                string Header = Raw.GetScanDescription(argScanNo);
                cidPeakProcessor.ProfileType = GlypID.enmProfileType.CENTROIDED;
                if (Header.Substring(Header.IndexOf("+") + 1).Trim().StartsWith("p"))
                {
                    cidPeakProcessor.ProfileType = GlypID.enmProfileType.PROFILE;
                }

                // cidPeakProcessor.DiscoverPeaks(ref _cidMzs, ref _cidIntensities, ref _cidPeaks,
                //         Convert.ToSingle(mobjTransformParameters.MinMZ), Convert.ToSingle(mobjTransformParameters.MaxMZ), false);

                for (int chNum = 0; chNum < _cidMzs.Length; chNum++)
                {
                    scan.MSPeaks.Add(new MSPeak(
                        Convert.ToSingle(_cidMzs[chNum]),
                        Convert.ToSingle(_cidIntensities[chNum])));
                }

                //for (int chNum = 0; chNum < _cidMzs.Length; chNum++)
                //{
                //    scan.MSPeaks.Add(new MSPeak(
                //        Convert.ToSingle(_cidMzs[chNum]),
                //        Convert.ToSingle(_cidIntensities[chNum])));
                //}

                // Get parent information
                scan.ParentScanNo = Raw.GetParentScan(scan.ScanNo);

                Raw.GetSpectrum(scan.ParentScanNo, ref _parentRawMzs, ref _parentRawIntensitys);
                parentPeakProcessor.ProfileType = GlypID.enmProfileType.PROFILE;
                parentPeakProcessor.DiscoverPeaks(ref _parentRawMzs, ref _parentRawIntensitys, ref _parentPeaks, Convert.ToSingle(mobjTransformParameters.MinMZ), Convert.ToSingle(mobjTransformParameters.MaxMZ), true);
                float _parentBackgroundIntensity = (float)parentPeakProcessor.GetBackgroundIntensity(ref _parentRawIntensitys);
                _transformResult = new GlypID.HornTransform.clsHornTransformResults[1];
                bool found = false;
                if (Raw.IsFTScan(scan.ParentScanNo))
                {
                    // High resolution data
                    found = mobjTransform.FindPrecursorTransform(Convert.ToSingle(_parentBackgroundIntensity), Convert.ToSingle(min_peptide_intensity), ref _parentRawMzs, ref _parentRawIntensitys, ref _parentPeaks, Convert.ToSingle(scan.ParentMZ), ref _transformResult);
                }
                if (!found)//de-isotope fail
                {
                    // Low resolution data or bad high res spectra
                    short cs = Raw.GetMonoChargeFromHeader(scan.ScanNo);
                    double monoMZ = Raw.GetMonoMzFromHeader(scan.ScanNo);
                    List<float> ParentMzs = new List<float>(_parentRawMzs);
                    int CloseIdx = MassUtility.GetClosestMassIdx(ParentMzs, Convert.ToSingle(monoMZ));

                    if (cs > 0)
                    {
                        short[] charges = new short[1];
                        charges[0] = cs;
                        mobjTransform.AllocateValuesToTransform(Convert.ToSingle(scan.ParentMZ), Convert.ToInt32(_parentRawIntensitys[CloseIdx]), ref charges, ref _transformResult);
                    }
                    else
                    {
                        // instrument has no charge just store 2 and 3.
                        short[] charges = new short[2];
                        charges[0] = 2;
                        charges[1] = 3;
                        mobjTransform.AllocateValuesToTransform(Convert.ToSingle(scan.ParentMZ), Convert.ToInt32(_parentRawIntensitys[CloseIdx]), ref charges, ref _transformResult);
                    }
                }

                if (_transformResult[0].mint_peak_index == -1) //De-isotope parent scan
                {
                    //Get parent info
                    MSScan _parentScan = GetScanFromFile(scan.ParentScanNo, argSingleToNoise, argPeakBackground, argPeptideBackground, argMaxCharge,Raw);
                    float[] _MSMzs = null;
                    float[] _MSIntensities = null;

                    Raw.GetSpectrum(scan.ParentScanNo, ref _MSMzs, ref  _MSIntensities);
                    // Now find peaks
                    parentPeakParameters.SignalToNoiseThreshold = 0;
                    parentPeakParameters.PeakBackgroundRatio = 0.01;
                    parentPeakProcessor.SetOptions(parentPeakParameters);
                    parentPeakProcessor.ProfileType = GlypID.enmProfileType.PROFILE;

                    parentPeakProcessor.DiscoverPeaks(ref _MSMzs, ref _MSIntensities, ref _cidPeaks,
                                            Convert.ToSingle(mobjTransformParameters.MinMZ), Convert.ToSingle(mobjTransformParameters.MaxMZ), true);

                    //Look for charge and mono.

                    float[] monoandcharge = FindChargeAndMono(_cidPeaks, Convert.ToSingle(Raw.GetParentMz(scan.ScanNo)), scan.ScanNo,Raw);
                    //scan.ParentMonoMW = _parentScan.MSPeaks[ClosedIdx].MonoMass;
                    //scan.ParentAVGMonoMW = _parentScan.MSPeaks[ClosedIdx].;
                    scan.ParentMZ = monoandcharge[0];
                    if (monoandcharge[1] == 0.0f)
                    {
                        scan.ParentCharge = Convert.ToInt32(Raw.GetMonoChargeFromHeader(scan.ParentScanNo));
                    }
                    else
                    {
                        scan.ParentCharge = Convert.ToInt32(monoandcharge[1]);
                    }

                    scan.ParentMonoMW = (monoandcharge[0] - Atoms.ProtonMass) * monoandcharge[1];

                }
                else
                {
                    scan.ParentMonoMW = (float)_transformResult[0].mdbl_mono_mw;
                    scan.ParentAVGMonoMW = (float)_transformResult[0].mdbl_average_mw;
                    scan.ParentMZ = (float)_transformResult[0].mdbl_mz;
                    scan.ParentCharge = (int)_transformResult[0].mshort_cs;
                }
                scan.IsCIDScan = Raw.IsCIDScan(argScanNo);
                scan.IsFTScan = Raw.IsFTScan(argScanNo);

                Array.Clear(_transformResult, 0, _transformResult.Length);
                Array.Clear(_cidPeaks, 0, _cidPeaks.Length);
                Array.Clear(_cidMzs, 0, _cidMzs.Length);
                Array.Clear(_cidIntensities, 0, _cidIntensities.Length);
                Array.Clear(_parentRawMzs, 0, _parentRawMzs.Length);
                Array.Clear(_parentRawIntensitys, 0, _parentRawIntensitys.Length);
            }
            else //MS Scan
            {
                scan.ParentMZ = 0.0f;
                double mdbl_current_background_intensity = 0;

                // Now find peaks
                parentPeakParameters.SignalToNoiseThreshold = argSingleToNoise;
                parentPeakParameters.PeakBackgroundRatio = argPeakBackground;
                parentPeakProcessor.SetOptions(parentPeakParameters);
                parentPeakProcessor.ProfileType = GlypID.enmProfileType.PROFILE;

                parentPeakProcessor.DiscoverPeaks(ref _cidMzs, ref _cidIntensities, ref _cidPeaks,
                                        Convert.ToSingle(mobjTransformParameters.MinMZ), Convert.ToSingle(mobjTransformParameters.MaxMZ), true);
                mdbl_current_background_intensity = parentPeakProcessor.GetBackgroundIntensity(ref _cidIntensities);

                // Settings
                min_peptide_intensity = mdbl_current_background_intensity * mobjTransformParameters.PeptideMinBackgroundRatio;
                if (mobjTransformParameters.UseAbsolutePeptideIntensity)
                {
                    if (min_peptide_intensity < mobjTransformParameters.AbsolutePeptideIntensity)
                        min_peptide_intensity = mobjTransformParameters.AbsolutePeptideIntensity;
                }
                mobjTransformParameters.PeptideMinBackgroundRatio = argPeptideBackground;
                mobjTransformParameters.MaxCharge = argMaxCharge;
                mobjTransform.TransformParameters = mobjTransformParameters;

                //  Now perform deisotoping
                _transformResult = new GlypID.HornTransform.clsHornTransformResults[1];
                mobjTransform.PerformTransform(Convert.ToSingle(mdbl_current_background_intensity), Convert.ToSingle(min_peptide_intensity), ref _cidMzs, ref _cidIntensities, ref _cidPeaks, ref _transformResult);
                // for getting results

                for (int chNum = 0; chNum < _transformResult.Length; chNum++)
                {
                    double sumintensity = 0.0;
                    double mostIntenseIntensity = 0.0;
                    for (int i = 0; i < _transformResult[chNum].marr_isotope_peak_indices.Length; i++)
                    {
                        sumintensity = sumintensity + _cidPeaks[_transformResult[chNum].marr_isotope_peak_indices[i]].mdbl_intensity;
                        if (Math.Abs(_transformResult[chNum].mdbl_most_intense_mw -
                            (_cidPeaks[_transformResult[chNum].marr_isotope_peak_indices[i]].mdbl_mz * _transformResult[chNum].mshort_cs - Atoms.ProtonMass * _transformResult[chNum].mshort_cs))
                            < 1.0 / _transformResult[chNum].mshort_cs)
                        {
                            mostIntenseIntensity = _cidPeaks[_transformResult[chNum].mint_peak_index].mdbl_intensity;
                        }
                    }
                    scan.MSPeaks.Add(new MSPeak(
                    Convert.ToSingle(_transformResult[chNum].mdbl_mono_mw),
                    _transformResult[chNum].mint_mono_intensity,
                    _transformResult[chNum].mshort_cs,
                    Convert.ToSingle(_transformResult[chNum].mdbl_mz),
                    Convert.ToSingle(_transformResult[chNum].mdbl_fit),
                    Convert.ToSingle(_transformResult[chNum].mdbl_most_intense_mw),
                    mostIntenseIntensity,
                    sumintensity
                    ));
                }
                Array.Clear(_transformResult, 0, _transformResult.Length);
                Array.Clear(_cidPeaks, 0, _cidPeaks.Length);
                Array.Clear(_cidMzs, 0, _cidMzs.Length);
                Array.Clear(_cidIntensities, 0, _cidIntensities.Length);
            }
            return scan;
        }
예제 #4
0
        //, float argPPM = 6, int argMinPeakCount=3)
        private MSScan GetScanFromFile(int argScanNo, float argMinSN = 2)
        {
            int mslevel = GetMsLevel(argScanNo);
            tolSN = argMinSN;
            MSScan scan = new MSScan(argScanNo);
            scan.MsLevel = GetMsLevel(argScanNo);
            scan.Time = GetRetentionTime(argScanNo);
            scan.ScanHeader =  GetScanDescription(argScanNo);

            double[,] peakData;
                if (GetMzAnalyzer(argScanNo) == ThermoMzAnalyzer.ITMS) //Low Res
                {
                    object massList = null;
                    object peakFlags = null;
                    int arraySize = -1;
                    double centroidPeakWidth = double.NaN;
                    _rawConnection.GetMassListFromScanNum(ref argScanNo, null, 0, 0, 0,0, ref centroidPeakWidth, ref massList, ref peakFlags, ref arraySize);
                    peakData = (double[,])massList;
                }
                else
                {
                    object labels = null;
                    object flags = null;
                    _rawConnection.GetLabelData(ref labels, ref flags, ref argScanNo);
                    peakData = (double[,])labels;
                }
                scan.RawMZs = new float[peakData.GetLength(1)];
                scan.RawIntensities = new float[peakData.GetLength(1)];
            if (mslevel == 1)
            {
                List<float> MzsAboveSN = new List<float>();
                List<float> IntensitysAboveSN = new List<float>();

                    for (int i = 0; i < peakData.GetLength(1); i++)
                    {
                        scan.RawMZs[i] = Convert.ToSingle(peakData[(int) RawLabelDataColumn.MZ, i]);
                        scan.RawIntensities[i] = Convert.ToSingle(peakData[(int) RawLabelDataColumn.Intensity, i]);
                        if (peakData.GetLength(0) >= 4) //Data contain SN
                        {
                            double Noise = peakData[(int) RawLabelDataColumn.NoiseLevel, i];
                            double SN = 0;
                            if (Noise.Equals(0))
                            {
                                SN = float.NaN;
                            }
                            else
                            {
                                SN = scan.RawIntensities[i]/Noise;
                            }
                            if (SN >= tolSN)
                            {
                                MzsAboveSN.Add(scan.RawMZs[i]);
                                IntensitysAboveSN.Add(scan.RawIntensities[i]);
                            }
                        }
                        else
                        {
                            MzsAboveSN.Add(scan.RawMZs[i]);
                            IntensitysAboveSN.Add(scan.RawIntensities[i]);
                        }
                    }
                    scan.MZs = MzsAboveSN.ToArray();
                    scan.Intensities = IntensitysAboveSN.ToArray();
            }
            else // MS/MS
            {
                scan.MZs = new float[peakData.GetLength(1)];
                scan.Intensities = new float[peakData.GetLength(1)];
                for (int i = 0; i < peakData.GetLength(1); i++)
                {
                    scan.MZs[i] = Convert.ToSingle(peakData[(int) RawLabelDataColumn.MZ, i]);
                    scan.Intensities[i] = Convert.ToSingle(peakData[(int) RawLabelDataColumn.Intensity, i]);
                }
                scan.ParentScanNo = GetParentScanNumber(argScanNo);
                scan.ParentMZ = GetPrecusorMz(argScanNo);
                scan.ParentCharge = GetPrecusorCharge(argScanNo);

                //Sometime get wrong value
                //scan.ParentMonoMz = Convert.ToSingle(GetExtraValue(argScanNo, "Monoisotopic M/Z:"));
                //Find in raw data
                scan.ParentMonoMz = GetPrecusorMz(argScanNo);
                MSScan parentScan = GetScanFromFile(scan.ParentScanNo);
                float peakBefore = scan.ParentMZ - (1/(float) scan.ParentCharge);
                float foundPeak = parentScan.RawMZs.OrderBy(x => Math.Abs(x - peakBefore)).ToList()[0];
                while (MassUtility.GetMassPPM(foundPeak, peakBefore) <= 10) //10PPM
                {
                    //Find another
                    scan.ParentMonoMz = foundPeak;
                    peakBefore = foundPeak - (1 / (float)scan.ParentCharge);
                    foundPeak = parentScan.MZs.OrderBy(x => Math.Abs(x - peakBefore)).ToList()[0];
                }
                scan.ParentBasePeak = parentScan.MaxIntensity;
                scan.ParentIntensity = parentScan.RawIntensities[parentScan.RawMZs.ToList().IndexOf(scan.ParentMonoMz)];
            }

            scan.IsCIDScan = IsCIDScan(argScanNo);
            scan.IsHCDScan = IsHCDScan(argScanNo);
            scan.IsFTScan = IsFTScan(argScanNo);
            return scan;
        }
예제 #5
0
        public static Image GetAnnotatedImage(string argPeptide, MSScan argScan, List<MSPoint> argPeaks, GlycanStructure argStructure)
        {
            float MaxX = argStructure.Root.FetchAllGlycanNode().OrderByDescending(o => o.IDMass).ToList()[0].IDMass;
            if (MaxX + 100 > 2000.0)
            {
                MaxX = 2000.0f;
            }
            else
            {
                MaxX = MaxX + 100;
            }
            ZedGraph.GraphPane Pane = new ZedGraph.GraphPane(new RectangleF(0.0f, 0.0f, 2000.0f, 1500.0f), argScan.ScanNo.ToString(), "Mass", "Intensity");
            //ZedGraph.MasterPane Pane = new ZedGraph.MasterPane(argTitle,new RectangleF(0.0f, 0.0f, 2400.0f, 1800.0f) );
            Pane.XAxis.MajorTic.IsInside = false;
            Pane.XAxis.MinorTic.IsInside = false;
            Pane.Legend.IsVisible = false;
            ZedGraph.PointPairList Peaks = new ZedGraph.PointPairList();

            double MaxIntensity = 0.0;
            /////////////////
            //Peaks
            ////////////////
            foreach (MSPoint p in argPeaks)
            {
                if (p.Intensity > MaxIntensity && p.Mass<=MaxX)
                {
                    MaxIntensity = p.Intensity;
                }
            }
            foreach (MSPoint p in argPeaks)
            {
                if (p.Mass <= MaxX)
                {
                    Peaks.Add(p.Mass, (p.Intensity/MaxIntensity)*100.0);
                }
            }
            Pane.AddStick("Peaks", Peaks, Color.Red);

            //////////////////
            //Y1 text object
            //////////////////
            /* ZedGraph.TextObj txtY1 = new ZedGraph.TextObj("Y1", argStructure.Y1.MZ, 102);
             txtY1.FontSpec.Size = txtY1.FontSpe.cSize*0.5f;
             txtY1.FontSpec.Border.IsVisible = false;
             Pane.GraphObjList.Insert(0, txtY1);*/

            /////////////////
            //Structure
            ////////////////
            GlycansDrawer GS;
            double previousBoundary = 0;

            foreach (GlycanTreeNode t in argStructure.Root.FetchAllGlycanNode().OrderBy(o => o.IDMass).ToList())
            {

                GS = new GlycansDrawer(t.IUPACFromRoot, false);
                double glycopeptideMZ = t.IDMass;
                //double glycopeptideMZ =argStructure.Y1.Mass - GlycanMass.GetGlycanMasswithCharge(Glycan.Type.HexNAc, FGS.Charge);
                //glycopeptideMZ = glycopeptideMZ +
                //                 FGS.NoOfHexNac * GlycanMass.GetGlycanAVGMasswithCharge(Glycan.Type.HexNAc, FGS.Charge);
                //glycopeptideMZ = glycopeptideMZ +
                //                 FGS.NoOfHex*GlycanMass.GetGlycanAVGMasswithCharge(Glycan.Type.Hex, FGS.Charge);
                //glycopeptideMZ = glycopeptideMZ +
                //                 FGS.NoOfDeHex * GlycanMass.GetGlycanAVGMasswithCharge(Glycan.Type.DeHex, FGS.Charge);
                //glycopeptideMZ = glycopeptideMZ +
                //                 FGS.NoOfNeuAc * GlycanMass.GetGlycanAVGMasswithCharge(Glycan.Type.NeuAc, FGS.Charge);
                //glycopeptideMZ = glycopeptideMZ +
                //                 FGS.NoOfNeuGc * GlycanMass.GetGlycanAVGMasswithCharge(Glycan.Type.NeuGc, FGS.Charge);
                Image imgStructure = GlycanImage.RotateImage(GS.GetImage(), 270);

                ZedGraph.TextObj txtGlycanMz = new ZedGraph.TextObj(glycopeptideMZ.ToString("0.000"), 100, 131);

                double PositionX = glycopeptideMZ;

                if (previousBoundary >= PositionX)
                {
                    PositionX = previousBoundary + 20;
                }

                if (imgStructure.Width > txtGlycanMz.Location.Width)
                {
                    previousBoundary = imgStructure.Width + PositionX;
                }
                else
                {
                    previousBoundary = (float)txtGlycanMz.Location.Width + PositionX;
                }
                ZedGraph.ImageObj glycan = new ZedGraph.ImageObj(imgStructure, PositionX, 130, imgStructure.Width + 20, imgStructure.Height);

                glycan.IsScaled = false;
                glycan.Location.AlignV = ZedGraph.AlignV.Bottom;

                txtGlycanMz.Location.X = glycan.Location.X + (float)glycan.Image.Width / 2 - (float)txtGlycanMz.Location.Width / 2;
                txtGlycanMz.FontSpec.Size = txtGlycanMz.FontSpec.Size * 0.3f;
                txtGlycanMz.FontSpec.Border.IsVisible = false;

                Pane.GraphObjList.Add(txtGlycanMz);
                Pane.GraphObjList.Add(glycan);

                double interval = 100000;
                int idx = 0;
                for (int i = 0; i < Peaks.Count; i++)
                {
                    if (Math.Abs(Peaks[i].X - glycopeptideMZ) < interval)
                    {
                        interval = Math.Abs((float)Peaks[i].X - glycopeptideMZ);
                        idx = i;
                    }
                }
                string mzLabelwPPM = Peaks[idx].X.ToString("0.000");// + "\n(" + Math.Abs(glycopeptideMZ - (float)Peaks[idx].X).ToString("0") + "da)";
                ZedGraph.TextObj PeakLabel = new ZedGraph.TextObj(mzLabelwPPM, Peaks[idx].X, Peaks[idx].Y + 3.0);
                PeakLabel.FontSpec.Size = PeakLabel.FontSpec.Size * 0.3f;
                PeakLabel.FontSpec.Border.IsVisible = false;
                PeakLabel.FontSpec.Fill.IsVisible = false;
                Pane.GraphObjList.Add(PeakLabel);
            }
            Pane.AxisChange();

            Pane.YAxis.Scale.Max = 145;
            Pane.XAxis.Scale.Min = Convert.ToInt32(argStructure.Y1.Mass - 100);
            Pane.XAxis.Scale.Max = Peaks[Peaks.Count - 1].X + 100;
            ////////////
            //Glycan Structure
            ////////////
            GS = new GlycansDrawer(argStructure.IUPACString, false);
            Image imgStruc = RotateImage( GS.GetImage() ,180);
            ZedGraph.ImageObj fullStructure = new ZedGraph.ImageObj(imgStruc, Pane.XAxis.Scale.Min + 20, 140, imgStruc.Width + 20, imgStruc.Height);
            fullStructure.IsScaled = false;
            Pane.GraphObjList.Add(fullStructure);
            ///////////////
            //Glycan M/Z
            //////////////
            double glycopeptidemz = GlycanMass.GetGlycanMasswithCharge(argStructure.Root.GlycanType,argStructure.Charge) + argStructure.Y1.Mass - GlycanMass.GetGlycanMasswithCharge(Glycan.Type.HexNAc, argStructure.Charge);
            ZedGraph.TextObj txtGlycanMZ = new ZedGraph.TextObj("\n              Precursor:" + argScan.ParentMZ.ToString("0.000")+"(" +argScan.ParentCharge.ToString()+")"+
                                                                                                                "\nPeptide Sequence:" + argPeptide
                    , Pane.GraphObjList[Pane.GraphObjList.Count - 1].Location.X2, 140);
            txtGlycanMZ.FontSpec.Size = txtGlycanMZ.FontSpec.Size * 0.3f;
            txtGlycanMZ.FontSpec.Border.IsVisible = false;
            txtGlycanMZ.FontSpec.Fill.IsVisible = false;
            Pane.GraphObjList.Add(txtGlycanMZ);
            Image tmp = (Image)Pane.GetImage();

            return tmp;
        }
예제 #6
0
        public MSScan ReadScan(int argScanNum)
        {
            string ScanXML = "";
            if (_scanOffset != null && _scanOffset.ContainsKey(argScanNum)) //has index offset
            {
                using (StreamReader sr = new StreamReader(_filepath))
                {
                    sr.BaseStream.Seek(_scanOffset[argScanNum], SeekOrigin.Begin);
                    string line = sr.ReadLine();
                    do
                    {
                        ScanXML = ScanXML + line+"\n";
                        line = sr.ReadLine();
                    } while (!line.Contains("</scan>"));
                    ScanXML = ScanXML + line + "\n";
                }
            }
            else //no indexOffset
            {
                using (XmlReader reader = XmlReader.Create(_filepath))
                {
                    while (reader.ReadToFollowing("scan"))
                    {
                        if (reader.GetAttribute("num") == argScanNum.ToString())
                        {
                            ScanXML = reader.ReadInnerXml();
                            break;
                        }
                    }
                }
            }
            MSScan _scan =new MSScan(argScanNum);
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(ScanXML);
            XmlNode XmlScan = doc.FirstChild;
            int PeakCount = 0;
            foreach (XmlAttribute attribute in XmlScan.Attributes)
            {
                switch (attribute.Name)
                {
                    case "msLevel":
                        _scan.MsLevel = Convert.ToInt32(attribute.Value);
                        break;
                    case"peaksCount":
                        PeakCount = Convert.ToInt32(attribute.Value);
                        break;
                    case "retentionTime":
                        _scan.Time = Convert.ToDouble(attribute.Value.Substring(2, attribute.Value.Length - 3)) / 60.0;
                        break;
                }
            }
            //Peaks
            XmlNode Peaks = XmlScan.FirstChild;
            while (Peaks.Name != "peaks")
            {
                Peaks =Peaks.NextSibling;
            }

            int Precision = Convert.ToInt32(Peaks.Attributes["precision"].Value);
            List<MSPoint> tmp = ParsePeakNode(Peaks.InnerText, PeakCount, Precision);
            float[] mz = new float[PeakCount];
            float[] intensity = new float[PeakCount];

            for (int i = 0; i < PeakCount; i++)
            {
                mz[i] = Convert.ToSingle(tmp[i].Mass);
                intensity[i] = Convert.ToSingle(tmp[i].Intensity);
            }
            _scan.RawMZs = mz;
            _scan.RawIntensities = intensity;
            _scan.MZs = mz;
            _scan.Intensities = intensity;
            return _scan;
        }
예제 #7
0
        /// <summary>
        /// Merge All Peaks to Scan 0
        /// </summary>
        /// <returns></returns>
        //public MSScan GetAllPeaks()
        //{
        //  xmlReader = new XmlTextReader(_filepath);
        //  MSScan _scan = new MSScan(0);
        //    //List<MSPoint> _msp = new List<MSPoint>();
        //    xmlReader.XmlResolver = null;
        //    try
        //    {
        //        while (xmlReader.Read())
        //        {
        //            switch (xmlReader.NodeType)
        //            {
        //                case XmlNodeType.Element: // The node is an element.
        //                    if (xmlReader.Name == "scan")
        //                    {
        //                        if (xmlReader.GetAttribute("msLevel") == "1")
        //                        {
        //                            int PeakCount = Convert.ToInt32(xmlReader.GetAttribute("peaksCount"));
        //                            int ScanNum = Convert.ToInt32(xmlReader.GetAttribute("num"));
        //                            xmlReader.Read();
        //                            xmlReader.Read();
        //                            if (xmlReader.Name == "peaks")
        //                            {
        //                                int Precision = Convert.ToInt32(xmlReader.GetAttribute("precision"));
        //                                xmlReader.Read();
        //                                string peakString = xmlReader.Value;
        //                                List<MSPoint> tmp = ParsePeakNode(peakString, PeakCount);
        //                                foreach (MSPoint p in tmp)
        //                                {
        //                                    _scan.AddPoint(p);
        //                                }
        //                            }
        //                        }
        //                    }
        //                    break;
        //            }
        //        }
        //       // _scan.ConvertHashTableToList();
        //        return _scan;
        //    }
        //    catch
        //    {
        //        throw new Exception("Reading Peak in mzXML format error!! Please Check input File");
        //    }
        //}
        private MSScan GetScanFromFile(int argScanNo)
        {
            MSScan _scan = new MSScan(argScanNo);

            return _scan;
        }
예제 #8
0
        //, float argPPM = 6, int argMinPeakCount=3)
        //private MSScan GetScanFromFile(int argScanNo)
        //{
        //    return GetScanFromFile(argScanNo);
        //}
        private MSScan GetScanFromFile(int argScanNo, float argMinSN = 2)
        {
            MSDataScan DataScan = _raw.GetMsScan(argScanNo);
            tolSN = argMinSN;
            //tolMinPeakCount = argMinPeakCount;
            //tolPPM = argPPM;
            MZPeak[] peaks;
            List<ThermoLabeledPeak> TPeaks = new List<ThermoLabeledPeak>();
            peaks = DataScan.MassSpectrum.GetPeaks();

            //Start Read Scan
            MSScan  scan = new MSScan(argScanNo);
            scan.MsLevel = GetMsLevel(argScanNo);
            scan.Time = _raw.GetRetentionTime(argScanNo);
            scan.ScanHeader = _raw.GetScanFilter(argScanNo);

            List<MSPeak> MSPsks = new List<MSPeak>();

            #region MSScan
            if (scan.MsLevel == 1)
            {
                float[] RawMz = new float[peaks.Length];
                float[] RawIntensity = new float[peaks.Length];

                for (int i = 0; i < peaks.Length; i++)
                {
                    RawMz[i] = Convert.ToSingle(peaks[i].MZ);
                    RawIntensity[i] = Convert.ToSingle(peaks[i].Intensity);
                    ThermoLabeledPeak TPeak = (ThermoLabeledPeak)peaks[i];
                    if ( TPeak.SN >= tolSN )
                    {
                        TPeaks.Add(TPeak);
                    }
                }
                float[] Mz = new float[TPeaks.Count];
                float[] Intensity = new float[TPeaks.Count];
                for (int i = 0; i < TPeaks.Count; i++)
                {
                    Mz[i] = Convert.ToSingle(TPeaks[i].MZ);
                    Intensity[i] = Convert.ToSingle(TPeaks[i].Intensity);
                }
                scan.RawMZs = RawMz;
                scan.RawIntensities = RawIntensity;
                scan.MZs = Mz;
                scan.Intensities = Intensity;
                //************************Peak Picking
                //scan.MSPeaks = MSPsks;
                //List<float> TPeaksMZ = new List<float>();
                //for (int i = 0; i < TPeaks.Count; i++)
                //{
                //    TPeaksMZ.Add(Convert.ToSingle(TPeaks[i].MZ));
                //}
                //do
                //{
                //    ThermoLabeledPeak BasePeak = TPeaks[0];
                //    List<ThermoLabeledPeak> clusterPeaks = new List<ThermoLabeledPeak>();
                //    List<int> RemoveIdx = new List<int>();
                //    RemoveIdx.Add(0);
                //    clusterPeaks.Add(BasePeak);
                //    double Interval = 1 / (double)BasePeak.Charge;
                //    double FirstMZ = BasePeak.MZ;
                //    for (int i = 1; i < TPeaks.Count; i++)
                //    {
                //        if (TPeaks[i].MZ - FirstMZ > Interval * 10)
                //        {
                //            break;
                //        }

                //        List<int> ClosePeaks = MassUtility.GetClosestMassIdxsWithinPPM(TPeaksMZ.ToArray(), Convert.ToSingle(BasePeak.MZ + Interval), argPPM);
                //        if (ClosePeaks.Count == 1 && TPeaks[ClosePeaks[0]].Charge == BasePeak.Charge)
                //        {
                //            BasePeak = TPeaks[i];
                //            clusterPeaks.Add(TPeaks[i]);
                //            RemoveIdx.Add(i);
                //        }
                //        else if (ClosePeaks.Count > 1)
                //        {
                //            double minPPM = 100;
                //            int minPPMIdx = 0;
                //            float maxIntensity = 0;
                //            int maxIntensityIdx = 0;
                //            for (int j = 0; j < ClosePeaks.Count; j++)
                //            {
                //                if (MassUtility.GetMassPPM(BasePeak.MZ + Interval, mz[ClosePeaks[j]]) < minPPM)
                //                {
                //                    minPPMIdx = ClosePeaks[j];
                //                    minPPM = MassUtility.GetMassPPM(BasePeak.MZ + Interval, mz[ClosePeaks[j]]);
                //                }
                //                if (intensity[ClosePeaks[j]] > maxIntensity)
                //                {
                //                    maxIntensity = intensity[ClosePeaks[j]];
                //                    maxIntensityIdx = ClosePeaks[j];
                //                }
                //            }
                //            BasePeak = TPeaks[minPPMIdx];
                //            clusterPeaks.Add(TPeaks[minPPMIdx]);
                //            RemoveIdx.Add(minPPMIdx);
                //        }
                //    }
                //    if (clusterPeaks.Count < argMinPeakCount)
                //    {
                //        TPeaks.RemoveAt(RemoveIdx[0]);
                //        TPeaksMZ.RemoveAt(RemoveIdx[0]);
                //    }
                //    else
                //    {
                //        float MostIntenseMZ = 0.0f;
                //        double MostIntenseIntneisty = 0;
                //        double ClusterIntensity = 0;
                //        RemoveIdx.Reverse();
                //        for (int i = 0; i < RemoveIdx.Count; i++)
                //        {
                //            if (TPeaks[RemoveIdx[i]].Intensity > MostIntenseIntneisty)
                //            {
                //                MostIntenseIntneisty = TPeaks[RemoveIdx[i]].Intensity;
                //                MostIntenseMZ = Convert.ToSingle(TPeaks[RemoveIdx[i]].MZ);
                //            }
                //            ClusterIntensity = ClusterIntensity + TPeaks[RemoveIdx[i]].Intensity;
                //            TPeaks.RemoveAt(RemoveIdx[i]);
                //            TPeaksMZ.RemoveAt(RemoveIdx[i]);
                //        }
                //        scan.MSPeaks.Add(new MSPeak(
                //                                                                 Convert.ToSingle(clusterPeaks[0].MZ),
                //                                                                 Convert.ToSingle(clusterPeaks[0].Intensity),
                //                                                                 clusterPeaks[0].Charge,
                //                                                                 Convert.ToSingle(clusterPeaks[0].MZ),
                //                                                                 Convert.ToSingle(clusterPeaks[0].SN),
                //                                                                 MostIntenseMZ,
                //                                                                 MostIntenseIntneisty,
                //                                                                 ClusterIntensity));

                //    }
                //} while (TPeaks.Count != 0);

            }
            #endregion
            #region MS/MS Scan
            else
            {
                float[] mz = new float[peaks.Length];
                float[] intensity = new float[peaks.Length];
                for (int i = 0; i < peaks.Length; i++)
                {
                    mz[i] = Convert.ToSingle(peaks[i].MZ);
                    intensity[i] = Convert.ToSingle(peaks[i].Intensity);
                    //MSPsks.Add(new MSPeak(mz[i], intensity[i]));
                }
                scan.MZs = mz;
                scan.Intensities = intensity;
                //scan.MSPeaks = MSPsks;
               // Get parent information

                scan.ParentScanNo = _raw.GetParentSpectrumNumber(argScanNo);
                scan.ParentMZ = Convert.ToSingle(_raw.GetPrecusorMz(argScanNo));
                scan.ParentCharge = _raw.GetPrecusorCharge(argScanNo);

                //Parent Mono
                if (scan.ParentScanNo != 0)
                {
                    MSScan ParentScan = GetScanFromFile(scan.ParentScanNo);
                    int ClosedIdx = MassUtility.GetClosestMassIdx(ParentScan.MZs, scan.ParentMZ);
                    List<int> Peaks = FindPeakIdx(ParentScan.MZs, ClosedIdx, scan.ParentCharge, 10);
                    scan.ParentMonoMz = ParentScan.MZs[Peaks[0]];
                }
            }
            #endregion
            scan.IsCIDScan = IsCIDScan(argScanNo);
            scan.IsHCDScan = IsHCDScan(argScanNo);
            scan.IsFTScan = IsFTScan(argScanNo);
            return scan;
        }
예제 #9
0
        private MSScan GetScanFromFile(int argScanNo, float argMinSN = 2)
        {
            int isProfile = 0;
            _rawConnection.IsProfileScanForScanNum(argScanNo, ref isProfile);

            object labels = null;
            object flags = null;
            _rawConnection.GetLabelData(ref labels, ref flags, ref argScanNo);
            double[,] LabeledPeaks = (double[,])labels;

            //Start Read Scan
            MSScan scan = new MSScan(argScanNo);
            List<ThermoLabeledPeak> FullLabeledPeak = new List<ThermoLabeledPeak>();
            float[] mz = new float[LabeledPeaks.GetLength(1)];
            float[] intensity = new float[LabeledPeaks.GetLength(1)];
            int j = 0;
            for (int i = 0; i < LabeledPeaks.GetLength(1); i++)
            {
                double sn = LabeledPeaks[1, i] / LabeledPeaks[4, i];
                if (sn >= argMinSN)
                {
                    mz[j] = Convert.ToSingle(LabeledPeaks[0, i]);
                    intensity[j] = Convert.ToSingle(LabeledPeaks[1, i]);
                    j++;
                    FullLabeledPeak.Add(new ThermoLabeledPeak(
                                                                                                        Convert.ToSingle(LabeledPeaks[0, i]),
                                                                                                        Convert.ToSingle(LabeledPeaks[1, i]),
                                                                                                        Convert.ToInt32( LabeledPeaks[5, i]),
                                                                                                        Convert.ToSingle(LabeledPeaks[4,i])));
                }
            }
            Array.Resize(ref mz, j);
            Array.Resize(ref intensity, j);

            //scan.MZs = ConvertDoubleArrayToFloatArray(CSMSLScan.MassSpectrum.GetMasses());
            scan.MZs = mz;
            //scan.Intensities = ConvertDoubleArrayToFloatArray(CSMSLScan.MassSpectrum.GetIntensities());
            scan.Intensities = intensity;
            scan.MsLevel = GetMsLevel(argScanNo);

            double retentionTime = 0;
            _rawConnection.RTFromScanNum(argScanNo, ref retentionTime);
            scan.Time = retentionTime;
            scan.ScanHeader = GetScanDescription(argScanNo);

            if (scan.MsLevel != 1)
            {
                for (int chNum = 0; chNum < scan.MZs.Length; chNum++)
                {
                    scan.MSPeaks.Add(new MSPeak(
                        Convert.ToSingle(scan.MZs[chNum]),
                        Convert.ToSingle(scan.Intensities[chNum])));
                }

                // Get parent information
                object value = null;
                _rawConnection.GetTrailerExtraValueForScanNum(argScanNo, "Master Scan Number:", ref value);
                scan.ParentScanNo = Convert.ToInt32(value);
                string ParentDesc = GetScanDescription(scan.ParentScanNo);

                //_rawConnection.GetPrecursorInfoFromScanNum(argScanNo, ref PrecursorInfo, ref PrecursorInfoSize);

                //scan.ParentMonoMW = Convert.ToSingle(PrecurorArray.);
                //scan.ParentMZ = Convert.ToSingle(PrecurorArray[1,0]);
                //scan.ParentCharge = Convert.ToInt32(PrecurorArray.nChargeState);
                scan.IsCIDScan = IsCIDScan(argScanNo);
                scan.IsFTScan = IsFTScan(argScanNo);

                //Array.Clear(_transformResult, 0, _transformResult.Length);
                //Array.Clear(_cidPeaks, 0, _cidPeaks.Length);
                //Array.Clear(_cidMzs, 0, _cidMzs.Length);
                //Array.Clear(_cidIntensities, 0, _cidIntensities.Length);
                //Array.Clear(_parentRawMzs, 0, _parentRawMzs.Length);
                //Array.Clear(_parentRawIntensitys, 0, _parentRawIntensitys.Length);
            }
            else //MS Scan
            {
                do
                {
                    ThermoLabeledPeak BasePeak = FullLabeledPeak[0];
                    List<ThermoLabeledPeak> clusterPeaks = new List<ThermoLabeledPeak>();
                    List<int> RemoveIdx = new List<int>();
                    RemoveIdx.Add(0);
                    clusterPeaks.Add(BasePeak);
                    double Interval = 1 / (double)BasePeak.Charge;
                    double FirstMZ = BasePeak.MZ;
                    for (int i = 1; i < FullLabeledPeak.Count; i++)
                    {
                        if (FullLabeledPeak[i].MZ - FirstMZ > Interval * 10)
                        {
                            break;
                        }
                        if ((FullLabeledPeak[i].MZ - (BasePeak.MZ + Interval)) < 0.1 && (FullLabeledPeak[i].MZ - (BasePeak.MZ + Interval)) >= 0 && clusterPeaks[0].Charge == FullLabeledPeak[i].Charge)
                        {
                            BasePeak = FullLabeledPeak[i];
                            clusterPeaks.Add(FullLabeledPeak[i]);
                            RemoveIdx.Add(i);
                        }
                    }
                    if (clusterPeaks.Count < 3)
                    {
                        FullLabeledPeak.RemoveAt(RemoveIdx[0]);
                    }
                    else
                    {
                        float MostIntenseMZ =0.0f;
                        double MostIntenseIntneisty = 0;
                        double ClusterIntensity = 0;
                        RemoveIdx.Reverse();
                        for (int i = 0; i < RemoveIdx.Count; i++)
                        {
                            if(FullLabeledPeak[RemoveIdx[i]].Intensity> MostIntenseIntneisty)
                            {
                                MostIntenseIntneisty = FullLabeledPeak[RemoveIdx[i]].Intensity;
                                MostIntenseMZ = FullLabeledPeak[RemoveIdx[i]].MZ;
                            }
                            ClusterIntensity = ClusterIntensity + FullLabeledPeak[RemoveIdx[i]].Intensity;
                            FullLabeledPeak.RemoveAt(RemoveIdx[i]);
                        }
                        scan.MSPeaks.Add(new MSPeak(clusterPeaks[0].Mass, clusterPeaks[0].Intensity, clusterPeaks[0].Charge, clusterPeaks[0].MZ, clusterPeaks[0].SN, MostIntenseMZ, MostIntenseIntneisty, ClusterIntensity));

                    }
                } while (FullLabeledPeak.Count != 0);

                //Array.Clear(_transformResult, 0, _transformResult.Length);
                //Array.Clear(_cidPeaks, 0, _cidPeaks.Length);
                //Array.Clear(_cidMzs, 0, _cidMzs.Length);
                //Array.Clear(_cidIntensities, 0, _cidIntensities.Length);
            }
            return scan;
        }
예제 #10
0
        private MSScan GetScanFromFile(int argScanNo)
        {
            MSScan scan = new MSScan(argScanNo);
            float[] _cidMzs = null;
            float[] _cidIntensities = null;

            Raw.GetSpectrum(argScanNo, ref _cidMzs, ref  _cidIntensities);
            scan.MsLevel = Raw.GetMSLevel(argScanNo);

            double min_peptide_intensity = 0;
            scan.Time = Raw.GetScanTime(scan.ScanNo);
            scan.ScanHeader = Raw.GetScanDescription(scan.ScanNo);
            if (scan.MsLevel != 1)
            {
                float[] _parentRawMzs = null;
                float[] _parentRawIntensitys = null;

                scan.ParentMZ = (float)Raw.GetParentMz(argScanNo);

                cidPeakProcessor.ProfileType = GlypID.enmProfileType.CENTROIDED;
                cidPeakProcessor.DiscoverPeaks(ref _cidMzs, ref _cidIntensities, ref _cidPeaks,
                        Convert.ToSingle(mobjTransformParameters.MinMZ), Convert.ToSingle(mobjTransformParameters.MaxMZ), false);

                for (int chNum = 0; chNum < _cidPeaks.Length; chNum++)
                {
                    scan.MSPeaks.Add(new MSPeak(
                        Convert.ToSingle(_cidPeaks[chNum].mdbl_mz),
                        Convert.ToSingle(_cidPeaks[chNum].mdbl_intensity)));
                }

                //for (int chNum = 0; chNum < _cidMzs.Length; chNum++)
                //{
                //    scan.MSPeaks.Add(new MSPeak(
                //        Convert.ToSingle(_cidMzs[chNum]),
                //        Convert.ToSingle(_cidIntensities[chNum])));
                //}

                // Get parent information
                scan.ParentScanNo = Raw.GetParentScan(scan.ScanNo);

                Raw.GetSpectrum(scan.ParentScanNo, ref _parentRawMzs, ref _parentRawIntensitys);
                parentPeakProcessor.ProfileType = GlypID.enmProfileType.PROFILE;
                parentPeakProcessor.DiscoverPeaks(ref _parentRawMzs, ref _parentRawIntensitys, ref _parentPeaks, Convert.ToSingle(mobjTransformParameters.MinMZ), Convert.ToSingle(mobjTransformParameters.MaxMZ), true);
                float _parentBackgroundIntensity = (float)parentPeakProcessor.GetBackgroundIntensity(ref _parentRawIntensitys);

                bool found = mobjTransform.FindPrecursorTransform(Convert.ToSingle(_parentBackgroundIntensity), Convert.ToSingle(min_peptide_intensity), ref _parentRawMzs, ref _parentRawIntensitys, ref _parentPeaks, Convert.ToSingle(scan.ParentMZ), ref _transformResult);
                if (Raw.IsFTScan(scan.ParentScanNo))
                {
                    // High resolution data
                    found = mobjTransform.FindPrecursorTransform(Convert.ToSingle(_parentBackgroundIntensity), Convert.ToSingle(min_peptide_intensity), ref _parentRawMzs, ref _parentRawIntensitys, ref _parentPeaks, Convert.ToSingle(scan.ParentMZ), ref _transformResult);
                }
                //if (!found) //de-isotope fail
                //{
                //    // Low resolution data or bad high res spectra
                //    short cs = Raw.GetMonoChargeFromHeader(scan.ScanNo);
                //    if (cs > 0)
                //    {
                //        short[] charges = new short[1];
                //        charges[0] = cs;
                //        mobjTransform.AllocateValuesToTransform(Convert.ToSingle(scan.ParentMZ), ref charges, ref _transformResult);
                //    }
                //    else
                //    {
                //        // instrument has no charge just store 2 and 3.
                //        short[] charges = new short[2];
                //        charges[0] = 2;
                //        charges[1] = 3;
                //        mobjTransform.AllocateValuesToTransform(Convert.ToSingle(scan.ParentMZ), ref charges, ref _transformResult);
                //    }
                //}
                scan.ParentMonoMW = (float)_transformResult[0].mdbl_mono_mw;
                scan.ParentAVGMonoMW = (float)_transformResult[0].mdbl_average_mw;
                scan.ParentCharge = (int)_transformResult[0].mshort_cs;

                Array.Clear(_transformResult, 0, _transformResult.Length);
                Array.Clear(_cidPeaks, 0, _cidPeaks.Length);
                Array.Clear(_cidMzs, 0, _cidMzs.Length);
                Array.Clear(_cidIntensities, 0, _cidIntensities.Length);
                Array.Clear(_parentRawMzs, 0, _parentRawMzs.Length);
                Array.Clear(_parentRawIntensitys, 0, _parentRawIntensitys.Length);
            }
            else //MS Scan
            {
                scan.ParentMZ = 0.0f;
                double mdbl_current_background_intensity = 0;

                // Now find peaks
                parentPeakParameters.SignalToNoiseThreshold = _singleToNoiseRatio;
                parentPeakParameters.PeakBackgroundRatio = _peakBackgroundRatio;
                parentPeakProcessor.SetOptions(parentPeakParameters);
                parentPeakProcessor.ProfileType = GlypID.enmProfileType.PROFILE;

                parentPeakProcessor.DiscoverPeaks(ref _cidMzs, ref _cidIntensities, ref _cidPeaks,
                                        Convert.ToSingle(mobjTransformParameters.MinMZ), Convert.ToSingle(mobjTransformParameters.MaxMZ), true);
                mdbl_current_background_intensity = parentPeakProcessor.GetBackgroundIntensity(ref _cidIntensities);

                // Settings
                min_peptide_intensity = mdbl_current_background_intensity * mobjTransformParameters.PeptideMinBackgroundRatio;
                if (mobjTransformParameters.UseAbsolutePeptideIntensity)
                {
                    if (min_peptide_intensity < mobjTransformParameters.AbsolutePeptideIntensity)
                        min_peptide_intensity = mobjTransformParameters.AbsolutePeptideIntensity;
                }
                mobjTransformParameters.PeptideMinBackgroundRatio = _peptideMinBackgroundRatio;
                mobjTransformParameters.MaxCharge = _maxCharge;
                mobjTransform.TransformParameters = mobjTransformParameters;

                //  Now perform deisotoping
                _transformResult = new GlypID.HornTransform.clsHornTransformResults[1];
                mobjTransform.PerformTransform(Convert.ToSingle(mdbl_current_background_intensity), Convert.ToSingle(min_peptide_intensity), ref _cidMzs, ref _cidIntensities, ref _cidPeaks, ref _transformResult);
                // for getting results

                for (int chNum = 0; chNum < _transformResult.Length; chNum++)
                {
                    double sumintensity = 0.0;
                    double mostIntenseIntensity = 0.0;
                    for (int i = 0; i < _transformResult[chNum].marr_isotope_peak_indices.Length; i++)
                    {
                        sumintensity = sumintensity + _cidPeaks[_transformResult[chNum].marr_isotope_peak_indices[i]].mdbl_intensity;
                        if (Math.Abs(_transformResult[chNum].mdbl_most_intense_mw -
                            (_cidPeaks[_transformResult[chNum].marr_isotope_peak_indices[i]].mdbl_mz * _transformResult[chNum].mshort_cs - Atoms.ProtonMass * _transformResult[chNum].mshort_cs)
                            ) < 1.0 / _transformResult[chNum].mshort_cs
                            )
                        {
                            mostIntenseIntensity = _cidPeaks[_transformResult[chNum].mint_peak_index].mdbl_intensity;
                        }
                    }
                    scan.MSPeaks.Add(new MSPeak(
                    Convert.ToSingle(_transformResult[chNum].mdbl_mono_mw),
                    _transformResult[chNum].mint_mono_intensity,
                    _transformResult[chNum].mshort_cs,
                    Convert.ToSingle(_transformResult[chNum].mdbl_mz),
                    Convert.ToSingle(_transformResult[chNum].mdbl_fit),
                    Convert.ToSingle(_transformResult[chNum].mdbl_most_intense_mw),
                    mostIntenseIntensity,
                    sumintensity));
                }
                Array.Clear(_transformResult, 0, _transformResult.Length);
                Array.Clear(_cidPeaks, 0, _cidPeaks.Length);
                Array.Clear(_cidMzs, 0, _cidMzs.Length);
                Array.Clear(_cidIntensities, 0, _cidIntensities.Length);
            }
            return scan;
        }
예제 #11
0
        private MSScan GetMSScan(int argScanNo)
        {
            MSScan msScan = new MSScan(argScanNo);
            // GlypID.Readers.clsRawData rawData = new GlypID.Readers.clsRawData() ;
            GlypID.HornTransform.clsHornTransform massTransform = new GlypID.HornTransform.clsHornTransform();
            GlypID.Peaks.clsPeakProcessor peakProcessor = new GlypID.Peaks.clsPeakProcessor();

            GlypID.HornTransform.clsHornTransformParameters transform_parameters = new GlypID.HornTransform.clsHornTransformParameters();
            GlypID.Peaks.clsPeakProcessorParameters peak_parameters = new GlypID.Peaks.clsPeakProcessorParameters();

            // Declarations
            float[] _mzs = null;
            float[] _intensities = null;
            GlypID.Peaks.clsPeak[] peaks;
            GlypID.HornTransform.clsHornTransformResults[] _transformResults;

            // Settings
            peak_parameters.SignalToNoiseThreshold = 3.0;
            peak_parameters.PeakBackgroundRatio = 5.0;

            peakProcessor.SetOptions(peak_parameters);
            peakProcessor.ProfileType = GlypID.enmProfileType.PROFILE;
            transform_parameters.PeptideMinBackgroundRatio = 5.0;
            transform_parameters.MaxCharge = 10;
            massTransform.TransformParameters = transform_parameters;

            // Load
            Raw = new GlypID.Readers.clsRawData(_fullFilePath, GlypID.Readers.FileType.FINNIGAN);

            if (Raw.GetMSLevel(argScanNo) == 1)
            {
                // Get spectra
                Raw.GetSpectrum(argScanNo, ref _mzs, ref _intensities);

                // Get peaks
                peaks = new GlypID.Peaks.clsPeak[1];
                peakProcessor.DiscoverPeaks(ref _mzs, ref _intensities, ref peaks, Convert.ToSingle(transform_parameters.MinMZ), Convert.ToSingle(transform_parameters.MaxMZ), true);

                // Deisotope
                double min_background_intensity = peakProcessor.GetBackgroundIntensity(ref _intensities);
                double min_peptide_intensity = min_background_intensity * transform_parameters.PeptideMinBackgroundRatio;

                _transformResults = new GlypID.HornTransform.clsHornTransformResults[1];
                massTransform.PerformTransform(Convert.ToSingle(min_background_intensity), Convert.ToSingle(min_peptide_intensity), ref _mzs, ref _intensities, ref peaks, ref _transformResults);

                Array.Clear(_transformResults, 0, _transformResults.Length);
                Array.Clear(peaks, 0, peaks.Length);
            }

            return msScan;
        }
예제 #12
0
파일: YxList.cs 프로젝트: chpaul/COL_Lib
 public YxList(MSScan argScan, List<ProteinInfo> argProtInfo, float argTorelance)
 {
     _scan = argScan;
     _pInfo = argProtInfo;
     _torelance = argTorelance;
 }
예제 #13
0
파일: frmMain.cs 프로젝트: chpaul/COL_Lib
 private void ZedGraphDisplay(MSScan argScan)
 {
     GraphPane GP = zedGraphControl1.GraphPane;
     GP.XAxis.Title.Text = "m/z";
     GP.YAxis.Title.Text = "Intensity";
     PointPairList pplRaw = new PointPairList();
     for (int i = 0; i < argScan.MZs.Length; i++)
     {
         pplRaw.Add(argScan.MZs[i], argScan.Intensities[i]);
     }
     PointPairList pplPeak = new PointPairList();
     for (int i = 0; i < argScan.MSPeaks.Count; i++)
     {
         pplPeak.Add(argScan.MSPeaks[i].MonoisotopicMZ,argScan.MSPeaks[i].MonoIntensity);
     }
     GP.AddBar("Raw", pplRaw, Color.Black);
     GP.AddBar("Peak", pplPeak, Color.Blue);
     zedGraphControl1.AxisChange();
 }
예제 #14
0
파일: frmMain.cs 프로젝트: chpaul/COL_Lib
        private void ReadandDisplayScan(int argMSScan)
        {
            if (raw != null)
            {
                scan = raw.ReadScan(argMSScan);
                StringBuilder SB = new StringBuilder();
                SB.Append("Scan Num:" + scan.ScanNo + Environment.NewLine);
                SB.Append("Scan Time:" + scan.Time + Environment.NewLine);
                SB.Append("Scan header:" + scan.ScanHeader + Environment.NewLine);
                SB.Append("Scan range:" + scan.MinMZ + "~" + scan.MaxMZ + Environment.NewLine);
                SB.Append("Scan MS Level:" + scan.MsLevel + Environment.NewLine);
                SB.Append("Scan is FT Scan:" + scan.IsFTScan + Environment.NewLine);
                SB.Append("Scan is CID:" + scan.IsCIDScan + Environment.NewLine + Environment.NewLine);
                if (scan.MsLevel == 2)
                {
                    SB.Append("Parent Scan Num:" + scan.ParentScanNo + Environment.NewLine);
                    SB.Append("Precursor M/Z:" + scan.ParentMZ + Environment.NewLine);
                    SB.Append("Precursor Charge:" + scan.ParentCharge + Environment.NewLine);
                    SB.Append("Precursor mono mass:" + scan.ParentMonoMW + Environment.NewLine + Environment.NewLine);
                }
                if (scan.IsHCDScan)
                {
                    HCDInfo HCD = ((ThermoRawReader) raw).GetHCDInfo(argMSScan);
                    SB.Append("HCD Score:" + HCD.HCDScore.ToString("0.00")+Environment.NewLine);
                    SB.Append("HCD Glycan Type:" + HCD.GlycanType + Environment.NewLine);
                }
                SB.Append("MS Peaks:" + scan.MSPeaks.Count + Environment.NewLine);
                SB.Append("DeisotopeMZ\tPeak Intensity\tMost intense Mz\tMost intense int\t Cluster int"+Environment.NewLine);
                foreach (MSPeak peak in scan.MSPeaks)
                {
                    SB.Append(peak.DeisotopeMz + "\t\t" + peak.MonoIntensity + "\t\t" + peak.MostIntenseMass + "\t\t" + peak.MostIntenseIntensity + "\t\t" + peak.ClusterIntensity + Environment.NewLine);
                }

                SB.Append(Environment.NewLine + Environment.NewLine + "MZs:" + scan.MZs.Length + Environment.NewLine);
                for (int i = 0; i < scan.MZs.Length; i++)
                {
                    SB.Append("[" + i.ToString() + "]" + scan.MZs[i].ToString("0.0000") + "\t" + scan.Intensities[i].ToString("0.0000") + Environment.NewLine);
                }
                txtPeaks_CSMSL.Text = SB.ToString();
                ZedGraphDisplay(scan);
            }
        }