Skip to content

Commit c16b4ee

Browse files
authored
Merge branch 'master' into InstallerArtifactCert
2 parents d36f371 + 1e7c7c2 commit c16b4ee

21 files changed

+9122
-258
lines changed

MetaMorpheus/GUI/MetaDraw/MetaDraw.xaml

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
where the view is what is displayed, the model or viewmodel holds the data to be displayed, and the controller instantiates and controls each of
1818
the other components -->
1919
<Grid>
20-
<TabControl >
20+
<TabControl x:Name="MainTabControl" >
2121
<TabControl.Resources>
2222
<Style TargetType="TabItem">
2323
<Setter Property="Template">
@@ -124,14 +124,16 @@
124124
<DataGridTextColumn Header="MS2 Scan" Binding="{Binding Ms2ScanNumber}" Width="70"
125125
ElementStyle="{StaticResource DataGridCenteredCellStyle}" />
126126
<DataGridTextColumn Header="Full Sequence" Binding="{Binding FullSequence}" Width="160" />
127-
<DataGridTextColumn Header="Protein Name" Binding="{Binding ProteinName}" Width="100"
127+
<DataGridTextColumn Header="Name" Binding="{Binding Name}" Width="100"
128128
/>
129129
<DataGridTextColumn Header="Organism Name" Binding="{Binding OrganismName}" Width="100" />
130130
<DataGridTextColumn Header="Q-Value" Binding="{Binding QValue}" Width="60"
131131
ElementStyle="{StaticResource DataGridCenteredCellStyle}"/>
132132
<DataGridTextColumn Header="PEP Value" Binding="{Binding PEP}" Width="70" />
133133
<DataGridTextColumn Header="MetaMorpheus Score" Binding="{Binding Score}"
134134
ElementStyle="{StaticResource DataGridCenteredCellStyle}"/>
135+
<DataGridTextColumn Header="File Name" Binding="{Binding FileNameWithoutExtension}"
136+
ElementStyle="{StaticResource DataGridCenteredCellStyle}"/>
135137
</DataGrid.Columns>
136138
</DataGrid>
137139
</Grid>
@@ -465,8 +467,9 @@
465467
<Grid.RowDefinitions>
466468
<RowDefinition Height="29"/>
467469
<RowDefinition Height="29"/>
468-
<RowDefinition Height="50*"/>
469-
<RowDefinition Height="40*"/>
470+
<RowDefinition Height="*"/>
471+
<RowDefinition Height="Auto"/>
472+
<RowDefinition Height="*"/>
470473
<RowDefinition Height="25"/>
471474
</Grid.RowDefinitions>
472475

@@ -492,16 +495,37 @@
492495
<Button x:Name="selectAllSourceFiles" HorizontalAlignment="Left" Content="Select all" Click="selectAllSourceFiles_Click"/>
493496
<Button x:Name="deselectAllSourceFiles" HorizontalAlignment="Right" Content="Deselect all" Click="deselectAllSourceFiles_Click"/>
494497
</DockPanel>
495-
<ListBox x:Name="selectSourceFileListBox" ItemsSource="{Binding}" SelectionMode="Multiple" SelectionChanged="selectSourceFileListBox_SelectionChanged" ScrollViewer.VerticalScrollBarVisibility="Visible"/>
498+
<ListBox x:Name="selectSourceFileListBox"
499+
ItemsSource="{Binding}"
500+
SelectionMode="Multiple"
501+
AllowDrop="True"
502+
SelectionChanged="selectSourceFileListBox_SelectionChanged"
503+
PreviewMouseLeftButtonDown="selectSourceFileListBox_PreviewMouseLeftButtonDown"
504+
PreviewMouseMove="selectSourceFileListBox_PreviewMouseMove"
505+
Drop="selectSourceFileListBox_Drop"
506+
DisplayMemberPath="."/>
496507
</DockPanel>
497508
</DockPanel>
498509

510+
<StackPanel Grid.Row="3" Orientation="Horizontal" HorizontalAlignment="Left" x:Name="PlotFilterCheckBoxes" Margin="3" >
511+
<CheckBox Content="Filtered Only?"
512+
IsChecked="{Binding Source={x:Static guiFunctions:MetaDrawSettingsViewModel.Instance}, Path=DisplayFilteredOnly}"
513+
Checked="DataVisualizationFilters_OnChecked"
514+
Unchecked="DataVisualizationFilters_OnChecked"
515+
Margin="10 0"/>
516+
<CheckBox Content="Normalize to File?"
517+
IsChecked="{Binding Source={x:Static guiFunctions:MetaDrawSettingsViewModel.Instance}, Path=NormalizeHistogramToFile}"
518+
Checked="DataVisualizationFilters_OnChecked"
519+
Unchecked="DataVisualizationFilters_OnChecked"
520+
Margin="10 0"/>
521+
</StackPanel>
522+
499523
<!--List of plot options-->
500-
<GroupBox Header="Plot Type" Name="plotType" Grid.Row="3">
524+
<GroupBox Header="Plot Type" Name="plotType" Grid.Row="4">
501525
<ListView x:Name="plotsListBox" ItemsSource="{Binding}" SelectionChanged ="PlotSelected" MaxHeight="400"/>
502526
</GroupBox>
503527

