Skip to content

Commit 37ee978

Browse files
Merge branch 'ypriverol-master'
2 parents 644bb86 + c171318 commit 37ee978

7 files changed

Lines changed: 233 additions & 40 deletions

File tree

ThermoRawFileParser.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@
124124
<Compile Include="MainClass.cs" />
125125
<Compile Include="Properties\AssemblyInfo.cs" />
126126
<Compile Include="RawFileParser.cs" />
127+
<Compile Include="Util\LimitedSizeDictionary.cs" />
127128
<Compile Include="Writer\ISpectrumWriter.cs" />
128129
<Compile Include="Writer\Metadata.cs" />
129130
<Compile Include="Writer\MetadataWriter.cs" />

ThermoRawFileParserTest/ThermoRawFileParserTest.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@
142142
</Reference>
143143
</ItemGroup>
144144
<ItemGroup>
145-
<Compile Include="Tests.cs" />
145+
<Compile Include="UtilTests.cs" />
146+
<Compile Include="WriterTests.cs" />
146147
<Compile Include="Properties\AssemblyInfo.cs" />
147148
</ItemGroup>
148149
<ItemGroup>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System.Text.RegularExpressions;
2+
using NUnit.Framework;
3+
4+
namespace ThermoRawFileParserTest
5+
{
6+
[TestFixture]
7+
public class UtilTests
8+
{
9+
[Test]
10+
public void TestRegex()
11+
{
12+
const string filterString = "ITMS + c NSI r d Full ms2 961.8803@cid35.00 [259.0000-1934.0000]";
13+
const string pattern = @"ms2 (.*?)@";
14+
15+
Match result = Regex.Match(filterString, pattern);
16+
if (result.Success)
17+
{
18+
Assert.AreEqual("961.8803", result.Groups[1].Value);
19+
}
20+
else
21+
{
22+
Assert.Fail();
23+
}
24+
}
25+
}
26+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
namespace ThermoRawFileParserTest
1111
{
1212
[TestFixture]
13-
public class Tests
13+
public class WriterTests
1414
{
1515
[Test]
1616
public void TestMgf()

Util/LimitedSizeDictionary.cs

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
4+
namespace ThermoRawFileParser.Util
5+
{
6+
//https://social.msdn.microsoft.com/Forums/vstudio/en-US/789c37ea-b9bf-4512-a418-f4f9532c59bf/dictionary-with-limited-size?forum=csharpgeneral
7+
public class LimitedSizeDictionary<TKey, TValue> : IDictionary<TKey, TValue>
8+
{
9+
private readonly Dictionary<TKey, TValue> _dict;
10+
private Queue<TKey> _queue;
11+
private readonly int _size;
12+
13+
public LimitedSizeDictionary(int size)
14+
{
15+
_size = size;
16+
_dict = new Dictionary<TKey, TValue>(size + 1);
17+
_queue = new Queue<TKey>(size);
18+
}
19+
20+
public void Add(TKey key, TValue value)
21+
{
22+
_dict.Add(key, value);
23+
if (_queue.Count == _size)
24+
_dict.Remove(_queue.Dequeue());
25+
_queue.Enqueue(key);
26+
}
27+
28+
public bool ContainsKey(TKey key)
29+
{
30+
return _dict.ContainsKey(key);
31+
}
32+
33+
public bool Remove(TKey key)
34+
{
35+
if (_dict.Remove(key))
36+
{
37+
var newQueue = new Queue<TKey>(_size);
38+
foreach (var item in _queue)
39+
if (!_dict.Comparer.Equals(item, key))
40+
newQueue.Enqueue(item);
41+
_queue = newQueue;
42+
return true;
43+
}
44+
else
45+
return false;
46+
}
47+
48+
public bool TryGetValue(TKey key, out TValue value)
49+
{
50+
return _dict.TryGetValue(key, out value);
51+
}
52+
53+
public TValue this[TKey key]
54+
{
55+
get => _dict[key];
56+
set => _dict[key] = value;
57+
}
58+
59+
public ICollection<TKey> Keys => _dict.Keys;
60+
61+
public ICollection<TValue> Values => _dict.Values;
62+
63+
public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
64+
{
65+
return _dict.GetEnumerator();
66+
}
67+
68+
IEnumerator IEnumerable.GetEnumerator()
69+
{
70+
return ((IEnumerable) _dict).GetEnumerator();
71+
}
72+
73+
public void Add(KeyValuePair<TKey, TValue> item)
74+
{
75+
((IDictionary<TKey, TValue>) _dict).Add(item);
76+
}
77+
78+
public void Clear()
79+
{
80+
_dict.Clear();
81+
}
82+
83+
public bool Contains(KeyValuePair<TKey, TValue> item)
84+
{
85+
return ((IDictionary<TKey, TValue>) _dict).Contains(item);
86+
}
87+
88+
public void CopyTo(KeyValuePair<TKey, TValue>[] array, int arrayIndex)
89+
{
90+
((IDictionary<TKey, TValue>) _dict).CopyTo(array, arrayIndex);
91+
}
92+
93+
public bool Remove(KeyValuePair<TKey, TValue> item)
94+
{
95+
return ((IDictionary<TKey, TValue>) _dict).Remove(item);
96+
}
97+
98+
public int Count => _dict.Count;
99+
100+
public bool IsReadOnly => ((IDictionary<TKey, TValue>) _dict).IsReadOnly;
101+
}
102+
}

Writer/MgfSpectrumWriter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public override void Write(IRawDataPlus rawFile, int firstScanNumber, int lastSc
5555
{
5656
Writer.WriteLine("BEGIN IONS");
5757
Writer.WriteLine($"TITLE={ConstructSpectrumTitle(scanNumber)}");
58-
Writer.WriteLine($"SCAN={scanNumber}");
58+
Writer.WriteLine($"SCANS={scanNumber}");
5959
Writer.WriteLine($"RTINSECONDS={(time * 60).ToString(CultureInfo.InvariantCulture)}");
6060
// Get the reaction information for the first precursor
6161
try

0 commit comments

Comments
 (0)