Skip to content

Commit c6e8598

Browse files
author
stefanks
authored
Merge pull request #223 from smith-chem-wisc/StefanBranch
calib and other
2 parents 69ac0e8 + 7406e71 commit c6e8598

12 files changed

+105
-23
lines changed

EngineLayer/Indexing/IndexingResults.cs

+6-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ namespace EngineLayer.Indexing
55
{
66
public class IndexingResults : MyResults
77
{
8+
89
#region Public Constructors
910

1011
public IndexingResults(List<CompactPeptide> peptideIndex, Dictionary<float, List<int>> fragmentIndexDict, IndexingEngine indexParams) : base(indexParams)
@@ -22,17 +23,18 @@ public IndexingResults(List<CompactPeptide> peptideIndex, Dictionary<float, List
2223

2324
#endregion Public Properties
2425

25-
#region Protected Properties
26+
#region Public Methods
2627

2728
public override string ToString()
2829
{
2930
var sb = new StringBuilder();
30-
sb.AppendLine(base.ToString());
31+
sb.Append(base.ToString());
3132
sb.AppendLine("\t\tfragmentIndexDict.Count: " + FragmentIndexDict.Count);
32-
sb.Append("\t\tpeptideIndex.Count: " + PeptideIndex.Count);
33+
sb.AppendLine("\t\tpeptideIndex.Count: " + PeptideIndex.Count);
3334
return sb.ToString();
3435
}
3536

36-
#endregion Protected Properties
37+
#endregion Public Methods
38+
3739
}
3840
}

EngineLayer/ModernSearch/ModernSearchResults.cs

+4-3
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,16 @@ public ModernSearchResults(List<PsmModern>[] newPsms, ModernSearchEngine s) : ba
2121

2222
#endregion Public Properties
2323

24-
#region Protected Properties
24+
#region Public Methods
2525

2626
public override string ToString()
2727
{
2828
var sb = new StringBuilder();
29-
sb.AppendLine(base.ToString());
29+
sb.Append(base.ToString());
3030
return sb.ToString();
3131
}
32-
#endregion Protected Properties
32+
33+
#endregion Public Methods
3334

3435
}
3536
}

EngineLayer/MyEngine.cs

+53
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,59 @@ private static IEnumerable<SearchMode> LoadSearchModesFromFile()
134134
yield return new OpenSearchMode();
135135
yield return new IntervalSearchMode(new List<DoubleRange> { new DoubleRange(-0.005, 0.005), new DoubleRange(21.981943 - 0.005, 21.981943 + 0.005) });
136136
yield return new IntervalSearchMode(new List<DoubleRange> { new DoubleRange(-187, double.PositiveInfinity) });
137+
foreach (var sm in GetResidueInclusionExclusionSearchModes(new DoubleRange(-187, double.PositiveInfinity), 0.0075))
138+
yield return sm;
139+
}
140+
141+
/// <summary>
142+
/// Ideally v is less than 0.00168565165, so no overlaps happen
143+
/// </summary>
144+
/// <param name="doubleRange"></param>
145+
/// <param name="v"></param>
146+
/// <returns></returns>
147+
private static IEnumerable<SearchMode> GetResidueInclusionExclusionSearchModes(DoubleRange doubleRange, double v)
148+
{
149+
List<double> massesToExclude = new List<double>();
150+
for (char c = 'A'; c <= 'Z'; c++)
151+
{
152+
Residue residue;
153+
if (Residue.TryGetResidue(c, out residue))
154+
{
155+
massesToExclude.Add(residue.MonoisotopicMass);
156+
massesToExclude.Add(-residue.MonoisotopicMass);
157+
for (char cc = 'A'; cc <= 'Z'; cc++)
158+
{
159+
Residue residueCC;
160+
if (Residue.TryGetResidue(cc, out residueCC))
161+
{
162+
massesToExclude.Add(residue.MonoisotopicMass + residueCC.MonoisotopicMass);
163+
massesToExclude.Add(residue.MonoisotopicMass - residueCC.MonoisotopicMass);
164+
massesToExclude.Add(-residue.MonoisotopicMass + residueCC.MonoisotopicMass);
165+
massesToExclude.Add(-residue.MonoisotopicMass - residueCC.MonoisotopicMass);
166+
}
167+
}
168+
}
169+
}
170+
List<double> filteredMasses = massesToExclude.GroupBy(b => Math.Round(b, 6)).Select(b => b.FirstOrDefault()).OrderBy(b => b).ToList();
171+
172+
yield return new DotSearchMode("Only AAs", filteredMasses, new Tolerance(ToleranceUnit.Absolute, v));
173+
174+
List<DoubleRange> doubleRanges = new List<DoubleRange>();
175+
176+
var prevGoodMin = double.NegativeInfinity;
177+
178+
for (int i = 0; i < filteredMasses.Count; i++)
179+
{
180+
if (Math.Round(filteredMasses[i], 6) == 0)
181+
continue;
182+
doubleRanges.Add(new DoubleRange(prevGoodMin, filteredMasses[i] - v));
183+
prevGoodMin = filteredMasses[i] + v;
184+
}
185+
doubleRanges.Add(new DoubleRange(prevGoodMin, double.PositiveInfinity));
186+
187+
doubleRanges = doubleRanges.Where(b => b.Minimum <= doubleRange.Maximum && b.Maximum >= doubleRange.Minimum).Select(b => new DoubleRange(Math.Max(doubleRange.Minimum, b.Minimum), Math.Min(doubleRange.Maximum, b.Maximum))).ToList();
188+
189+
yield return new IntervalSearchMode("Exclude AAs", doubleRanges);
137190
}
138191

