Ejemplo n.º 1
0
        public void UpdateAnnotations( MassSpectrum spectrum )
        {
            if( currentSpectrum != spectrum )
            {
                currentSpectrum = spectrum;
                Text = TabText = "Annotations for spectrum " + spectrum.Id;
                runOverrideToolStripButton.Text = "Override " + spectrum.Source.Source.Name + " Annotations";

                annotationsListView.VirtualListSize = spectrum.AnnotationList.Count;

                if (spectrum.AnnotationList.Count > 0)
                    selectIndex(spectrum.AnnotationList.Count - 1);
            }

            annotationsListView.Refresh();
        }
        public override SpectrumChartData CreateSpectrumDetails(MassSpectrumItem massSpectrumItem, MassSpectrum referenceSpectrum = null)
        {
            ArgumentHelper.AssertNotNull(massSpectrumItem, "massSpectrumItem");

            // clone given spectrum
            var spectrum = massSpectrumItem.Spectrum.Clone();
            if (spectrum == null){
                return null;
            }

            //// get ions for respective polarity
            //var ions = spectrum.ScanEvent.Polarity == PolarityType.Negative
            //	? m_unknownFeatureIonInstanceItems.Where(w => w.Charge < 0)
            //	: m_unknownFeatureIonInstanceItems.Where(w => w.Charge > 0);

            // annotate nearest centroids
            foreach (var ion in m_unknownFeatureIonInstanceItems){
                // annotate isotopes
                foreach (var peak in m_chromatogramPeakItemsMap[ion.GetIDs()]){
                    var centroid = spectrum.PeakCentroids.FindClosestPeak(peak.Mass);
                    if (centroid != null){
                        centroid.DisplayPriority = 2;
                    }
                }
            }

            // create spectrum chart data
            var massRange = Range.Create(spectrum.Header.LowPosition, spectrum.Header.HighPosition);
            if (spectrum.ScanEvent.MSOrder == MSOrderType.MS1){
                var peaks = m_chromatogramPeakItemsMap.SelectMany(s => s.Value).ToList();
                massRange = Range.Create(Math.Max(0, peaks.Min(m => m.Mass)) - 4, peaks.Max(m => m.Mass) + 5);
            }

            return new SpectrumChartData{
                MassRange = massRange,
                SpectrumDistanceDetails = null,
                Spectrum = spectrum,
                SpectrumHeaderText = CreateSpectrumChartHeader(spectrum, m_extraHeaderLine, m_fileNames[spectrum.Header.FileID])
            };
        }
Ejemplo n.º 3
0
 public MassSpectrum GetMassSpectrum( MassSpectrum metaSpectrum, SpectrumList spectrumList )
 {
     MassSpectrum spectrum = new MassSpectrum( metaSpectrum, spectrumList.spectrum( metaSpectrum.Index, true ) );
     //MassSpectrum realMetaSpectrum = ( metaSpectrum.Tag as DataGridViewRow ).Tag as MassSpectrum;
     //realMetaSpectrum.Element.dataProcessing = spectrum.Element.dataProcessing;
     //realMetaSpectrum.Element.defaultArrayLength = spectrum.Element.defaultArrayLength;
     return spectrum;
 }
Ejemplo n.º 4
0
        public void UpdateProcessing( MassSpectrum spectrum )
        {
            if( processingListView.VirtualListSize != spectrum.ProcessingList.Count )
            {
                processingListView.VirtualListSize = spectrum.ProcessingList.Count;
                selectIndex( spectrum.ProcessingList.Count - 1 );
            }

            if( currentSpectrum != spectrum )
            {
                currentSpectrum = spectrum;
                Text = TabText = "Processing for spectrum " + spectrum.Id;
                runOverrideToolStripButton.Text = "Override " + spectrum.Source.Source.Name + " Processing";
                processingListView_SelectedIndexChanged( this, EventArgs.Empty );
            }

            processingListView.Refresh();
        }
