Skip to content

Commit

Permalink
Added ability to select your own tolerance for MetaDraw fragmentation…
Browse files Browse the repository at this point in the history
… reanalysis
  • Loading branch information
nbollis committed Sep 19, 2024
1 parent 5a03e38 commit 3df63d3
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 27 deletions.
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();

}
}
}
20 changes: 16 additions & 4 deletions MetaMorpheus/Test/MetaDraw/FragmentReanalysis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ public static void TestFragmentationReanalysisViewModel_DefaultProperties()
var viewModel = new FragmentationReanalysisViewModel();

// check default parameters on loading
Assert.That(viewModel.SelectedDissociationType, Is.EqualTo(DissociationType.HCD));
Assert.AreEqual(DissociationType.HCD, viewModel.SelectedDissociationType);
Assert.False(viewModel.Persist);
Assert.False(viewModel.UseInternalIons);
Assert.That(viewModel.MinInternalIonLength, Is.EqualTo(10));
Assert.That(viewModel.DissociationTypes.Count(), Is.EqualTo(7));
Assert.AreEqual(10, viewModel.MinInternalIonLength);
Assert.AreEqual(7, viewModel.DissociationTypes.Count());
Assert.AreEqual(20, viewModel.ProductIonMassTolerance);

var productsToUse = viewModel.PossibleProducts.Where(p => p.Use).Select(p => p.ProductType).ToList();
var hcdProducts = Omics.Fragmentation.Peptide.DissociationTypeCollection.ProductsFromDissociationType[DissociationType.HCD];
Expand Down Expand Up @@ -97,13 +98,24 @@ public static void TestFragmentationReanalysisViewModel_RematchIons()
var psmToResearch = parsedPsms.First();
var scan = dataFile.GetOneBasedScan(psmToResearch.Ms2ScanNumber);

// increase product ion tolerance and ensure more ions are found
viewModel.ProductIonMassTolerance = 200;
var newMatchedIons = viewModel.MatchIonsWithNewTypes(scan, psmToResearch);
Assert.Less(psmToResearch.MatchedIons.Count, newMatchedIons.Count);

// decrease product ion tolerance and ensure fewer ions are found
viewModel.ProductIonMassTolerance = 2;
newMatchedIons = viewModel.MatchIonsWithNewTypes(scan, psmToResearch);
Assert.Less(newMatchedIons.Count, psmToResearch.MatchedIons.Count);
viewModel.ProductIonMassTolerance = 20;

// ensure ambiguous psms get kicked out before reanalysis
var ambiguousPsm = parsedPsms.First(p => p.FullSequence.Contains('|'));
var newIons = viewModel.MatchIonsWithNewTypes(scan, ambiguousPsm);
CollectionAssert.AreEqual(ambiguousPsm.MatchedIons, newIons);

viewModel.PossibleProducts.ForEach(p => p.Use = true);
var newMatchedIons = viewModel.MatchIonsWithNewTypes(scan, psmToResearch);
newMatchedIons = viewModel.MatchIonsWithNewTypes(scan, psmToResearch);

// searching with additional ions should yield more
Assert.That(psmToResearch.MatchedIons.Count, Is.LessThan(newMatchedIons.Count));
Expand Down

0 comments on commit 3df63d3

Please sign in to comment.