139192
private static int GuessCharge(List<IMzPeak> mzPeaks)

EngineLayer/SearchModes/DotSearchMode.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using MzLibUtil;
2-
using Spectra;
32
using System;
43
using System.Collections.Generic;
54
using System.Globalization;
@@ -25,8 +24,7 @@ public DotSearchMode(IEnumerable<double> acceptableMassShifts, Tolerance tol) :
2524

2625
public DotSearchMode(string FileNameAddition, IEnumerable<double> acceptableMassShifts, Tolerance tol) : base(FileNameAddition)
2726
{
28-
HashSet<double> hs = new HashSet<double>(acceptableMassShifts.Select(b => Math.Round(b, 5)));
29-
this.acceptableSortedMassShifts = hs.OrderBy(b => b).ToList();
27+
this.acceptableSortedMassShifts = acceptableMassShifts.OrderBy(b => b).ToList();
3028
this.tol = tol;
3129
this.NumNotches = acceptableSortedMassShifts.Count;
3230
}

EngineLayer/SearchModes/IntervalSearchMode.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ public class IntervalSearchMode : SearchMode
1818

1919
#region Public Constructors
2020

21-
public IntervalSearchMode(string fileNameAddition, IEnumerable<DoubleRange> nonOverlappingDoubleRanges) : base(fileNameAddition)
21+
public IntervalSearchMode(string fileNameAddition, IEnumerable<DoubleRange> doubleRanges) : base(fileNameAddition)
2222
{
23-
intervals = nonOverlappingDoubleRanges.OrderBy(b => b.Mean).ToList();
23+
intervals = doubleRanges.OrderBy(b => b.Mean).ToList();
2424
means = intervals.Select(b => b.Mean).ToArray();
2525
}
2626

GUI/CalibrateTaskWindow.xaml

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
<TextBox x:Name="precursorMassToleranceTextBox" HorizontalAlignment="Left" TextWrapping="Wrap" Width="45" />
1414
<ComboBox x:Name="precursorMassToleranceComboBox" HorizontalAlignment="Left" />
1515
</StackPanel>
16+
<StackPanel Orientation="Horizontal" Margin="5">
17+
<Label x:Name="ff" Content="Max Degrees Of Parallelism" />
18+
<TextBox x:Name="maxDegreesOfParallelism" Width="45" Text="-1"/>
19+
</StackPanel>
1620
<Grid>
1721
<Grid.ColumnDefinitions>
1822
<ColumnDefinition Width="1*" />

