glydevkit 0.2.beta.1-java → 0.2.0-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c912a7e2a35037df8e3878dbd2afaaa8647034457ee4569ce84a8e78b1c6b3d8
4
- data.tar.gz: f87718ac5617735afe4d38026cc66ebcf23bbd15d41b718515d15b248800a088
3
+ metadata.gz: 83d750624afd79f057a3c1bf09acd73237fadc17d3c3344c6bbc7983400fbd92
4
+ data.tar.gz: 4fe3a25745004d021729937595129af9254f2c16d7202acb92206456f2b81f74
5
5
  SHA512:
6
- metadata.gz: aab88ca9b8ca7c18ff72c342ffa66ddb5649a76bba36c81de8d07f4b2654a9435c0d00b694620a365ad685b8e18670db4e470da5f3cab45599d1a5f1ab70e649
7
- data.tar.gz: 4e44ccc0ebb190851a9e577d7cda0ac458821320df6c2d15f1675fe279bed673f7daa730ac4a06fa4e0e134a20f816f194c34795b73f4c376a4e530be9f1f3d3
6
+ metadata.gz: 605f961468391e725a90013390cc276f25bd081ef0c4f4c1101dec66b5fe702cf2a1e054835a8f61e788807e16439339f2042e1c95b729802bdd781f9dd7c980
7
+ data.tar.gz: 3d8ffbe6557a41bb9378ada4e32d5d7a5431d299b5590f90aa1cdf8776bb4a598b0f0221bf923de7092ce6232f7fcb138e66f767f7825e50d3a7cd8d45e80abf
data/jar.yml CHANGED
@@ -92,6 +92,6 @@ libraries:
92
92
 
93
93
  - name: MolWURCS
94
94
  info: https://gitlab.com/glycoinfo/molwurcs
95
- version: 0.10.2
96
- url: https://gitlab.com/glycoinfo/molwurcs/-/package_files/89942780/download
95
+ version: 0.11.0
96
+ url: https://gitlab.com/glycoinfo/molwurcs/-/package_files/106726568/download
97
97
  file: jar/MolWURCS.jar
@@ -0,0 +1,64 @@
1
+ require "java"
2
+
3
+ require_relative '../jar/cdk.jar'
4
+
5
+ java_import 'org.openscience.cdk.similarity.Tanimoto'
6
+ java_import 'org.openscience.cdk.DefaultChemObjectBuilder'
7
+ java_import 'org.openscience.cdk.smiles.SmilesParser'
8
+ java_import 'org.openscience.cdk.fingerprint.CircularFingerprinter'
9
+ java_import 'org.openscience.cdk.layout.StructureDiagramGenerator'
10
+ java_import 'org.openscience.cdk.depict.DepictionGenerator'
11
+
12
+ module GlyDevKit
13
+ class CDK
14
+
15
+ def sim(seq1,seq2,format)
16
+ if format == "wurcs"
17
+ Tanimoto.calculate(w2bit(seq1), w2bit(seq2))
18
+ elsif format == "smiles"
19
+ Tanimoto.calculate(smiles2bit(seq1), smiles2bit(seq2))
20
+ end
21
+ end
22
+
23
+ def mol2svg(smiles)
24
+
25
+ begin
26
+ sp = SmilesParser.new(DefaultChemObjectBuilder.getInstance)
27
+ molecule = sp.parseSmiles(smiles)
28
+
29
+ sdg = StructureDiagramGenerator.new(molecule)
30
+ sdg.generateCoordinates
31
+ molecule = sdg.molecule
32
+
33
+ depiction_gen = DepictionGenerator.new
34
+ return depiction_gen.withSize(30, 30).depict(molecule).toSvgStr
35
+
36
+ rescue => e
37
+ puts e.message
38
+ end
39
+ end
40
+
41
+ private
42
+
43
+ def w2bit(w)
44
+ mw = GlyDevKit::MolWURCS.new
45
+ smiles = mw.wurcs2mol(w,"smiles")[:smiles]
46
+
47
+ sp = SmilesParser.new(DefaultChemObjectBuilder.getInstance())
48
+ molecule = sp.parseSmiles(smiles)
49
+ fingerprinter = CircularFingerprinter.new
50
+ fingerprinter.calculate(molecule)
51
+ return fingerprinter.getBitFingerprint(molecule).asBitSet()
52
+ end
53
+
54
+ def smiles2bit(s)
55
+
56
+ sp = SmilesParser.new(DefaultChemObjectBuilder.getInstance())
57
+ molecule = sp.parseSmiles(s)
58
+ fingerprinter = CircularFingerprinter.new
59
+ fingerprinter.calculate(molecule)
60
+ return fingerprinter.getBitFingerprint(molecule).asBitSet()
61
+ end
62
+
63
+ end
64
+ end
@@ -8,9 +8,18 @@ java_import 'org.glycoinfo.WURCSFramework.wurcs.graph.WURCSGraph'
8
8
  java_import 'org.glycoinfo.WURCSFramework.util.WURCSException'
9
9
 
10
10
  module GlyDevKit
