glydevkit 0.2.0.pre.beta.3-java → 0.2.0.pre.beta.4-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: 1af9e073bb01829204d62aa99b527a421ab3c44cf01ff34aca8d757a22d43bb7
4
+ data.tar.gz: a639692f34e5d2c99fc18967dc3f1f3d02790584b272e737df1cbe69d6dbfad1
5
5
  SHA512:
6
- metadata.gz: 2127c1b0b02039ffad57f603152b14bc644f73ea17a6a2ff26b4725b44ca8a5df17cee9b220d13ab507c28e715ab1f00c36b8af2d5ee59c37b863ddb03f6e071
7
- data.tar.gz: 0e636a9fb70ceaac43e60caa4e5378ea0ae7b6691fd8840047ec03ad563d0e9f40d3052edf3e119c451c4a5506d14215857bc7877869b8c21411d4594c595282
6
+ metadata.gz: bfc94222a42b893911f7865be8823b73a30dbce0090349fa3692b67e25eae7924b38ac3a2867833ec8b3b9a696eb262a39de5c4a8f147c6cacd5d639832e3eb0
7
+ data.tar.gz: 82ffbf1270ee2235c5785e812ce41779e01933aba7952e040a309864333ce3beca14e6ece778625731dc32fdb7c3230485cfee9cc3a0aa5f0dda096c5d63be2c
@@ -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,7 @@ 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/glytoucan_data_handler'
8
9
  require 'glydevkit/subsumption'
9
10
  require 'glydevkit/wurcs_frame_work'
10
11
  require 'glydevkit/mol_wurcs'
data/lib/init.rb CHANGED
@@ -2,6 +2,9 @@ require 'open-uri'
2
2
  require 'net/http'
3
3
  require 'fileutils'
4
4
  require 'yaml'
5
+ require 'digest'
6
+ require 'fileutils'
7
+
5
8
 
6
9
  module Init
7
10
 
@@ -67,7 +70,44 @@ Set recommended Java library version? (No/yes)
67
70
  end
68
71
  end
69
72
  end
73
+
74
+ def self.switch_WFW_version(version)
75
+ base = File.dirname(__FILE__) + "/jar/"
76
+
77
+ source_file = File.join(base, "wurcsframework-#{version}.jar")
78
+ destination_file = File.join(base, "wurcsframework.jar")
79
+
80
+ if File.exist?(source_file)
81
+ begin
82
+ FileUtils.cp(source_file, destination_file)
83
+ puts "Switched to version #{version} successfully!"
84
+ rescue StandardError => e
85
+ puts "Failed to switch versions: #{e.message}"
86
+ end
87
+ else
88
+ puts "Source file #{source_file} does not exist."
89
+ end
90
+ end
91
+
92
+ def self.check_WFW_version()
93
+ target_file_path = File.dirname(__FILE__) + '/jar/wurcsframework.jar'
94
+ folder_path = File.dirname(__FILE__) + '/jar'
95
+
96
+ matching_files = find_matching_files(target_file_path, folder_path)
97
+
98
+ unless matching_files.empty?
99
+ matching_files.each do |file|
100
+ version = extract_version_from_filename(file)
101
+ if version
102
+ puts "version number: #{version}"
103
+ else
104
+ puts ""
105
+ end
106
+ end
107
+ end
108
+ end
70
109
 
110
+ private
71
111
  # Loads the settings from a YAML file and prepares the environment.
72
112
  #
73
113
  # @param file_path [String] The path to the settings file.
@@ -98,4 +138,40 @@ Set recommended Java library version? (No/yes)
98
138
 
99
139
  downloads
100
140
  end
101
- end
141
+
142
+ def self.calculate_file_hash(file_path)
143
+ hash_func = Digest::SHA256.new
144
+ begin
145
+ File.open(file_path, 'rb') do |file|
146
+ while chunk = file.read(8192)
147
+ hash_func.update(chunk)
148
+ end
149
+ end
150
+ rescue IOError => e
151
+ puts "ファイルの読み込み中にエラーが発生しました: #{file_path}, エラー: #{e}"
152
+ return nil
153
+ end
154
+ hash_func.hexdigest
155
+ end
156
+
157
+ def self.find_matching_files(target_file_path, folder_path)
158
+ target_file_hash = calculate_file_hash(target_file_path)
159
+ return unless target_file_hash
160
+
161
+ matching_files = Dir.glob("#{folder_path}/**/*").select do |file_path|
162
+ next unless File.file?(file_path)
163
+ next if File.identical?(target_file_path, file_path)
164
+
165
+ file_hash = calculate_file_hash(file_path)
166
+ file_hash == target_file_hash unless file_hash.nil?
167
+ end
168
+
169
+ matching_files
170
+ end
171
+
172
+ def self.extract_version_from_filename(filename)
173
+ match_data = filename.match(/-(\d+\.\d+\.\d+)\.jar$/)
174
+ match_data ? match_data[1] : nil
175
+ end
176
+
177
+ 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.4
5
5
  platform: java
6
6
  authors:
7
7
  - Akihiro Fujita
@@ -24,7 +24,7 @@ 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
+ description: The Glycoscience Development Kit (GlyDevKit) is a JRuby library for glyco-informatics
28
28
  email:
29
29
  - akihirof0005@gmail.com
30
30
  executables: []
@@ -37,6 +37,7 @@ files:
37
37
  - lib/glydevkit/gly_tou_can.rb
38
38
  - lib/glydevkit/glycan_builder.rb
39
39
  - lib/glydevkit/glycan_format_converter.rb
40
+ - lib/glydevkit/glytoucan_data_handler.rb
40
41
  - lib/glydevkit/mol_wurcs.rb
41
42
  - lib/glydevkit/subsumption.rb
42
43
  - lib/glydevkit/wurcs_frame_work.rb
@@ -65,8 +66,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
65
66
  - !ruby/object:Gem::Version
66
67
  version: '0'
67
68
  requirements: []
68
- rubygems_version: 3.5.18
69
+ rubygems_version: 3.5.22
69
70
  signing_key:
70
71
  specification_version: 4
71
- summary: The Glycoscience Development Kit (GlyDevKit) is a JRuby library for glycaninformatics
72
+ summary: The Glycoscience Development Kit (GlyDevKit) is a JRuby library for glyco-informatics
72
73
  test_files: []