Ejemplo n.º 5
0
        private void showSpectrum( MassSpectrum spectrum, bool isOverlay )
        {
            ZedGraph.GraphPane pane = zedGraphControl1.GraphPane;

            if( isOverlay && pane.CurveList.Count > overlayColors.Length )
                MessageBox.Show( "SeeMS only supports up to " + overlayColors.Length + " simultaneous overlays.", "Too many overlays", MessageBoxButtons.OK, MessageBoxIcon.Stop );

            // set form title
            if( !isOverlay )
                Text = String.Format( "{0} - {1}", currentDataSource.Name, spectrum.Id );
            else
                Text += "," + spectrum.Id;

            if( !isOverlay )
                pane.CurveList.Clear();

            if( currentGraphItem != null && !currentGraphItem.IsMassSpectrum )
            {
                zedGraphControl1.RestoreScale( pane );
                zedGraphControl1.ZoomOutAll( pane );
            }
            bool isScaleAuto = !pane.IsZoomed;

            //pane.GraphObjList.Clear();

            // the header does not have the data points
            pane.YAxis.Title.Text = "Intensity";
            pane.XAxis.Title.Text = "m/z";

            PointList pointList = spectrum.PointList;
            if( pointList.FullCount > 0 )
            {
                int bins = (int) pane.CalcChartRect( zedGraphControl1.CreateGraphics() ).Width;
                if( isScaleAuto )
                    pointList.SetScale( bins, pointList[0].X, pointList[pointList.Count - 1].X );
                else
                    pointList.SetScale( bins, pane.XAxis.Scale.Min, pane.XAxis.Scale.Max );

                if( spectrum.Element.spectrumDescription.hasCVParam(pwiz.CLI.msdata.CVID.MS_centroid_mass_spectrum) )
                {
                    ZedGraph.StickItem stick = pane.AddStick( spectrum.Id, pointList, Color.Gray );
                    stick.Symbol.IsVisible = false;
                    stick.Line.Width = 1;
                } else
                    pane.AddCurve( spectrum.Id, pointList, Color.Gray, ZedGraph.SymbolType.None );
            }
            pane.AxisChange();

            if( isOverlay )
            {
                pane.Legend.IsVisible = true;
                pane.Legend.Position = ZedGraph.LegendPos.TopCenter;
                for( int i = 0; i < pane.CurveList.Count; ++i )
                {
                    pane.CurveList[i].Color = overlayColors[i];
                    ( pane.CurveList[i] as ZedGraph.LineItem ).Line.Width = 2;
                }
            } else
            {
                pane.Legend.IsVisible = false;
                currentGraphItem = spectrum;
            }

            SetDataLabelsVisible( true );
            zedGraphControl1.Refresh();
        }
Ejemplo n.º 6
0
 internal SpectrumListCellDoubleClickEventArgs( SpectrumListForm sender, DataGridViewCellMouseEventArgs e )
     : base(e.Button, e.Clicks, e.X, e.Y, e.Delta)
 {
     if( e.RowIndex > -1 && e.RowIndex < sender.GridView.RowCount )
         spectrum = sender.GridView.Rows[e.RowIndex].Tag as MassSpectrum;
 }
Ejemplo n.º 7
0
        public void Add( MassSpectrum spectrum )
        {
            Spectrum s = spectrum.Element;
            SpectrumDescription sd = s.spectrumDescription;
            Scan scan = sd.scan;
            InstrumentConfiguration ic = scan.instrumentConfiguration;
            DataProcessing dp = s.dataProcessing;

            CVParam param;

            param = s.cvParam( CVID.MS_ms_level );
            int msLevel = param.cvid != CVID.CVID_Unknown ? Convert.ToInt32( (string) param.value ) : 0;

            param = scan.cvParam( CVID.MS_scan_time );
            double scanTime = param.cvid != CVID.CVID_Unknown ? Convert.ToDouble( (string) param.value ) : 0;

            param = sd.cvParam( CVID.MS_base_peak_m_z );
            double bpmz = param.cvid != CVID.CVID_Unknown ? Convert.ToDouble( (string) param.value ) : 0;

            param = sd.cvParam( CVID.MS_base_peak_intensity );
            double bpi = param.cvid != CVID.CVID_Unknown ? Convert.ToDouble( (string) param.value ) : 0;

            param = sd.cvParam( CVID.MS_total_ion_current );
            double tic = param.cvid != CVID.CVID_Unknown ? Convert.ToDouble( (string) param.value ) : 0;

            param = scan.cvParamChild( CVID.MS_polarity );
            string polarity = param.cvid != CVID.CVID_Unknown ? param.name : "unknown";

            int rowIndex = gridView.Rows.Add(
                s.id, s.nativeID, s.index,
                s.cvParamChild( CVID.MS_spectrum_type ).name,
                msLevel,
                scanTime,
                s.defaultArrayLength,
                ( ic != null ? ic.id : "unknown" ),
                bpmz,
                bpi,
                tic,
                ( dp != null ? dp.id : "unknown" ),
                polarity,
                "",
                ""
            );
            gridView.Rows[rowIndex].Tag = spectrum;
            spectrum.Tag = gridView.Rows[rowIndex];
        }