11
- class GlyTouCan
12
- def archetype(w)
13
- Hash[Archetype.beBorn(w)]
11
+ class GlyTouCan
12
+ # Converts a WURCS string to its archetype representation.
13
+ #
14
+ # @param w [String] The WURCS string.
15
+ # @return [Hash] The archetype representation of the WURCS string.
16
+ #
17
+ # @example
18
+ # require glydevkit
19
+ # glytoucan = GlyDevKit::GlyTouCan.new
20
+ # archetype = glytoucan.archetype("WURCS=2.0/...")
21
+ def archetype(w)
22
+ Hash[Archetype.beBorn(w)]
23
+ end
14
24
  end
15
25
  end
16
- end
@@ -8,69 +8,135 @@ java_import 'org.glycoinfo.GlycanFormatconverter.io.GlycoCT.WURCSToGlycoCT'
8
8
  java_import 'org.glycoinfo.GlycanFormatconverter.io.IUPAC.IUPACStyleDescriptor'
9
9
  java_import 'org.glycoinfo.GlycanFormatconverter.io.WURCS.WURCSImporter'
10
10
  java_import 'org.glycoinfo.GlycanFormatconverter.util.ExporterEntrance'
11
-
11
+ java_import 'org.glycoinfo.GlycanFormatconverter.Glycan.GlyContainer'
12
+ java_import 'org.glycoinfo.GlycanFormatconverter.Glycan.GlycanException'
13
+ java_import 'org.glycoinfo.GlycanFormatconverter.io.GlyCoExporterException'
14
+ java_import 'org.glycoinfo.GlycanFormatconverter.io.GlyCoImporterException'
15
+ java_import 'org.glycoinfo.GlycanFormatconverter.io.IUPAC.IUPACStyleDescriptor'
16
+ java_import 'org.glycoinfo.GlycanFormatconverter.io.IUPAC.condensed.IUPACCondensedImporter'
17
+ java_import 'org.glycoinfo.GlycanFormatconverter.io.IUPAC.extended.IUPACExtendedImporter'
18
+
12
19
  module GlyDevKit
13
- class GlycanFormatConverter
20
+ class GlycanFormatConverter
14
21
 
15
- def wurcs2iupac(wurcs,style)
16
- ret = {}
17
- ret["input"] = wurcs
18
-
19
- begin
20
- wi = WURCSImporter.new
21
- gc = wi.start(wurcs)
22
- ee = ExporterEntrance.new(gc)
22
+ # Converts a WURCS string to IUPAC format.
23
+ #
24
+ # @param wurcs [String] The WURCS string to be converted.
25
+ # @param style [String] The desired IUPAC style ("condensed", "extended", or "glycam").
26
+ # @return [Hash] A hash containing the input WURCS string and the resulting IUPAC format.
27
+ #
28
+ # @example
29
+ # converter = GlyDevKit::GlycanFormatConverter.new
30
+ # result = converter.wurcs2iupac("WURCS=2.0/...", "condensed")
31
+ def wurcs2iupac(wurcs, style)
32
+ ret = {}
33
+ ret["input"] = wurcs
23
34
 
24
- if style == "condensed"
25
- iupaccondensed = ee.toIUPAC(IUPACStyleDescriptor::CONDENSED)
26
- ret["IUPACcondensed"] = iupaccondensed
27
- elsif style == "extended"
28
- iupacextended = ee.toIUPAC(IUPACStyleDescriptor::GREEK)
29
- ret["IUPACextended"] = iupacextended
30
- else
31
- glycam = ee.toIUPAC(IUPACStyleDescriptor::GLYCANWEB)
32
- ret["GLYCAM"] = glycam
33
- end
35
+ begin
36
+ wi = WURCSImporter.new
37
+ gc = wi.start(wurcs)
38
+ ee = ExporterEntrance.new(gc)
34
39
 
35
- rescue GlyCoExporterException, GlycanException, TrivialNameException, WURCSException => e
36
- logger.error("{}", e)
37
- ret["message"] = e.to_s
38
- rescue Exception => e
39
- logger.error("{}", e)
40
- ret["message"] = e.to_s
41
- end
42
- return ret
43
- end
40
+ if style == "condensed"
41
+ iupaccondensed = ee.toIUPAC(IUPACStyleDescriptor::CONDENSED)
42
+ ret["IUPACcondensed"] = iupaccondensed
43
+ elsif style == "extended"
44
+ iupacextended = ee.toIUPAC(IUPACStyleDescriptor::GREEK)
45
+ ret["IUPACextended"] = iupacextended
46
+ else
47
+ glycam = ee.toIUPAC(IUPACStyleDescriptor::GLYCANWEB)
48
+ ret["GLYCAM"] = glycam
49
+ end
44
50
 
