Skip to content

Commit

Permalink
MetaDraw Bug Fix(es) and QOL Update (#2420)
Browse files Browse the repository at this point in the history
* Updated to MzLib 1.0.548 and fixed custom ions in search tasks

* reverted calibration task change

* merged in master bbbyy

* Spectral Library from Command Line (#2386)

* Updated to MzLib 1.0.548 and fixed custom ions in search tasks

* reverted calibration task change

* merged in master bbbyy

* Enabled Library Loading from command line

* Adjusted MetaDrawSettings IO to default to default values instead of a uniform default

* Tested MetaDraw Settings loading under numerous conditions

* Fixed crash on MetaDraw tab switch while selecting ambiguous result

* fixed crash on ambiguous selected on chimera tab to child scan

* general cleanup

* Adjusted test data to expand code coverage

* Added ability to select your own tolerance for MetaDraw fragmentation reanalysis

---------

Co-authored-by: trishorts <[email protected]>
  • Loading branch information
nbollis and trishorts authored Sep 25, 2024
1 parent e1c39e7 commit 6dd10e0
Show file tree
Hide file tree
Showing 9 changed files with 220 additions and 46 deletions.
53 changes: 43 additions & 10 deletions MetaMorpheus/GUI/MetaDraw/MetaDraw.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,16 @@ private void dataGridScanNums_SelectedCellsChanged(object sender, SelectedCellsC
// Chimera plotter
if (MetaDrawTabControl.SelectedContent is Grid { Name: "chimeraPlotGrid" })
{
ClearPresentationArea();
chimeraPlot.Visibility = Visibility.Visible;
List<PsmFromTsv> chimericPsms = MetaDrawLogic.FilteredListOfPsms
.Where(p => p.Ms2ScanNumber == psm.Ms2ScanNumber && p.FileNameWithoutExtension == psm.FileNameWithoutExtension).ToList();
MetaDrawLogic.DisplayChimeraSpectra(chimeraPlot, chimericPsms, out List<string> error);
if (error != null && error.Count > 0)
Debugger.Break();
ClearPresentationArea();
wholeSequenceCoverageHorizontalScroll.Visibility = Visibility.Collapsed;

AmbiguousWarningTextBlocks.Visibility = Visibility.Collapsed;
AmbiguousSequenceOptionBox.Visibility = Visibility.Collapsed;

if (MetaDrawSettings.ShowLegend)
{
Expand All @@ -217,7 +219,27 @@ private void dataGridScanNums_SelectedCellsChanged(object sender, SelectedCellsC
// 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;
// From chimeric scan view to child scan view with ambiguous selected
if (AmbiguousSequenceOptionBox.SelectedItem == null)
{
// set to first and break the loop if casted successfully
foreach (var ambiguousResult in AmbiguousSequenceOptionBox.Items)
{
psm = ambiguousResult as PsmFromTsv;
if (psm != null)
break;
}

AmbiguousWarningTextBlocks.Visibility = Visibility.Collapsed;
AmbiguousSequenceOptionBox.Visibility = Visibility.Visible;
AmbiguousSequenceOptionBox.SelectedItem = psm;
}
// selecting a different ambiguous result from the combobox in child scan view
else
{
psm = (PsmFromTsv)AmbiguousSequenceOptionBox.SelectedItem;
}

if (FragmentationReanalysisViewModel.Persist || sender is FragmentationReanalysisViewModel)
{
oldMatchedIons = psm.MatchedIons;
Expand Down Expand Up @@ -918,8 +940,15 @@ private void AmbiguousSequenceOptionBox_SelectionChanged(object sender, Selectio
SetSequenceDrawingPositionSettings(true);
object obj = new object();
if (AmbiguousSequenceOptionBox.Items.Count > 0)
{
dataGridScanNums_SelectedCellsChanged(obj, null);
MetaDrawLogic.DisplaySequences(stationarySequenceCanvas, scrollableSequenceCanvas, sequenceAnnotationCanvas, psm);
MetaDrawLogic.DisplaySequences(stationarySequenceCanvas, scrollableSequenceCanvas,
sequenceAnnotationCanvas, psm);
}
else
{
AmbiguousSequenceOptionBox.Visibility = Visibility.Hidden;
}
}

/// <summary>
Expand Down Expand Up @@ -1033,6 +1062,7 @@ private void MetaDrawTabControl_OnSelectionChanged(object sender, SelectionChang
if (e.RemovedItems.Count > 0 && ((TabItem)e.RemovedItems[0]).Name == "ChimeraScanPlot")
{
MetaDrawLogic.FilterPsms();
ClearPresentationArea();

// reselect what was selected
if (selectedPsm != null && MetaDrawLogic.FilteredListOfPsms.Contains(selectedPsm))
Expand All @@ -1047,12 +1077,15 @@ private void MetaDrawTabControl_OnSelectionChanged(object sender, SelectionChang
if (e.AddedItems.Count > 0 && ((TabItem)e.AddedItems[0]).Name == "ChimeraScanPlot")
{
MetaDrawLogic.FilterPsmsToChimerasOnly();
ClearPresentationArea();

// reselect what was selected
if (selectedPsm == null || !MetaDrawLogic.FilteredListOfPsms.Contains(selectedPsm)) return;
int psmIndex = MetaDrawLogic.FilteredListOfPsms.IndexOf(selectedPsm);
dataGridScanNums.SelectedIndex = psmIndex;
dataGridScanNums_SelectedCellsChanged(new object(), null);
// reselect what was selected if possible
if (selectedPsm != null && MetaDrawLogic.FilteredListOfPsms.Contains(selectedPsm))
{
int psmIndex = MetaDrawLogic.FilteredListOfPsms.IndexOf(selectedPsm);
dataGridScanNums.SelectedIndex = psmIndex;
dataGridScanNums_SelectedCellsChanged(new object(), null);
}
}
}

Expand All @@ -1066,11 +1099,11 @@ private void ClearPresentationArea()
DrawnSequence.ClearCanvas(map);
DrawnSequence.ClearCanvas(sequenceText);
DrawnSequence.ClearCanvas(sequenceAnnotationCanvas);
plotView.Visibility = Visibility.Hidden;
GrayBox.Opacity = 0;
wholeSequenceCoverageHorizontalScroll.Visibility = Visibility.Collapsed;
AmbiguousSequenceOptionBox.Items.Clear();
plotView.Visibility = Visibility.Hidden;
chimeraPlot.Visibility = Visibility.Hidden;

if (ChimeraLegend != null)
ChimeraLegend.Visibility = false;
Expand Down
56 changes: 34 additions & 22 deletions MetaMorpheus/GUI/Views/FragmentReanalysisControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,46 @@

<!-- All options in the header -->
<Grid Grid.Row="0">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="3*"/>
<ColumnDefinition Width="3*"/>
<ColumnDefinition Width="3*"/>
</Grid.ColumnDefinitions>

<Button Grid.Row="0" Grid.Column="0" x:Name="SearchButton" Grid.RowSpan="2" Content="Search" VerticalAlignment="Center" Margin="5 3"
VerticalContentAlignment="Center" Click="SearchWithNewIons_OnClick"/>
<CheckBox Grid.Row="0" Grid.Column="1" Grid.RowSpan="2" Content="Persist?" VerticalAlignment="Center"
IsChecked="{Binding Persist}"
Margin="5 3" ToolTip="Research each identification as they are selected"/>
<Button Grid.Row="0" Grid.Column="0" x:Name="SearchButton" Content="Search"
VerticalAlignment="Center" Margin="5 3"
VerticalContentAlignment="Center" Click="SearchWithNewIons_OnClick" />

<StackPanel Grid.Row="0" Grid.Column="2" Orientation="Horizontal" VerticalAlignment="Center">
<TextBlock Text="Set Dissociation Type: " VerticalAlignment="Center"/>
<ComboBox x:Name="DissociationTypeComboBox" ItemsSource="{Binding DissociationTypes}"
SelectedItem="{Binding SelectedDissociationType}"
Margin="5 3" VerticalContentAlignment="Center" Width="80" />
<CheckBox Grid.Row="0" Grid.Column="1" Content="Persist?" VerticalAlignment="Center"
IsChecked="{Binding Persist}"
Margin="5 3" ToolTip="Research each identification as they are selected" />

<StackPanel Grid.Row="0" Grid.Column="2" Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Left">
<TextBlock Text="Set Dissociation Type: " VerticalAlignment="Center" />
<ComboBox x:Name="DissociationTypeComboBox" ItemsSource="{Binding DissociationTypes}"
SelectedItem="{Binding SelectedDissociationType}"
Margin="5 3" VerticalContentAlignment="Center" Width="80"
HorizontalContentAlignment="Center"/>
</StackPanel>

<StackPanel Grid.Row="0" Grid.Column="3" Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Left">
<TextBlock Text="Mass Tolerance (ppm): " VerticalAlignment="Center" />
<local:DoubleTextBoxControl Text="{Binding ProductIonMassTolerance, FallbackValue=20}"
HorizontalAlignment="Center" HorizontalContentAlignment="Center"
VerticalAlignment="Center" VerticalContentAlignment="Center"
BorderThickness="1" />
</StackPanel>
<StackPanel Grid.Row="0" Grid.Column="3" Orientation="Horizontal" VerticalAlignment="Center">
<CheckBox Content="Use internal ions of minimum length " IsChecked="{Binding UseInternalIons}"
HorizontalContentAlignment="Right" VerticalAlignment="Center" />
<local:IntegerTexBoxControl Text="{Binding MinInternalIonLength, FallbackValue=10}"
HorizontalAlignment="Center" HorizontalContentAlignment="Center" IsEnabled="{Binding UseInternalIons}"
VerticalAlignment="Center" VerticalContentAlignment="Center" BorderThickness="1" />

<StackPanel Grid.Row="0" Grid.Column="4" Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Left">
<CheckBox Content="Use internal ions of minimum length " IsChecked="{Binding UseInternalIons}"
HorizontalContentAlignment="Right" VerticalAlignment="Center" />
<local:IntegerTexBoxControl Text="{Binding MinInternalIonLength, FallbackValue=10}"
HorizontalAlignment="Center" HorizontalContentAlignment="Center"
IsEnabled="{Binding UseInternalIons}"
VerticalAlignment="Center" VerticalContentAlignment="Center"
BorderThickness="1" />
</StackPanel>
</Grid>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using EngineLayer;
using iText.StyledXmlParser.Jsoup;
using MassSpectrometry;
using MzLibUtil;
using Omics;
using Omics.Fragmentation;
using Proteomics.ProteolyticDigestion;
Expand All @@ -26,6 +27,7 @@ public FragmentationReanalysisViewModel(bool isProtein = true)
_isProtein = isProtein;
UseInternalIons = false;
MinInternalIonLength = 10;
ProductIonMassTolerance = 20;
if (isProtein)
{
DissociationTypes = new ObservableCollection<DissociationType>(Enum.GetValues<DissociationType>()
Expand Down Expand Up @@ -91,6 +93,14 @@ public bool UseInternalIons
set { _useInternalIons = value; OnPropertyChanged(nameof(UseInternalIons)); }
}

private double _productIonMassTolerance;

public double ProductIonMassTolerance
{
get => _productIonMassTolerance;
set { _productIonMassTolerance = value; OnPropertyChanged(nameof(ProductIonMassTolerance)); }
}

private IEnumerable<FragmentViewModel> GetPossibleProducts(bool isProtein)
{
foreach (var product in Enum.GetValues<ProductType>())
Expand Down Expand Up @@ -211,13 +221,15 @@ public List<MatchedFragmentIon> MatchIonsWithNewTypes(MsDataScan ms2Scan, PsmFro

// TODO: Adjust decon params for when RNA gets incorporated
var commonParams = new CommonParameters();
if (Math.Abs(commonParams.ProductMassTolerance.Value - ProductIonMassTolerance) > 0.00001)
commonParams.ProductMassTolerance = new PpmTolerance(ProductIonMassTolerance);

var specificMass = new Ms2ScanWithSpecificMass(ms2Scan, psmToRematch.PrecursorMz,
psmToRematch.PrecursorCharge, psmToRematch.FileNameWithoutExtension, commonParams);

return MetaMorpheusEngine.MatchFragmentIons(specificMass, allProducts, commonParams, false)
.Union(psmToRematch.MatchedIons.Where(p => _productsToUse.Contains(p.NeutralTheoreticalProduct.ProductType)))
.ToList();

}
}
}
2 changes: 1 addition & 1 deletion MetaMorpheus/GuiFunctions/MetaDraw/MetaDrawLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ public void FilterPsmsToChimerasOnly()
{
FilteredListOfPsms.Clear();

var filteredChimericPsms = ChimericPsms.Where(p => MetaDrawSettings.FilterAcceptsPsm(p));
var filteredChimericPsms = ChimericPsms.Where(MetaDrawSettings.FilterAcceptsPsm);
foreach (var psm in filteredChimericPsms)
{
if (filteredChimericPsms.Count(p => p.Ms2ScanNumber == psm.Ms2ScanNumber && p.FileNameWithoutExtension == psm.FileNameWithoutExtension) > 1)
Expand Down
30 changes: 27 additions & 3 deletions MetaMorpheus/GuiFunctions/MetaDraw/MetaDrawSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,9 @@ public static MetaDrawSettingsSnapshot MakeSnapShot()
/// <summary>
/// Loads in settings based upon SettingsSnapshot parameter
/// </summary>
public static void LoadSettings(MetaDrawSettingsSnapshot settings)
public static void LoadSettings(MetaDrawSettingsSnapshot settings, out bool flaggedErrorOnRead)
{
flaggedErrorOnRead = false;
DisplayIonAnnotations = settings.DisplayIonAnnotations;
AnnotateMzValues = settings.AnnotateMzValues;
AnnotateCharges = settings.AnnotateCharges;
Expand Down Expand Up @@ -504,11 +505,15 @@ public static void LoadSettings(MetaDrawSettingsSnapshot settings)

break;
}
default:
throw new MetaMorpheusException("Cannot parse Product Ion Color values");
}
}
catch (Exception e)

Check warning on line 512 in MetaMorpheus/GuiFunctions/MetaDraw/MetaDrawSettings.cs

View workflow job for this annotation

GitHub Actions / ubuntu-latest

The variable 'e' is declared but never used

Check warning on line 512 in MetaMorpheus/GuiFunctions/MetaDraw/MetaDrawSettings.cs

View workflow job for this annotation

GitHub Actions / windows-latest

The variable 'e' is declared but never used

Check warning on line 512 in MetaMorpheus/GuiFunctions/MetaDraw/MetaDrawSettings.cs

View workflow job for this annotation

GitHub Actions / macos-latest

The variable 'e' is declared but never used
{
Debugger.Break();
SetDefaultProductTypeColors();
flaggedErrorOnRead = true;
}

try // Beta Product Type Colors
Expand Down Expand Up @@ -537,11 +542,15 @@ public static void LoadSettings(MetaDrawSettingsSnapshot settings)

break;
}
default:
throw new MetaMorpheusException("Cannot parse Beta Product Ion Color values");
}
}
catch (Exception e)

Check warning on line 549 in MetaMorpheus/GuiFunctions/MetaDraw/MetaDrawSettings.cs

View workflow job for this annotation

GitHub Actions / ubuntu-latest

The variable 'e' is declared but never used

Check warning on line 549 in MetaMorpheus/GuiFunctions/MetaDraw/MetaDrawSettings.cs

View workflow job for this annotation

GitHub Actions / windows-latest

The variable 'e' is declared but never used

Check warning on line 549 in MetaMorpheus/GuiFunctions/MetaDraw/MetaDrawSettings.cs

View workflow job for this annotation

GitHub Actions / macos-latest

The variable 'e' is declared but never used
{
Debugger.Break();
SetDefaultBetaProductTypeColors();
flaggedErrorOnRead = true;
}

try // Modification Type Colors
Expand Down Expand Up @@ -569,11 +578,15 @@ public static void LoadSettings(MetaDrawSettingsSnapshot settings)

break;
}
default:
throw new MetaMorpheusException("Cannot parse Modification Color values");
}
}
catch (Exception e)

Check warning on line 585 in MetaMorpheus/GuiFunctions/MetaDraw/MetaDrawSettings.cs

View workflow job for this annotation

GitHub Actions / ubuntu-latest

The variable 'e' is declared but never used

Check warning on line 585 in MetaMorpheus/GuiFunctions/MetaDraw/MetaDrawSettings.cs

View workflow job for this annotation

GitHub Actions / windows-latest

The variable 'e' is declared but never used

Check warning on line 585 in MetaMorpheus/GuiFunctions/MetaDraw/MetaDrawSettings.cs

View workflow job for this annotation

GitHub Actions / macos-latest

The variable 'e' is declared but never used
{
Debugger.Break();
SetDefaultModificationColors();
flaggedErrorOnRead = true;
}

try // Coverage Type Colors
Expand All @@ -598,18 +611,25 @@ public static void LoadSettings(MetaDrawSettingsSnapshot settings)
if (CoverageTypeToColor.ContainsKey(key))
CoverageTypeToColor[key] = DrawnSequence.ParseOxyColorFromName(savedProductType.Split(',')[1]);
}

break;
}
default:
throw new MetaMorpheusException("Cannot parse Sequence Coverage color values");

}
}
catch (Exception e)

