Skip to content

Commit

Permalink
Major change to how masses are calculated. Remove lazy evalution from…
Browse files Browse the repository at this point in the history
… Chemical formula and Amino Acid Polymer for significant speed improvements.
  • Loading branch information
dbaileychess committed Jul 8, 2013
1 parent ac41823 commit c21fd36
Show file tree
Hide file tree
Showing 22 changed files with 247 additions and 114 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ ehthumbs.db
# TESTS #
#########
TestResults/
*.psess
*.vsp


# Nuget #
#########
Expand Down
10 changes: 5 additions & 5 deletions CSMSL.Examples/Examples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ private static void Main(string[] args)
private static void StartExamples()
{
// Examples coding
ChemicalFormulaExamples();
//ChemicalFormulaExamples();
//PeptideExamples();

// Example Objects
//VennDiagramExamples();

// Example programs
//TrypticDigestion.Start(Protease.Trypsin);
TrypticDigestion.Start(Protease.Trypsin);

// Example Protein Grouping
//ProteinGroupingExample.Start(Protease.Trypsin);
Expand Down Expand Up @@ -203,19 +203,19 @@ private static void ChemicalFormulaExamples()
/// <param name="formula"></param>
private static void WriteFormulaToConsole(ChemicalFormula formula)
{
Console.WriteLine("Formula {0} mass is {1}", formula, formula.Mass.Monoisotopic);
Console.WriteLine("Formula {0} mass is {1} or {2}", formula, formula.Mass.MonoisotopicMass, formula.MonoisotopicMass);
}

private static void WritePeptideToConsole(Peptide peptide)
{
ChemicalFormula formula;
peptide.TryGetChemicalFormula(out formula);
Console.WriteLine("{0,-5} {1,-5} {2,-5}", peptide, formula, peptide.Mass.Monoisotopic);
Console.WriteLine("{0,-5} {1,-5} {2,-5}", peptide, formula, peptide.Mass.MonoisotopicMass);
}

private static void WriteFragmentToConsole(Fragment frag)
{
Console.WriteLine("{0,-4} {1,-20}", frag, frag.Mass.Monoisotopic);
Console.WriteLine("{0,-4} {1,-20}", frag, frag.Mass.MonoisotopicMass);
}
}
}
2 changes: 1 addition & 1 deletion CSMSL.Examples/TrypticDigestion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static void Start(IProtease protease, int maxMissed = 3, int minLength =
foreach (Peptide peptide in protein.Digest(protease, maxMissed, minLength, maxLength))
{
peps.Add(peptide);
allMzs.Add(peptide.Mass.ToMz(1)); // forces the calculation of the mass and thus chemical formula
allMzs.Add(peptide.ToMz(2)); // forces the calculation of the mass and thus chemical formula
}
prots.Add(protein);
}
Expand Down
4 changes: 2 additions & 2 deletions CSMSL.Tests/Chemistry/ChemicalFormulaTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public void BasicChemicalFormulaMassMonoisotopic()
{
ChemicalFormula water = new ChemicalFormula("H2O");

Assert.AreEqual(2 * Constants.Hydrogen + Constants.Oxygen, water.Mass.Monoisotopic);
Assert.AreEqual(2 * Constants.Hydrogen + Constants.Oxygen, water.Mass.MonoisotopicMass);
}

[Test]
Expand Down Expand Up @@ -296,7 +296,7 @@ public void EmptyFormulaMassIsNotNull()
[Test]
public void EmptyFormulaMonoisotopicMassIsZero()
{
Assert.AreEqual(0.0, EmptyFormula.Mass.Monoisotopic);
Assert.AreEqual(0.0, EmptyFormula.Mass.MonoisotopicMass);
}

[Test]
Expand Down
6 changes: 3 additions & 3 deletions CSMSL.Tests/Chemistry/MassTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public void DefaultMassMonoisotopic()
{
Mass m = new Mass();

Assert.AreEqual(0.0, m.Monoisotopic);
Assert.AreEqual(0.0, m.MonoisotopicMass);
}