45
- def wurcs2glycoct(wurcs)
46
- ret = {}
47
- ret["input"] = wurcs
48
- begin
49
- converter = WURCSToGlycoCT.new
50
- converter.start(wurcs)
51
- message = converter.getErrorMessages
52
- if message.empty?
53
- ret["GlycoCT"] = converter.getGlycoCT
54
- ret["message"] = ""
55
- else
56
- ret["GlycoCT"] = ""
57
- ret["message"] = message
51
+ rescue GlyCoExporterException, GlycanException, TrivialNameException, WURCSException => e
52
+ logger.error("{}", e)
53
+ ret["message"] = e.to_s
54
+ rescue Exception => e
55
+ logger.error("{}", e)
56
+ ret["message"] = e.to_s
57
+ end
58
+ return ret
58
59
  end
60
+
61
+ # Converts a WURCS string to GlycoCT format.
62
+ #
63
+ # @param wurcs [String] The WURCS string to be converted.
64
+ # @return [Hash] A hash containing the input WURCS string and the resulting GlycoCT format.
65
+ #
66
+ # @example
67
+ # converter = GlyDevKit::GlycanFormatConverter.new
68
+ # result = converter.wurcs2glycoct("WURCS=2.0/...")
69
+ def wurcs2glycoct(wurcs)
70
+ ret = {}
71
+ ret["input"] = wurcs
72
+ begin
73
+ converter = WURCSToGlycoCT.new
74
+ converter.start(wurcs)
75
+ message = converter.getErrorMessages
76
+ if message.empty?
77
+ ret["GlycoCT"] = converter.getGlycoCT
78
+ ret["message"] = ""
79
+ else
80
+ ret["GlycoCT"] = ""
81
+ ret["message"] = message
82
+ end
59
83
  rescue Exception => e
60
- ret["GlycoCT"] = ""
61
- ret["message"] = e.to_s
84
+ ret["GlycoCT"] = ""
85
+ ret["message"] = e.to_s
86
+ end
87
+ return ret
88
+ end
89
+
90
+ # Converts a WURCS string to GLYCAM format.
91
+ #
92
+ # @param wurcs [String] The WURCS string to be converted.
93
+ # @return [String] The resulting GLYCAM format string.
94
+ #
95
+ # @example
96
+ # converter = GlyDevKit::GlycanFormatConverter.new
97
+ # result = converter.wurcs2glycam("WURCS=2.0/...")
98
+ def wurcs2glycam(wurcs)
99
+ wi = WURCSImporter.new
100
+ ee = ExporterEntrance.new(wi.start(wurcs))
101
+ begin
102
+ ee.toIUPAC(IUPACStyleDescriptor::GLYCANWEB)
103
+ rescue => e
104
+ e.printStackTrace()
105
+ end
62
106
  end
63
- return ret
64
- end
65
107
 
66
- def wurcs2glycam(wurcs)
67
- wi = WURCSImporter.new
68
- ee = ExporterEntrance.new(wi.start(wurcs))
69
- begin
70
- ee.toIUPAC(IUPACStyleDescriptor::GLYCANWEB)
71
- rescue => e
72
- e.printStackTrace()
108
+ # Converts an IUPAC string to WURCS format.
109
+ #
110
+ # @param iupac [String] The IUPAC string to be converted.
111
+ # @param style [String] The style of the IUPAC string ("condensed" or "extended").
112
+ # @return [Hash] A hash containing the input IUPAC string and the resulting WURCS format.
113
+ #
114
+ # @example
115
+ # converter = GlyDevKit::GlycanFormatConverter.new
116
+ # result = converter.iupac2wurcs("Man(a1-3)[Man(a1-6)]Man(b1-4)GlcNAc(b1-4)GlcNAc(b1-", "condensed")
117
+ def iupac2wurcs(iupac, style)
118
+ ret = {}
119
+ ret["input"] = iupac
120
+
121
+ begin
122
+ if style == "condensed"
123
+ ici = IUPACCondensedImporter.new
124
+ gc = ici.start(iupac)
125
+ else
126
+ iei = IUPACExtendedImporter.new
127
+ gc = iei.start(iupac)
128
+ end
129
+
130
+ ee = ExporterEntrance.new(gc)
131
+ wurcs = ee.toWURCS
132
+ ret["wurcs"] = wurcs
133
+
134
+ rescue GlyCoImporterException, GlycanException, WURCSException => e
135
+ ret["message"] = e.to_s
136
+ rescue StandardError => e
137
+ ret["message"] = e.to_s
138
+ end
139
+ return ret
140
+ end
73
141
  end
74
142
  end
