public string ToSerializableString() { // Replace tab with something that XML parsers won't mess with var tsv = ToTSV(); return(AccessionNumbers.EscapeTabsForXML(tsv)); }
public List <string> AsFields() { var massOrFormula = !string.IsNullOrEmpty(Formula) ? Formula : string.Format(CultureInfo.InvariantCulture, "{0:F09}/{1:F09}", MonoisotopicMass, AverageMass); // Not L10N var parts = new[] { Name, massOrFormula, AccessionNumbers.ToString() }; return((parts.All(string.IsNullOrEmpty) ? new[] { InvariantName } : parts).ToList()); }
public List <string> AsFields() { var massOrFormula = !string.IsNullOrEmpty(Formula) ? Formula : FormattedMasses(MonoisotopicMass, AverageMass); var parts = new[] { Name, massOrFormula, AccessionNumbers.ToString() }; return((parts.All(string.IsNullOrEmpty) ? new[] { InvariantName } : parts).ToList()); }
public override int GetHashCode() { unchecked { int hashCode = (Formula != null ? Formula.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Name != null ? Name.GetHashCode() : 0); hashCode = (hashCode * 397) ^ MonoisotopicMass.GetHashCode(); hashCode = (hashCode * 397) ^ AverageMass.GetHashCode(); hashCode = (hashCode * 397) ^ AccessionNumbers.GetHashCode(); return(hashCode); } }
public override string ToString() { var result = string.Empty; if (AccessionNumbers != null && AccessionNumbers.Any()) { foreach (var key in PREFERRED_ACCESSION_TYPE_ORDER) { string value; if (AccessionNumbers.TryGetValue(key, out value) && !string.IsNullOrEmpty(value)) { result += string.Format("{0}{1}:{2}", // Not L10N string.IsNullOrEmpty(result) ? string.Empty : TextUtil.SEPARATOR_TSV_STR, key, value); } } } return(result); }
public void WriteXml(XmlWriter writer, Adduct adduct) { if (adduct.IsEmpty) { writer.WriteAttributeIfString(ATTR.neutral_formula, Formula); } else { writer.WriteAttributeIfString(ATTR.ion_formula, (Formula ?? string.Empty) + (adduct.IsProteomic ? string.Empty : adduct.ToString())); } Assume.IsFalse(AverageMass.IsMassH()); // We're going to read these as neutral masses Assume.IsFalse(MonoisotopicMass.IsMassH()); writer.WriteAttributeNullable(ATTR.neutral_mass_average, AverageMass); writer.WriteAttributeNullable(ATTR.neutral_mass_monoisotopic, MonoisotopicMass); if (!string.IsNullOrEmpty(Name)) { writer.WriteAttribute(ATTR.custom_ion_name, Name); } writer.WriteAttributeIfString(ATTR.id, AccessionNumbers.ToSerializableString()); }
public int CompareTo(CustomMolecule other) { if (other == null) { return(1); } var result = string.CompareOrdinal(Name, other.Name); if (result == 0) { result = string.CompareOrdinal(Formula, other.Formula); if (result == 0) { result = AccessionNumbers.CompareTo(other.AccessionNumbers); if (result == 0) { result = MonoisotopicMass.Equals(other.MonoisotopicMass, 5E-10) ? // Allow for float vs double serialization effects 0 : MonoisotopicMass.CompareTo(other.MonoisotopicMass); } } } return(result); }
protected const string massFormatRegex = @"(?:[a-z][a-z]+)\s+\[([+-]?\d*\.\d+)(?![-+0-9\.])\/([+-]?\d*\.\d+)(?![-+0-9\.])\]"; // Not L10N public SmallMoleculeLibraryAttributes GetSmallMoleculeLibraryAttributes() { return(SmallMoleculeLibraryAttributes.Create(Name, Formula, AccessionNumbers.GetInChiKey(), AccessionNumbers.GetNonInChiKeys())); }
public override int GetHashCode() { return((AccessionNumbers != null && AccessionNumbers.Any()) ? AccessionNumbers.GetHashCode() : 0); }
public string GetSMILES() { string smiles; return(AccessionNumbers != null && AccessionNumbers.TryGetValue(TagSMILES, out smiles) ? smiles : null); }
public string GetSMILES() { string cas; return(AccessionNumbers != null && AccessionNumbers.TryGetValue(TagSMILES, out cas) ? cas : null); }
public string GetHMDB() { string cas; return(AccessionNumbers != null && AccessionNumbers.TryGetValue(TagHMDB, out cas) ? cas : null); }
public string GetInChI() { string inchikey; return(AccessionNumbers != null && AccessionNumbers.TryGetValue(TagInChI, out inchikey) ? inchikey : null); }
public SmallMoleculeLibraryAttributes GetSmallMoleculeLibraryAttributes() { return(SmallMoleculeLibraryAttributes.Create(Name, Formula, MonoisotopicMass, AverageMass, // In case forumla is empty AccessionNumbers.GetInChiKey(), AccessionNumbers.GetNonInChiKeys())); }
public string GetKEGG() { string kegg; return(AccessionNumbers != null && AccessionNumbers.TryGetValue(TagKEGG, out kegg) ? kegg : null); }
public string GetNonInChiKeys() { return(AccessionNumbers != null && AccessionNumbers.Any() ? AccessionNumbers.Where(k => k.Key != TagInChiKey).Select(kvp => string.Format("{0}:{1}", kvp.Key, kvp.Value)).ToDsvLine(TextUtil.SEPARATOR_TSV) : // Not L10N null); }
public string GetHMDB() { string hmdb; return(AccessionNumbers != null && AccessionNumbers.TryGetValue(TagHMDB, out hmdb) ? hmdb : null); }