rbbt-util 5.35.1 → 5.35.2
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 +4 -4
- data/lib/rbbt/util/python/util.rb +19 -0
- data/lib/rbbt/util/python.rb +80 -10
- data/test/rbbt/util/python/test_util.rb +8 -0
- data/test/rbbt/util/test_python.rb +50 -0
- metadata +87 -87
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7fc87aa89e132735c535df80f34cfd0f31fb44475d55d08fb194ee50e045f884
|
4
|
+
data.tar.gz: e1c380d68af04bd683a3a06e675b6e8744497869d95ac96620e7864f05e8aeb7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dd65fb3be5c880288fa1718d6a2327d1e799f7c9b415785cdcb5f1cd9d18d02664347e6dc16dde2a78d727ab86ab292d272fc2a608ea7a9a1eb7c0e88f213131
|
7
|
+
data.tar.gz: 603ca603814e8405dcc88ed0a499ddb92658d2831887d8c8110ba60737a83317ee7d68e00a3b51a48734a6bb90f2539d654169b07a8609a60fe02351d8426394
|
@@ -31,4 +31,23 @@ module RbbtPython
|
|
31
31
|
tsv
|
32
32
|
end
|
33
33
|
|
34
|
+
def self.list2ruby(list)
|
35
|
+
return list unless PyCall::List === list
|
36
|
+
list.collect do |e|
|
37
|
+
list2ruby(e)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.numpy2ruby(numpy)
|
42
|
+
list2ruby(numpy.tolist)
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.obj2hash(obj)
|
46
|
+
hash = {}
|
47
|
+
RbbtPython.iterate obj.keys do |k|
|
48
|
+
hash[k] = obj[k]
|
49
|
+
end
|
50
|
+
hash
|
51
|
+
end
|
52
|
+
|
34
53
|
end
|
data/lib/rbbt/util/python.rb
CHANGED
@@ -5,6 +5,16 @@ require 'rbbt/util/python/util'
|
|
5
5
|
module RbbtPython
|
6
6
|
extend PyCall::Import
|
7
7
|
|
8
|
+
class RbbtPythonException < StandardError; end
|
9
|
+
|
10
|
+
class Binding
|
11
|
+
include PyCall::Import
|
12
|
+
|
13
|
+
def run(*args, &block)
|
14
|
+
instance_exec(*args, &block)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
8
18
|
def self.script(text, options = {})
|
9
19
|
Log.debug "Running python script:\n#{text.dup}"
|
10
20
|
text = StringIO.new text unless IO === text
|
@@ -12,8 +22,13 @@ module RbbtPython
|
|
12
22
|
end
|
13
23
|
|
14
24
|
def self.add_path(path)
|
15
|
-
|
16
|
-
|
25
|
+
begin
|
26
|
+
self.run 'sys' do
|
27
|
+
sys.path.append path
|
28
|
+
end
|
29
|
+
rescue
|
30
|
+
raise RbbtPythonException,
|
31
|
+
"Could not add path #{Misc.fingerprint path} to python sys: " + $!.message
|
17
32
|
end
|
18
33
|
end
|
19
34
|
|
@@ -26,19 +41,64 @@ module RbbtPython
|
|
26
41
|
end
|
27
42
|
|
28
43
|
def self.init_rbbt
|
29
|
-
if ! defined?(@@
|
44
|
+
if ! defined?(@@__init_rbbt_python) || ! @@__init_rbbt_python
|
30
45
|
Log.debug "Loading python 'rbbt' module into pycall RbbtPython module"
|
31
46
|
RbbtPython.add_paths(Rbbt.python.find_all)
|
32
47
|
RbbtPython.pyimport("rbbt")
|
33
|
-
@@
|
48
|
+
@@__init_rbbt_python = true
|
34
49
|
end
|
35
50
|
end
|
36
51
|
|
52
|
+
def self.import_method(module_name, method_name, as = nil)
|
53
|
+
RbbtPython.pyfrom module_name, import: method_name
|
54
|
+
RbbtPython.method(method_name)
|
55
|
+
end
|
56
|
+
|
37
57
|
def self.exec(script)
|
38
58
|
PyCall.exec(script)
|
39
59
|
end
|
40
60
|
|
41
|
-
def self.
|
61
|
+
def self.iterate_index(elem, options = {})
|
62
|
+
iii :interate_index
|
63
|
+
bar = options[:bar]
|
64
|
+
|
65
|
+
len = PyCall.len(elem)
|
66
|
+
case bar
|
67
|
+
when TrueClass
|
68
|
+
bar = Log::ProgressBar.new nil, :desc => "RbbtPython iterate"
|
69
|
+
when String
|
70
|
+
bar = Log::ProgressBar.new nil, :desc => bar
|
71
|
+
end
|
72
|
+
|
73
|
+
len.times do |i|
|
74
|
+
begin
|
75
|
+
yield elem[i]
|
76
|
+
bar.tick if bar
|
77
|
+
rescue PyCall::PyError
|
78
|
+
if $!.type.to_s == "<class 'StopIteration'>"
|
79
|
+
break
|
80
|
+
else
|
81
|
+
raise $!
|
82
|
+
end
|
83
|
+
rescue
|
84
|
+
bar.error if bar
|
85
|
+
raise $!
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
Log::ProgressBar.remove_bar bar if bar
|
90
|
+
nil
|
91
|
+
end
|
92
|
+
|
93
|
+
def self.iterate(iterator, options = {}, &block)
|
94
|
+
if ! iterator.respond_to?(:__next__)
|
95
|
+
if iterator.respond_to?(:__iter__)
|
96
|
+
iterator = iterator.__iter__
|
97
|
+
else
|
98
|
+
return iterate_index(iterator, options, &block)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
42
102
|
bar = options[:bar]
|
43
103
|
|
44
104
|
case bar
|
@@ -50,7 +110,8 @@ module RbbtPython
|
|
50
110
|
|
51
111
|
while true
|
52
112
|
begin
|
53
|
-
|
113
|
+
elem = iterator.__next__
|
114
|
+
yield elem
|
54
115
|
bar.tick if bar
|
55
116
|
rescue PyCall::PyError
|
56
117
|
if $!.type.to_s == "<class 'StopIteration'>"
|
@@ -79,12 +140,12 @@ module RbbtPython
|
|
79
140
|
|
80
141
|
def self.run(mod = nil, imports = nil, &block)
|
81
142
|
if mod
|
82
|
-
if
|
83
|
-
pyfrom mod, :import => imports
|
84
|
-
elsif Hash === imports
|
143
|
+
if Hash === imports
|
85
144
|
pyimport mod, **imports
|
86
|
-
|
145
|
+
elsif imports.nil?
|
87
146
|
pyimport mod
|
147
|
+
else
|
148
|
+
pyfrom mod, :import => imports
|
88
149
|
end
|
89
150
|
end
|
90
151
|
|
@@ -124,4 +185,13 @@ module RbbtPython
|
|
124
185
|
module_eval(&block)
|
125
186
|
end
|
126
187
|
end
|
188
|
+
|
189
|
+
def self.new_binding
|
190
|
+
Binding.new
|
191
|
+
end
|
192
|
+
|
193
|
+
def self.binding_run(binding = nil, *args, &block)
|
194
|
+
binding = new_binding
|
195
|
+
binding.instance_exec *args, &block
|
196
|
+
end
|
127
197
|
end
|
@@ -13,5 +13,13 @@ class TestPythonUtil < Test::Unit::TestCase
|
|
13
13
|
assert_equal tsv, new_tsv
|
14
14
|
end
|
15
15
|
|
16
|
+
def test_numpy
|
17
|
+
ra = RbbtPython.run :numpy, :as => :np do
|
18
|
+
na = np.array([[[1,2,3], [4,5,6]]])
|
19
|
+
RbbtPython.numpy2ruby na
|
20
|
+
end
|
21
|
+
assert_equal 6, ra[0][1][2]
|
22
|
+
end
|
23
|
+
|
16
24
|
end
|
17
25
|
|
@@ -81,5 +81,55 @@ def python_print():
|
|
81
81
|
end
|
82
82
|
assert defined
|
83
83
|
end
|
84
|
+
|
85
|
+
def test_iterate
|
86
|
+
a2, b2 = nil, nil
|
87
|
+
RbbtPython.run :numpy, as: :np do
|
88
|
+
a = np.array([1,2])
|
89
|
+
a2 = RbbtPython.collect a do |e|
|
90
|
+
e * 2
|
91
|
+
end
|
92
|
+
b = PyCall.tuple([1,2])
|
93
|
+
b2 = RbbtPython.collect b do |e|
|
94
|
+
e * 2
|
95
|
+
end
|
96
|
+
end
|
97
|
+
assert_equal [2,4], a2
|
98
|
+
assert_equal [2,4], b2
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_lambda
|
102
|
+
l = PyCall.eval "lambda e: e + 2"
|
103
|
+
assert_equal 5, l.(3)
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_binding
|
107
|
+
raised = false
|
108
|
+
RbbtPython.binding_run do
|
109
|
+
pyimport :torch
|
110
|
+
pyfrom :torch, import: ["nn"]
|
111
|
+
begin
|
112
|
+
torch
|
113
|
+
rescue
|
114
|
+
raised = true
|
115
|
+
end
|
116
|
+
end
|
117
|
+
assert ! raised
|
118
|
+
|
119
|
+
raised = false
|
120
|
+
RbbtPython.binding_run do
|
121
|
+
begin
|
122
|
+
torch
|
123
|
+
rescue
|
124
|
+
raised = true
|
125
|
+
end
|
126
|
+
end
|
127
|
+
assert raised
|
128
|
+
end
|
129
|
+
|
130
|
+
def test_import_method
|
131
|
+
random = RbbtPython.import_method :torch, :rand, :random
|
132
|
+
assert random.call(1).numpy.to_f > 0
|
133
|
+
end
|
84
134
|
end
|
85
135
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rbbt-util
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.35.
|
4
|
+
version: 5.35.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Miguel Vazquez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-02-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -613,113 +613,113 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
613
613
|
- !ruby/object:Gem::Version
|
614
614
|
version: '0'
|
615
615
|
requirements: []
|
616
|
-
rubygems_version: 3.1.
|
616
|
+
rubygems_version: 3.1.2
|
617
617
|
signing_key:
|
618
618
|
specification_version: 4
|
619
619
|
summary: Utilities for the Ruby Bioinformatics Toolkit (rbbt)
|
620
620
|
test_files:
|
621
|
+
- test/test_helper.rb
|
622
|
+
- test/rbbt/entity/test_identifiers.rb
|
623
|
+
- test/rbbt/test_resource.rb
|
624
|
+
- test/rbbt/test_association.rb
|
625
|
+
- test/rbbt/hpc/test_orchestrate.rb
|
626
|
+
- test/rbbt/hpc/test_slurm.rb
|
627
|
+
- test/rbbt/hpc/orchestrate/test_batches.rb
|
628
|
+
- test/rbbt/hpc/orchestrate/test_rules.rb
|
629
|
+
- test/rbbt/hpc/orchestrate/test_chains.rb
|
630
|
+
- test/rbbt/hpc/test_batch.rb
|
631
|
+
- test/rbbt/persist/test_tsv.rb
|
632
|
+
- test/rbbt/persist/tsv/test_kyotocabinet.rb
|
633
|
+
- test/rbbt/persist/tsv/test_lmdb.rb
|
634
|
+
- test/rbbt/persist/tsv/test_tokyocabinet.rb
|
635
|
+
- test/rbbt/persist/tsv/test_cdb.rb
|
636
|
+
- test/rbbt/persist/tsv/test_leveldb.rb
|
637
|
+
- test/rbbt/persist/tsv/test_sharder.rb
|
638
|
+
- test/rbbt/test_packed_index.rb
|
621
639
|
- test/rbbt/test_entity.rb
|
640
|
+
- test/rbbt/test_fix_width_table.rb
|
622
641
|
- test/rbbt/workflow/test_remote_workflow.rb
|
642
|
+
- test/rbbt/workflow/test_doc.rb
|
643
|
+
- test/rbbt/workflow/step/test_save_load_inputs.rb
|
644
|
+
- test/rbbt/workflow/step/test_dependencies.rb
|
645
|
+
- test/rbbt/workflow/test_schedule.rb
|
623
646
|
- test/rbbt/workflow/util/test_archive.rb
|
624
647
|
- test/rbbt/workflow/util/test_orchestrator.rb
|
625
648
|
- test/rbbt/workflow/util/test_data.rb
|
626
|
-
- test/rbbt/workflow/test_doc.rb
|
627
|
-
- test/rbbt/workflow/test_schedule.rb
|
628
|
-
- test/rbbt/workflow/test_step.rb
|
629
|
-
- test/rbbt/workflow/step/test_dependencies.rb
|
630
|
-
- test/rbbt/workflow/step/test_save_load_inputs.rb
|
631
649
|
- test/rbbt/workflow/test_task.rb
|
632
|
-
- test/rbbt/
|
633
|
-
- test/rbbt/
|
650
|
+
- test/rbbt/workflow/test_step.rb
|
651
|
+
- test/rbbt/test_tsv.rb
|
652
|
+
- test/rbbt/test_annotations.rb
|
653
|
+
- test/rbbt/test_knowledge_base.rb
|
654
|
+
- test/rbbt/util/test_migrate.rb
|
655
|
+
- test/rbbt/util/test_simpleDSL.rb
|
656
|
+
- test/rbbt/util/concurrency/processes/test_socket.rb
|
657
|
+
- test/rbbt/util/concurrency/test_processes.rb
|
658
|
+
- test/rbbt/util/concurrency/test_threads.rb
|
659
|
+
- test/rbbt/util/test_filecache.rb
|
660
|
+
- test/rbbt/util/simpleopt/test_get.rb
|
661
|
+
- test/rbbt/util/simpleopt/test_parse.rb
|
662
|
+
- test/rbbt/util/simpleopt/test_setup.rb
|
663
|
+
- test/rbbt/util/test_misc.rb
|
664
|
+
- test/rbbt/util/test_excel2tsv.rb
|
665
|
+
- test/rbbt/util/test_semaphore.rb
|
634
666
|
- test/rbbt/util/test_procpath.rb
|
667
|
+
- test/rbbt/util/R/test_model.rb
|
668
|
+
- test/rbbt/util/R/test_eval.rb
|
669
|
+
- test/rbbt/util/R/test_plot.rb
|
670
|
+
- test/rbbt/util/test_open.rb
|
671
|
+
- test/rbbt/util/test_tmpfile.rb
|
672
|
+
- test/rbbt/util/test_cmd.rb
|
673
|
+
- test/rbbt/util/test_concurrency.rb
|
674
|
+
- test/rbbt/util/test_colorize.rb
|
675
|
+
- test/rbbt/util/test_config.rb
|
635
676
|
- test/rbbt/util/python/test_util.rb
|
636
|
-
- test/rbbt/util/
|
677
|
+
- test/rbbt/util/test_log.rb
|
678
|
+
- test/rbbt/util/test_simpleopt.rb
|
679
|
+
- test/rbbt/util/test_python.rb
|
680
|
+
- test/rbbt/util/test_chain_methods.rb
|
637
681
|
- test/rbbt/util/misc/test_omics.rb
|
638
|
-
- test/rbbt/util/misc/test_pipes.rb
|
639
|
-
- test/rbbt/util/misc/test_serialize.rb
|
640
|
-
- test/rbbt/util/misc/test_format.rb
|
641
|
-
- test/rbbt/util/misc/test_communication.rb
|
642
682
|
- test/rbbt/util/misc/test_lock.rb
|
643
683
|
- test/rbbt/util/misc/test_multipart_payload.rb
|
644
684
|
- test/rbbt/util/misc/test_bgzf.rb
|
645
|
-
- test/rbbt/util/
|
646
|
-
- test/rbbt/util/
|
647
|
-
- test/rbbt/util/
|
648
|
-
- test/rbbt/util/
|
649
|
-
- test/rbbt/util/
|
650
|
-
- test/rbbt/util/test_config.rb
|
651
|
-
- test/rbbt/util/test_log.rb
|
652
|
-
- test/rbbt/util/test_simpleDSL.rb
|
685
|
+
- test/rbbt/util/misc/test_development.rb
|
686
|
+
- test/rbbt/util/misc/test_serialize.rb
|
687
|
+
- test/rbbt/util/misc/test_format.rb
|
688
|
+
- test/rbbt/util/misc/test_communication.rb
|
689
|
+
- test/rbbt/util/misc/test_pipes.rb
|
653
690
|
- test/rbbt/util/log/test_progress.rb
|
654
|
-
- test/rbbt/util/test_tmpfile.rb
|
655
691
|
- test/rbbt/util/test_R.rb
|
656
|
-
- test/rbbt/
|
657
|
-
- test/rbbt/
|
658
|
-
- test/rbbt/
|
659
|
-
- test/rbbt/
|
660
|
-
- test/rbbt/
|
661
|
-
- test/rbbt/
|
662
|
-
- test/rbbt/
|
663
|
-
- test/rbbt/
|
664
|
-
- test/rbbt/
|
665
|
-
- test/rbbt/
|
666
|
-
- test/rbbt/
|
667
|
-
- test/rbbt/
|
668
|
-
- test/rbbt/
|
669
|
-
- test/rbbt/
|
670
|
-
- test/rbbt/
|
671
|
-
- test/rbbt/
|
672
|
-
- test/rbbt/
|
673
|
-
- test/rbbt/tsv/test_change_id.rb
|
674
|
-
- test/rbbt/tsv/test_attach.rb
|
675
|
-
- test/rbbt/tsv/test_filter.rb
|
676
|
-
- test/rbbt/tsv/test_marshal.rb
|
692
|
+
- test/rbbt/test_workflow.rb
|
693
|
+
- test/rbbt/knowledge_base/test_entity.rb
|
694
|
+
- test/rbbt/knowledge_base/test_enrichment.rb
|
695
|
+
- test/rbbt/knowledge_base/test_traverse.rb
|
696
|
+
- test/rbbt/knowledge_base/test_syndicate.rb
|
697
|
+
- test/rbbt/knowledge_base/test_registry.rb
|
698
|
+
- test/rbbt/knowledge_base/test_query.rb
|
699
|
+
- test/rbbt/association/test_item.rb
|
700
|
+
- test/rbbt/association/test_util.rb
|
701
|
+
- test/rbbt/association/test_open.rb
|
702
|
+
- test/rbbt/association/test_database.rb
|
703
|
+
- test/rbbt/association/test_index.rb
|
704
|
+
- test/rbbt/annotations/test_util.rb
|
705
|
+
- test/rbbt/test_monitor.rb
|
706
|
+
- test/rbbt/resource/test_path.rb
|
707
|
+
- test/rbbt/test_hpc.rb
|
708
|
+
- test/rbbt/test_persist.rb
|
677
709
|
- test/rbbt/tsv/test_parser.rb
|
678
710
|
- test/rbbt/tsv/test_csv.rb
|
679
|
-
- test/rbbt/tsv/
|
680
|
-
- test/rbbt/tsv/test_matrix.rb
|
711
|
+
- test/rbbt/tsv/test_manipulate.rb
|
681
712
|
- test/rbbt/tsv/test_field_index.rb
|
682
713
|
- test/rbbt/tsv/test_util.rb
|
683
|
-
- test/rbbt/tsv/
|
714
|
+
- test/rbbt/tsv/test_accessor.rb
|
715
|
+
- test/rbbt/tsv/test_filter.rb
|
716
|
+
- test/rbbt/tsv/test_stream.rb
|
684
717
|
- test/rbbt/tsv/test_parallel.rb
|
685
|
-
- test/rbbt/tsv/
|
718
|
+
- test/rbbt/tsv/test_marshal.rb
|
719
|
+
- test/rbbt/tsv/test_matrix.rb
|
720
|
+
- test/rbbt/tsv/test_attach.rb
|
686
721
|
- test/rbbt/tsv/test_excel.rb
|
687
|
-
- test/rbbt/tsv/
|
722
|
+
- test/rbbt/tsv/test_change_id.rb
|
723
|
+
- test/rbbt/tsv/test_index.rb
|
688
724
|
- test/rbbt/tsv/parallel/test_traverse.rb
|
689
|
-
- test/rbbt/tsv/
|
690
|
-
- test/rbbt/test_association.rb
|
691
|
-
- test/rbbt/hpc/test_batch.rb
|
692
|
-
- test/rbbt/hpc/orchestrate/test_chains.rb
|
693
|
-
- test/rbbt/hpc/orchestrate/test_rules.rb
|
694
|
-
- test/rbbt/hpc/orchestrate/test_batches.rb
|
695
|
-
- test/rbbt/hpc/test_slurm.rb
|
696
|
-
- test/rbbt/hpc/test_orchestrate.rb
|
697
|
-
- test/rbbt/association/test_database.rb
|
698
|
-
- test/rbbt/association/test_item.rb
|
699
|
-
- test/rbbt/association/test_open.rb
|
700
|
-
- test/rbbt/association/test_util.rb
|
701
|
-
- test/rbbt/association/test_index.rb
|
702
|
-
- test/rbbt/test_knowledge_base.rb
|
703
|
-
- test/rbbt/persist/tsv/test_kyotocabinet.rb
|
704
|
-
- test/rbbt/persist/tsv/test_cdb.rb
|
705
|
-
- test/rbbt/persist/tsv/test_lmdb.rb
|
706
|
-
- test/rbbt/persist/tsv/test_sharder.rb
|
707
|
-
- test/rbbt/persist/tsv/test_leveldb.rb
|
708
|
-
- test/rbbt/persist/tsv/test_tokyocabinet.rb
|
709
|
-
- test/rbbt/persist/test_tsv.rb
|
710
|
-
- test/rbbt/test_tsv.rb
|
711
|
-
- test/rbbt/test_annotations.rb
|
712
|
-
- test/rbbt/test_fix_width_table.rb
|
713
|
-
- test/rbbt/test_workflow.rb
|
714
|
-
- test/rbbt/entity/test_identifiers.rb
|
715
|
-
- test/rbbt/annotations/test_util.rb
|
716
|
-
- test/rbbt/test_hpc.rb
|
717
|
-
- test/rbbt/test_monitor.rb
|
718
|
-
- test/rbbt/test_persist.rb
|
719
|
-
- test/rbbt/knowledge_base/test_entity.rb
|
720
|
-
- test/rbbt/knowledge_base/test_registry.rb
|
721
|
-
- test/rbbt/knowledge_base/test_syndicate.rb
|
722
|
-
- test/rbbt/knowledge_base/test_query.rb
|
723
|
-
- test/rbbt/knowledge_base/test_enrichment.rb
|
724
|
-
- test/rbbt/knowledge_base/test_traverse.rb
|
725
|
-
- test/test_helper.rb
|
725
|
+
- test/rbbt/tsv/parallel/test_through.rb
|