75
- end
76
- end
@@ -0,0 +1,110 @@
1
+ require 'json'
2
+ require 'uri'
3
+ require 'net/http'
4
+ require 'zlib'
5
+ java_import 'java.util.Base64'
6
+
7
+ module GlyDevKit
8
+ class GlytoucanDataHandler
9
+ attr_reader :all_data
10
+
11
+ def initialize
12
+ @gtcfilepath = File.join(Dir.home, '.glycobook', 'gtcdata.json')
13
+ if File.exist?(@gtcfilepath)
14
+ creation_time = File.ctime(@gtcfilepath)
15
+ one_hours_ago = Time.now - (1 * 60 * 60) # 1時間前の時刻
16
+ if creation_time > one_hours_ago
17
+ @all_data = JSON.parse(File.read(@gtcfilepath))
18
+ return
19
+ end
20
+ end
21
+ @all_data = save_glytoucan_data
22
+ end
23
+
24
+ def get_wurcs_by_gtcid(id)
25
+ return "not found" if @all_data["wurcs"][id].nil?
26
+ decode_lambda = ->(encoded_str) { decode(encoded_str) }
27
+ @all_data["wurcs"][id]&.map(&decode_lambda)
28
+ end
29
+
30
+ def get_gtcid_by_wurcs(w)
31
+ return "not found" if @all_data["encode-wurcs-key"][encode(w)].nil?
32
+ @all_data["encode-wurcs-key"][encode(w)]
33
+ end
34
+
35
+ private
36
+
37
+ require 'zlib'
38
+ java_import 'java.util.Base64'
39
+
40
+ def encode(input_string)
41
+ compressed_data = Zlib::Deflate.deflate(input_string)
42
+ encoder = Base64.getUrlEncoder()
43
+ encoder.encodeToString(compressed_data.to_java_bytes)
44
+ end
45
+
46
+ def decode(encoded_string)
47
+ decoder = Base64.getUrlDecoder()
48
+ compressed_data = decoder.decode(encoded_string)
49
+ Zlib::Inflate.inflate(String.from_java_bytes(compressed_data))
50
+ end
51
+
52
+
53
+ def sparql_query
54
+ <<-EOS
55
+ PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
56
+ PREFIX glycan: <http://purl.jp/bio/12/glyco/glycan#>
57
+
58
+ SELECT DISTINCT ?Saccharide ?WurcsSeq
59
+ WHERE {
60
+ GRAPH <http://rdf.glytoucan.org/core> {
61
+ ?Saccharide glycan:has_resource_entry ?ResEntry .
62
+ ?s glycan:has_resource_entry ?ResEntry .
63
+ }
64
+
65
+ ?Saccharide glycan:has_glycosequence ?GSeq .
66
+
67
+ GRAPH <http://rdf.glytoucan.org/sequence/wurcs> {
68
+ OPTIONAL {
69
+ ?GSeq glycan:has_sequence ?WurcsSeq .
70
+ }
71
+ }
72
+
73
+ FILTER NOT EXISTS {
74
+ GRAPH <http://rdf.glytoucan.org/archive> {
75
+ ?Saccharide rdf:type ?ArchiveSaccharide .
76
+ }
77
+ }
78
+ }
79
+ EOS
80
+ end
81
+
82
+ def fetch_glytoucan_data
83
+ hash1 = {}
84
+ hash2 = {}
85
+ api = 'https://ts.glytoucan.org/sparql?default-graph-uri=&query=' + URI.encode_www_form_component(sparql_query) + '&format=application%2Fsparql-results%2Bjson&timeout=0&signal_void=on'
86
+ response = JSON.parse(Net::HTTP.get(URI(api)))
87
+ response['results']['bindings'].map do |item|
88
+ id = URI(item['Saccharide']['value']).path.split('/').last
89
+ encode_wurcs = encode(item['WurcsSeq']['value'])
90
+ if hash1[id].nil?
91
+ hash1[id] = [encode_wurcs]
92
+ else
93
+ hash1[id].push(encode_wurcs)
94
+ end
95
+ if hash2[encode_wurcs].nil?
96
+ hash2[encode_wurcs] = [id]
97
+ else
98
+ hash2[encode_wurcs].push(id)
99
+ end
100
+ end
101
+ return {"wurcs" => hash1, "encode-wurcs-key" => hash2}
102
+ end
103
+
104
+ def save_glytoucan_data
105
+ data = fetch_glytoucan_data
106
+ File.write(@gtcfilepath, data.to_json)
107
+ data
108
+ end
109
+ end
110
+ end
@@ -21,6 +21,12 @@ java_import 'java.util.ArrayList'
21
21
  java_import 'java.io.StringWriter'
22
22
  java_import 'java.io.IOException'
23
23
  java_import 'java.io.StringReader'
24
+ java_import "org.openscience.cdk.interfaces.IAtomContainer"
25
+ java_import "org.openscience.cdk.smiles.SmilesParser"
26
+ java_import "org.glycoinfo.MolWURCS.exchange.toWURCS.MoleculeToWURCSGraph"
27
+ java_import "org.glycoinfo.WURCSFramework.util.WURCSFactory"
28
+ java_import "org.glycoinfo.WURCSFramework.wurcs.graph.WURCSGraph"
29
+ java_import "org.openscience.cdk.interfaces.IAtomContainer"
24
30
 
25
31
  module GlyDevKit
26
32
  class MolWURCS
@@ -41,6 +47,19 @@ class MolWURCS
41
47
  end
42
48
  end
43
49
 
50
+ def mol2wurcs(smiles)
51
+ parser = SmilesParser.new(DefaultChemObjectBuilder.getInstance)
52
+ molecule = parser.parseSmiles(smiles)
53
+ begin
54
+ graphs = MoleculeToWURCSGraph.new.start(molecule)
55
+ rescue StandardError => e
56
+ puts "An error occurred: #{e.message}"
57
+ puts "This method currently only supports up to WURCSFramework version 1.2.16. You need to downgrade the WURCSFramework using the command: `ruby -r init -e \'Init.switch_WFW_version(\"1.2.16\")\'`."
58
+ raise
59
+ end
60
+ factory = WURCSFactory.new(graphs[0])
61
+ return {"wurcs": factory.getWURCS(), "input": smiles}
62
+ end
44
63
  private