504-
<DockPanel Grid.Row="4" Margin="2">
528+
<DockPanel Grid.Row="5" Margin="2">
505529
<Button Content="Export to PDF" Width="100" Click="CreatePlotPdf_Click" />
506530
</DockPanel>
507531
</Grid>
@@ -524,9 +548,13 @@
524548
Width="2"/>
525549

526550
<!--Plot-->
527-
<GroupBox Grid.Column="2" Header="Plot">
528-
<oxy:PlotView Grid.Row="0" x:Name="plotViewStat" Model="{Binding Model}" SizeChanged="PlotViewStat_SizeChanged" FontSize="16" FontStretch="Expanded" BorderBrush="LightGray" Grid.ColumnSpan="2"/>
529-
</GroupBox>
551+
<Grid Grid.Column="2">
552+
<oxy:PlotView Grid.Row="0" x:Name="plotViewStat" Model="{Binding Model}" SizeChanged="PlotViewStat_SizeChanged" FontSize="16" FontStretch="Expanded" BorderBrush="LightGray" />
553+
554+
<local:SettingsButtonControl Height="52" x:Name="DataVisualizationSettingsButton"
555+
HorizontalAlignment="Left" VerticalAlignment="Top"
556+
Panel.ZIndex="1" SelectedTabIndex="3" />
557+
</Grid>
530558
</Grid>
531559
</DockPanel>
532560
</TabItem>

MetaMorpheus/GUI/MetaDraw/MetaDraw.xaml.cs

Lines changed: 103 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using EngineLayer;
33
using GuiFunctions;
44
using GuiFunctions.MetaDraw;
5-
using MassSpectrometry;
65
using Omics.Fragmentation;
76
using OxyPlot;
87
using Readers;
@@ -11,7 +10,6 @@
1110
using System.Collections.ObjectModel;
1211
using System.ComponentModel;
1312
using System.Data;
14-
using System.Diagnostics;
1513
using System.Globalization;
1614
using System.IO;
1715
using System.Linq;
@@ -22,6 +20,8 @@
2220
using System.Windows;
2321
using System.Windows.Controls;
2422
using System.Windows.Data;
23+
using System.Windows.Input;
24+
using System.Windows.Media;
2525