Check warning on line 621 in MetaMorpheus/GuiFunctions/MetaDraw/MetaDrawSettings.cs

View workflow job for this annotation

GitHub Actions / ubuntu-latest

The variable 'e' is declared but never used

Check warning on line 621 in MetaMorpheus/GuiFunctions/MetaDraw/MetaDrawSettings.cs

View workflow job for this annotation

GitHub Actions / windows-latest

The variable 'e' is declared but never used

Check warning on line 621 in MetaMorpheus/GuiFunctions/MetaDraw/MetaDrawSettings.cs

View workflow job for this annotation

GitHub Actions / macos-latest

The variable 'e' is declared but never used
{
Debugger.Break();
Debugger.Break();
SetDefaultCoverageTypeColors();
flaggedErrorOnRead = true;
}

try // Spectrum Descriptors
{
if (!settings.SpectrumDescriptionValues.Any())
throw new MetaMorpheusException("Cannot parse Spectrum Descriptor values");

var firstSplit = settings.SpectrumDescriptionValues.First().Split(',');
switch (firstSplit.Length)
{
Expand All @@ -633,11 +653,15 @@ public static void LoadSettings(MetaDrawSettingsSnapshot settings)

break;
}
default:
throw new MetaMorpheusException("Cannot parse Spectrum Descriptor values");
}
}
catch (Exception e)