GUI/CalibrateTaskWindow.xaml.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using EngineLayer;
22
using MzLibUtil;
3-
using Spectra;
43
using System;
54
using System.Collections.ObjectModel;
65
using System.Globalization;
@@ -71,6 +70,7 @@ private void UpdateFieldsFromTask(CalibrationTask task)
7170

7271
bCheckBox.IsChecked = task.BIons;
7372
yCheckBox.IsChecked = task.YIons;
73+
maxDegreesOfParallelism.Text = task.MaxDegreeOfParallelism.ToString(CultureInfo.InvariantCulture);
7474

7575
foreach (var modList in task.ListOfModListsFixed)
7676
ModFileListInWindow.First(b => b.FileName.Equals(modList.FileName)).Fixed = true;
@@ -128,6 +128,8 @@ private void saveButton_Click(object sender, RoutedEventArgs e)
128128
TheTask.PrecursorMassTolerance.Value = double.Parse(precursorMassToleranceTextBox.Text, CultureInfo.InvariantCulture);
129129
TheTask.PrecursorMassTolerance.Unit = (ToleranceUnit)precursorMassToleranceComboBox.SelectedIndex;
130130

131+
TheTask.MaxDegreeOfParallelism = int.Parse(maxDegreesOfParallelism.Text);
132+
131133
DialogResult = true;
132134
}
133135

GUI/ForDisplayingInDataGrids/MetaMorpheusTaskForDataGrid.cs

+17-2
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,28 @@ namespace MetaMorpheusGUI
44
{
55
internal class MetaMorpheusTaskForDataGrid
66
{
7-
public string Task { get { return metaMorpheusTask.GetType().Name; } }
8-
public bool IsMySelected { get; set; }
7+
8+
#region Public Fields
9+
910
public readonly MetaMorpheusTask metaMorpheusTask;
1011

12+
#endregion Public Fields
13+
14+
#region Public Constructors
15+
1116
public MetaMorpheusTaskForDataGrid(MetaMorpheusTask theTask)
1217
{
1318
this.metaMorpheusTask = theTask;
1419
}
20+
21+
#endregion Public Constructors
22+
23+
#region Public Properties
24+
25+
public string Task { get { return metaMorpheusTask.GetType().Name; } }
26+
public bool InProgress { get; set; }
27+
28+
#endregion Public Properties
29+
1530
}
1631
}

GUI/MainWindow.xaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@
148148
<Setter Property="BorderBrush" Value="Transparent" />
149149
<Setter Property="Foreground" Value="Black" />
150150
</Trigger>
151-
<DataTrigger Binding="{Binding IsMySelected}" Value="True">
151+
<DataTrigger Binding="{Binding InProgress}" Value="True">
152152
<Setter Property="Foreground" Value="Blue" />
153153
<Setter Property="FontWeight" Value="Bold" />
154154
</DataTrigger>
@@ -164,7 +164,7 @@
164164
<Setter Property="BorderBrush" Value="Transparent" />
165165
<Setter Property="Foreground" Value="Black" />
166166
</Trigger>
167-
<DataTrigger Binding="{Binding IsMySelected}" Value="True">
167+
<DataTrigger Binding="{Binding InProgress}" Value="True">
168168
<Setter Property="Foreground" Value="Blue" />
169169
<Setter Property="FontWeight" Value="Bold" />
170170
</DataTrigger>