Ejemplo n.º 8
0
        private void initializeManagedDataSource( ManagedDataSource managedDataSource )
        {
            try
            {
                DataSource source = managedDataSource.Source;
                MSDataFile msDataFile = source.MSDataFile;
                ChromatogramListForm chromatogramListForm = managedDataSource.ChromatogramListForm;
                SpectrumListForm spectrumListForm = managedDataSource.SpectrumListForm;

                chromatogramListForm.Text = source.Name + " chromatograms";
                chromatogramListForm.TabText = source.Name + " chromatograms";
                chromatogramListForm.ShowIcon = false;
                chromatogramListForm.CellDoubleClick += new ChromatogramListCellDoubleClickHandler( chromatogramListForm_CellDoubleClick );

                spectrumListForm.Text = source.Name + " spectra";
                spectrumListForm.TabText = source.Name + " spectra";
                spectrumListForm.ShowIcon = false;
                spectrumListForm.CellDoubleClick += new SpectrumListCellDoubleClickHandler( spectrumListForm_CellDoubleClick );

                bool firstChromatogramLoaded = false;
                bool firstSpectrumLoaded = false;
                GraphForm firstGraph = null;

                ChromatogramList cl = msDataFile.run.chromatogramList;
                SpectrumList sl = msDataFile.run.spectrumList;

                if( sl == null )
                    throw new Exception( "Error loading metadata: no spectrum list" );

                int ticIndex = 0;
                if( cl != null )
                {
                    ticIndex = cl.findNative( "TIC" );
                    if( ticIndex < cl.size() )
                    {
                        pwiz.CLI.msdata.Chromatogram tic = cl.chromatogram( ticIndex );
                        Chromatogram ticChromatogram = new Chromatogram( source, tic );
                        chromatogramListForm.Add( ticChromatogram );
                        source.Chromatograms.Add( ticChromatogram );
                        firstGraph = OpenGraph( true );
                        showData( firstGraph, managedDataSource, ticChromatogram );
                        firstChromatogramLoaded = true;
                        chromatogramListForm.Show( mainForm.DockPanel, DockState.DockBottomAutoHide );
                        Application.DoEvents();
                    }
                }

                CVParam spectrumType = msDataFile.fileDescription.fileContent.cvParamChild( CVID.MS_spectrum_type );
                if( spectrumType.cvid == CVID.CVID_Unknown && !sl.empty() )
                    spectrumType = sl.spectrum( 0 ).cvParamChild( CVID.MS_spectrum_type );

                if( spectrumType.cvid == CVID.MS_SRM_spectrum )
                {
                    if( cl != null && cl.empty() )
                        throw new Exception( "Error loading metadata: SRM file contains no chromatograms" );

                } else //if( spectrumType.cvid == CVID.MS_MS1_spectrum ||
                       //    spectrumType.cvid == CVID.MS_MSn_spectrum )
                {
                    if( sl.empty() )
                        throw new Exception( "Error loading metadata: MSn file contains no spectra" );
                }// else
                //	throw new Exception( "Error loading metadata: unable to open files with spectrum type \"" + spectrumType.name + "\"" );

                if( cl != null )
                {
                    // load the rest of the chromatograms
                    for( int i = 0; i < cl.size(); ++i )
                    {
                        if( i == ticIndex )
                            continue;
                        pwiz.CLI.msdata.Chromatogram c = cl.chromatogram( i );

                        mainForm.SetStatusLabel( String.Format( "Loading chromatograms from source file ({0} of {1})...",
                                        ( i + 1 ), cl.size() ) );
                        mainForm.SetProgressPercentage( ( i + 1 ) * 100 / cl.size() );

                        Chromatogram chromatogram = new Chromatogram( source, c );
                        chromatogramListForm.Add( chromatogram );
                        source.Chromatograms.Add( chromatogram );
                        if( !firstChromatogramLoaded )
                        {
                            firstChromatogramLoaded = true;
                            chromatogramListForm.Show( mainForm.DockPanel, DockState.DockBottomAutoHide );
                            firstGraph = OpenGraph( true );
                            showData( firstGraph, managedDataSource, chromatogram );
                        }
                        Application.DoEvents();
                    }
                }

                // get all scans by sequential access
                for( int i = 0; i < sl.size(); ++i )
                {
                    pwiz.CLI.msdata.Spectrum s = sl.spectrum( i );

                    if( ( ( i + 1 ) % 100 ) == 0 || ( i + 1 ) == sl.size() )
                    {
                        mainForm.SetStatusLabel( String.Format( "Loading spectra from source file ({0} of {1})...",
                                        ( i + 1 ), sl.size() ) );
                        mainForm.SetProgressPercentage( ( i + 1 ) * 100 / sl.size() );
                    }

                    MassSpectrum spectrum = new MassSpectrum( source, s );
                    spectrumListForm.Add( spectrum );
                    source.Spectra.Add( spectrum );
                    if( !firstSpectrumLoaded )
                    {
                        firstSpectrumLoaded = true;
                        spectrumListForm.Show( mainForm.DockPanel, DockState.DockBottomAutoHide );
                        if( firstChromatogramLoaded )
                        {
                            GraphForm spectrumGraph = CreateGraph();
                            spectrumGraph.Show( firstGraph.Pane, DockPaneAlignment.Bottom, 0.5 );
                            showData( spectrumGraph, managedDataSource, spectrum );
                        } else
                        {
                            firstGraph = OpenGraph( true );
                            showData( firstGraph, managedDataSource, spectrum );
                        }
                    }
                    Application.DoEvents();
                }

                mainForm.SetStatusLabel( "Finished loading source metadata." );
                mainForm.SetProgressPercentage( 100 );

            } catch( Exception ex )
            {
                string message = "SeeMS encountered an error reading metadata from \"" + managedDataSource.Source.CurrentFilepath + "\" (" + ex.Message + ")";
                if( ex.InnerException != null )
                    message += "\n\nAdditional information: " + ex.InnerException.Message;
                MessageBox.Show( message,
                                "Error reading source metadata",
                                MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1,
                                0, false );
                mainForm.SetStatusLabel( "Failed to read source metadata." );
            }
        }
