/// <summary>Gets the modification.</summary> /// <param name="descriptor">The descriptor.</param> /// <returns></returns> public IProteoformMassDelta?GetModification(IProFormaDescriptor descriptor) { if (double.TryParse(descriptor.Value, out double mass)) { return(new MassModification(mass)); } else { throw new ProteoformModificationLookupException($"Could not parse mass string for descriptor {descriptor}"); } }
/// <summary>Gets the modification.</summary> /// <param name="descriptor">The descriptor.</param> /// <returns></returns> public IProteoformMassDelta?GetModification(IProFormaDescriptor descriptor) { if (ChemicalFormula.TryParseString(descriptor.Value, this._elementProvider, out IChemicalFormula chemicalFormula)) { return(new FormulaModification(chemicalFormula)); } else { throw new ProteoformModificationLookupException($"Could not parse formula string for descriptor {descriptor}"); } }
/// <summary> /// Gets the modification. /// </summary> /// <param name="descriptor">The descriptor.</param> /// <returns></returns> public IProteoformMassDelta?GetModification(IProFormaDescriptor descriptor) { foreach (var lookup in _lookups) { if (lookup.CanHandleDescriptor(descriptor)) { return(lookup.GetModification(descriptor)); } } throw new ProteoformGroupCreateException($"Couldn't handle value for descriptor {descriptor}."); }
/// <summary> /// Determines whether this instance [can handle descriptor] the specified descriptor. /// </summary> /// <param name="descriptor">The descriptor.</param> /// <returns> /// <c>true</c> if this instance [can handle descriptor] the specified descriptor; otherwise, <c>false</c>. /// </returns> public virtual bool CanHandleDescriptor(IProFormaDescriptor descriptor) { var nonDefault = descriptor.EvidenceType == this.EvidenceType && (descriptor.Key == ProFormaKey.Name || descriptor.Key == ProFormaKey.Identifier); if (!this.IsDefaultModificationType || nonDefault) { return(nonDefault); } // If this is the default modification type, allow no evidence name check. return(_modificationNames?.ContainsKey(descriptor.Value) ?? false); }
/// <summary> /// Determines whether this instance [can handle descriptor] the specified descriptor. /// </summary> /// <param name="descriptor">The descriptor.</param> /// <returns> /// <c>true</c> if this instance [can handle descriptor] the specified descriptor; otherwise, <c>false</c>. /// </returns> public virtual bool CanHandleDescriptor(IProFormaDescriptor descriptor) { var nonDefault = descriptor.EvidenceType == this.EvidenceType && (descriptor.Key == ProFormaKey.Name || descriptor.Key == ProFormaKey.Identifier); if (!this.IsDefaultModificationType) { return(nonDefault); } // If this is the default modification type, allow one more condition. return(nonDefault || (descriptor.Key == ProFormaKey.Name && descriptor.EvidenceType == ProFormaEvidenceType.None)); }
/// <summary> /// Gets the modification. /// </summary> /// <param name="descriptor">The descriptor.</param> /// <returns></returns> public virtual IProteoformMassDelta GetModification(IProFormaDescriptor descriptor) { if (_modifications == null) { throw new Exception("Modification array in not initialized."); } if (descriptor.Value == null) { throw new ProteoformModificationLookupException($"Value is NULL in descriptor {descriptor}."); } if (descriptor.Key == ProFormaKey.Name) { string value = descriptor.Value; IProteoformMassDelta modification = _modifications .SingleOrDefault(x => x != null && ((ModificationWrapper)x).Modification.Name == value); if (modification == null) { throw new ProteoformModificationLookupException($"Could not find modification using Name in descriptor {descriptor}."); } return(modification); } else if (descriptor.Key == ProFormaKey.Identifier) { string value = this.RemovePrefix(descriptor.Value); if (int.TryParse(value, out int id)) { if (id < 0 || id > _modifications.Length - 1 || _modifications[id] == null) { throw new ProteoformModificationLookupException($"Could not find modification using ID in descriptor {descriptor}."); } return(_modifications[id]); } throw new ProteoformModificationLookupException($"Invalid integer in descriptor {descriptor}."); } throw new ProteoformModificationLookupException($"Couldn't handle value for descriptor {descriptor}."); }
/// <summary> /// Gets the modification. /// </summary> /// <param name="descriptor">The descriptor.</param> /// <returns></returns> public virtual IProteoformMassDelta GetModification(IProFormaDescriptor descriptor) { if (_modifications == null) { throw new Exception("Modification array in not initialized."); } if (descriptor.Value == null) { throw new ProteoformModificationLookupException($"Value is NULL in descriptor {descriptor}."); } if (descriptor.Key == ProFormaKey.Name) { string value = descriptor.Value; if (_modificationNames != null) { if (!_modificationNames.ContainsKey(value)) { throw new ProteoformModificationLookupException($"Could not find modification using Name in descriptor {descriptor}."); } return(_modificationNames[value]); } } else if (descriptor.Key == ProFormaKey.Identifier) { string value = this.RemovePrefix(descriptor.Value); if (int.TryParse(value, out int id)) { if (id < 0 || id > _modifications.Length - 1 || _modifications[id] == null) { throw new ProteoformModificationLookupException($"Could not find modification using ID in descriptor {descriptor}."); } return(_modifications[id]); } throw new ProteoformModificationLookupException($"Invalid integer in descriptor {descriptor}."); } throw new ProteoformModificationLookupException($"Couldn't handle value for descriptor {descriptor}."); }
private string CreateDescriptorText(IProFormaDescriptor descriptor) { return(descriptor.Key switch { ProFormaKey.Formula => $"Formula:{descriptor.Value}", ProFormaKey.Glycan => $"Glycan:{descriptor.Value}", ProFormaKey.Info => $"Info:{descriptor.Value}", var x when x == ProFormaKey.Name || x == ProFormaKey.Mass => descriptor.EvidenceType switch { ProFormaEvidenceType.None => descriptor.Value, // We assume the name is enough ProFormaEvidenceType.Observed => $"Obs:{descriptor.Value}", ProFormaEvidenceType.Unimod => $"U:{descriptor.Value}", ProFormaEvidenceType.Resid => $"R:{descriptor.Value}", ProFormaEvidenceType.PsiMod => $"M:{descriptor.Value}", ProFormaEvidenceType.XlMod => $"X:{descriptor.Value}", ProFormaEvidenceType.Gno => $"G:{descriptor.Value}", ProFormaEvidenceType.Brno => $"B:{descriptor.Value}", _ => throw new Exception($"Can't handle {descriptor.Key} with evidence type: {descriptor.EvidenceType}.") },
/// <summary> /// Gets the modification. /// </summary> /// <param name="descriptor">The descriptor.</param> /// <returns></returns> public IProteoformMassDelta GetModification(IProFormaDescriptor descriptor) { string abbreviation = descriptor.Value; switch (abbreviation) { case "ac": return(_modifications[0]); case "me1": return(_modifications[1]); case "me2s": return(_modifications[2]); case "me2a": return(_modifications[3]); case "me2": return(_modifications[4]); case "me3": return(_modifications[5]); case "ph": return(_modifications[6]); default: throw new ProteoformModificationLookupException($"Couldn't handle value for descriptor {descriptor}."); } }
/// <summary> /// Determines whether this instance [can handle descriptor] the specified descriptor. /// </summary> /// <param name="descriptor">The descriptor.</param> /// <returns> /// <c>true</c> if this instance [can handle descriptor] the specified descriptor; otherwise, <c>false</c>. /// </returns> public bool CanHandleDescriptor(IProFormaDescriptor descriptor) { return(descriptor.Key == ProFormaKey.Name && descriptor.EvidenceType == ProFormaEvidenceType.Brno && descriptor.Value != null); }
/// <summary> /// Determines whether this instance [can handle descriptor] the specified descriptor. /// </summary> /// <param name="descriptor">The descriptor.</param> /// <returns> /// <c>true</c> if this instance [can handle descriptor] the specified descriptor; otherwise, <c>false</c>. /// </returns> public bool CanHandleDescriptor(IProFormaDescriptor descriptor) { return(_lookups.Any(x => x.CanHandleDescriptor(descriptor))); }
/// <summary> /// Gets the modification. /// </summary> /// <param name="descriptor">The descriptor.</param> /// <returns></returns> public IProteoformMassDelta?GetModification(IProFormaDescriptor descriptor) => null;
/// <summary> /// Determines whether this instance [can handle descriptor] the specified descriptor. /// </summary> /// <param name="descriptor">The descriptor.</param> /// <returns> /// <c>true</c> if this instance [can handle descriptor] the specified descriptor; otherwise, <c>false</c>. /// </returns> public bool CanHandleDescriptor(IProFormaDescriptor descriptor) { return(descriptor.Key == _key); }
/// <summary>Determines whether this instance [can handle descriptor] the specified descriptor.</summary> /// <param name="descriptor">The descriptor.</param> /// <returns> /// <c>true</c> if this instance [can handle descriptor] the specified descriptor; otherwise, <c>false</c>.</returns> public bool CanHandleDescriptor(IProFormaDescriptor descriptor) { return(descriptor.Key == ProFormaKey.Mass); }