45
64
 
46
65
  # Reads WURCS and returns a molecule set
@@ -2,12 +2,22 @@ require 'java'
2
2
 
3
3
  module GlyDevKit
4
4
 
5
- class WurcsFrameWork
5
+ class WURCSFramework
6
6
 
7
- require_relative '../jar/wurcsframework.jar'
7
+ # Import the JAR file
8
+ require_relative '../jar/wurcsframework.jar'
8
9
  java_import 'org.glycoinfo.WURCSFramework.util.validation.WURCSValidator'
9
-
10
- def validator(w,maxbranch)
10
+
11
+ # Validates a WURCS data string.
12
+ #
13
+ # @param w [String] The WURCS string to be validated.
14
+ # @param maxbranch [Integer] The maximum allowed branch count for validation.
15
+ # @return [Hash] A hash containing the validation results, including any warnings, errors, and unverifiable issues.
16
+ #
17
+ # @example
18
+ # wurcs = "WURCS=2.0/3,5,4/[a2122h-1b_1-5_2*NCC/3=O][a1122h-1b_1-5][a1122h-1a_1-5]/1-1-2-3-3/a4-b1_b4-c1_c3-d1_c6-e1"
19
+ # result = validator(wurcs, 10)
20
+ def validator(w, maxbranch)
11
21
  validator = WURCSValidator.new
12
22
  validator.setMaxBranchCount(maxbranch)
13
23
  validator.start(w)
@@ -25,6 +35,11 @@ module GlyDevKit
25
35
  }
26
36
  end
27
37
 
38
+
39
+ # Converts WURCS data to a graph object.
40
+ #
41
+ # @param w [String] WURCS format data
42
+ # @return [Object, nil] Graph object or nil if an error occurs
28
43
  def to_graph(w)
29
44
  wgn = WURCSGraphNormalizer.new
30
45
  begin
@@ -38,6 +53,12 @@ module GlyDevKit
38
53
  end
39
54
  end
40
55
 
56
+ # Retrieves the anomeric status of a backbone.
57
+ # @param a_o_backbone [Backbone] The backbone object to evaluate.
58
+ # @return [String, nil] A string representing the anomeric status, or nil if it cannot be determined.
59
+ #
60
+ # @example
61
+ # status = get_anomeric_status(backbone)
41
62
  def get_anomeric_status(a_o_backbone)
42
63
  a_o_backbone.get_backbone_carbons.each do |t_o_bc|
43
64
  return "archetype_anomer" if %w[u U].include?(t_o_bc.get_descriptor.get_char.chr)
@@ -55,6 +76,11 @@ module GlyDevKit
55
76
  end
56
77
  end
57
78
 
79
+
80
+ # Retrieves the ring type of a backbone.
81
+ #
82
+ # @param a_o_backbone [Object] Backbone object
83
+ # @return [String, nil] Ring type as a string or nil if not applicable
58
84
  def get_ring_type(a_o_backbone)
59
85
  a_o_backbone.get_backbone_carbons.each do |t_o_bc|
60
86
  return "archetype_ringtype" if %w[u U].include?(t_o_bc.get_descriptor.get_char.chr)
@@ -79,6 +105,10 @@ module GlyDevKit
79
105
  nil
80
106
  end
81
107
 
108
+ # Calculates the mass of a WURCS data string.
109
+ #
110
+ # @param w [String] WURCS format data
111
+ # @return [Float, nil] Mass or nil if an error occurs
82
112
  def getWURCSMass(w)
83
113
  importer = WURCSImporter.new
84
114
  wurcs_array = importer.extractWURCSArray(w)
data/lib/glydevkit.rb CHANGED
@@ -5,10 +5,12 @@ require 'glydevkit/Loggerinit'
5
5
  require 'glydevkit/glycan_builder'
6
6
  require 'glydevkit/glycan_format_converter'
7
7
  require 'glydevkit/gly_tou_can'
8
+ require 'glydevkit/cdk'
9
+ require 'glydevkit/glytoucan_data_handler'
8
10
  require 'glydevkit/subsumption'
9
11
  require 'glydevkit/wurcs_frame_work'
10
12
  require 'glydevkit/mol_wurcs'
11
13
  require 'open-uri'
12
14
  require 'net/http'
13
15
  require 'fileutils'
14
- require 'yaml'
16
+ require 'yaml'
data/lib/init.rb CHANGED
@@ -2,34 +2,17 @@ require 'open-uri'
2
2
  require 'net/http'
3
3
  require 'fileutils'
4
4
  require 'yaml'
5
+ require 'digest'
6
+ require 'fileutils'
7
+ require 'terminal-table'
5
8
 