Ejemplo n.º 9
0
        public SpectrumViewer(string filename, object index, string interpretation)
        {
            // Prepare the annotation
            annotation = new PeptideFragmentationAnnotation(interpretation, 1, 2, false, true, false, false, true, false, false, true, false, true);
            annotation.OptionsPanel.Dock = DockStyle.None;
            annotation.OptionsPanel.Dock = DockStyle.Fill;

            // Get the mass spectrum
            spectrum = SpectrumCache.GetMassSpectrum(filename,index);
            if(spectrum == null)
                return;

            // Add annotation to the mass spectrum and get a new graph control
            spectrum.AnnotationList.Clear();
            spectrum.AnnotationList.Add((IAnnotation)annotation);
            graph = new MSGraphControl();
            graph.AddGraphItem(graph.GraphPane, spectrum);
            graph.Dock = DockStyle.Fill;
  

            // Create new panels and add the graph and annotations
            spectrumPanel = new Panel();
            spectrumPanel.Controls.Add(graph);
            spectrumPanel.Dock = DockStyle.None;
            spectrumPanel.Dock = DockStyle.Fill;
            annotationPanel = new Panel();
            annotationPanel.Controls.Add(annotation.OptionsPanel);
            annotationPanel.Dock = DockStyle.None;
            annotationPanel.Dock = DockStyle.Fill;
            fragmentationPanel = new Panel();
            annotation.FragmentInfoGridView.Location = new Point(0,0);
            annotation.FragmentInfoGridView.ScrollBars = ScrollBars.Both;
            annotation.FragmentInfoGridView.Dock = DockStyle.None;
            annotation.FragmentInfoGridView.Dock = DockStyle.Fill;
            annotation.FragmentInfoGridView.BorderStyle = BorderStyle.FixedSingle;
            fragmentationPanel.Controls.Add(annotation.FragmentInfoGridView);
            fragmentationPanel.Dock = DockStyle.None;
            fragmentationPanel.Dock = DockStyle.Fill;

            // Add the call back for refreshing
            annotation.OptionsChanged += new EventHandler(OnOptionsChanged);
        }
Ejemplo n.º 10
0
		internal SpectrumListCellDoubleClickEventArgs( SpectrumListForm sender, DataGridViewCellMouseEventArgs e )
            : base( e.ColumnIndex, e.RowIndex, e.X, e.Y, e )
		{
            if( e.RowIndex > -1 && e.RowIndex < sender.GridView.RowCount )
                spectrum = sender.GetSpectrum( e.RowIndex );
		}
Ejemplo n.º 11
0
 public int IndexOf( MassSpectrum spectrum )
 {
     return spectraSource.Find( "Id", spectrum.Id );
 }