Check warning on line 660 in MetaMorpheus/GuiFunctions/MetaDraw/MetaDrawSettings.cs

View workflow job for this annotation

GitHub Actions / ubuntu-latest

The variable 'e' is declared but never used

Check warning on line 660 in MetaMorpheus/GuiFunctions/MetaDraw/MetaDrawSettings.cs

View workflow job for this annotation

GitHub Actions / windows-latest

The variable 'e' is declared but never used

Check warning on line 660 in MetaMorpheus/GuiFunctions/MetaDraw/MetaDrawSettings.cs

View workflow job for this annotation

GitHub Actions / macos-latest

The variable 'e' is declared but never used
{
Debugger.Break();
SetDefaultProductTypeColors();
flaggedErrorOnRead = true;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,10 @@ public void LoadSettings()
{
MetaDrawSettingsSnapshot settings = null;
settings = XmlReaderWriter.ReadFromXmlFile<MetaDrawSettingsSnapshot>(SettingsPath);
MetaDrawSettings.LoadSettings(settings);
MetaDrawSettings.LoadSettings(settings, out bool flaggedErrorOnRead);

if (flaggedErrorOnRead)
SaveAsDefault();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<string>true</string>
<string>true</string>
<string>true</string>
<string>gobbledygook</string>
</SpectrumDescriptionValues>
<ProductTypeToColorValues>
<string>Aqua</string>
Expand Down Expand Up @@ -3823,6 +3824,7 @@
<string>Hullabaloo</string>
<string>Aqua</string>
<string>Aqua</string>
<string>Claptrap</string>
</CoverageTypeToColorValues>
<UnannotatedPeakColor>LightGray</UnannotatedPeakColor>
<InternalIonColor>Purple</InternalIonColor>
Expand Down
Loading

0 comments on commit 6dd10e0

Please sign in to comment.