glycobook 0.1.0.alpha.21-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: 3a227432de6774f55812c86238f8d902f4828eabb6b6b43492df5039e19f0817
4
- data.tar.gz: 1b78af14d379b5761825836a9c3a55ef6e51e21261982226101aa16746b8da63
3
+ metadata.gz: 54291cdf1cc15d9494b5f931527624edea2b22e4406b86a5e2da164c34928d6d
4
+ data.tar.gz: ceabbea0e098bd5d424d9d2379f1014869242517179a26b04e4d12865bc4a63d
5
5
  SHA512:
6
- metadata.gz: 1a2321e9a25ff82ed4b05b863d615a89666e17baf4c71c4316be00694c5008c7f12ddddec8621a0ab469ec7dda8e0f73d063e54c225b6587fd6c17a74c26edec
7
- data.tar.gz: baed8895eda5734856a734bc84cbe53703c8639ddf25f985ee4b734b71f968eea4e9a1c01192ee33fe8b6f4d8083a746d405b7d35c954e9c6a794f3e28146e1f
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
@@ -9,48 +9,95 @@ java_import 'org.openscience.cdk.interfaces.IAtomContainerSet'
9
9
  java_import 'org.openscience.cdk.io.IChemObjectWriter'
10
10
  java_import 'org.openscience.cdk.io.ISimpleChemObjectReader'
11
11
  java_import 'org.openscience.cdk.silent.AtomContainerSet'
12
+ java_import 'org.openscience.cdk.DefaultChemObjectBuilder'
13
+ java_import 'org.openscience.cdk.io.SDFWriter'
14
+ java_import 'org.openscience.cdk.smiles.SmiFlavor'
15
+ java_import 'org.openscience.cdk.smiles.SmilesGenerator'
16
+ java_import 'org.openscience.cdk.silent.SilentChemObjectBuilder'
12
17
  java_import 'java.io.StringReader'
13
18
  java_import 'java.nio.file.Files'
14
19
  java_import 'java.nio.file.Paths'
15
20
  java_import 'java.io.IOException'
16
21
  java_import 'java.lang.System'
17
22
  java_import 'java.util.ArrayList'
23
+ java_import 'java.io.StringWriter'
18
24
 
19
25
  module GlycoBook
20
- class MolWURCS
21
-
22
- def wurcs2mdlmol(w)
23
-
24
- begin
25
- reader = ChemFormatType::WURCS.createReader
26
- reader.setReader(StringReader.new(w))
27
- return unless reader.accepts(AtomContainerSet.java_class)
28
- mols = AtomContainerSet.new
29
- mols = reader.read(mols)
30
- reader.close
31
- rescue CDKException, IOException => e
32
- e.printStackTrace()
33
- end
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?
34
30
 
35
- return if mols.nil?
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
36
40
 
37
- # write mol
38
- string_writer = java.io.StringWriter.new
41
+ private
39
42
 
40
- begin
41
- writer = org.openscience.cdk.io.SDFWriter.new(string_writer)
42
- if writer.accepts(mols.java_class)
43
- writer.write(mols)
44
- elsif writer.accepts(mols.get_atom_container(0).java_class)
45
- writer.write(mols.get_atom_container(0))
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
46
56
  end
47
- writer.close
48
- rescue Java::OrgOpenscienceCdkException::CDKException, Java::JavaIo::IOException => e
49
- e.printStackTrace()
50
- end
51
57
 
52
- return string_writer.to_s
53
- end
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
54
70
 
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
91
+
92
+ # Writes molecule set using provided writer
93
+ def write_molecule_set(mols, writer)
94
+ if writer.accepts(mols.java_class)
95
+ writer.write(mols)
96
+ elsif writer.accepts(mols.get_atom_container(0).java_class)
97
+ writer.write(mols.get_atom_container(0))
98
+ end
99
+ writer.close
100
+ end
101
+
102
+ end
55
103
  end
56
- 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.21
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-20 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.3.26
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