glycobook 0.1.0.alpha.22-java → 0.1.0.alpha.23-java

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c30b663e17567babecd2deaee54be71f43e7fc30452bff1dbbd751156a5e07fb
4
- data.tar.gz: 9e1c862ce6ff0b91391338d4b42953ea2e53b05265550b4bccb4b1449d8bd3d0
3
+ metadata.gz: 54291cdf1cc15d9494b5f931527624edea2b22e4406b86a5e2da164c34928d6d
4
+ data.tar.gz: ceabbea0e098bd5d424d9d2379f1014869242517179a26b04e4d12865bc4a63d
5
5
  SHA512:
6
- metadata.gz: e156bf8df3954c0f29a926fe00ee122ba4ef8e3eda04fe7d9d02f624abd6b6abefd2faef729de5ad8f037ba09356a9b84fcb63c358ed3637cfd0c488cb7bd18d
7
- data.tar.gz: 9a873652978c7c9bca1dcd975ad7afb6fd4f87d913973f860e46eb4499bac1dd3756cca68ccd9205210359b60d72e34daac383c7fbaae5594ebdebef5553efa8
6
+ metadata.gz: 711e5450c4a6db15dc122620ce179a995260a1203c36d929f922e592ff6b585716ae0513ebec06dc933d7ced9d34ed1450e9853afe0e28c6e8dd6614f1031ecd
7
+ data.tar.gz: ab7f7c353eb54c5047cbb64b4ff6e51fade4fed1bc7fa95afa7ac597ec9bced8c007cbd9dac8ae627d940367f9ecd17830d1d6bb98f8468761420927f7060293
@@ -10,18 +10,18 @@ class JRubySLF4JLogger < Logger
10
10
  super(STDOUT) # STDOUT is dummy
11
11
  @java_logger = LoggerFactory.getLogger(name)
12
12
  end
13
- def add(severity, progname , message, &block)
13
+ def add(severity, message, progname, &block)
14
14
 
15
15
  message = block.call if block
16
16
  message = message.to_s
17
17
 
18
18
  case severity
19
19
  when 0 # Logger::DEBUG
20
- @java_logger.debug(message)
20
+ @java_logger.info(message)
21
21
  when 1 # Logger::INFO
22
22
  @java_logger.info(message)
23
23
  when 2 # Logger::WARN
24
- @java_logger.warn(message)
24
+ @java_logger.info(message)
25
25
  when 3, 4# Logger::ERROR, Logger::FATAL
26
26
  @java_logger.error(message)
27
27
  else
@@ -11,6 +11,7 @@ java_import 'org.openscience.cdk.io.ISimpleChemObjectReader'
11
11
  java_import 'org.openscience.cdk.silent.AtomContainerSet'
12
12
  java_import 'org.openscience.cdk.DefaultChemObjectBuilder'
13
13
  java_import 'org.openscience.cdk.io.SDFWriter'
14
+ java_import 'org.openscience.cdk.smiles.SmiFlavor'
14
15
  java_import 'org.openscience.cdk.smiles.SmilesGenerator'
15
16
  java_import 'org.openscience.cdk.silent.SilentChemObjectBuilder'
16
17
  java_import 'java.io.StringReader'
@@ -22,60 +23,81 @@ java_import 'java.util.ArrayList'
22
23
  java_import 'java.io.StringWriter'
23
24
 
24
25
  module GlycoBook
25
- class MolWURCS
26
+ class MolWURCS
27
+ def wurcs2mol(w, format)
28
+ mols = read_wurcs(w)
29
+ return {"flag": false,"wurcs": w, "message": "WURCS strings that could not be parsed to the atomic level"} if mols.nil?
26
30
 
27
- def wurcs2mol(w,format)
31
+ case format
32
+ when "sdf"
33
+ {"wurcs": w}.merge(export_to_sdf(mols))
34
+ when "smiles"
35
+ {"wurcs": w}.merge(export_to_smiles(mols))
36
+ else
37
+ {"flag": false,"wurcs": w, "#{format}": "", "message": "Undefined format"}
38
+ end
39
+ end
28
40
 
