Exemple #1
0
        /// <summary>
        /// add precursor and non-matched annotations
        /// </summary>
        public override void AddAnnotations(pwiz.MSGraph.MSGraphPane graphPane, Graphics g, pwiz.MSGraph.MSPointList pointList, ZedGraph.GraphObjList annotations)
        {
            base.AddAnnotations(graphPane, g, pointList, annotations);
            //using( Spectrum element = Element )
            {
                foreach (Precursor p in Element.precursors)
                {
                    foreach (SelectedIon si in p.selectedIons)
                    {
                        double  precursorMz          = (double)si.cvParam(CVID.MS_selected_ion_m_z).value;
                        int     precursorCharge      = 0;
                        CVParam precursorChargeParam = si.cvParam(CVID.MS_charge_state);
                        if (precursorChargeParam.empty())
                        {
                            precursorChargeParam = si.cvParam(CVID.MS_possible_charge_state);
                        }
                        if (!precursorChargeParam.empty())
                        {
                            precursorCharge = (int)precursorChargeParam.value;
                        }


                        double           stickLength  = 0.1;
                        ZedGraph.LineObj stickOverlay = new ZedGraph.LineObj(precursorMz, 1, precursorMz, stickLength);
                        stickOverlay.Location.CoordinateFrame = ZedGraph.CoordType.XScaleYChartFraction;
                        stickOverlay.Line.Width = 3;
                        stickOverlay.Line.Style = System.Drawing.Drawing2D.DashStyle.Dot;
                        stickOverlay.Line.Color = Color.Green;

                        annotations.Add(stickOverlay);

                        // Create a text label from the X data value
                        string precursorLabel;
                        if (precursorCharge > 0)
                        {
                            precursorLabel = String.Format("{0}\n(+{1} precursor)", precursorMz.ToString("f3"), precursorCharge);
                        }
                        else
                        {
                            precursorLabel = String.Format("{0}\n(precursor of unknown charge)", precursorMz.ToString("f3"));
                        }
                        ZedGraph.TextObj text = new ZedGraph.TextObj(precursorLabel, precursorMz, stickLength,
                                                                     ZedGraph.CoordType.XScaleYChartFraction, ZedGraph.AlignH.Center, ZedGraph.AlignV.Bottom);
                        text.ZOrder                    = ZedGraph.ZOrder.A_InFront;
                        text.FontSpec.FontColor        = stickOverlay.Line.Color;
                        text.FontSpec.Border.IsVisible = false;
                        text.FontSpec.Fill.IsVisible   = false;
                        //text.FontSpec.Fill = new Fill( Color.FromArgb( 100, Color.White ) );
                        text.FontSpec.Angle = 0;
                        annotations.Add(text);
                    }
                }
            }
        }
Exemple #2
0
        public override Spectrum spectrum(int index, bool getBinaryData)
        {
            Spectrum s = base.spectrum(index, true);

            if (s.cvParam(CVID.MS_MSn_spectrum).empty() ||
                (int)s.cvParam(CVID.MS_ms_level).value == 1)
            {
                if (!getBinaryData)
                {
                    s.binaryDataArrays.Clear();
                }
                return(s);
            }

            PrecursorList pl = s.precursors;

            BinaryData            mzArray        = s.getMZArray().data;
            BinaryData            intensityArray = s.getIntensityArray().data;
            PointDataMap <double> mziMap         = new PointDataMap <double>();

            for (int i = 0; i < (int)s.defaultArrayLength; ++i)
            {
                mziMap.Insert(mzArray[i], intensityArray[i]);
            }

            Set <double> pointsToRemove = new Set <double>();

            foreach (Precursor p in pl)
            {
                foreach (SelectedIon si in p.selectedIons)
                {
                    double mz = (double)si.cvParam(CVID.MS_selected_ion_m_z).value;
                    PointDataMap <double> .Enumerator itr = mziMap.LowerBound(mz - 4.0);
                    if (itr != null && itr.IsValid)
                    {
                        while (itr.IsValid && itr.Current.Key - mz < 4.0)
                        {
                            pointsToRemove.Add(itr.Current.Key);
                            itr.MoveNext();
                        }
                    }

                    CVParam chargeParam = si.cvParam(CVID.MS_charge_state);
                    if (!chargeParam.empty())
                    {
                        int z = (int)chargeParam.value;
                        for (int i = 1; i < z; ++i)
                        {
                            double strippedMz = (mz * z) / (z - i);
                            itr = mziMap.LowerBound(strippedMz - 4.0);
                            if (itr != null && itr.IsValid)
                            {
                                while (itr.IsValid && itr.Current.Key - strippedMz < 4.0)
                                {
                                    pointsToRemove.Add(itr.Current.Key);
                                    itr.MoveNext();
                                }
                            }
                        }
                    }
                }
            }

            if (getBinaryData)
            {
                mzArray.Clear();
                intensityArray.Clear();
                foreach (PointDataMap <double> .MapPair pair in mziMap)
                {
                    if (pointsToRemove.Contains(pair.Key))
                    {
                        continue;
                    }

                    mzArray.Add(pair.Key);
                    intensityArray.Add(pair.Value);
                }
                s.defaultArrayLength = (ulong)mzArray.Count;
            }
            else
            {
                s.binaryDataArrays.Clear();
                s.defaultArrayLength -= (ulong)pointsToRemove.Count;
            }

            return(s);
        }
