Skip to content

Commit

Permalink
Merge pull request #148 from Alexander-Sol/pipEcho
Browse files Browse the repository at this point in the history
Pip ECHO
  • Loading branch information
Alexander-Sol authored Nov 22, 2024
2 parents 1755b30 + 73519ce commit 01d36f4
Show file tree
Hide file tree
Showing 12 changed files with 202 additions and 50 deletions.
2 changes: 1 addition & 1 deletion CMD/CMD.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.7.82" />
<PackageReference Include="MathNet.Numerics" Version="5.0.0" />
<PackageReference Include="mzLib" Version="1.0.552" />
<PackageReference Include="mzLib" Version="1.0.553" />
<PackageReference Include="NetSerializer" Version="4.1.2" />
<PackageReference Include="Nett" Version="0.15.0" />
<PackageReference Include="SharpLearning.Common.Interfaces" Version="0.28.0" />
Expand Down
24 changes: 22 additions & 2 deletions CMD/FlashLFQExecutable.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using CommandLine;
using CommandLine.Text;
using Easy.Common.Extensions;
using FlashLFQ;
using IO.ThermoRawFileReader;
using MzLibUtil;
Expand All @@ -24,6 +25,8 @@ public static void Main(string[] args)
.WithNotParsed(errs => DisplayHelp(parserResult, errs));
}

public static FlashLfqResults Results;