6
- module Init
7
- def self.load_settings(file_path, flag)
8
- downloads = []
9
-
10
- unless Dir.exist?(ENV['HOME'] + "/.glycobook")
11
- Dir.mkdir(ENV['HOME'] + "/.glycobook")
12
- end
13
-
14
- folder_path = File.dirname(__FILE__) + "/jar"
15
- unless Dir.exist?(folder_path)
16
- FileUtils.mkdir_p(folder_path)
17
- end
18
-
19
- if File.exist?(file_path)
20
- downloads = YAML.load_file(file_path)
21
- else
22
- FileUtils.cp(File.dirname(File.expand_path(__FILE__)) + "/../jar.yml", file_path)
23
- end
24
-
25
- if flag
26
- FileUtils.cp(File.dirname(File.expand_path(__FILE__)) + "/../jar.yml", file_path)
27
- downloads = YAML.load_file(file_path)
28
- end
29
9
 
30
- downloads
31
- end
10
+ module Init
32
11
 
12
+ # Runs the initialization process to resolve Java dependencies.
13
+ #
14
+ # Prompts the user for input on whether to resolve dependencies and set recommended versions.
15
+ # Downloads the necessary libraries based on the settings in the YAML file.
33
16
  def self.run
34
17
  puts <<-EOT
35
18
  Would you like to resolve Java dependencies? (No/yes)
@@ -56,7 +39,7 @@ Set recommended Java library version? (No/yes)
56
39
 
57
40
  downloads = load_settings(ENV['HOME'] + "/.glycobook/jar.yml", flag)
58
41
 
59
- # ダウンロードを実行する
42
+ # Execute the downloads
60
43
  downloads["libraries"].each do |download|
61
44
  url = URI(download["url"])
62
45
  http = Net::HTTP.new(url.host, url.port)
@@ -88,5 +71,121 @@ Set recommended Java library version? (No/yes)
88
71
  end
89
72
  end
90
73
  end
