Class: GlyDevKit::GlycanFormatConverter

Inherits:
Object
  • Object
show all
Defined in:
lib/glydevkit/glycan_format_converter.rb

Instance Method Summary collapse

Instance Method Details

#iupac2wurcs(iupac, style) ⇒ Hash

Converts an IUPAC string to WURCS format.

Examples:

converter = GlyDevKit::GlycanFormatConverter.new
result = converter.iupac2wurcs("Man(a1-3)[Man(a1-6)]Man(b1-4)GlcNAc(b1-4)GlcNAc(b1-", "condensed")


117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/glydevkit/glycan_format_converter.rb', line 117

def iupac2wurcs(iupac, style)
    ret = {}
    ret["input"] = iupac
  
    begin
      if style == "condensed"
        ici = IUPACCondensedImporter.new
        gc = ici.start(iupac)
      else
        iei = IUPACExtendedImporter.new
        gc = iei.start(iupac)
      end
  
      ee = ExporterEntrance.new(gc)
      wurcs = ee.toWURCS
      ret["wurcs"] = wurcs
  
    rescue GlyCoImporterException, GlycanException, WURCSException => e
      ret["message"] = e.to_s
    rescue StandardError => e
      ret["message"] = e.to_s
    end
    return ret
end

#wurcs2glycam(wurcs) ⇒ String

Converts a WURCS string to GLYCAM format.

Examples:

converter = GlyDevKit::GlycanFormatConverter.new
result = converter.wurcs2glycam("WURCS=2.0/...")


98
99
100
101
102
103
104
105
106
# File 'lib/glydevkit/glycan_format_converter.rb', line 98

def wurcs2glycam(wurcs)
  wi = WURCSImporter.new
  ee = ExporterEntrance.new(wi.start(wurcs))
  begin
    ee.toIUPAC(IUPACStyleDescriptor::GLYCANWEB)
  rescue => e
    e.printStackTrace()
  end
end

#wurcs2glycoct(wurcs) ⇒ Hash

Converts a WURCS string to GlycoCT format.

Examples:

converter = GlyDevKit::GlycanFormatConverter.new
result = converter.wurcs2glycoct("WURCS=2.0/...")


69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/glydevkit/glycan_format_converter.rb', line 69

def wurcs2glycoct(wurcs)
  ret = {}
  ret["input"] = wurcs
  begin
    converter = WURCSToGlycoCT.new
    converter.start(wurcs)
    message = converter.getErrorMessages
    if message.empty?
      ret["GlycoCT"] = converter.getGlycoCT
      ret["message"] = ""
    else
      ret["GlycoCT"] = ""
      ret["message"] = message
    end
  rescue Exception => e
    ret["GlycoCT"] = ""
    ret["message"] = e.to_s
  end
  return ret
end

#wurcs2iupac(wurcs, style) ⇒ Hash

Converts a WURCS string to IUPAC format.

Examples:

converter = GlyDevKit::GlycanFormatConverter.new
result = converter.wurcs2iupac("WURCS=2.0/...", "condensed")


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/glydevkit/glycan_format_converter.rb', line 31

def wurcs2iupac(wurcs, style)
  ret = {}
  ret["input"] = wurcs

  begin
    wi = WURCSImporter.new
    gc = wi.start(wurcs)
    ee = ExporterEntrance.new(gc)

    if style == "condensed"
      iupaccondensed = ee.toIUPAC(IUPACStyleDescriptor::CONDENSED)
      ret["IUPACcondensed"] = iupaccondensed
    elsif style == "extended"
      iupacextended = ee.toIUPAC(IUPACStyleDescriptor::GREEK)
      ret["IUPACextended"] = iupacextended
    else
      glycam = ee.toIUPAC(IUPACStyleDescriptor::GLYCANWEB)
      ret["GLYCAM"] = glycam
    end

  rescue GlyCoExporterException, GlycanException, TrivialNameException, WURCSException => e
    logger.error("{}", e)
    ret["message"] = e.to_s
  rescue Exception => e
    logger.error("{}", e)
    ret["message"] = e.to_s
  end
  return ret
end