private void initializeManagedDataSource( ManagedDataSource managedDataSource, object idOrIndex, IAnnotation annotation, string[] spectrumListFilters ) { try { SpectrumSource source = managedDataSource.Source; MSData msDataFile = source.MSDataFile; ChromatogramListForm chromatogramListForm = managedDataSource.ChromatogramListForm; SpectrumListForm spectrumListForm = managedDataSource.SpectrumListForm; chromatogramListForm.CellDoubleClick += new ChromatogramListCellDoubleClickHandler( chromatogramListForm_CellDoubleClick ); chromatogramListForm.CellClick += new ChromatogramListCellClickHandler( chromatogramListForm_CellClick ); chromatogramListForm.GotFocus += new EventHandler( form_GotFocus ); spectrumListForm.CellDoubleClick += new SpectrumListCellDoubleClickHandler( spectrumListForm_CellDoubleClick ); spectrumListForm.CellClick += new SpectrumListCellClickHandler( spectrumListForm_CellClick ); spectrumListForm.FilterChanged += new SpectrumListFilterChangedHandler( spectrumListForm_FilterChanged ); spectrumListForm.GotFocus += new EventHandler( form_GotFocus ); bool firstChromatogramLoaded = false; bool firstSpectrumLoaded = false; GraphForm firstGraph = null; ChromatogramList cl = msDataFile.run.chromatogramList; SpectrumList sl = msDataFile.run.spectrumList; //sl = new SpectrumList_Filter( sl, new SpectrumList_FilterAcceptSpectrum( acceptSpectrum ) ); if (sl.size()+cl.size() == 0) throw new Exception("Error loading metadata: no spectra or chromatograms"); Type indexType = typeof(MassSpectrum); int index = -1; if( idOrIndex is int ) index = (int) idOrIndex; else if( idOrIndex is string ) { int findIndex = sl.find(idOrIndex as string); if (findIndex != sl.size()) index = findIndex; if (index == -1) { indexType = typeof(Chromatogram); findIndex = cl.find(idOrIndex as string); if (findIndex != cl.size()) index = findIndex; } } // conditionally load the spectrum at the specified index first if( index > -1 ) { GraphItem item = null; if (indexType == typeof(MassSpectrum)) { MassSpectrum spectrum = managedDataSource.GetMassSpectrum(index); if (spectrumListFilters.Length > 0) spectrum = managedDataSource.GetMassSpectrum(spectrum, spectrumListFilters); spectrum.AnnotationSettings = defaultScanAnnotationSettings; spectrumListForm.Add(spectrum); source.Spectra.Add(spectrum); firstSpectrumLoaded = true; if (ShowSpectrumListForNewSources) { spectrumListForm.Show(DockPanel, DockState.DockBottom); Application.DoEvents(); } if (annotation != null) spectrum.AnnotationList.Add(annotation); item = spectrum; } else { Chromatogram chromatogram = managedDataSource.GetChromatogram(index); chromatogram.AnnotationSettings = defaultChromatogramAnnotationSettings; chromatogramListForm.Add(chromatogram); source.Chromatograms.Add(chromatogram); firstChromatogramLoaded = true; if (ShowChromatogramListForNewSources) { chromatogramListForm.Show(DockPanel, DockState.DockBottom); Application.DoEvents(); } item = chromatogram; } firstGraph = OpenFileUsesCurrentGraphForm && CurrentGraphForm != null ? CurrentGraphForm : OpenGraph(OpenFileGivesFocus); showData(firstGraph, item); return; } int ticIndex = cl.find( "TIC" ); if( ticIndex < cl.size() ) { pwiz.CLI.msdata.Chromatogram tic = cl.chromatogram( ticIndex ); Chromatogram ticChromatogram = managedDataSource.GetChromatogram( ticIndex ); ticChromatogram.AnnotationSettings = defaultChromatogramAnnotationSettings; chromatogramListForm.Add( ticChromatogram ); source.Chromatograms.Add( ticChromatogram ); if( !firstSpectrumLoaded ) { firstGraph = OpenGraph( true ); showData( firstGraph, ticChromatogram ); firstChromatogramLoaded = true; if (ShowChromatogramListForNewSources) { chromatogramListForm.Show(DockPanel, DockState.DockBottom); Application.DoEvents(); } } } // get spectrum type from fileContent if possible, otherwise from first spectrum CVParam spectrumType = msDataFile.fileDescription.fileContent.cvParamChild( CVID.MS_spectrum_type ); if( spectrumType.cvid == CVID.CVID_Unknown && sl.size() > 0 ) spectrumType = sl.spectrum( 0 ).cvParamChild( CVID.MS_spectrum_type ); // load the rest of the chromatograms for( int i = 0; i < cl.size(); ++i ) { if( i == ticIndex ) continue; Chromatogram chromatogram = managedDataSource.GetChromatogram( i ); if (OnLoadDataSourceProgress(String.Format("Loading chromatograms from {0} ({1} of {2})...", managedDataSource.Source.Name, (i + 1), cl.size()), (i + 1) * 100 / cl.size())) return; chromatogram.AnnotationSettings = defaultChromatogramAnnotationSettings; chromatogramListForm.Add( chromatogram ); source.Chromatograms.Add( chromatogram ); if( !firstSpectrumLoaded && !firstChromatogramLoaded ) { firstChromatogramLoaded = true; if (ShowChromatogramListForNewSources) { chromatogramListForm.Show(DockPanel, DockState.DockBottom); Application.DoEvents(); } firstGraph = OpenGraph( true ); showData(firstGraph, chromatogram ); } Application.DoEvents(); } // get all scans by sequential access for( int i = 0; i < sl.size(); ++i ) { if( i == index ) // skip the preloaded spectrum continue; MassSpectrum spectrum = managedDataSource.GetMassSpectrum( i ); if (((i + 1) % 100) == 0 || (i + 1) == sl.size()) { if (OnLoadDataSourceProgress(String.Format("Loading spectra from {0} ({1} of {2})...", managedDataSource.Source.Name, (i + 1), sl.size()), (i + 1) * 100 / sl.size())) return; } spectrum.AnnotationSettings = defaultScanAnnotationSettings; spectrumListForm.Add( spectrum ); source.Spectra.Add( spectrum ); if( !firstSpectrumLoaded ) { firstSpectrumLoaded = true; spectrumListForm.Show( DockPanel, DockState.DockBottom ); Application.DoEvents(); if( firstChromatogramLoaded ) { GraphForm spectrumGraph = CreateGraph(); spectrumGraph.Show( firstGraph.Pane, DockPaneAlignment.Bottom, 0.5 ); showData(spectrumGraph, spectrum ); } else { firstGraph = OpenGraph( true ); showData(firstGraph, spectrum ); } } Application.DoEvents(); } OnLoadDataSourceProgress("Finished loading source metadata.", 100); } catch( Exception ex ) { string message = "SeeMS encountered an error reading metadata from \"" + managedDataSource.Source.CurrentFilepath + "\" (" + ex.ToString() + ")"; if( ex.InnerException != null ) message += "\n\nAdditional information: " + ex.InnerException.ToString(); MessageBox.Show( message, "Error reading source metadata", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 0, false ); OnLoadDataSourceProgress("Failed to load data: " + ex.Message, 100); } }
public void OpenFile( string filepath, object idOrIndex, IAnnotation annotation, string spectrumListFilters ) { try { OnLoadDataSourceProgress("Opening data source: " + Path.GetFileNameWithoutExtension(filepath), 0); string[] spectrumListFilterList = spectrumListFilters.Split(';'); if (!dataSourceMap.ContainsKey(filepath)) { var newSource = new ManagedDataSource(new SpectrumSource(filepath)); dataSourceMap.Add(filepath, newSource); if (spectrumListFilters.Length > 0) SpectrumListFactory.wrap(newSource.Source.MSDataFile, spectrumListFilterList); initializeManagedDataSource( newSource, idOrIndex, annotation, spectrumListFilterList ); } else { GraphForm graph = OpenFileUsesCurrentGraphForm && CurrentGraphForm != null ? CurrentGraphForm : OpenGraph(OpenFileGivesFocus); ManagedDataSource source = dataSourceMap[filepath]; int index = -1; if( idOrIndex is int ) index = (int) idOrIndex; else if( idOrIndex is string ) { SpectrumList sl = source.Source.MSDataFile.run.spectrumList; int findIndex = sl.find( idOrIndex as string ); if( findIndex != sl.size() ) index = findIndex; } // conditionally load the spectrum at the specified index if( index > -1 ) { MassSpectrum spectrum = source.GetMassSpectrum( index ); if (spectrumListFilters.Length > 0) SpectrumListFactory.wrap(source.Source.MSDataFile, spectrumListFilterList); spectrum.AnnotationSettings = defaultScanAnnotationSettings; if( annotation != null ) spectrum.AnnotationList.Add( annotation ); if (source.Source.Spectra.Count < source.Source.MSDataFile.run.spectrumList.size() && source.SpectrumListForm.IndexOf(spectrum) < 0) { source.SpectrumListForm.Add(spectrum); source.Source.Spectra.Add(spectrum); } showData(graph, spectrum); } else { if( source.Source.Chromatograms.Count > 0 ) showData(graph, source.Source.Chromatograms[0]); else showData(graph, source.Source.Spectra[0]); } } } catch( Exception ex ) { string message = ex.Message; if( ex.InnerException != null ) message += "\n\nAdditional information: " + ex.InnerException.Message; MessageBox.Show( message, "Error opening source file", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 0, false ); OnLoadDataSourceProgress("Failed to load data: " + ex.Message, 100); } }
private void showDataOverlay( GraphForm hostGraph, ManagedDataSource managedDataSource, GraphItem item ) { if( item.IsChromatogram ) { hostGraph.ShowDataOverlay( managedDataSource.Source, managedDataSource.Source.GetChromatogram( item.Index, true ) ); } else { SpectrumList sl = managedDataSource.SpectrumProcessingForm.ProcessingListView.ProcessingWrapper( managedDataSource.Source.MSDataFile.run.spectrumList ); hostGraph.ShowDataOverlay( managedDataSource.Source, managedDataSource.Source.GetMassSpectrum( item as MassSpectrum, sl ) ); } }
private void showDataOverlay( GraphForm hostGraph, ManagedDataSource managedDataSource, DataGridViewRow row ) { showDataOverlay( hostGraph, managedDataSource, row.Tag as GraphItem ); }
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." ); } }