74
+
75
+ def self.switch_WFW_version(version)
76
+ base = File.dirname(__FILE__) + "/jar/"
77
+
78
+ source_file = File.join(base, "wurcsframework-#{version}.jar")
79
+ destination_file = File.join(base, "wurcsframework.jar")
80
+
81
+ if File.exist?(source_file)
82
+ begin
83
+ FileUtils.cp(source_file, destination_file)
84
+ puts "Switched to version #{version} successfully!"
85
+ rescue StandardError => e
86
+ puts "Failed to switch versions: #{e.message}"
87
+ end
88
+ else
89
+ puts "Source file #{source_file} does not exist."
90
+ end
91
+ end
92
+
93
+ def self.show_WFW_version()
94
+ target_file_path = File.dirname(__FILE__) + '/jar/wurcsframework.jar'
95
+ folder_path = File.dirname(__FILE__) + '/jar'
96
+
97
+ matching_files = find_matching_files(target_file_path, folder_path)
98
+
99
+ unless matching_files.empty?
100
+ matching_files.each do |file|
101
+ version = extract_version_from_filename(file)
102
+ if version
103
+ puts "version number: #{version}"
104
+ else
105
+ puts ""
106
+ end
107
+ end
108
+ end
109
+ end
110
+
111
+ def self.show_dependencies
112
+ yaml_data = File.read(Dir.home+'/.glycobook/jar.yml')
113
+ parsed_data = YAML.load(yaml_data)
114
+ rows = []
115
+ #rows.push(["name","version","Link"])
116
+ rows.push(["name","version"])
117
+ parsed_data["libraries"].each{|item|
118
+ #rows.push([item["name"].to_s , item["version"].to_s , item["info"].to_s ])
119
+ rows.push([item["name"].to_s , item["version"].to_s )
120
+ }
121
+ puts Terminal::Table.new rows: rows
91
122
  end
92
123
 
124
+ private
125
+ # Loads the settings from a YAML file and prepares the environment.
126
+ #
127
+ # @param file_path [String] The path to the settings file.
128
+ # @param flag [Boolean] Whether to use the recommended Java library version.
129
+ # @return [Array<Hash>] The list of downloads specified in the settings file.
130
+ def self.load_settings(file_path, flag)
131
+ downloads = []
132
+
133
+ unless Dir.exist?(ENV['HOME'] + "/.glycobook")
134
+ Dir.mkdir(ENV['HOME'] + "/.glycobook")
135
+ end
136
+
137
+ folder_path = File.dirname(__FILE__) + "/jar"
138
+ unless Dir.exist?(folder_path)
139
+ FileUtils.mkdir_p(folder_path)
140
+ end
141
+
142
+ if File.exist?(file_path)
143
+ downloads = YAML.load_file(file_path)
144
+ else
145
+ FileUtils.cp(File.dirname(File.expand_path(__FILE__)) + "/../jar.yml", file_path)
146
+ end
147
+
148
+ if flag
149
+ FileUtils.cp(File.dirname(File.expand_path(__FILE__)) + "/../jar.yml", file_path)
150
+ downloads = YAML.load_file(file_path)
151
+ end
152
+
153
+ downloads
154
+ end
155
+
156
+ def self.calculate_file_hash(file_path)
157
+ hash_func = Digest::SHA256.new
158
+ begin
159
+ File.open(file_path, 'rb') do |file|
160
+ while chunk = file.read(8192)
161
+ hash_func.update(chunk)
162
+ end
163
+ end
164
+ rescue IOError => e
165
+ puts "ファイルの読み込み中にエラーが発生しました: #{file_path}, エラー: #{e}"
166
+ return nil
167
+ end
168
+ hash_func.hexdigest
169
+ end
170
+
171
+ def self.find_matching_files(target_file_path, folder_path)
172
+ target_file_hash = calculate_file_hash(target_file_path)
173
+ return unless target_file_hash
174
+
175
+ matching_files = Dir.glob("#{folder_path}/**/*").select do |file_path|
176
+ next unless File.file?(file_path)
177
+ next if File.identical?(target_file_path, file_path)
178
+
179
+ file_hash = calculate_file_hash(file_path)
180
+ file_hash == target_file_hash unless file_hash.nil?
181
+ end
182
+
183
+ matching_files
184
+ end
185
+
186
+ def self.extract_version_from_filename(filename)
187
+ match_data = filename.match(/-(\d+\.\d+\.\d+)\.jar$/)
188
+ match_data ? match_data[1] : nil
189
+ end
190
+
191
+ end
data/lib/wurcsverify.rb CHANGED
@@ -17,6 +17,10 @@ class WurcsVerify
17
17
  @@v130 = "1.3.0"
18
18
  @@v131 = "1.3.1"
19
19
 
20
+ # Initializes the WurcsVerify class.
21
+ #
22
+ # Sets up custom class loaders for different versions of the WURCS Framework.
23
+ # Loads the WURCSValidator classes for each version.
20
24
  def initialize
21
25
  @wfw_glytoucan_loader = self.create_custom_classloader("jar/wurcsframework-" + @@gtc_version + ".jar")
22
26
  @wfw_v131_loader = self.create_custom_classloader("jar/wurcsframework-" + @@v131 + ".jar")
@@ -30,13 +34,22 @@ class WurcsVerify
30
34
  @validator_v1215 = java.lang.Class.forName("org.glycoinfo.WURCSFramework.util.validation.WURCSValidator", true, @wfw_v1215_loader)
31
35
  end
32
36
 
37
+ # Creates a custom class loader for a given JAR file.
38
+ #
39
+ # @param jar_path [String] The path to the JAR file.
40
+ # @return [URLClassLoader] The custom class loader.
33
41
  def create_custom_classloader(jar_path)
34
42
  absolute_path = File.dirname(File.expand_path(__FILE__)) + "/" + jar_path
35
43
  url = URL.new("file:#{absolute_path}")
36
44
  URLClassLoader.newInstance([url].to_java(URL), java.lang.Thread.currentThread.getContextClassLoader)
37
45
  end
38
46
 
39
- def validatorVerify(w,style)
47
+ # Verifies the WURCS string using different versions of the WURCS Framework.
48
+ #
49
+ # @param w [String] The WURCS string to verify.
50
+ # @param style [String] The verification style ("v3" or "wfw").
51
+ # @return [Hash] The verification results.
52
+ def validatorVerify(w, style)
40
53
  v_glytoucan = @validator_glytoucan.new_instance
41
54
  v_glytoucan.start(w)
42
55
 
@@ -53,18 +66,20 @@ class WurcsVerify
53
66
  v_1215.start(w)
54
67
 
55
68
  if (style == "v3")
56
- ret = {@@gtc_version => self.dovalidatorv3(v_glytoucan,@@gtc_version),
57
- @@v131 => self.dovalidatorv3(v_131, @@v131),
58
- @@v130 => self.dovalidatorv3(v_130, @@v130),
69
+ ret = {
70
+ @@gtc_version => self.dovalidatorv3(v_glytoucan, @@gtc_version),
71
+ @@v131 => self.dovalidatorv3(v_131, @@v131),
72
+ @@v130 => self.dovalidatorv3(v_130, @@v130),
59
73
  @@v1215 => self.dovalidatorv3(v_1215, @@v1215),
60
74
  @@v1216 => self.dovalidatorv3(v_1216, @@v1216)
61
75
  }
62
76
  elsif (style == "wfw")
63
- ret = {@@gtc_version => self.dovalidator(v_glytoucan,@@gtc_version),
64
- @@v131 => self.dovalidator(v_131, @@v131),
65
- @@v130 => self.dovalidator(v_130, @@v130),
66
- @@v1215 => self.dovalidator(v_1215, @@v1215),
67
- @@v1216 => self.dovalidator(v_1216, @@v1216)
77
+ ret = {
78
+ @@gtc_version => self.dovalidator(v_glytoucan, @@gtc_version),
79
+ @@v131 => self.dovalidator(v_131, @@v131),
80
+ @@v130 => self.dovalidator(v_130, @@v130),
81
+ @@v1215 => self.dovalidator(v_1215, @@v1215),
82
+ @@v1216 => self.dovalidator(v_1216, @@v1216)
68
83
  }
69
84
  else
70
85
  pp "strange second paramerters"
@@ -72,23 +87,40 @@ class WurcsVerify
72
87
  return ret
73
88
  end
74
89
 
75
- def dovalidatorv3(validator,version)
90
+ # Performs validation and returns detailed reports for v3 style.
91
+ #
92
+ # @param validator [Object] The validator instance.
93
+ # @param version [String] The version of the WURCS Framework.
94
+ # @return [Hash] The validation report.
95
+ def dovalidatorv3(validator, version)
76
96
  if validator.getReport().respond_to?(:isStandardized)
77
97
  flag = validator.getReport().isStandardized()
78
98
  else
79
99
  flag = "undef"
80
100
  end
81
- reports = { "VALIDATOR" => ["WURCSFramework-" + version],
82
- "WARNING" => validator.getReport().hasWarning(),
83
- "FLAG" => flag,
84
- "ERROR" => validator.getReport().hasError(),
85
- "UNVERIFIABLE" => validator.getReport().hasUnverifiable() }
86
- return {"message" => reports,
87
- "StandardWURCS" => validator.getReport().standard_string(),
88
- "RESULTS" => validator.getReport().getResults() }
101
+ reports = {
102
+ "VALIDATOR" => ["WURCSFramework-" + version],
103
+ "WARNING" => validator.getReport().hasWarning(),
104
+ "FLAG" => flag,
105
+ "ERROR" => validator.getReport().hasError(),
106
+ "UNVERIFIABLE" => validator.getReport().hasUnverifiable()
107
+ }
108
+ return {
109
+ "message" => reports,
110
+ "StandardWURCS" => validator.getReport().standard_string(),
111
+ "RESULTS" => validator.getReport().getResults()
112
+ }
89
113
  end
90
- def dovalidator(validator,version)
91
- return {"VALIDATOR" => ["WURCSFramework-" + version],
92
- "Report" => validator.getReport().getResults()}
114
+
115
+ # Performs validation and returns basic reports.
116
+ #
117
+ # @param validator [Object] The validator instance.
118
+ # @param version [String] The version of the WURCS Framework.
119
+ # @return [Hash] The validation report.
120
+ def dovalidator(validator, version)
121
+ return {
122
+ "VALIDATOR" => ["WURCSFramework-" + version],
123
+ "Report" => validator.getReport().getResults()
124
+ }
93
125
  end
94
126
  end
metadata CHANGED
@@ -1,22 +1,22 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glydevkit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.beta.1
4
+ version: 0.2.0
5
5
  platform: java
6
6
  authors:
7
7
  - Akihiro Fujita
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-08-27 00:00:00.000000000 Z
11
+ date: 2024-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
+ name: java
14
15
  requirement: !ruby/object:Gem::Requirement
15
16
  requirements:
16
17
  - - "~>"
17
18
  - !ruby/object:Gem::Version
18
19
  version: 0.0.2
19
- name: java
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
@@ -24,7 +24,49 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.0.2
27
- description: The Glycoscience Development Kit (GlyDevKit) is a JRuby library for glycaninformatics
27
+ - !ruby/object:Gem::Dependency
28
+ name: yaml
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: terminal-table
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: colorize
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: The Glycoscience Development Kit (GlyDevKit) is a JRuby library for glyco-informatics
28
70
  email:
29
71
  - akihirof0005@gmail.com
30
72
  executables: []
@@ -34,9 +76,11 @@ files:
34
76
  - jar.yml
35
77
  - lib/glydevkit.rb
36
78
  - lib/glydevkit/Loggerinit.rb
79
+ - lib/glydevkit/cdk.rb
37
80
  - lib/glydevkit/gly_tou_can.rb
38
81
  - lib/glydevkit/glycan_builder.rb
39
82
  - lib/glydevkit/glycan_format_converter.rb
83
+ - lib/glydevkit/glytoucan_data_handler.rb
40
84
  - lib/glydevkit/mol_wurcs.rb
41
85
  - lib/glydevkit/subsumption.rb
42
86
  - lib/glydevkit/wurcs_frame_work.rb
@@ -48,7 +92,8 @@ licenses:
48
92
  metadata:
49
93
  source_code_uri: https://github.com/akihirof0005/glydevkit
50
94
  homepage_uri: https://github.com/akihirof0005/glydevkit/blob/main/README.md
51
- changelog_uri: https://github.com/akihirof0005/glycobooks
95
+ changelog_uri: https://github.com/akihirof0005/glydevkit
96
+ documentation: https://akihirof0005.github.io/glydevkit/index.html
52
97
  post_install_message:
53
98
  rdoc_options: []
54
99
  require_paths:
@@ -64,8 +109,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
64
109
  - !ruby/object:Gem::Version
65
110
  version: '0'
66
111
  requirements: []
67
- rubygems_version: 3.5.6
112
+ rubygems_version: 3.5.22
68
113
  signing_key:
69
114
  specification_version: 4
70
- summary: The Glycoscience Development Kit (GlyDevKit) is a JRuby library for glycaninformatics
115
+ summary: The Glycoscience Development Kit (GlyDevKit) is a JRuby library for glyco-informatics
71
116
  test_files: []