glydevkit 0.2.0.pre.beta.3-java → 0.2.0.pre.beta.5-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: 9856e9002c021a262dca282c8b739e04e11c463827508692ed0efeb99861c4ac
4
- data.tar.gz: 56d06305cde3e9996f5448d116b3da478ed2f08c94b35210f7e882c354e3d626
3
+ metadata.gz: d0da30a2e521fae84bf371cdd61851281e7130d6489d4aa4feb5bf012b63805d
4
+ data.tar.gz: 10216bee959df9fcfa6bf6fc7739ec44b4df0044cb4af79c1c05656fc119f871
5
5
  SHA512:
6
- metadata.gz: 2127c1b0b02039ffad57f603152b14bc644f73ea17a6a2ff26b4725b44ca8a5df17cee9b220d13ab507c28e715ab1f00c36b8af2d5ee59c37b863ddb03f6e071
7
- data.tar.gz: 0e636a9fb70ceaac43e60caa4e5378ea0ae7b6691fd8840047ec03ad563d0e9f40d3052edf3e119c451c4a5506d14215857bc7877869b8c21411d4594c595282
6
+ metadata.gz: f176a08059f508e695ff75125e28e4487b99b89f34f1d79521f05d5f1a0e94f00884b28ee7edcb7c91e5d482d7be88ce6973ba8cf32fe54609c765de078013dd
7
+ data.tar.gz: 2028230f807361373c1bbb0d89eca163a3f929e80ff795e38093dfbe49957ef2f01720a1f50c2487ebb9fd4335c976e4e57ea97bc8b426a097f682a6d8d1c252
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,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
data/lib/glydevkit.rb CHANGED
@@ -5,6 +5,8 @@ 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'
data/lib/init.rb CHANGED
@@ -2,6 +2,10 @@ 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'
8
+
5
9
 
6
10
  module Init
7
11
 
@@ -67,7 +71,55 @@ Set recommended Java library version? (No/yes)
67
71
  end
68
72
  end
69
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
70
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
+ parsed_data["libraries"].each{|item|
117
+ rows.push([item["name"].to_s , item["version"].to_s , item["info"].to_s ])
118
+ }
119
+ puts Terminal::Table.new rows: rows
120
+ end
121
+
122
+ private
71
123
  # Loads the settings from a YAML file and prepares the environment.
72
124
  #
73
125
  # @param file_path [String] The path to the settings file.
@@ -98,4 +150,40 @@ Set recommended Java library version? (No/yes)
98
150
 
99
151
  downloads
100
152
  end
101
- end
153
+
154
+ def self.calculate_file_hash(file_path)
155
+ hash_func = Digest::SHA256.new
156
+ begin
157
+ File.open(file_path, 'rb') do |file|
158
+ while chunk = file.read(8192)
159
+ hash_func.update(chunk)
160
+ end
161
+ end
162
+ rescue IOError => e
163
+ puts "ファイルの読み込み中にエラーが発生しました: #{file_path}, エラー: #{e}"
164
+ return nil
165
+ end
166
+ hash_func.hexdigest
167
+ end
168
+
169
+ def self.find_matching_files(target_file_path, folder_path)
170
+ target_file_hash = calculate_file_hash(target_file_path)
171
+ return unless target_file_hash
172
+
173
+ matching_files = Dir.glob("#{folder_path}/**/*").select do |file_path|
174
+ next unless File.file?(file_path)
175
+ next if File.identical?(target_file_path, file_path)
176
+
177
+ file_hash = calculate_file_hash(file_path)
178
+ file_hash == target_file_hash unless file_hash.nil?
179
+ end
180
+
181
+ matching_files
182
+ end
183
+
184
+ def self.extract_version_from_filename(filename)
185
+ match_data = filename.match(/-(\d+\.\d+\.\d+)\.jar$/)
186
+ match_data ? match_data[1] : nil
187
+ end
188
+
189
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glydevkit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0.pre.beta.3
4
+ version: 0.2.0.pre.beta.5
5
5
  platform: java
6
6
  authors:
7
7
  - Akihiro Fujita
@@ -11,20 +11,48 @@ cert_chain: []
11
11
  date: 2024-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: java
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
16
  - - "~>"
18
17
  - !ruby/object:Gem::Version
19
18
  version: 0.0.2
20
- type: :runtime
19
+ name: java
21
20
  prerelease: false
21
+ type: :runtime
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
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
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ name: yaml
34
+ prerelease: false
35
+ type: :runtime
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ name: terminal-table
48
+ prerelease: false
49
+ type: :runtime
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: The Glycoscience Development Kit (GlyDevKit) is a JRuby library for glyco-informatics
28
56
  email:
29
57
  - akihirof0005@gmail.com
30
58
  executables: []
@@ -37,6 +65,7 @@ files:
37
65
  - lib/glydevkit/gly_tou_can.rb
38
66
  - lib/glydevkit/glycan_builder.rb
39
67
  - lib/glydevkit/glycan_format_converter.rb
68
+ - lib/glydevkit/glytoucan_data_handler.rb
40
69
  - lib/glydevkit/mol_wurcs.rb
41
70
  - lib/glydevkit/subsumption.rb
42
71
  - lib/glydevkit/wurcs_frame_work.rb
@@ -61,12 +90,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
61
90
  version: '0'
62
91
  required_rubygems_version: !ruby/object:Gem::Requirement
63
92
  requirements:
64
- - - ">="
93
+ - - ">"
65
94
  - !ruby/object:Gem::Version
66
- version: '0'
95
+ version: 1.3.1
67
96
  requirements: []
68
- rubygems_version: 3.5.18
97
+ rubygems_version: 3.3.26
69
98
  signing_key:
70
99
  specification_version: 4
71
- summary: The Glycoscience Development Kit (GlyDevKit) is a JRuby library for glycaninformatics
100
+ summary: The Glycoscience Development Kit (GlyDevKit) is a JRuby library for glyco-informatics
72
101
  test_files: []