2626
namespace MetaMorpheusGUI
2727
{
@@ -87,7 +87,7 @@ public MetaDraw(string[]? filesToLoad = null)
8787

8888
private void Window_Drop(object sender, DragEventArgs e)
8989
{
90-
string[] files = ((string[])e.Data.GetData(DataFormats.FileDrop)).OrderBy(p => p).ToArray();
90+
string[] files = ((string[])e.Data.GetData(DataFormats.FileDrop))?.OrderBy(p => p).ToArray();
9191

9292
if (files != null)
9393
{
@@ -459,7 +459,7 @@ private void RefreshPlotsAfterSettingsChange(object sender, MetaDrawSettingsChan
459459

460460
// save current selected PSM
461461
var selectedItem = dataGridScanNums.SelectedItem as SpectrumMatchFromTsv;
462-
var selectedChimeraGroup = ChimeraAnalysisTabViewModel.SelectedChimeraGroup;
462+
var selectedChimeraGroup = ChimeraAnalysisTabViewModel?.SelectedChimeraGroup;
463463

464464
// filter based on new settings
465465
if (e.FilterChanged)
@@ -476,6 +476,11 @@ private void RefreshPlotsAfterSettingsChange(object sender, MetaDrawSettingsChan
476476
}
477477
}
478478

479+
if (e.DataVisualizationChanged && (string)((TabItem)MainTabControl.SelectedItem).Header == "Data Visualization")
480+
{
481+
PlotSelected(plotsListBox, null);
482+
}
483+
479484
// Reselect items and refresh plots
480485
if (selectedItem != null)
481486
{
@@ -718,6 +723,8 @@ private void SequenceAnnotationExportButton_Click(object sender, RoutedEventArgs
718723
}
719724
}
720725

726+
#region Data Visualization Tab
727+
721728
private void SetUpPlots()
722729
{
723730
foreach (var plot in PlotModelStat.PlotNames)
@@ -832,21 +839,40 @@ private async void PlotSelected(object sender, SelectionChangedEventArgs e)
832839
Dictionary<string, ObservableCollection<SpectrumMatchFromTsv>> psmsBSF = new();
833840
foreach (string fileName in selectSourceFileListBox.SelectedItems)
834841
{
835-
psmsBSF.Add(fileName, MetaDrawLogic.SpectralMatchesGroupedByFile[fileName]);
842+
psmsBSF.Add(fileName, new ObservableCollection<SpectrumMatchFromTsv>());
836843
foreach (SpectrumMatchFromTsv psm in MetaDrawLogic.SpectralMatchesGroupedByFile[fileName])
837844
{
838-
psms.Add(psm);
845+
if (!MetaDrawSettings.DisplayFilteredOnly)
846+
{
847+
psms.Add(psm);
848+
psmsBSF[fileName].Add(psm);
849+
}
850+
else if (MetaDrawSettings.FilterAcceptsPsm(psm))
851+
{
852+
psms.Add(psm);
853+
psmsBSF[fileName].Add(psm);
854+
}
839855
}
840856
}
841-
PlotModelStat plot = await Task.Run(() => new PlotModelStat(plotName, psms, psmsBSF));
857+
858+
PlotModelStat plot = null;
859+
try
860+
{
861+
plot = await Task.Run(() => new PlotModelStat(plotName, psms, psmsBSF));
862+
}
863+
catch (Exception ex)
864+
{
865+
MessageBox.Show($"An error occurred while generating the plot '{plotName}':\n{ex.Message}", "Plot Generation Error", MessageBoxButton.OK, MessageBoxImage.Error);
866+
return;
867+
}
842868
plotViewStat.DataContext = plot;
843869
PlotViewStat_SizeChanged(plotViewStat, null);
844870
}
845871

846872
private void selectSourceFileListBox_SelectionChanged(object sender, EventArgs e)
847873
{
848874
// refreshes the plot using the new source file
849-
if (plotsListBox.SelectedIndex > -1 && selectSourceFileListBox.SelectedItems.Count != 0)
875+
if (plotsListBox?.SelectedIndex > -1 && selectSourceFileListBox?.SelectedItems.Count != 0)
850876
{
851877
PlotSelected(plotsListBox, null);
852878
}
@@ -886,6 +912,75 @@ private void PlotViewStat_SizeChanged(object sender, SizeChangedEventArgs e)
886912
}
887913
}
888914

915+
916+
private Point _dragStartPoint;
917+
private object _draggedData;
918+
private void selectSourceFileListBox_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
919+
{
920+
_dragStartPoint = e.GetPosition(null);
921+
_draggedData = GetDataFromListBoxItemUnderMouse(e.GetPosition(selectSourceFileListBox));
922+
}
923+
924+
private void selectSourceFileListBox_PreviewMouseMove(object sender, MouseEventArgs e)
925+
{
926+
if (e.LeftButton == MouseButtonState.Pressed && _draggedData != null)
927+
{
928+
Point currentPosition = e.GetPosition(null);
929+
if (Math.Abs(currentPosition.X - _dragStartPoint.X) > SystemParameters.MinimumHorizontalDragDistance ||
930+
Math.Abs(currentPosition.Y - _dragStartPoint.Y) > SystemParameters.MinimumVerticalDragDistance)
931+
{
932+
DragDrop.DoDragDrop(selectSourceFileListBox, _draggedData, DragDropEffects.Move);
933+
_draggedData = null;
934+
}
935+
}
936+
}
937+
938+
private void selectSourceFileListBox_Drop(object sender, DragEventArgs e)
939+
{
940+
var droppedData = e.Data.GetData(typeof(string)) as string;
941+
var targetData = GetDataFromListBoxItemUnderMouse(e.GetPosition(selectSourceFileListBox));
942+
if (droppedData == null || targetData == null || droppedData == targetData)
943+
return;
944+
945+
int removedIdx = PsmStatPlotFiles.IndexOf(droppedData);
946+
int targetIdx = PsmStatPlotFiles.IndexOf(targetData as string);
947+
if (removedIdx < 0 || targetIdx < 0)
948+
return;
949+
950+
if (removedIdx < targetIdx)
951+
{
952+
PsmStatPlotFiles.Insert(targetIdx + 1, droppedData);
953+
PsmStatPlotFiles.RemoveAt(removedIdx);
954+
}
955+
else
956+
{
957+
int remIdx = removedIdx + 1;
958+
if (PsmStatPlotFiles.Count + 1 <= remIdx) return;
959+
PsmStatPlotFiles.Insert(targetIdx, droppedData);
960+
PsmStatPlotFiles.RemoveAt(remIdx);
961+
}
962+
}
963+
964+
// Helper to get the data object from the ListBoxItem under the mouse
965+
private object GetDataFromListBoxItemUnderMouse(Point point)
966+
{
967+
var element = selectSourceFileListBox.InputHitTest(point) as DependencyObject;
968+
while (element != null && !(element is ListBoxItem))
969+
element = VisualTreeHelper.GetParent(element);
970+
971+
return (element as ListBoxItem)?.DataContext;
972+
}
973+
974+
private void DataVisualizationFilters_OnChecked(object sender, RoutedEventArgs e)
975+
{
976+
if (plotsListBox?.SelectedIndex > -1 && selectSourceFileListBox?.SelectedItems.Count != 0)
977+
{
978+
PlotSelected(plotsListBox, null);
979+
}
980+
}
981+
982+
#endregion
983+
889984
/// <summary>
890985
/// Redraws the Stationary Sequence whenever the scrolling sequence is scrolled
891986
/// </summary>

0 commit comments

Comments
 (0)