Esempio n. 1
0
        public string ToSerializableString()
        {
            // Replace tab with something that XML parsers won't mess with
            var tsv = ToTSV();

            return(AccessionNumbers.EscapeTabsForXML(tsv));
        }
Esempio n. 2
0
        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());
        }
Esempio n. 3
0
        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());
        }
Esempio n. 4
0
 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);
     }
 }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
 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());
 }
Esempio n. 7
0
        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);
        }
Esempio n. 8
0
        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()));
        }
Esempio n. 9
0
 public override int GetHashCode()
 {
     return((AccessionNumbers != null && AccessionNumbers.Any()) ? AccessionNumbers.GetHashCode() : 0);
 }
Esempio n. 10
0
        public string GetSMILES()
        {
            string smiles;

            return(AccessionNumbers != null && AccessionNumbers.TryGetValue(TagSMILES, out smiles) ? smiles : null);
        }
Esempio n. 11
0
        public string GetSMILES()
        {
            string cas;

            return(AccessionNumbers != null && AccessionNumbers.TryGetValue(TagSMILES, out cas) ? cas : null);
        }
Esempio n. 12
0
        public string GetHMDB()
        {
            string cas;

            return(AccessionNumbers != null && AccessionNumbers.TryGetValue(TagHMDB, out cas) ? cas : null);
        }
Esempio n. 13
0
        public string GetInChI()
        {
            string inchikey;

            return(AccessionNumbers != null && AccessionNumbers.TryGetValue(TagInChI, out inchikey) ? inchikey : null);
        }
Esempio n. 14
0
 public SmallMoleculeLibraryAttributes GetSmallMoleculeLibraryAttributes()
 {
     return(SmallMoleculeLibraryAttributes.Create(Name, Formula,
                                                  MonoisotopicMass, AverageMass, // In case forumla is empty
                                                  AccessionNumbers.GetInChiKey(), AccessionNumbers.GetNonInChiKeys()));
 }
Esempio n. 15
0
        public string GetKEGG()
        {
            string kegg;

            return(AccessionNumbers != null && AccessionNumbers.TryGetValue(TagKEGG, out kegg) ? kegg : null);
        }
Esempio n. 16
0
 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);
 }
Esempio n. 17
0
        public string GetHMDB()
        {
            string hmdb;

            return(AccessionNumbers != null && AccessionNumbers.TryGetValue(TagHMDB, out hmdb) ? hmdb : null);
        }