[Test]
Expand All @@ -28,7 +28,7 @@ public void MonoisotopicOnlyMassInConstructor()
{
Mass m = new Mass(524.342);

Assert.AreEqual(524.342, m.Monoisotopic);
Assert.AreEqual(524.342, m.MonoisotopicMass);
}

[Test]
Expand All @@ -44,7 +44,7 @@ public void MonoisotopicMassInConstructor()
{
Mass m = new Mass(524.342, 524.500);

Assert.AreEqual(524.342, m.Monoisotopic);
Assert.AreEqual(524.342, m.MonoisotopicMass);
}

[Test]
Expand Down
14 changes: 7 additions & 7 deletions CSMSL.Tests/Proteomics/FragmentTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,55 +69,55 @@ public void FragmentCTerminalMod()
MockPeptideEveryAminoAcid.SetModification(NamedChemicalFormula.TMT6plex, Terminus.C);
Fragment fragment = MockPeptideEveryAminoAcid.Fragment(FragmentTypes.x, 1);

fragment.Mass.Monoisotopic.Should().Equal(436.21608990639004);
fragment.Mass.MonoisotopicMass.Should().Equal(436.21608990639004);
}

[Test]
public void FragmentChemicalFormulaAIon()
{
Fragment fragment = MockPeptideEveryAminoAcid.Fragment(FragmentTypes.a, 1);

fragment.Mass.Monoisotopic.Should().Equal(43.042199165149988);
fragment.Mass.MonoisotopicMass.Should().Equal(43.042199165149988);
}

[Test]
public void FragmentChemicalFormulaBIon()
{
Fragment fragment = MockPeptideEveryAminoAcid.Fragment(FragmentTypes.b, 1);

fragment.Mass.Monoisotopic.Should().Equal(71.037113784709987);
fragment.Mass.MonoisotopicMass.Should().Equal(71.037113784709987);
}

[Test]
public void FragmentChemicalFormulaCIon()
{
Fragment fragment = MockPeptideEveryAminoAcid.Fragment(FragmentTypes.c, 1);

fragment.Mass.Monoisotopic.Should().Equal(88.063662885719992);
fragment.Mass.MonoisotopicMass.Should().Equal(88.063662885719992);
}

[Test]
public void FragmentChemicalFormulaXIon()
{
Fragment fragment = MockPeptideEveryAminoAcid.Fragment(FragmentTypes.x, 1);

fragment.Mass.Monoisotopic.Should().Equal(207.05315777167004);
fragment.Mass.MonoisotopicMass.Should().Equal(207.05315777167004);
}

[Test]
public void FragmentChemicalFormulaYIon()
{
Fragment fragment = MockPeptideEveryAminoAcid.Fragment(FragmentTypes.y, 1);

fragment.Mass.Monoisotopic.Should().Equal(181.07389321625004);
fragment.Mass.MonoisotopicMass.Should().Equal(181.07389321625004);
}

[Test]
public void FragmentChemicalFormulaZIon()
{
Fragment fragment = MockPeptideEveryAminoAcid.Fragment(FragmentTypes.z, 1);

fragment.Mass.Monoisotopic.Should().Equal(164.04734411524004);
fragment.Mass.MonoisotopicMass.Should().Equal(164.04734411524004);
}
}
}
6 changes: 3 additions & 3 deletions CSMSL.Tests/Proteomics/PeptideTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void SetUp()
[Test]
public void PeptideMass()
{
Assert.AreEqual(MockPeptideEveryAminoAcid.Mass.Monoisotopic, 2394.12490682513);
Assert.AreEqual(MockPeptideEveryAminoAcid.Mass.MonoisotopicMass, 2394.12490682513);
}

[Test]
Expand Down Expand Up @@ -161,7 +161,7 @@ public void ParseNamedChemicalNamedChemicalModification()
{
Peptide peptide = new Peptide("T[TMT 6-plex]HGEAK[Acetyl]K[TMT 6-plex]");

peptide.Mass.Monoisotopic.Should().Equal(1269.74468058495);
Assert.AreEqual(1269.74468058495, peptide.MonoisotopicMass);
}