29
- begin
30
- reader = ChemFormatType::WURCS.createReader
31
- reader.setReader(StringReader.new(w))
32
- return unless reader.accepts(AtomContainerSet.java_class)
33
- mols = AtomContainerSet.new
34
- mols = reader.read(mols)
35
- reader.close
36
- rescue CDKException, IOException => e
37
- e.printStackTrace()
38
- end
41
+ private
42
+
43
+ # Reads WURCS and returns a molecule set
44
+ def read_wurcs(w)
45
+ begin
46
+ reader = ChemFormatType::WURCS.createReader
47
+ reader.setReader(StringReader.new(w))
48
+ return nil unless reader.accepts(AtomContainerSet.java_class)
49
+ mols = reader.read(AtomContainerSet.new)
50
+ reader.close
51
+ mols
52
+ rescue CDKException, IOException => e
53
+ e.printStackTrace
54
+ nil
55
+ end
56
+ end
57
+
58
+ # Exports molecule set to SDF format
59
+ def export_to_sdf(mols)
60
+ string_writer = StringWriter.new
61
+ begin
62
+ writer = SDFWriter.new(string_writer)
63
+ write_molecule_set(mols, writer)
64
+ {"sdf": string_writer.to_s}
65
+ rescue CDKException, IOException => e
66
+ e.printStackTrace
67
+ {"flag": false,"sdf": "", "message": e.message}
68
+ end
69
+ end
39
70
 
40
- return if mols.nil?
41
- if format == "sdf"
42
- # write mol
43
- string_writer = java.io.StringWriter.new
71
+ # Exports molecule set to SMILES format
72
+ def export_to_smiles(mols)
73
+ smiles_gen = SmilesGenerator.new(SmiFlavor::Isomeric)
74
+ string_writer = StringWriter.new
75
+ begin
76
+ mols.atomContainers.each do |mol|
77
+ smiles = smiles_gen.create(mol)
78
+ string_writer.write(smiles)
79
+ end
80
+ smiles = string_writer.toString
81
+ if (smiles == "")
82
+ {"flag": false,"smiles": smiles, "message": "the case of successfully converted to empty characters in the library"}
83
+ else
84
+ {"flag": true,"smiles": smiles}
85
+ end
86
+ rescue CDKException, IOException => e
87
+ e.printStackTrace
88
+ {"flag": false,"smiles": "", "message": e.message}
89
+ end
90
+ end
44
91
 
45
- begin
46
- writer = org.openscience.cdk.io.SDFWriter.new(string_writer)
92
+ # Writes molecule set using provided writer
93
+ def write_molecule_set(mols, writer)
47
94
  if writer.accepts(mols.java_class)
48
95
  writer.write(mols)
49
96
  elsif writer.accepts(mols.get_atom_container(0).java_class)
50
97
  writer.write(mols.get_atom_container(0))
51
98
  end
52
99
  writer.close
53
- rescue Java::OrgOpenscienceCdkException::CDKException, Java::JavaIo::IOException => e
54
- e.printStackTrace()
55
100
  end
56
101
 
57
- return string_writer.to_s
58
-
59
- elsif format == "smiles"
60
- # SMILESジェネレータの生成
61
- smiles_gen = SmilesGenerator.absolute()
62
-
63
- string_writer = java.io.StringWriter.new
64
-
65
- begin
66
- mols.atomContainers.each do |mol|
67
- # 各分子に対してSMILES表現の生成
68
- smiles = smiles_gen.createSMILES(mol)
69
- string_writer.write(smiles + "\n")
70
- end
71
-
72
- # 生成したSMILESの出力
73
- return string_writer.toString
74
- rescue Java::OrgOpenscienceCdkException::CDKException, Java::JavaIo::IOException => e
75
- e.printStackTrace()
76
- return ""
77
- end
78
102
  end
79
103
  end
80
- end
81
- end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glycobook
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.alpha.22
4
+ version: 0.1.0.alpha.23
5
5
  platform: java
6
6
  authors:
7
7
  - Akihiro Fujita
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-21 00:00:00.000000000 Z
11
+ date: 2023-11-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -17,8 +17,8 @@ dependencies:
17
17
  - !ruby/object:Gem::Version
18
18
  version: 0.0.2
19
19
  name: java
20
- prerelease: false
21
20
  type: :runtime
21
+ prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
@@ -64,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
64
64
  - !ruby/object:Gem::Version
65
65
  version: 1.3.1
66
66
  requirements: []
67
- rubygems_version: 3.2.33
67
+ rubygems_version: 3.4.22
68
68
  signing_key:
69
69
  specification_version: 4
70
70
  summary: Glycobook is a JRuby library for glycaninformatics