-
Notifications
You must be signed in to change notification settings - Fork 41
Quant interfaces #985
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Alexander-Sol
wants to merge
2
commits into
smith-chem-wisc:master
Choose a base branch
from
Alexander-Sol:QuantInterfaces
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Quant interfaces #985
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| using System.Collections.Generic; | ||
|
|
||
| namespace FlashLFQ | ||
| { | ||
| /// <summary> | ||
| /// Defines the interface for peptides that can be quantified | ||
| /// </summary> | ||
| public interface IQuantifiablePeptide | ||
| { | ||
| /// <summary> | ||
| /// The peptide sequence | ||
| /// </summary> | ||
| string Sequence { get; } | ||
|
|
||
| /// <summary> | ||
| /// Whether this peptide should be used for protein quantification | ||
| /// </summary> | ||
| bool UseForProteinQuant { get; } | ||
|
|
||
| /// <summary> | ||
| /// The protein groups this peptide belongs to | ||
| /// </summary> | ||
| IEnumerable<IQuantifiableProteinGroup> ProteinGroups { get; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the intensity for a specific file | ||
| /// </summary> | ||
| double GetIntensity(IQuantifiableSpectraFile fileInfo); | ||
|
|
||
| /// <summary> | ||
| /// Gets the detection type for a specific file | ||
| /// </summary> | ||
| DetectionType GetDetectionType(IQuantifiableSpectraFile fileInfo); | ||
|
|
||
| /// <summary> | ||
| /// Determines if this peptide has unambiguous quantification | ||
| /// </summary> | ||
| bool UnambiguousPeptideQuant(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| using System.Collections.Generic; | ||
|
|
||
| namespace FlashLFQ | ||
| { | ||
| /// <summary> | ||
| /// Defines the interface for protein groups that can be quantified | ||
| /// </summary> | ||
| public interface IQuantifiableProteinGroup | ||
| { | ||
| /// <summary> | ||
| /// The protein group name/identifier | ||
| /// </summary> | ||
| string ProteinGroupName { get; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the intensity for a specific file | ||
| /// </summary> | ||
| double GetIntensity(IQuantifiableSpectraFile fileInfo); | ||
|
|
||
| /// <summary> | ||
| /// Sets the intensity for a specific file | ||
| /// </summary> | ||
| void SetIntensity(IQuantifiableSpectraFile fileInfo, double intensity); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| namespace FlashLFQ | ||
| { | ||
| /// <summary> | ||
| /// Defines the interface for spectra file information | ||
| /// </summary> | ||
| public interface IQuantifiableSpectraFile | ||
| { | ||
| /// <summary> | ||
| /// The filename without extension | ||
| /// </summary> | ||
| string FilenameWithoutExtension { get; } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cap on Name |
||
|
|
||
| /// <summary> | ||
| /// The experimental condition | ||
| /// </summary> | ||
| string Condition { get; } | ||
|
|
||
| /// <summary> | ||
| /// The biological replicate number | ||
| /// </summary> | ||
| int BiologicalReplicate { get; } | ||
|
|
||
| /// <summary> | ||
| /// The technical replicate number | ||
| /// </summary> | ||
| int TechnicalReplicate { get; } | ||
|
|
||
| /// <summary> | ||
| /// The fraction number | ||
| /// </summary> | ||
| int Fraction { get; } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
mzLib/FlashLFQ/ProteinQuantification/GenericProteinQuantificationEngine.cs
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Love the dependency injection and inversion of control here |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| using Easy.Common.Extensions; | ||
| using MathNet.Numerics.Statistics; | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
|
|
||
| namespace FlashLFQ | ||
| { | ||
| /// <summary> | ||
| /// Defines the strategy interface for protein quantification algorithms | ||
| /// </summary> | ||
| public interface IProteinQuantificationStrategy<TPeptide, TProteinGroup, TSpectraFile> | ||
| where TPeptide : IQuantifiablePeptide | ||
| where TProteinGroup : IQuantifiableProteinGroup | ||
| where TSpectraFile : IQuantifiableSpectraFile | ||
| { | ||
| /// <summary> | ||
| /// Quantifies proteins based on their constituent peptides | ||
| /// </summary> | ||
| void QuantifyProteins( | ||
| Dictionary<TProteinGroup, List<TPeptide>> proteinGroupToPeptides, | ||
| List<TSpectraFile> spectraFiles, | ||
| bool useSharedPeptides); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Generic protein quantification engine that uses a strategy pattern | ||
| /// to support different quantification algorithms (Top3, MedianPolish, etc.) | ||
| /// </summary> | ||
| public class GenericProteinQuantificationEngine<TPeptide, TProteinGroup, TSpectraFile> | ||
| where TPeptide : IQuantifiablePeptide | ||
| where TProteinGroup : IQuantifiableProteinGroup | ||
| where TSpectraFile : IQuantifiableSpectraFile | ||
| { | ||
| private readonly IProteinQuantificationStrategy<TPeptide, TProteinGroup, TSpectraFile> _strategy; | ||
| private readonly Dictionary<string, TPeptide> _peptideModifiedSequences; | ||
| private readonly Dictionary<string, TProteinGroup> _proteinGroups; | ||
| private readonly List<TSpectraFile> _spectraFiles; | ||
|
|
||
| public GenericProteinQuantificationEngine( | ||
| IProteinQuantificationStrategy<TPeptide, TProteinGroup, TSpectraFile> strategy, | ||
| Dictionary<string, TPeptide> peptideModifiedSequences, | ||
| Dictionary<string, TProteinGroup> proteinGroups, | ||
| List<TSpectraFile> spectraFiles) | ||
| { | ||
| _strategy = strategy ?? throw new ArgumentNullException(nameof(strategy)); | ||
| _peptideModifiedSequences = peptideModifiedSequences ?? throw new ArgumentNullException(nameof(peptideModifiedSequences)); | ||
| _proteinGroups = proteinGroups ?? throw new ArgumentNullException(nameof(proteinGroups)); | ||
| _spectraFiles = spectraFiles ?? throw new ArgumentNullException(nameof(spectraFiles)); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Runs the protein quantification using the configured strategy | ||
| /// </summary> | ||
| public void Run(bool useSharedPeptides = false) | ||
| { | ||
| // Reset protein intensities to 0 | ||
| foreach (var proteinGroup in _proteinGroups) | ||
| { | ||
| foreach (TSpectraFile file in _spectraFiles) | ||
| { | ||
| proteinGroup.Value.SetIntensity(file, 0); | ||
| } | ||
| } | ||
|
|
||
| // Associate peptides with proteins | ||
| Dictionary<TProteinGroup, List<TPeptide>> proteinGroupToPeptides = | ||
| new Dictionary<TProteinGroup, List<TPeptide>>(); | ||
|
|
||
| List<TPeptide> peptides = _peptideModifiedSequences.Values | ||
| .Where(p => p.UnambiguousPeptideQuant()) | ||
| .ToList(); | ||
|
|
||
| foreach (TPeptide peptide in peptides) | ||
| { | ||
| if (!peptide.UseForProteinQuant) | ||
| { | ||
| continue; | ||
| } | ||
|
|
||
| // Handle shared peptides based on useSharedPeptides parameter | ||
| bool isSharedPeptide = peptide.ProteinGroups.Count() > 1; | ||
| if (!useSharedPeptides && isSharedPeptide) | ||
| { | ||
| continue; | ||
| } | ||
|
|
||
| foreach (var pg in peptide.ProteinGroups) | ||
| { | ||
| TProteinGroup proteinGroup = (TProteinGroup)pg; | ||
|
|
||
| if (proteinGroupToPeptides.TryGetValue(proteinGroup, out var peptidesForThisProtein)) | ||
| { | ||
| peptidesForThisProtein.Add(peptide); | ||
| } | ||
| else | ||
| { | ||
| proteinGroupToPeptides.Add(proteinGroup, new List<TPeptide> { peptide }); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Execute the quantification strategy | ||
| _strategy.QuantifyProteins(proteinGroupToPeptides, _spectraFiles, useSharedPeptides); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably use BaseSequence or FullSequence so it maps better with our existing objects.