[Test]
Expand All @@ -186,7 +186,7 @@ public void ParseNamedChemicalModificationRegisterNew()
NamedChemicalFormula.AddModification("C2H3NO", "Test");
Peptide peptide = new Peptide("T[TMT 6-plex]HGEAK[Test]K[TMT 6-plex]");

peptide.Mass.Monoisotopic.Should().Equal(1284.7555796218198);
peptide.Mass.MonoisotopicMass.Should().Equal(1284.7555796218198);
}

[Test]
Expand Down
8 changes: 8 additions & 0 deletions CSMSL.sln
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CSMSL.Tests", "CSMSL.Tests\
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MzML", "CSMSL\IO\MzML\MzML.csproj", "{012434FB-88A9-4DEC-B887-5F64C0B481D4}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{59DB6973-98AE-4FAC-9D7D-DADEC35C9BA1}"
ProjectSection(SolutionItems) = preProject
Performance1.psess = Performance1.psess
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -122,4 +127,7 @@ Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(Performance) = preSolution
HasPerformanceSessions = true
EndGlobalSection
EndGlobal
2 changes: 1 addition & 1 deletion CSMSL/Analysis/Identification/MSSearchEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public abstract class MSSearchEngine

public void LoadPeptides(IEnumerable<AminoAcidPolymer> peptides)
{
_peptides = peptides.OrderBy(pep => pep.Mass.Monoisotopic).ToList();
_peptides = peptides.OrderBy(pep => pep.Mass.MonoisotopicMass).ToList();
}

public void AddVariableModification(IChemicalFormula modification, char residue)
Expand Down
2 changes: 1 addition & 1 deletion CSMSL/Analysis/Quantitation/IsobaricTag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public double reporterMass
{
get
{
return _reporterFormula.Mass.Monoisotopic;
return _reporterFormula.Mass.MonoisotopicMass;
}
}

Expand Down
15 changes: 12 additions & 3 deletions CSMSL/Analysis/Quantitation/QuantitationChannelSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,9 @@ public QuantitationChannelSet(string name, QuantitationChannelSetMassType massTy

public IQuantitationChannel Add(IQuantitationChannel channel)
{
_channels.Add(channel.ReporterMass.Monoisotopic, channel);
_channels.Add(channel.ReporterMass.MonoisotopicMass, channel);
_totalMass.Add(channel.Mass);

return channel;
}

Expand All @@ -122,7 +123,7 @@ public void Clear()

public bool Remove(IQuantitationChannel channel)
{
if (_channels.Remove(channel.Mass.Monoisotopic))
if (_channels.Remove(channel.Mass.MonoisotopicMass))
{
_totalMass.Remove(channel.Mass);
return true;
Expand Down Expand Up @@ -159,7 +160,7 @@ public MassRange MassRange
{
get
{
return new MassRange(LightestChannel.ReporterMass.Monoisotopic, HeaviestChannel.ReporterMass.Monoisotopic);
return new MassRange(LightestChannel.ReporterMass.MonoisotopicMass, HeaviestChannel.ReporterMass.MonoisotopicMass);
}
}

Expand All @@ -171,6 +172,11 @@ public int Count
}
}

public double MonoisotopicMass
{
get { throw new NotImplementedException(); }
}

public override string ToString()
{
return Name;
Expand Down Expand Up @@ -384,5 +390,8 @@ private static void GetUniquePeptides_helper(IList<QuantitationChannelSet> sets,
#endregion





}
}
1 change: 1 addition & 0 deletions CSMSL/CSMSL.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
<Compile Include="Chemistry\IChemicalFormula.cs" />
<Compile Include="Chemistry\Isotope.cs" />
<Compile Include="Chemistry\PeriodicTable.cs" />
<Compile Include="ClassExtensions.cs" />
<Compile Include="Constants.cs" />
<Compile Include="Chemistry\IMass.cs" />
<Compile Include="IO\Fasta.cs" />
Expand Down
Loading

0 comments on commit c21fd36

Please sign in to comment.