2
2
using EngineLayer ;
3
3
using GuiFunctions ;
4
4
using GuiFunctions . MetaDraw ;
5
- using MassSpectrometry ;
6
5
using Omics . Fragmentation ;
7
6
using OxyPlot ;
8
7
using Readers ;
11
10
using System . Collections . ObjectModel ;
12
11
using System . ComponentModel ;
13
12
using System . Data ;
14
- using System . Diagnostics ;
15
13
using System . Globalization ;
16
14
using System . IO ;
17
15
using System . Linq ;
22
20
using System . Windows ;
23
21
using System . Windows . Controls ;
24
22
using System . Windows . Data ;
23
+ using System . Windows . Input ;
24
+ using System . Windows . Media ;
25
25
26
26
namespace MetaMorpheusGUI
27
27
{
@@ -87,7 +87,7 @@ public MetaDraw(string[]? filesToLoad = null)
87
87
88
88
private void Window_Drop ( object sender , DragEventArgs e )
89
89
{
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 ( ) ;
91
91
92
92
if ( files != null )
93
93
{
@@ -459,7 +459,7 @@ private void RefreshPlotsAfterSettingsChange(object sender, MetaDrawSettingsChan
459
459
460
460
// save current selected PSM
461
461
var selectedItem = dataGridScanNums . SelectedItem as SpectrumMatchFromTsv ;
462
- var selectedChimeraGroup = ChimeraAnalysisTabViewModel . SelectedChimeraGroup ;
462
+ var selectedChimeraGroup = ChimeraAnalysisTabViewModel ? . SelectedChimeraGroup ;
463
463
464
464
// filter based on new settings
465
465
if ( e . FilterChanged )
@@ -476,6 +476,11 @@ private void RefreshPlotsAfterSettingsChange(object sender, MetaDrawSettingsChan
476
476
}
477
477
}
478
478
479
+ if ( e . DataVisualizationChanged && ( string ) ( ( TabItem ) MainTabControl . SelectedItem ) . Header == "Data Visualization" )
480
+ {
481
+ PlotSelected ( plotsListBox , null ) ;
482
+ }
483
+
479
484
// Reselect items and refresh plots
480
485
if ( selectedItem != null )
481
486
{
@@ -718,6 +723,8 @@ private void SequenceAnnotationExportButton_Click(object sender, RoutedEventArgs
718
723
}
719
724
}
720
725
726
+ #region Data Visualization Tab
727
+
721
728
private void SetUpPlots ( )
722
729
{
723
730
foreach ( var plot in PlotModelStat . PlotNames )
@@ -832,21 +839,40 @@ private async void PlotSelected(object sender, SelectionChangedEventArgs e)
832
839
Dictionary < string , ObservableCollection < SpectrumMatchFromTsv > > psmsBSF = new ( ) ;
833
840
foreach ( string fileName in selectSourceFileListBox . SelectedItems )
834
841
{
835
- psmsBSF . Add ( fileName , MetaDrawLogic . SpectralMatchesGroupedByFile [ fileName ] ) ;
842
+ psmsBSF . Add ( fileName , new ObservableCollection < SpectrumMatchFromTsv > ( ) ) ;
836
843
foreach ( SpectrumMatchFromTsv psm in MetaDrawLogic . SpectralMatchesGroupedByFile [ fileName ] )
837
844
{
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
+ }
839
855
}
840
856
}
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
+ }
842
868
plotViewStat . DataContext = plot ;
843
869
PlotViewStat_SizeChanged ( plotViewStat , null ) ;
844
870
}
845
871
846
872
private void selectSourceFileListBox_SelectionChanged ( object sender , EventArgs e )
847
873
{
848
874
// 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 )
850
876
{
851
877
PlotSelected ( plotsListBox , null ) ;
852
878
}
@@ -886,6 +912,75 @@ private void PlotViewStat_SizeChanged(object sender, SizeChangedEventArgs e)
886
912
}
887
913
}
888
914
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
+
889
984
/// <summary>
890
985
/// Redraws the Stationary Sequence whenever the scrolling sequence is scrolled
891
986
/// </summary>
0 commit comments