Skip to content

Commit

Permalink
fix culture-dependent double parsing in a few places (#2069)
Browse files Browse the repository at this point in the history
  • Loading branch information
rmillikin authored Jun 10, 2021
1 parent 774eddb commit 5ef29e5
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 9 deletions.
6 changes: 3 additions & 3 deletions EngineLayer/SpectralLibrarySearch/SpectralLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,23 +204,23 @@ private LibrarySpectrum ReadLibrarySpectrum(StreamReader reader, bool onlyReadHe
int indOfParent = Array.IndexOf(split, "Parent");
if (indOfParent > 0)
{
precursorMz = double.Parse(split[indOfParent + 1]);
precursorMz = double.Parse(split[indOfParent + 1], CultureInfo.InvariantCulture);
}
}

// get RT
int indOfRt = Array.IndexOf(split, "iRT");
if (indOfRt > 0)
{
rt = double.Parse(split[indOfRt + 1]);
rt = double.Parse(split[indOfRt + 1], CultureInfo.InvariantCulture);
}
else
{
indOfRt = Array.IndexOf(split, "RT");

if (indOfRt > 0)
{
rt = double.Parse(split[indOfRt + 1]);
rt = double.Parse(split[indOfRt + 1], CultureInfo.InvariantCulture);
}
}

Expand Down
3 changes: 2 additions & 1 deletion GUI/MetaDraw/MetaDrawSettingsWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using EngineLayer.GlycoSearch;
using GuiFunctions;
using System.ComponentModel;
using System.Globalization;
using System.Windows;

namespace MetaMorpheusGUI
Expand Down Expand Up @@ -55,7 +56,7 @@ private void Save_Click(object sender, RoutedEventArgs e)

if (!string.IsNullOrWhiteSpace(qValueBox.Text))
{
if (double.TryParse(qValueBox.Text, out double qValueFilter) && qValueFilter >= 0 && qValueFilter <= 1)
if (double.TryParse(qValueBox.Text, NumberStyles.Any, CultureInfo.InvariantCulture, out double qValueFilter) && qValueFilter >= 0 && qValueFilter <= 1)
{
MetaDrawSettings.QValueFilter = qValueFilter;
}
Expand Down
2 changes: 1 addition & 1 deletion GUI/TaskWindows/GPTMDTaskWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ private void SaveButton_Click(object sender, RoutedEventArgs e)
double? minimumAllowedIntensityRatioToBasePeak = null;
if (!string.IsNullOrWhiteSpace(MinimumAllowedIntensityRatioToBasePeakTexBox.Text))
{
if (double.TryParse(MinimumAllowedIntensityRatioToBasePeakTexBox.Text, out double minimumAllowedIntensityRatio))
if (double.TryParse(MinimumAllowedIntensityRatioToBasePeakTexBox.Text, NumberStyles.Any, CultureInfo.InvariantCulture, out double minimumAllowedIntensityRatio))
{
minimumAllowedIntensityRatioToBasePeak = minimumAllowedIntensityRatio;
}
Expand Down
4 changes: 2 additions & 2 deletions GUI/TaskWindows/SearchTaskWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -495,13 +495,13 @@ private void SaveButton_Click(object sender, RoutedEventArgs e)
}

double? minimumAllowedIntensityRatioToBasePeak = null;
if (double.TryParse(MinimumAllowedIntensityRatioToBasePeakTexBox.Text, out double minimumAllowedIntensityRatio))
if (double.TryParse(MinimumAllowedIntensityRatioToBasePeakTexBox.Text, NumberStyles.Any, CultureInfo.InvariantCulture, out double minimumAllowedIntensityRatio))
{
minimumAllowedIntensityRatioToBasePeak = minimumAllowedIntensityRatio;
}

double? windowWidthThompsons = null;
if (double.TryParse(WindowWidthThomsonsTextBox.Text, out double windowWidth))
if (double.TryParse(WindowWidthThomsonsTextBox.Text, NumberStyles.Any, CultureInfo.InvariantCulture, out double windowWidth))
{
windowWidthThompsons = windowWidth;
}
Expand Down
2 changes: 1 addition & 1 deletion GUI/Util/GlobalGuiSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ public static bool CheckPeakFindingTolerance(string text)

public static bool CheckHistogramBinWidth(string text)
{
if (!float.TryParse(text, out float binWidth) || binWidth < 0 || binWidth > 1)
if (!double.TryParse(text, NumberStyles.Any, CultureInfo.InvariantCulture, out double binWidth) || binWidth < 0 || binWidth > 1)
{
MessageBox.Show("The histogram bin width must be between zero and one Daltons. \n You entered " + '"' + text + '"');
return false;
Expand Down
2 changes: 1 addition & 1 deletion GuiFunctions/MetaDraw/PeptideSpectrumMatchPlot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ protected void AnnotateProperties()
text.Append("\r\n");

text.Append("Theoretical Mass: ");
text.Append(double.TryParse(SpectrumMatch.PeptideMonoMass, out var monoMass) ? monoMass.ToString("F3") : SpectrumMatch.PeptideMonoMass);
text.Append(double.TryParse(SpectrumMatch.PeptideMonoMass, NumberStyles.Any, CultureInfo.InvariantCulture, out var monoMass) ? monoMass.ToString("F3") : SpectrumMatch.PeptideMonoMass);
text.Append("\r\n");

text.Append("Score: ");
Expand Down

0 comments on commit 5ef29e5

Please sign in to comment.