Exemple #3
0
        public void updateRow(SpectrumDataSet.SpectrumTableRow row, MassSpectrum spectrum)
        {
            spectrumList[spectrum.Index] = spectrum;

            Spectrum                s    = spectrum.Element; //GetElement(false);
            DataProcessing          dp   = spectrum.DataProcessing;
            Scan                    scan = null;
            InstrumentConfiguration ic   = null;

            if (s.scanList.scans.Count > 0)
            {
                scan = s.scanList.scans[0];
                ic   = scan.instrumentConfiguration;
            }

            if (dp == null)
            {
                dp = s.dataProcessing;
            }

            CVParam param;

            param       = s.cvParam(CVID.MS_ms_level);
            row.MsLevel = !param.empty() ? (int)param.value : 0;

            param = scan != null?scan.cvParam(CVID.MS_scan_start_time) : new CVParam();

            row.ScanTime = !param.empty() ? (double)param.value : 0;

            param          = s.cvParam(CVID.MS_base_peak_m_z);
            row.BasePeakMz = !param.empty() ? (double)param.value : 0;

            param = s.cvParam(CVID.MS_base_peak_intensity);
            row.BasePeakIntensity = !param.empty() ? (double)param.value : 0;

            param = s.cvParam(CVID.MS_total_ion_current);
            row.TotalIonCurrent = !param.empty() ? (double)param.value : 0;

            var precursorInfo    = new StringBuilder();
            var isolationWindows = new StringBuilder();

            if (row.MsLevel == 1 || s.precursors.Count == 0)
            {
                precursorInfo.Append("n/a");
                isolationWindows.Append("n/a");
            }
            else
            {
                foreach (Precursor p in s.precursors)
                {
                    foreach (SelectedIon si in p.selectedIons)
                    {
                        if (precursorInfo.Length > 0)
                        {
                            precursorInfo.Append(",");
                        }
                        precursorInfo.AppendFormat("{0:G8}", (double)si.cvParam(CVID.MS_selected_ion_m_z).value);
                    }

                    var     iw = p.isolationWindow;
                    CVParam isolationTarget = iw.cvParam(CVID.MS_isolation_window_target_m_z);
                    if (!isolationTarget.empty())
                    {
                        double iwMz = (double)isolationTarget.value;

                        if (isolationWindows.Length > 0)
                        {
                            isolationWindows.Append(",");
                        }

                        CVParam lowerOffset = iw.cvParam(CVID.MS_isolation_window_lower_offset);
                        CVParam upperOffset = iw.cvParam(CVID.MS_isolation_window_upper_offset);
                        if (lowerOffset.empty() || upperOffset.empty())
                        {
                            isolationWindows.AppendFormat("{0:G8}", iwMz);
                        }
                        else
                        {
                            isolationWindows.AppendFormat("[{0:G8}-{1:G8}]", iwMz - (double)lowerOffset.value, iwMz + (double)upperOffset.value);
                        }
                    }
                }
            }

            if (precursorInfo.Length == 0)
            {
                precursorInfo.Append("unknown");
            }
            row.PrecursorInfo = precursorInfo.ToString();

            if (isolationWindows.Length == 0)
            {
                isolationWindows.Append("unknown");
            }
            row.IsolationWindows = isolationWindows.ToString();

            StringBuilder scanInfo = new StringBuilder();

            foreach (Scan scan2 in s.scanList.scans)
            {
                if (scan2.scanWindows.Count > 0)
                {
                    foreach (ScanWindow sw in scan2.scanWindows)
                    {
                        if (scanInfo.Length > 0)
                        {
                            scanInfo.Append(",");
                        }
                        scanInfo.AppendFormat("[{0:G8}-{1:G8}]",
                                              (double)sw.cvParam(CVID.MS_scan_window_lower_limit).value,
                                              (double)sw.cvParam(CVID.MS_scan_window_upper_limit).value);
                    }
                }
            }

            if (scanInfo.Length == 0)
            {
                scanInfo.Append("unknown");
            }
            row.ScanInfo = scanInfo.ToString();

            row.IonMobility = scan != null ? (double)scan.cvParam(CVID.MS_ion_mobility_drift_time).value : 0;
            if (row.IonMobility == 0 && scan != null)
            {
                row.IonMobility = (double)scan.cvParam(CVID.MS_inverse_reduced_ion_mobility).value;
                if (row.IonMobility == 0)
                {
                    // Early version of drift time info, before official CV params
                    var userparam = scan.userParam("drift time");
                    if (!userparam.empty())
                    {
                        row.IonMobility = userparam.timeInSeconds() * 1000.0;
                    }
                }
            }
            row.SpotId       = s.spotID;
            row.SpectrumType = s.cvParamChild(CVID.MS_spectrum_type).name;
            row.DataPoints   = s.defaultArrayLength;
            row.IcId         = (ic == null || ic.id.Length == 0 ? "unknown" : ic.id);
            row.DpId         = (dp == null || dp.id.Length == 0 ? "unknown" : dp.id);
        }