GUI/MainWindow.xaml.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ private void Po_startingSingleTaskHander(object sender, SingleTaskEventArgs s)
162162
}
163163
else
164164
{
165-
taskEngineObservableCollection.First(b => b.metaMorpheusTask.Equals(s.TheTask)).IsMySelected = true;
165+
taskEngineObservableCollection.First(b => b.metaMorpheusTask.Equals(s.TheTask)).InProgress = true;
166166
statusLabel.Content = "Running " + s.TheTask.TaskType + " task";
167167
outProgressBar.IsIndeterminate = true;
168168

@@ -180,7 +180,7 @@ private void Po_finishedSingleTaskHandler(object sender, SingleTaskEventArgs s)
180180
}
181181
else
182182
{
183-
taskEngineObservableCollection.First(b => b.metaMorpheusTask.Equals(s.TheTask)).IsMySelected = false;
183+
taskEngineObservableCollection.First(b => b.metaMorpheusTask.Equals(s.TheTask)).InProgress = false;
184184
statusLabel.Content = "Finished " + s.TheTask.TaskType + " task";
185185
outProgressBar.Value = 100;
186186

TaskLayer/CalibrationTask/CalibrationTask.cs

+10-3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ public CalibrationTask()
3939

4040
TaskType = MyTask.Calibrate;
4141
MaxNumPeaksPerScan = 400;
42+
43+
MaxDegreeOfParallelism = -1;
4244
}
4345

4446
#endregion Public Constructors
@@ -50,6 +52,7 @@ public CalibrationTask()
5052
public List<ModList> ListOfModListsLocalize { get; set; }
5153
public Tolerance ProductMassTolerance { get; set; }
5254
public Tolerance PrecursorMassTolerance { get; set; }
55+
public int MaxDegreeOfParallelism { get; set; }
5356

5457
#endregion Public Properties
5558

@@ -112,13 +115,17 @@ protected override MyResults RunSpecific()
112115
lp.Add(ProductType.Y);
113116
}
114117

115-
Parallel.For(0, currentRawFileList.Count, spectraFileIndex =>
118+
object lock1 = new object();
119+
object lock2 = new object();
120+
ParallelOptions parallelOptions = new ParallelOptions();
121+
parallelOptions.MaxDegreeOfParallelism = MaxDegreeOfParallelism;
122+
Parallel.For(0, currentRawFileList.Count, parallelOptions, spectraFileIndex =>
116123
{
117124
var compactPeptideToProteinPeptideMatching = new Dictionary<CompactPeptide, HashSet<PeptideWithSetModifications>>();
118125
var origDataFileName = currentRawFileList[spectraFileIndex];
119126
LocalMS2Scan[] listOfSortedms2Scans;
120127
IMsDataFile<IMsDataScan<IMzSpectrum<IMzPeak>>> myMsDataFile;
121-
lock (myTaskResults)
128+
lock (lock1) // Lock because reading is sequential
122129
{
123130
StartingDataFile(origDataFileName);
124131
Status("Loading spectra file " + origDataFileName + "...");
@@ -183,7 +190,7 @@ protected override MyResults RunSpecific()
183190
{
184191
Status("Creating _indexedmzMLConnection, putting data in it, and writing!");
185192
var path = Path.Combine(OutputFolder, Path.GetFileNameWithoutExtension(origDataFileName) + "-Calibrated.mzML");
186-
lock (myTaskResults)
193+
lock (lock2) // Lock because writing is sequential
187194
{
188195
MzmlMethods.CreateAndWriteMyIndexedMZmlwithCalibratedSpectra(((CalibrationResults)result).MyMSDataFile, path);
189196

TaskLayer/GPTMDTask/GPTMDTask.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ protected override MyResults RunSpecific()
208208
IEnumerable<Tuple<double, double>> combos = LoadCombos().ToList();
209209

210210
// Do not remove the zero!!! It's needed here
211-
SearchMode searchMode = new DotSearchMode("", gptmdModifications.SelectMany(b => b.massesObserved).Concat(combos.Select(b => b.Item1 + b.Item2)).Concat(new List<double> { 0 }).OrderBy(b => b), PrecursorMassTolerance);
211+
SearchMode searchMode = new DotSearchMode("", gptmdModifications.SelectMany(b => b.massesObserved).Concat(combos.Select(b => b.Item1 + b.Item2)).Concat(new List<double> { 0 }).GroupBy(b => Math.Round(b, 6)).Select(b => b.FirstOrDefault()).OrderBy(b => b), PrecursorMassTolerance);
212212
var searchModes = new List<SearchMode> { searchMode };
213213

214214
List<PsmParent>[] allPsms = new List<PsmParent>[1];

0 commit comments

Comments
 (0)