Ejemplo n.º 12
0
		public void Add( MassSpectrum spectrum )
		{
            SpectrumDataSet.SpectrumTableRow row = spectrumDataSet.SpectrumTable.NewSpectrumTableRow();
            row.Id = spectrum.Id;

            if( nativeIdFormat != CVID.CVID_Unknown )
            {
                gridView.Columns["Id"].Visible = false;

                // guard against case where input is mzXML which
                // is identified as, say, Agilent-derived, but 
                // which uses "scan" (as mzXML must) instead
                // of the Agilent "scanID" (as this mzML-centric code expects)
                bool foundit = false;

                string[] nameValuePairs = spectrum.Id.Split(' ');
                foreach( string nvp in nameValuePairs )
                {
                    string[] nameValuePair = nvp.Split('=');
                    if (row.Table.Columns.Contains(nameValuePair[0]))
                    {
                        row[nameValuePair[0]] = nameValuePair[1];
                        foundit = true;
                    }
                }
                if (!foundit)
                {
                    // mismatch between nativeID format and actual (probably mzXML) format
                    // better to show an ill-fit match - eg "scan" (mzXML) and "scanID" (Agilent)
                    // than no info at all
                    string nativeIdDefinition = new CVTermInfo(nativeIdFormat).def;
                    string[] idPair = nativeIdDefinition.Split('=');
                    if (row.Table.Columns.Contains(idPair[0]))
                    {
                        string[] valPair = spectrum.Id.Split('=');
                        row[idPair[0]] = (valPair.Length > 1) ? valPair[1] : spectrum.Id;
                        foundit = true;
                    }
                }
            }

            row.Index = spectrum.Index;
            updateRow( row, spectrum );
            spectrumDataSet.SpectrumTable.AddSpectrumTableRow( row );

            //int rowIndex = gridView.Rows.Add();
			//gridView.Rows[rowIndex].Tag = spectrum;
            spectrum.Tag = this;

            if( spectrum.Element.spotID.Length > 0 )
                gridView.Columns["SpotId"].Visible = true;

            //UpdateRow( rowIndex );
		}
Ejemplo n.º 13
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;

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

            if( precursorInfo.Length == 0 )
                precursorInfo.Append( "unknown" );
            row.PrecursorInfo = precursorInfo.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}-{1}]",
                                              (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.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 );
        }
Ejemplo n.º 14
0
        public void Add( MassSpectrum spectrum )
        {
            SpectrumDataSet.SpectrumTableRow row = spectrumDataSet.SpectrumTable.NewSpectrumTableRow();
            row.Id = spectrum.Id;

            if( nativeIdFormat != CVID.CVID_Unknown )
            {
                gridView.Columns["Id"].Visible = false;

                string[] nameValuePairs = spectrum.Id.Split( " ".ToCharArray() );
                foreach( string nvp in nameValuePairs )
                {
                    string[] nameValuePair = nvp.Split( "=".ToCharArray() );
                    row[nameValuePair[0]] = nameValuePair[1];
                }
            }

            row.Index = spectrum.Index;
            updateRow( row, spectrum );
            spectrumDataSet.SpectrumTable.AddSpectrumTableRow( row );

            //int rowIndex = gridView.Rows.Add();
            //gridView.Rows[rowIndex].Tag = spectrum;
            spectrum.Tag = this;

            if( spectrum.Element.spotID.Length > 0 )
                gridView.Columns["SpotId"].Visible = true;

            //UpdateRow( rowIndex );
        }
Ejemplo n.º 15
0
 public MassSpectrum GetMassSpectrum( MassSpectrum metaSpectrum, string[] spectrumListFilters )
 {
     var tmp = source.MSDataFile.run.spectrumList;
     try
     {
         SpectrumListFactory.wrap(source.MSDataFile, spectrumListFilters);
         return GetMassSpectrum(metaSpectrum, source.MSDataFile.run.spectrumList);
     }
     finally
     {
         source.MSDataFile.run.spectrumList = tmp;
     }
 }
Ejemplo n.º 16
0
 private MassSpectrum getMetaSpectrum( MassSpectrum spectrum )
 {
     return spectrum.OwningListForm.GetSpectrum( spectrum.OwningListForm.IndexOf( spectrum ) );
 }
Ejemplo n.º 17
0
 public MassSpectrum GetMassSpectrum( MassSpectrum metaSpectrum, SpectrumList spectrumList )
 {
     MassSpectrum spectrum = new MassSpectrum( this, spectrumList.spectrum( metaSpectrum.Index, true ) );
     spectrum.Tag = metaSpectrum.Tag;
     return spectrum;
 }