static void DisplayHelp<T>(ParserResult<T> result, IEnumerable<Error> errs)
{
var helpText = HelpText.AutoBuild(result, h =>
Expand Down Expand Up @@ -191,14 +194,27 @@ private static void Run(FlashLfqSettings settings)
List<Identification> ids;
try
{
ids = PsmReader.ReadPsms(settings.PsmIdentificationPath, settings.Silent, spectraFileInfos);
ids = PsmReader.ReadPsms(settings.PsmIdentificationPath, settings.Silent, spectraFileInfos, usePepQValue: settings.UsePepQValue).ToList();
}
catch (Exception e)
{
Console.WriteLine("Problem reading PSMs: " + e.Message);
return;
}

// determine which peptides should be quantified and used as donors for MBR
List<string> peptidesToQuantify;
try
{
peptidesToQuantify = PsmReader.ReadPsms(settings.PeptideIdentificationPath, settings.Silent, spectraFileInfos, usePepQValue: settings.UsePepQValue)
.Select(id => id.ModifiedSequence).ToList();
}
catch (Exception e)
{
Console.WriteLine("Problem reading Peptidess: " + e.Message);
return;
}

if (ids.Any())
{
if (!settings.Silent)
Expand All @@ -218,7 +234,10 @@ private static void Run(FlashLfqSettings settings)
FlashLfqResults results = null;
try
{
engine = FlashLfqSettings.CreateEngineWithSettings(settings, ids);
if (peptidesToQuantify != null && peptidesToQuantify.IsNotNullOrEmpty())
engine = FlashLfqSettings.CreateEngineWithSettings(settings, ids, peptidesToQuantify);
else
engine = FlashLfqSettings.CreateEngineWithSettings(settings, ids);

// run
results = engine.Run();
Expand All @@ -243,6 +262,7 @@ private static void Run(FlashLfqSettings settings)
// output
if (results != null)
{
Results = results;
try
{
OutputWriter.WriteOutput(settings.PsmIdentificationPath, results, settings.Silent, settings.OutputPath);
Expand Down
4 changes: 3 additions & 1 deletion GUI/DataGridObjects/IdentificationFileForDataGrid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ namespace GUI.DataGridObjects
{
public class IdentificationFileForDataGrid
{
public IdentificationFileForDataGrid(string filePath)
public IdentificationFileForDataGrid(string filePath, bool? peptideFile = null)
{
FilePath = filePath;
FileName = Path.GetFileName(filePath);
PeptideFile = peptideFile ?? FileName.ToLower().Contains("peptides");
}

public string FileName { get; }
public string FilePath { get; }
public bool PeptideFile { get; set; }
}
}
2 changes: 1 addition & 1 deletion GUI/GUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MathNet.Numerics" Version="5.0.0" />
<PackageReference Include="mzLib" Version="1.0.552" />
<PackageReference Include="mzLib" Version="1.0.553" />
<PackageReference Include="NetSerializer" Version="4.1.2" />
<PackageReference Include="Nett" Version="0.15.0" />
<PackageReference Include="SharpLearning.Common.Interfaces" Version="0.28.0" />
Expand Down
51 changes: 40 additions & 11 deletions GUI/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,9 @@
<!--Tutorial text-->
<TextBlock Foreground="DarkGray" Grid.Row="1" TextWrapping="WrapWithOverflow" >
Add your identification (PSM) files here. Accepted file formats are MetaMorpheus .psmtsv, Morpheus .tsv,
MaxQuant msms.txt, PeptideShaker .tabular, or generic .txt/.tsv
MaxQuant msms.txt, PeptideShaker .tabular, or generic .txt/.tsv. For MetaMorpheus results, we recommend including
the AllPeptides.psmtsv file as well.

</TextBlock>

<!--Button to add ID files-->
Expand All @@ -254,7 +256,8 @@
</DataGrid.Resources>
<DataGrid.Columns>
<!--The rest of the columns-->
<DataGridTextColumn Header="File" Binding="{Binding FilePath}" Width="590" />
<DataGridTextColumn Header="File" Binding="{Binding FilePath}" Width="510" />
<DataGridCheckBoxColumn Header="Peptide IDs" Binding="{Binding PeptideFile}" Width="90" />

<!--Defines the "delete" column-->
<DataGridTemplateColumn>
Expand Down Expand Up @@ -354,6 +357,7 @@
<RowDefinition Height="28" />
<RowDefinition Height="28" />
<RowDefinition Height="28" />
<RowDefinition Height="28" />
<RowDefinition Height="29" />
<RowDefinition Height="1*" />
</Grid.RowDefinitions>
Expand All @@ -376,34 +380,59 @@
<Label Content="PPM Tolerance" Foreground="DarkGray" />
</StackPanel>

<CheckBox Name="normalizeCheckbox" Content="Normalize Intensities" Foreground="DarkGray" Grid.Row="3" Style="{StaticResource SquareCheckbox}"
ToolTip="Corrects systematic intensity errors with median normalization. The main assumption is that most proteins do not change in abundance between samples" />
<Grid Grid.Row= "3">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>

<CheckBox Name="mbrCheckbox" Content="Match Between Runs" Foreground="DarkGray" Grid.Row="4" Style="{StaticResource SquareCheckbox}"
ToolTip="Maps MS/MS identifications from one run onto other runs in which they were not identified, using retention time and isotopic envelope similarity"/>
<CheckBox Name="mbrCheckbox" Content="Peptide-identity-propagation (Match-betweeen-runs)" Foreground="DarkGray"
Grid.Row="3" Grid.Column= "0" Style="{StaticResource SquareCheckbox}" Checked="MbrCheckbox_Checked" Unchecked="MbrCheckbox_Checked"
Height="21"
ToolTip="Maps MS/MS identifications from one run onto other runs in which they were not identified, using retention time and isotopic envelope similarity"/>

<StackPanel Name="MbrFdrPanel" Orientation="Horizontal"
Grid.Row="3" Grid.Column= "1" Margin="30,0,0,0" IsEnabled="{Binding IsEnabled, ElementName=mbrCheckbox}"
ToolTip="The false discovery rate threshold for reported PIP events. Default is 0.01.">
<TextBox Name="mbrFDRTextBox" Width="50" Height="21" Background="Transparent" Foreground="DarkGray"
BorderBrush="DarkGray" BorderThickness="1" FontSize="13" />
<Label Content="PIP FDR Cutoff" Foreground="DarkGray" />
</StackPanel>
</Grid>

<CheckBox Name="normalizeCheckbox" Content="Normalize Intensities" Foreground="DarkGray"
Grid.Row="4" Style="{StaticResource SquareCheckbox}"
ToolTip="Corrects systematic intensity errors with median normalization. The main assumption is that most proteins do not change in abundance between samples" />

<CheckBox Name="pepQValueCheckbox" Content="Use PEP Q Values" Foreground="DarkGray"
Grid.Row="5" Style="{StaticResource SquareCheckbox}"
ToolTip="Determines how FlashLFQ chooses which peptides to quantify (only applies to MetaMorpheus identifications). Using PEP Q generally yields more peptide IDs" />

<CheckBox Name="sharedPeptideCheckbox" Content="Use shared peptides for protein quantification" Foreground="DarkGray" Grid.Row="5"
<CheckBox Name="sharedPeptideCheckbox" Content="Use shared peptides for protein quantification" Foreground="DarkGray"
Grid.Row="6"
Style="{StaticResource SquareCheckbox}"
ToolTip="Uses peptide sequences shared between proteins for protein quantification" />

<CheckBox Name="bayesianCheckbox" Content="Bayesian Protein Fold-Change Analysis" Foreground="DarkGray"
Grid.Row="6" Style="{StaticResource SquareCheckbox}" Checked="BayesianCheckbox_Checked" Unchecked="BayesianCheckbox_Checked"
Grid.Row="7" Style="{StaticResource SquareCheckbox}" Checked="BayesianCheckbox_Checked" Unchecked="BayesianCheckbox_Checked"
ToolTip="This estimates each protein's fold-change relative to the control condition using Bayesian statistics. Also calculates posterior error probability (PEP) and false discovery rate (FDR)"/>

<StackPanel Name="BayesianSettings1" Orientation="Horizontal" Margin="20,0,0,0" Grid.Row="7" IsEnabled="{Binding IsEnabled, ElementName=bayesianCheckbox}"
<StackPanel Name="BayesianSettings1" Orientation="Horizontal" Margin="20,0,0,0"
Grid.Row="8" IsEnabled="{Binding IsEnabled, ElementName=bayesianCheckbox}"
ToolTip="The condition to calculate protein fold-changes relative to">
<ComboBox Name="ControlConditionComboBox" ItemsSource="{Binding}" MinWidth="80" IsEnabledChanged="BaseConditionComboBox_IsEnabledChanged" />
<Label Content="Control Condition" Foreground="DarkGray" />
</StackPanel>

<StackPanel Name="BayesianSettings2" Orientation="Horizontal" Grid.Row="8" Margin="20,0,0,0" IsEnabled="{Binding IsEnabled, ElementName=bayesianCheckbox}"
<StackPanel Name="BayesianSettings2" Orientation="Horizontal"
Grid.Row="9" Margin="20,0,0,0" IsEnabled="{Binding IsEnabled, ElementName=bayesianCheckbox}"
ToolTip="The protein log2-transformed fold-change that is considered to be not important, or background">
<Label Content="Log2 Fold-change cutoff:" Foreground="DarkGray" />
<TextBox Name="FoldChangeCutoffManualTextBox" Width="40" Height="21" Foreground="DarkGray" Background="Transparent"
BorderBrush="DarkGray" BorderThickness="1" FontSize="13" />
</StackPanel>

<Expander Header="Advanced Settings" Foreground="DarkGray" Grid.Row="9" Margin="0,20,0,0" >
<Expander Header="Advanced Settings" Foreground="DarkGray" Grid.Row="10" Margin="0,20,0,0" >
<Grid Margin="20,0,0,0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
Expand Down
46 changes: 43 additions & 3 deletions GUI/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using FlashLFQ;
using GUI.DataGridObjects;
using IO.ThermoRawFileReader;
using MzLibUtil;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
Expand Down Expand Up @@ -66,6 +67,7 @@ public MainWindow()

BayesianSettings1.Visibility = Visibility.Hidden;
BayesianSettings2.Visibility = Visibility.Hidden;
MbrFdrPanel.Visibility = Visibility.Hidden;

var _writer = new TextBoxWriter(notificationsTextBox);
Console.SetOut(_writer);
Expand All @@ -80,7 +82,9 @@ private void PopulateSettings()
ppmToleranceTextBox.Text = settings.PpmTolerance.ToString("F1");
normalizeCheckbox.IsChecked = settings.Normalize;
mbrCheckbox.IsChecked = settings.MatchBetweenRuns;
mbrFDRTextBox.Text = "0.01";
sharedPeptideCheckbox.IsChecked = settings.UseSharedPeptidesForProteinQuant;
pepQValueCheckbox.IsChecked = settings.UsePepQValue;
bayesianCheckbox.IsChecked = settings.BayesianProteinQuant;
FoldChangeCutoffManualTextBox.Text = "0.5";

Expand Down Expand Up @@ -125,9 +129,20 @@ private void ParseSettings()
throw new Exception("The PPM tolerance must be a decimal number");
}

// MBR FDR
if (double.TryParse(mbrFDRTextBox.Text, NumberStyles.Number, CultureInfo.InvariantCulture, out double mbrFdr))
{
settings.MbrDetectionQValueThreshold = mbrFdr;
}
else
{
throw new Exception("The PIP FDR must be a decimal number");
}

settings.Normalize = normalizeCheckbox.IsChecked.Value;
settings.MatchBetweenRuns = mbrCheckbox.IsChecked.Value;
settings.UseSharedPeptidesForProteinQuant = sharedPeptideCheckbox.IsChecked.Value;
settings.UsePepQValue = pepQValueCheckbox.IsChecked.Value;
settings.BayesianProteinQuant = bayesianCheckbox.IsChecked.Value;

settings.Integrate = integrateCheckBox.IsChecked.Value;
Expand Down Expand Up @@ -428,6 +443,7 @@ private void Run_Click(object sender, RoutedEventArgs e)
ppmToleranceTextBox.IsEnabled = false;
normalizeCheckbox.IsEnabled = false;
mbrCheckbox.IsEnabled = false;
MbrFdrPanel.IsEnabled = false;
sharedPeptideCheckbox.IsEnabled = false;
bayesianCheckbox.IsEnabled = false;
BayesianSettings1.IsEnabled = false;
Expand Down Expand Up @@ -498,12 +514,24 @@ private void RunFlashLfq()
{
// read IDs
var ids = new List<Identification>();
List<string> peptidesToQuantify = null;

try
{
foreach (var identFile in idFiles)
var allPepFile = idFiles.FirstOrDefault(idFile => idFile.PeptideFile);
if(allPepFile!=null)
{
// Read in the peptide file, select only the peptdies that pass the q-value threshold
peptidesToQuantify = PsmReader.ReadPsms(allPepFile.FilePath, false,
spectraFiles.Select(p => p.SpectraFileInfo).ToList(),
usePepQValue: settings.UsePepQValue)
.Select(id => id.ModifiedSequence).ToList();
}
foreach (var identFile in idFiles.Where(idFile => idFile != allPepFile))
{
ids = ids.Concat(PsmReader.ReadPsms(identFile.FilePath, false, spectraFiles.Select(p => p.SpectraFileInfo).ToList())).ToList();
ids = ids.Concat(PsmReader.ReadPsms(identFile.FilePath, false,
spectraFiles.Select(p => p.SpectraFileInfo).ToList(),
usePepQValue: settings.UsePepQValue)).ToList();
}
}
catch (Exception e)
Expand Down Expand Up @@ -557,7 +585,7 @@ private void RunFlashLfq()
// run FlashLFQ engine
try
{
flashLfqEngine = FlashLfqSettings.CreateEngineWithSettings(settings, ids);
flashLfqEngine = FlashLfqSettings.CreateEngineWithSettings(settings, ids, peptidesToQuantify);

results = flashLfqEngine.Run();
}
Expand Down Expand Up @@ -842,5 +870,17 @@ private void BayesianCheckbox_Checked(object sender, RoutedEventArgs e)
BayesianSettings2.Visibility = Visibility.Hidden;
}
}

private void MbrCheckbox_Checked(object sender, RoutedEventArgs e)
{
if (mbrCheckbox.IsChecked.Value)
{
MbrFdrPanel.Visibility = Visibility.Visible;
}
else
{
MbrFdrPanel.Visibility = Visibility.Hidden;
}
}
}
}
10 changes: 6 additions & 4 deletions Test/Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ public static void TestParallelProcessingMetaMorpheusOutputWithExtensions()
File.Delete(proteinsPath);
}

[Test]
[Test]
public static void TestParallelProcessingMetaMorpheusOutputWithExtensionsAndWindowsPath()
{
string search = "Parallel";
Expand Down Expand Up @@ -553,17 +553,19 @@ public static void TestSettingsPassing()
|| name == "OutputPath"
|| name == "ReadOnlyFileSystem"
|| name == "PrintThermoLicenceViaCommandLine"
|| name == "AcceptThermoLicenceViaCommandLine")
|| name == "AcceptThermoLicenceViaCommandLine"
|| name == "PeptideIdentificationPath"
|| name == "UsePepQValue")
{
continue;
}

var engineProperty = engineProperties.First(p => p.Name == name);
var engineProperty = engineProperties.FirstOrDefault(p => p.Name == name);

var settingsValue = property.GetValue(settings);
var engineValue = engineProperty.GetValue(e);

Assert.AreEqual(settingsValue, engineValue);
Assert.That(settingsValue, Is.EqualTo(engineValue));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Test/Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MathNet.Numerics" Version="5.0.0" />
<PackageReference Include="mzLib" Version="1.0.552" />
<PackageReference Include="mzLib" Version="1.0.553" />
<PackageReference Include="NetSerializer" Version="4.1.2" />
<PackageReference Include="nunit" Version="4.2.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
Expand Down
Loading

0 comments on commit 01d36f4

Please sign in to comment.