Skip to content
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions mzLib/Omics/BioPolymer/IHasSequenceVariants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,19 @@ public interface IHasSequenceVariants
/// </summary>
List<TruncationProduct> TruncationProducts { get; }


/// <summary>
/// Used to construct a new variant of the same type as the original and is called in <see cref="VariantApplication"/>
/// Constructs a new variant biopolymer instance from the original, applying the specified sequence variants and modifications.
/// The method sets both the full set of database sequence variants and the subset of applied variants, ensuring that only unapplied variants remain in the SequenceVariations list,
/// while applied variants are tracked in AppliedSequenceVariations. This enables accurate representation of both the original and variant-specific annotations.
/// </summary>
/// <remarks>The generic structure enables proteins to produce proteins and RNA to produce RNA</remarks>
/// <returns></returns>
TBioPolymerType CreateVariant<TBioPolymerType>(string variantBaseSequence, TBioPolymerType original, IEnumerable<SequenceVariation> appliedSequenceVariants,
IEnumerable<TruncationProduct> applicableProteolysisProducts, IDictionary<int, List<Modification>> oneBasedModifications, string sampleNameForVariants)
TBioPolymerType CreateVariant<TBioPolymerType>(
string variantBaseSequence,
TBioPolymerType original,
IEnumerable<SequenceVariation>? sequenceVariants, // NEW: pass DB variants explicitly
IEnumerable<SequenceVariation>? appliedSequenceVariants,
IEnumerable<TruncationProduct> applicableProteolysisProducts,
IDictionary<int, List<Modification>> oneBasedModifications,
string sampleNameForVariants)
where TBioPolymerType : IHasSequenceVariants;
}
28 changes: 23 additions & 5 deletions mzLib/Omics/BioPolymer/VariantApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,24 @@ public static List<TBioPolymerType> ApplyVariants<TBioPolymerType>(TBioPolymerTy
.OrderByDescending(v => v.OneBasedBeginPosition) // apply variants at the end of the protein sequence first
.ToList();

TBioPolymerType proteinCopy = protein.CreateVariant(protein.BaseSequence, protein, null, protein.TruncationProducts, protein.OneBasedPossibleLocalizedModifications, null);

// If there aren't any variants to apply, just return the base protein
// If there aren't any variants to apply, just return the original as-is
if (uniqueEffectsToApply.Count == 0)
{
return new List<TBioPolymerType> { proteinCopy };
return new List<TBioPolymerType> { protein };
}

// Start from a normalized copy whose “unapplied” list is the DB list.
TBioPolymerType proteinCopy = protein.CreateVariant(
protein.BaseSequence,
protein,
protein.SequenceVariations, // pass DB variants
null, // none applied yet
protein.TruncationProducts,
protein.OneBasedPossibleLocalizedModifications,
null);



HashSet<string> individuals = new HashSet<string>(uniqueEffectsToApply.SelectMany(v => v.Description.Genotypes.Keys));
List<TBioPolymerType> variantProteins = new();
List<TBioPolymerType> newVariantProteins = new();
Expand Down Expand Up @@ -253,7 +263,15 @@ private static TBioPolymerType ApplySingleVariant<TBioPolymerType>(SequenceVaria
Dictionary<int, List<Modification>> adjustedModifications = AdjustModificationIndices(variantGettingApplied, variantSequence, protein);
List<SequenceVariation> adjustedAppliedVariations = AdjustSequenceVariationIndices(variantGettingApplied, variantSequence, appliedVariations);

return protein.CreateVariant(variantSequence, protein, adjustedAppliedVariations, adjustedProteolysisProducts, adjustedModifications, individual);
// Pass BOTH lists: current DB list (possibly already filtered on the interim proteoform) + newly applied
return protein.CreateVariant(
variantSequence,
protein,
protein.SequenceVariations, // carry forward the current “unapplied” list
adjustedAppliedVariations,
adjustedProteolysisProducts,
adjustedModifications,
individual);
}

/// <summary>
Expand Down
41 changes: 33 additions & 8 deletions mzLib/Proteomics/Protein/Protein.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,13 @@ public Protein(Protein originalProtein, string newBaseSequence)
/// <param name="applicableProteolysisProducts"></param>
/// <param name="oneBasedModifications"></param>
/// <param name="sampleNameForVariants"></param>
public Protein(string variantBaseSequence, Protein protein, IEnumerable<SequenceVariation> appliedSequenceVariations,
IEnumerable<TruncationProduct> applicableProteolysisProducts, IDictionary<int, List<Modification>> oneBasedModifications, string sampleNameForVariants)
public Protein(string variantBaseSequence,
Protein protein,
IEnumerable<SequenceVariation>? sequenceVariations,
IEnumerable<SequenceVariation>? appliedSequenceVariations,
IEnumerable<TruncationProduct> applicableProteolysisProducts,
IDictionary<int, List<Modification>> oneBasedModifications,
string sampleNameForVariants)
: this(
variantBaseSequence,
VariantApplication.GetAccession(protein, appliedSequenceVariations),
Expand All @@ -143,11 +148,11 @@ public Protein(string variantBaseSequence, Protein protein, IEnumerable<Sequence
oneBasedModifications: oneBasedModifications != null ? oneBasedModifications.ToDictionary(x => x.Key, x => x.Value) : new Dictionary<int, List<Modification>>(),
proteolysisProducts: new List<TruncationProduct>(applicableProteolysisProducts ?? new List<TruncationProduct>()),
name: VariantApplication.GetVariantName(protein.Name, appliedSequenceVariations),
fullName: VariantApplication.GetVariantName(protein.FullName, appliedSequenceVariations),
fullName: VariantApplication.GetVariantName(protein.FullName, appliedSequenceVariations),
isDecoy: protein.IsDecoy,
isContaminant: protein.IsContaminant,
databaseReferences: new List<DatabaseReference>(protein.DatabaseReferences),
sequenceVariations: new List<SequenceVariation>(protein.SequenceVariations),
sequenceVariations: new List<SequenceVariation>(sequenceVariations ?? protein.SequenceVariations),
disulfideBonds: new List<DisulfideBond>(protein.DisulfideBonds),
spliceSites: new List<SpliceSite>(protein.SpliceSites),
databaseFilePath: protein.DatabaseFilePath,
Expand Down Expand Up @@ -596,15 +601,35 @@ private Protein GenerateFullyLabeledSilacProtein(SilacLabel label)
/// </summary>
public IDictionary<int, List<Modification>> OriginalNonVariantModifications { get; set; }

public TBioPolymerType CreateVariant<TBioPolymerType>(string variantBaseSequence, TBioPolymerType original, IEnumerable<SequenceVariation> appliedSequenceVariants,
IEnumerable<TruncationProduct> applicableProteolysisProducts, IDictionary<int, List<Modification>> oneBasedModifications, string sampleNameForVariants)
public TBioPolymerType CreateVariant<TBioPolymerType>(
string variantBaseSequence,
TBioPolymerType original,
IEnumerable<SequenceVariation>? sequenceVariants,
IEnumerable<SequenceVariation>? appliedSequenceVariants,
IEnumerable<TruncationProduct> applicableProteolysisProducts,
IDictionary<int, List<Modification>> oneBasedModifications,
string sampleNameForVariants)
where TBioPolymerType : IHasSequenceVariants
{
if (original is not Protein originalProtein)
throw new ArgumentException("The original BioPolymer must be Protein to create a protein variant");

var variantProtein = new Protein(variantBaseSequence, originalProtein, appliedSequenceVariants,
applicableProteolysisProducts, oneBasedModifications, sampleNameForVariants);
var variantProtein = new Protein(
variantBaseSequence,
originalProtein,
sequenceVariants ?? originalProtein.SequenceVariations,
appliedSequenceVariants,
applicableProteolysisProducts,
oneBasedModifications,
sampleNameForVariants);

// Remove any applied variants from the list of (unapplied) database sequence variations
if (appliedSequenceVariants != null && appliedSequenceVariants.Any())
{
var appliedSimple = new HashSet<string>(appliedSequenceVariants.Select(v => v.SimpleString()));
variantProtein.SequenceVariations.RemoveAll(sv => appliedSimple.Contains(sv.SimpleString()));
}

return (TBioPolymerType)(IHasSequenceVariants)variantProtein;
}
#endregion
Expand Down
Loading
Loading