private UnimodModification ConvertToModification(OboTerm term) { string code = term.Id; string name = term.Name; string?definition = null; string?diffFormula = null; double diffMonoMass = 0; double diffAvMass = 0; if (term.ValuePairs != null) { foreach (OboTagValuePair pair in term.ValuePairs) { if (pair.Tag == "def") { definition = pair.Value.Replace("\\", string.Empty); } else if (pair.Tag == "xref" && pair.Value.StartsWith("delta_composition")) { diffFormula = pair.Value.Replace("\"", string.Empty).Substring(18); } else if (pair.Tag == "xref" && pair.Value.StartsWith("delta_mono_mass")) { diffMonoMass = Convert.ToDouble(pair.Value.Replace("\"", string.Empty).Substring(16)); } else if (pair.Tag == "xref" && pair.Value.StartsWith("delta_avge_mass")) { diffAvMass = Convert.ToDouble(pair.Value.Replace("\"", string.Empty).Substring(16)); } } } if (definition != null && diffFormula != null) { return(new UnimodModification(code, name, definition, diffFormula, diffMonoMass, diffAvMass)); } throw new Exception("Could not find required 'definition' field."); }
private XlmodTerm ConvertToModification(OboTerm oboTerm) { string?definition = null; ICollection <XlmodSynonym>? synonyms = null; ICollection <XlmodExternalReference>?externalReferences = null; ICollection <XlmodProperty>? properties = null; ICollection <XlmodRelationship>? relationships = null; ICollection <string>?isA = null; if (oboTerm.ValuePairs != null) { foreach (OboTagValuePair pair in oboTerm.ValuePairs) { var valueSpan = pair.Value.AsSpan(); switch (pair.Tag) { case "synonym": // "Text" Score Type [] { int endOfQuote = valueSpan.LastIndexOf('"'); var text = valueSpan.Slice(1, endOfQuote - 1); var type = valueSpan.Slice(endOfQuote + 2, valueSpan.LastIndexOf('[') - endOfQuote - 3); Utility.LazyCreateAndAdd(ref synonyms, new XlmodSynonym(type.ToString(), text.ToString())); } break; case "def": { // "defString" [dbName1:acc1, dbName2:acc2] int endOfQuote = valueSpan.LastIndexOf('"'); definition = valueSpan.Slice(1, endOfQuote - 1).ToString(); string refs = valueSpan.Slice(endOfQuote + 3, valueSpan.Length - endOfQuote - 4).ToString(); if (refs != "") { string[] splitComma = refs.Split(','); foreach (string reference in splitComma.Select(s => s.Trim(' '))) { string[] splitColon2 = reference.Split(':'); Utility.LazyCreateAndAdd(ref externalReferences, new XlmodExternalReference(splitColon2[0], splitColon2[1])); } } } break; case "property_value": // property_value: doubletDeltaMass: "8.05016" xsd:double { int startOfQuote = valueSpan.IndexOf('"'); int endOfQuote = valueSpan.LastIndexOf('"'); var name = valueSpan.Slice(0, startOfQuote - 2); var value = valueSpan.Slice(startOfQuote + 1, endOfQuote - startOfQuote - 1); var dataType = valueSpan.Slice(endOfQuote + 2); Utility.LazyCreateAndAdd(ref properties, new XlmodProperty(name.ToString(), value.ToString(), dataType.ToString())); } break; case "relationship": // relationship: has_property XLMOD:00014 ! hydrophilic { int spaceIndex = valueSpan.IndexOf(' '); var type = valueSpan.Slice(0, spaceIndex); var id = valueSpan.Slice(spaceIndex + 1, valueSpan.IndexOf('!') - spaceIndex - 2); Utility.LazyCreateAndAdd(ref relationships, new XlmodRelationship(type.ToString(), id.ToString())); } break; case "is_a": // MOD:00000 ! description string modNum = valueSpan.Slice(0, valueSpan.IndexOf(' ') - 1).ToString(); Utility.LazyCreateAndAdd(ref isA, modNum); break; } } } if (definition != null) { return(new XlmodTerm(oboTerm.Id, oboTerm.Name, definition, externalReferences, isA, relationships, synonyms, properties)); } throw new Exception("Could not find required 'definition' field."); }
private PsiModTerm ConvertToModification(OboTerm oboTerm) { string?definition = null; ICollection <PsiModSynonym>? synonyms = null; ICollection <PsiModExternalReference>?externalReferences = null; ICollection <string>?isA = null; string?comment = null; bool isObsolete = false; string?remap = null; double?diffAvg = null; string?diffFormula = null; double?diffMono = null; double?massAvg = null; string?massFormula = null; double?massMono = null; int formalCharge = 0; ICollection <char>?origin = null; PsiModModificationSource?source = null; Terminus?terminus = null; if (oboTerm.ValuePairs != null) { foreach (OboTagValuePair pair in oboTerm.ValuePairs) { switch (pair.Tag) { case "synonym": // "Text" Score Type [] string[] splitQuote = pair.Value.Trim('"').Split('"'); string text = splitQuote[0]; string[] split = splitQuote[1].Trim(' ').Split(' '); string scope = split[0]; string type = split[1]; Utility.LazyCreateAndAdd(ref synonyms, new PsiModSynonym(type, text, scope)); break; case "def": // "defString" [dbName1:acc1, dbName2:acc2] string[] splitQuot = pair.Value.Substring(1).Split('"'); definition = splitQuot[0]; string refs = splitQuot[1]; refs = refs.Trim(' ', '[', ']'); if (refs != "") { string[] splitComma = refs.Split(','); foreach (string reference in splitComma.Select(s => s.Trim(' '))) { string[] splitColon2 = reference.Split(':'); Utility.LazyCreateAndAdd(ref externalReferences, new PsiModExternalReference(splitColon2[0], splitColon2[1])); } } break; case "comment": comment = pair.Value; break; case "xref": int colonIndex = pair.Value.IndexOf(':'); string key = pair.Value[0..colonIndex];