diff --git a/MetaMorpheus/EngineLayer/PsmTsv/PsmFromTsv.cs b/MetaMorpheus/EngineLayer/PsmTsv/PsmFromTsv.cs index d2b495858..3a539c073 100644 --- a/MetaMorpheus/EngineLayer/PsmTsv/PsmFromTsv.cs +++ b/MetaMorpheus/EngineLayer/PsmTsv/PsmFromTsv.cs @@ -33,7 +33,7 @@ public class PsmFromTsv public double Score { get; } public string ProteinAccession { get; } public double? SpectralAngle { get; } - public List MatchedIons { get; } + public List MatchedIons { get; set; } public Dictionary> ChildScanMatchedIons { get; } // this is only used in crosslink for now, but in the future will be used for other experiment types public double QValue { get; } diff --git a/MetaMorpheus/GUI/MetaDraw/MetaDraw.xaml b/MetaMorpheus/GUI/MetaDraw/MetaDraw.xaml index 959d8418d..0e325fa91 100644 --- a/MetaMorpheus/GUI/MetaDraw/MetaDraw.xaml +++ b/MetaMorpheus/GUI/MetaDraw/MetaDraw.xaml @@ -208,7 +208,8 @@ - + + @@ -248,8 +249,16 @@ - + + + + + Research the spectra file against the sequence with different fragment ions. + + + diff --git a/MetaMorpheus/GUI/MetaDraw/MetaDraw.xaml.cs b/MetaMorpheus/GUI/MetaDraw/MetaDraw.xaml.cs index 8e0408b2f..c23820447 100644 --- a/MetaMorpheus/GUI/MetaDraw/MetaDraw.xaml.cs +++ b/MetaMorpheus/GUI/MetaDraw/MetaDraw.xaml.cs @@ -1,6 +1,7 @@ using Easy.Common.Extensions; using EngineLayer; using GuiFunctions; +using MassSpectrometry; using OxyPlot; using System; using System.Collections.Generic; @@ -16,6 +17,7 @@ using System.Windows; using System.Windows.Controls; using System.Windows.Data; +using Omics.Fragmentation; namespace MetaMorpheusGUI { @@ -36,6 +38,7 @@ public partial class MetaDraw : Window private static List AcceptedResultsFormats = new List { ".psmtsv", ".tsv" }; private static List AcceptedSpectralLibraryFormats = new List { ".msp" }; private MetaDrawSettingsViewModel SettingsView; + private FragmentationReanalysisViewModel FragmentationReanalysisViewModel; public MetaDraw() { @@ -52,6 +55,8 @@ public MetaDraw() itemsControlSampleViewModel = new ParentChildScanPlotsView(); ParentChildScanViewPlots.DataContext = itemsControlSampleViewModel; + AdditionalFragmentIonControl.DataContext = FragmentationReanalysisViewModel ??= new FragmentationReanalysisViewModel(); + AdditionalFragmentIonControl.LinkMetaDraw(this); propertyView = new DataTable(); propertyView.Columns.Add("Name", typeof(string)); @@ -60,6 +65,7 @@ public MetaDraw() dataGridScanNums.DataContext = MetaDrawLogic.PeptideSpectralMatchesView; + Title = "MetaDraw: version " + GlobalVariables.MetaMorpheusVersion; base.Closing += this.OnClosing; @@ -71,7 +77,7 @@ public MetaDraw() SetUpPlots(); plotsListBox.ItemsSource = plotTypes; - exportPdfs.Content = MetaDrawSettings.ExportType; ; + exportPdfs.Content = MetaDrawSettings.ExportType; } private void Window_Drop(object sender, DragEventArgs e) @@ -156,6 +162,9 @@ private void AddFile(string filePath) /// /// Event triggers when a different cell is selected in the PSM data grid + /// + /// if sender is FragmentationReanalysisViewModel, then this method was run by clicking the search button on the FragmentationReanalysisViewModel + /// /// private void dataGridScanNums_SelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e) { @@ -172,6 +181,13 @@ private void dataGridScanNums_SelectedCellsChanged(object sender, SelectedCellsC plotView.Visibility = Visibility.Visible; PsmFromTsv psm = (PsmFromTsv)dataGridScanNums.SelectedItem; + List oldMatchedIons = null; + if (FragmentationReanalysisViewModel.Persist && sender is DataGrid) + { + oldMatchedIons = psm.MatchedIons; + ReplaceFragmentIonsOnPsmFromFragmentReanalysisViewModel(psm); + } + // Chimera plotter if (MetaDrawTabControl.SelectedContent is Grid { Name: "chimeraPlotGrid" }) { @@ -197,8 +213,19 @@ private void dataGridScanNums_SelectedCellsChanged(object sender, SelectedCellsC } SetSequenceDrawingPositionSettings(true); + // Psm selected from ambiguous dropdown => adjust the psm to be drawn + // Clicking the research button on an ambiguous psm => research with new ions + if (psm.FullSequence.Contains('|') && (sender.ToString() == "System.Object" || sender is FragmentationReanalysisViewModel)) + { + psm = (PsmFromTsv)AmbiguousSequenceOptionBox.SelectedItem; + if (FragmentationReanalysisViewModel.Persist || sender is FragmentationReanalysisViewModel) + { + oldMatchedIons = psm.MatchedIons; + ReplaceFragmentIonsOnPsmFromFragmentReanalysisViewModel(psm); + } + } // Selection of ambiguous psm => clean up the canvases and show the option box - if (psm.FullSequence.Contains('|') && sender.ToString() != "System.Object") + else if(psm.FullSequence.Contains('|') && sender.ToString() != "System.Object") { // clear all drawings of the previous non-ambiguous psm ClearPresentationArea(); @@ -215,12 +242,8 @@ private void dataGridScanNums_SelectedCellsChanged(object sender, SelectedCellsC } return; } - // Psm selected from ambiguous dropdown => adjust the psm to be drawn - else if (psm.FullSequence.Contains('|') && sender.ToString() == "System.Object") - { - psm = (PsmFromTsv)AmbiguousSequenceOptionBox.SelectedItem; - } - // Selection of non-ambiguous psm => clear items in the drop down + + // Selection of non-ambiguous psm => clear psms in the drop down else if (!psm.FullSequence.Contains('|')) { AmbiguousSequenceOptionBox.Items.Clear(); @@ -307,6 +330,10 @@ private void dataGridScanNums_SelectedCellsChanged(object sender, SelectedCellsC propertyView.Rows.Add(temp[i].Name, temp[i].GetValue(psm, null)); } } + + // put the original ions back in place if they were altered + if (oldMatchedIons != null && !psm.MatchedIons.SequenceEqual(oldMatchedIons)) + psm.MatchedIons = oldMatchedIons; } private void selectSpectraFileButton_Click(object sender, RoutedEventArgs e) @@ -587,12 +614,12 @@ private void ExportSpectrumLibraryButton_Click(object sender, RoutedEventArgs e) return; } - List items = new List(); + List psms = new List(); foreach (var cell in dataGridScanNums.SelectedItems) { var psm = (PsmFromTsv)cell; - items.Add(psm); + psms.Add(psm); } string directoryPath = Path.Combine(Path.GetDirectoryName(MetaDrawLogic.PsmResultFilePaths.First()), @@ -604,12 +631,21 @@ private void ExportSpectrumLibraryButton_Click(object sender, RoutedEventArgs e) Directory.CreateDirectory(directoryPath); } - directoryPath = Path.Combine(directoryPath, "spectrumLibrary.msp"); - - File.WriteAllLines(directoryPath, items.Select(i => i.ToLibrarySpectrum().ToString()).ToArray()); - - MessageBox.Show(MetaDrawSettings.ExportType + "(s) exported to: " + directoryPath); + var libraryPath = Path.Combine(directoryPath, "spectrumLibrary.msp"); + // research all identifications with the newly matched ion types + using (var sw = new StreamWriter(File.Create(libraryPath))) + { + foreach (var psm in psms) + { + var oldIons = psm.MatchedIons; + ReplaceFragmentIonsOnPsmFromFragmentReanalysisViewModel(psm); + sw.WriteLine(psm.ToLibrarySpectrum().ToString()); + psm.MatchedIons = oldIons; + } + } + + MessageBox.Show("Spectral Library exported to: " + libraryPath); } private void SequenceCoverageExportButton_Click(object sender, RoutedEventArgs e) @@ -990,6 +1026,9 @@ private void MetaDrawTabControl_OnSelectionChanged(object sender, SelectionChang { PsmFromTsv selectedPsm = (PsmFromTsv)dataGridScanNums.SelectedItem; + if (e.OriginalSource is not TabControl) // only clicking on different MetaDrawTabs will trigger this event + return; + // switch from chimera to other views if (e.RemovedItems.Count > 0 && ((TabItem)e.RemovedItems[0]).Name == "ChimeraScanPlot") { @@ -1056,6 +1095,38 @@ private void ToggleButtonsEnabled(bool value) exportSpectrumLibrary.IsEnabled = value; } - + /// + /// Method to fire the plotting method with new fragment ions + /// + /// + /// + /// + internal void SearchWithNewIons_OnClick(object sender, RoutedEventArgs e) + { + // find currently selected psm + var psm = dataGridScanNums.SelectedItem as PsmFromTsv; + if (psm is null) + return; + + // replace the ions and replot + var oldIons = psm.MatchedIons; + ReplaceFragmentIonsOnPsmFromFragmentReanalysisViewModel(psm); + dataGridScanNums.SelectedItem = psm; + dataGridScanNums_SelectedCellsChanged(FragmentationReanalysisViewModel, null); + + // put the old ions back + psm.MatchedIons = oldIons; + } + + /// + /// Replaces matched fragment ions on a psm with new ion types after a quick search + /// + /// + private void ReplaceFragmentIonsOnPsmFromFragmentReanalysisViewModel(PsmFromTsv psm) + { + var scan = MetaDrawLogic.GetMs2ScanFromPsm(psm); + var newIons = FragmentationReanalysisViewModel.MatchIonsWithNewTypes(scan, psm); + psm.MatchedIons = newIons; + } } } \ No newline at end of file diff --git a/MetaMorpheus/GUI/Views/FragmentReanalysisControl.xaml b/MetaMorpheus/GUI/Views/FragmentReanalysisControl.xaml new file mode 100644 index 000000000..71de1ed97 --- /dev/null +++ b/MetaMorpheus/GUI/Views/FragmentReanalysisControl.xaml @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + + + + + + + +