Skip to content

Commit c12296a

Browse files
authored
Merge pull request #104 from topdownproteomics/concrete-chemical-formula
Concrete Chemical Formula
2 parents 892da32 + 67da599 commit c12296a

30 files changed

+350
-181
lines changed

src/TopDownProteomics.Benchmarks/Program.cs

+32-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Diagnostics;
4+
using System.Linq;
5+
using TopDownProteomics.Biochemistry;
36
using TopDownProteomics.Chemistry;
47
using TopDownProteomics.Tools;
58

@@ -11,15 +14,16 @@ internal class Program
1114

1215
private static void Main(string[] args)
1316
{
14-
BenchmarkIsotopicEvelopeGeneration();
17+
//BenchmarkIsotopicEnvelopeGeneration();
18+
BenchmarkChemicalFormulaAsKey();
1519
}
1620

17-
private static void BenchmarkIsotopicEvelopeGeneration()
21+
private static void BenchmarkIsotopicEnvelopeGeneration()
1822
{
1923
// Generate the formulas
2024
var random = new Random(1);
2125

22-
var chemicalFormulas = new IChemicalFormula[MaxRunValue];
26+
var chemicalFormulas = new ChemicalFormula[MaxRunValue];
2327
IElementProvider elementProvider = new MockElementProvider();
2428

2529
for (int i = 2; i < MaxRunValue; i++)
@@ -62,5 +66,30 @@ private static void BenchmarkIsotopicEvelopeGeneration()
6266

6367
Console.WriteLine("Elapsed time for Northwestern Port: " + stopwatch.Elapsed);
6468
}
69+
70+
private static void BenchmarkChemicalFormulaAsKey()
71+
{
72+
IElementProvider elementProvider = new MockElementProvider();
73+
IResidueProvider residueProvider = new IupacAminoAcidProvider(elementProvider);
74+
75+
string sequence = "MLTELEKALNSIIDVYHKYSLIKGNFHAVYRDDLKKLLETECPQYIRKKGADVWFKELDINTDGAVNFQEFLILVIKMGVAAHKKSHEESHKE";
76+
var residues = sequence.Select(x => residueProvider.GetResidue(x));
77+
ChemicalFormula[] formulas = residues.Select(x => x.GetChemicalFormula()).ToArray();
78+
79+
Dictionary<ChemicalFormula, bool> dictionary = new();
80+
Stopwatch stopwatch = Stopwatch.StartNew();
81+
82+
for (int i = 0; i < 9_000; i++)
83+
{
84+
for (int j = 0; j < formulas.Length; j++)
85+
{
86+
if (!dictionary.ContainsKey(formulas[j]))
87+
dictionary.Add(formulas[j], true);
88+
}
89+
}
90+
91+
stopwatch.Stop();
92+
Console.WriteLine(stopwatch.Elapsed);
93+
}
6594
}
6695
}

src/TopDownProteomics/Biochemistry/GlycanResidue.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public GlycanResidue(string symbol, string name, IReadOnlyCollection<IEntityCard
3232
/// Gets the chemical formula.
3333
/// </summary>
3434
/// <returns></returns>
35-
public IChemicalFormula GetChemicalFormula() => new ChemicalFormula(_elements);
35+
public ChemicalFormula GetChemicalFormula() => new ChemicalFormula(_elements);
3636

3737
/// <summary>
3838
/// Gets the elements.

src/TopDownProteomics/Biochemistry/IupacAminoAcidProvider.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,9 @@ public AminoAcid(char symbol, string name, IReadOnlyCollection<IEntityCardinalit
227227
public string Name { get; }
228228
public char Symbol { get; }
229229

230-
public IChemicalFormula GetChemicalFormula() => new ChemicalFormula(_elements);
230+
public ChemicalFormula GetChemicalFormula() => new ChemicalFormula(_elements);
231231

232232
public double GetMass(MassType massType) => this.GetChemicalFormula().GetMass(massType);
233233
}
234234
}
235-
}
235+
}

0 commit comments

Comments
 (0)