miga-base 0.2.0.6 → 0.2.0.7
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/Gemfile +3 -0
- data/LICENSE +201 -0
- data/README.md +17 -335
- data/Rakefile +31 -0
- data/actions/add_result +2 -5
- data/actions/add_taxonomy +4 -7
- data/actions/create_dataset +5 -6
- data/actions/create_project +2 -5
- data/actions/daemon +2 -5
- data/actions/download_dataset +88 -58
- data/actions/find_datasets +36 -38
- data/actions/import_datasets +2 -5
- data/actions/index_taxonomy +2 -5
- data/actions/list_datasets +47 -49
- data/actions/list_files +7 -11
- data/actions/unlink_dataset +2 -5
- data/bin/miga +1 -1
- data/lib/miga/common.rb +132 -0
- data/lib/miga/daemon.rb +229 -168
- data/lib/miga/dataset.rb +354 -277
- data/lib/miga/gui.rb +346 -269
- data/lib/miga/metadata.rb +115 -71
- data/lib/miga/project.rb +361 -259
- data/lib/miga/remote_dataset.rb +200 -148
- data/lib/miga/result.rb +150 -99
- data/lib/miga/tax_index.rb +124 -67
- data/lib/miga/taxonomy.rb +129 -100
- data/lib/miga/version.rb +57 -0
- data/lib/miga.rb +2 -77
- data/scripts/_distances_noref_nomulti.bash +2 -0
- data/scripts/_distances_ref_nomulti.bash +2 -0
- data/scripts/aai_distances.bash +1 -0
- data/scripts/ani_distances.bash +1 -0
- data/scripts/assembly.bash +1 -0
- data/scripts/cds.bash +1 -0
- data/scripts/clade_finding.bash +17 -1
- data/scripts/distances.bash +1 -0
- data/scripts/essential_genes.bash +1 -0
- data/scripts/haai_distances.bash +1 -0
- data/scripts/init.bash +2 -0
- data/scripts/mytaxa.bash +1 -0
- data/scripts/mytaxa_scan.bash +1 -0
- data/scripts/ogs.bash +1 -0
- data/scripts/read_quality.bash +1 -0
- data/scripts/ssu.bash +1 -0
- data/scripts/subclades.bash +1 -0
- data/scripts/trimmed_fasta.bash +1 -0
- data/scripts/trimmed_reads.bash +1 -0
- data/test/common_test.rb +82 -0
- data/test/daemon_test.rb +53 -0
- data/test/dataset_test.rb +156 -0
- data/test/jruby_gui_test.rb +20 -0
- data/test/metadata_test.rb +48 -0
- data/test/project_test.rb +54 -0
- data/test/remote_dataset_test.rb +41 -0
- data/test/tax_index_test.rb +44 -0
- data/test/taxonomy_test.rb +36 -0
- data/test/test_helper.rb +32 -0
- metadata +53 -38
data/scripts/haai_distances.bash
CHANGED
data/scripts/init.bash
CHANGED
data/scripts/mytaxa.bash
CHANGED
data/scripts/mytaxa_scan.bash
CHANGED
data/scripts/ogs.bash
CHANGED
data/scripts/read_quality.bash
CHANGED
data/scripts/ssu.bash
CHANGED
data/scripts/subclades.bash
CHANGED
data/scripts/trimmed_fasta.bash
CHANGED
data/scripts/trimmed_reads.bash
CHANGED
data/test/common_test.rb
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class CommonTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
$gui_tests = !ENV["GUI_TESTS"].nil?
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_debug
|
10
|
+
assert_respond_to(MiGA::MiGA, :DEBUG)
|
11
|
+
assert_respond_to(MiGA::MiGA, :DEBUG_ON)
|
12
|
+
assert_respond_to(MiGA::MiGA, :DEBUG_OFF)
|
13
|
+
MiGA::MiGA.DEBUG_ON
|
14
|
+
err = capture_stderr do
|
15
|
+
MiGA::MiGA.DEBUG "Tralari"
|
16
|
+
end
|
17
|
+
assert_equal("Tralari\n", err.string)
|
18
|
+
MiGA::MiGA.DEBUG_OFF
|
19
|
+
err = capture_stderr do
|
20
|
+
MiGA::MiGA.DEBUG "Tralara"
|
21
|
+
end
|
22
|
+
assert_equal("", err.string)
|
23
|
+
ensure
|
24
|
+
MiGA::MiGA.DEBUG_OFF
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_debug_trace
|
28
|
+
assert_respond_to(MiGA::MiGA, :DEBUG)
|
29
|
+
assert_respond_to(MiGA::MiGA, :DEBUG_ON)
|
30
|
+
assert_respond_to(MiGA::MiGA, :DEBUG_OFF)
|
31
|
+
omit_if($gui_tests, "JRuby doesn't like interceptions.")
|
32
|
+
MiGA::MiGA.DEBUG_TRACE_ON
|
33
|
+
err = capture_stderr do
|
34
|
+
MiGA::MiGA.DEBUG "Dandadi"
|
35
|
+
end
|
36
|
+
assert(err.string =~ /Dandadi\n .*block in test_debug_trace/)
|
37
|
+
MiGA::MiGA.DEBUG_TRACE_OFF
|
38
|
+
err = capture_stderr do
|
39
|
+
MiGA::MiGA.DEBUG "Dandada"
|
40
|
+
end
|
41
|
+
assert_equal("Dandada\n", err.string)
|
42
|
+
ensure
|
43
|
+
MiGA::MiGA.DEBUG_TRACE_OFF
|
44
|
+
MiGA::MiGA.DEBUG_OFF
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_generic_transfer
|
48
|
+
$tmp = Dir.mktmpdir
|
49
|
+
hello = File.expand_path("Hello", $tmp)
|
50
|
+
world = File.expand_path("World", $tmp)
|
51
|
+
assert_respond_to(File, :generic_transfer)
|
52
|
+
FileUtils.touch(hello)
|
53
|
+
File.generic_transfer(hello, world, :symlink)
|
54
|
+
assert_equal("link", File.ftype(world), "World should be a link.")
|
55
|
+
File.generic_transfer(hello, world, :copy)
|
56
|
+
assert_equal("link", File.ftype(world), "World should still be a link.")
|
57
|
+
File.unlink world
|
58
|
+
File.generic_transfer(hello, world, :hardlink)
|
59
|
+
assert_equal("file", File.ftype(world), "A hardlink should be a file.")
|
60
|
+
File.open(hello, "w"){ |fh| fh.print "!" }
|
61
|
+
File.open(world, "r"){ |fh| assert_equal("!", fh.gets) }
|
62
|
+
File.unlink world
|
63
|
+
File.generic_transfer(hello, world, :copy)
|
64
|
+
assert_equal("file", File.ftype(world), "A copy should be a file.")
|
65
|
+
File.unlink world
|
66
|
+
assert_raise do
|
67
|
+
File.generic_transfer(hello, world, :monkey)
|
68
|
+
end
|
69
|
+
assert(!File.exist?(world), "A monkey shouldn't create files.")
|
70
|
+
ensure
|
71
|
+
FileUtils.rm_rf $tmp
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_tabulate
|
75
|
+
tab = MiGA::MiGA.tabulate(%w[a b], [%w[123 45], %w[678 90]])
|
76
|
+
assert_equal(" a b ", tab[0])
|
77
|
+
assert_equal(" - - ", tab[1])
|
78
|
+
assert_equal("123 45", tab[2])
|
79
|
+
assert_equal("678 90", tab[3])
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
data/test/daemon_test.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
require "miga/daemon"
|
3
|
+
|
4
|
+
class DaemonTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
$tmp = Dir.mktmpdir
|
8
|
+
ENV["MIGA_HOME"] = $tmp
|
9
|
+
FileUtils.touch("#{ENV["MIGA_HOME"]}/.miga_rc")
|
10
|
+
File.open("#{ENV["MIGA_HOME"]}/.miga_daemon.json", "w") do |fh|
|
11
|
+
fh.puts '{"maxjobs":1,"ppn":1,"latency":2}'
|
12
|
+
end
|
13
|
+
$p1 = MiGA::Project.new(File.expand_path("project1", $tmp))
|
14
|
+
$d1 = MiGA::Daemon.new($p1)
|
15
|
+
end
|
16
|
+
|
17
|
+
def teardown
|
18
|
+
FileUtils.rm_rf $tmp
|
19
|
+
ENV["MIGA_HOME"] = nil
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_last_alive
|
23
|
+
p = MiGA::Project.new(File.expand_path("last_alive", $tmp))
|
24
|
+
d = MiGA::Daemon.new(p)
|
25
|
+
assert_nil(d.last_alive)
|
26
|
+
d.declare_alive
|
27
|
+
assert(d.last_alive - DateTime.now < 1)
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_options
|
31
|
+
assert_respond_to($d1, :default_options)
|
32
|
+
assert_equal(:normal, $d1.default_options[:dir_mode])
|
33
|
+
assert_equal(2, $d1.runopts(:latency))
|
34
|
+
assert_equal(1, $d1.maxjobs)
|
35
|
+
assert_equal(2, $d1.latency)
|
36
|
+
assert_equal(1, $d1.ppn)
|
37
|
+
$d1.runopts(:alo, :ha)
|
38
|
+
assert_equal(:ha, $d1.runopts(:alo))
|
39
|
+
$d1.runopts(:maxjobs, "1")
|
40
|
+
assert_equal(1, $d1.maxjobs)
|
41
|
+
assert_raise do
|
42
|
+
$d1.runopts(:latency, "!")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_say
|
47
|
+
out = capture_stdout do
|
48
|
+
$d1.say "Olm"
|
49
|
+
end
|
50
|
+
assert(out.string =~ /^\[.*\] Olm/)
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
@@ -0,0 +1,156 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
require "miga/project"
|
3
|
+
|
4
|
+
class DatasetTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
$tmp = Dir.mktmpdir
|
8
|
+
ENV["MIGA_HOME"] = $tmp
|
9
|
+
FileUtils.touch("#{ENV["MIGA_HOME"]}/.miga_rc")
|
10
|
+
FileUtils.touch("#{ENV["MIGA_HOME"]}/.miga_daemon.json")
|
11
|
+
$p1 = MiGA::Project.new(File.expand_path("project1", $tmp))
|
12
|
+
$d1 = $p1.add_dataset("dataset1")
|
13
|
+
end
|
14
|
+
|
15
|
+
def teardown
|
16
|
+
FileUtils.rm_rf $tmp
|
17
|
+
ENV["MIGA_HOME"] = nil
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_known_types
|
21
|
+
assert_respond_to(MiGA::Dataset, :KNOWN_TYPES)
|
22
|
+
assert(MiGA::Dataset.KNOWN_TYPES.has_key?(:genome))
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_exist
|
26
|
+
assert_respond_to(MiGA::Dataset, :exist?)
|
27
|
+
assert(MiGA::Dataset.exist?($p1, "dataset1"))
|
28
|
+
assert(! MiGA::Dataset.exist?($p1, "Nope"))
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_info_fields
|
32
|
+
assert_respond_to(MiGA::Dataset, :INFO_FIELDS)
|
33
|
+
assert(MiGA::Dataset.INFO_FIELDS.include?("name"))
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_initialize
|
37
|
+
assert_raise do
|
38
|
+
MiGA::Dataset.new($p1, "dataset-1")
|
39
|
+
end
|
40
|
+
assert_equal($p1, $d1.project)
|
41
|
+
assert_equal("dataset1", $d1.name)
|
42
|
+
assert($d1.is_ref?)
|
43
|
+
assert_equal(MiGA::Metadata, $d1.metadata.class)
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_save
|
47
|
+
d2 = $p1.add_dataset("ds_save")
|
48
|
+
assert_respond_to(d2, :save)
|
49
|
+
d2.save
|
50
|
+
assert(!d2.is_multi?)
|
51
|
+
assert(!d2.is_nonmulti?)
|
52
|
+
assert_nil(d2.metadata[:type])
|
53
|
+
d2.metadata[:tax] = {:ns=>"COMMUNITY"}
|
54
|
+
d2.save
|
55
|
+
assert_equal(:metagenome, d2.metadata[:type])
|
56
|
+
assert(d2.is_multi?)
|
57
|
+
assert(!d2.is_nonmulti?)
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_remove
|
61
|
+
d2 = $p1.add_dataset("ds_remove")
|
62
|
+
assert(File.exist?(d2.metadata.path))
|
63
|
+
d2.remove!
|
64
|
+
assert(! File.exist?(d2.metadata.path))
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_info
|
68
|
+
assert_equal($d1.name, $d1.info.first)
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_add_result
|
72
|
+
d2 = $p1.add_dataset("ds_add_result")
|
73
|
+
assert_nil(d2.add_result(:koop))
|
74
|
+
assert_nil(d2.add_result(:raw_reads))
|
75
|
+
FileUtils.touch(
|
76
|
+
File.expand_path("data/01.raw_reads/#{d2.name}.1.fastq",$p1.path))
|
77
|
+
assert_nil(d2.add_result(:raw_reads))
|
78
|
+
FileUtils.touch(
|
79
|
+
File.expand_path("data/01.raw_reads/#{d2.name}.done",$p1.path))
|
80
|
+
assert_equal(MiGA::Result, d2.add_result(:raw_reads).class)
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_preprocessing
|
84
|
+
d2 = $p1.add_dataset("ds_preprocessing")
|
85
|
+
assert_nil(d2.first_preprocessing)
|
86
|
+
assert_nil(d2.next_preprocessing)
|
87
|
+
assert(! d2.done_preprocessing?)
|
88
|
+
FileUtils.touch(File.expand_path(
|
89
|
+
"data/02.trimmed_reads/#{d2.name}.1.clipped.fastq",$p1.path))
|
90
|
+
FileUtils.touch(File.expand_path(
|
91
|
+
"data/02.trimmed_reads/#{d2.name}.done",$p1.path))
|
92
|
+
assert_equal(:trimmed_reads, d2.first_preprocessing(true))
|
93
|
+
assert_equal(:read_quality, d2.next_preprocessing(true))
|
94
|
+
assert(! d2.done_preprocessing?(true))
|
95
|
+
assert(d2.ignore_task?(:mytaxa))
|
96
|
+
assert(d2.ignore_task?(:distances))
|
97
|
+
d2.metadata[:type] = :metagenome
|
98
|
+
assert(! d2.ignore_task?(:mytaxa))
|
99
|
+
assert(d2.ignore_task?(:distances))
|
100
|
+
d2.metadata[:type] = :genome
|
101
|
+
assert(d2.ignore_task?(:mytaxa))
|
102
|
+
assert(! d2.ignore_task?(:distances))
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_profile_advance
|
106
|
+
d2 = $p1.add_dataset("ds_profile_advance")
|
107
|
+
assert_equal(0, d2.profile_advance(true).first)
|
108
|
+
assert_equal(0, d2.profile_advance(true).last)
|
109
|
+
assert_equal(0, d2.profile_advance(true).inject(:+))
|
110
|
+
Dir.mkdir(File.expand_path(
|
111
|
+
"data/03.read_quality/#{d2.name}.solexaqa",$p1.path))
|
112
|
+
Dir.mkdir(File.expand_path(
|
113
|
+
"data/03.read_quality/#{d2.name}.fastqc",$p1.path))
|
114
|
+
FileUtils.touch(File.expand_path(
|
115
|
+
"data/03.read_quality/#{d2.name}.done",$p1.path))
|
116
|
+
assert_equal([0,0,1,2], d2.profile_advance(true)[0..3])
|
117
|
+
assert_equal(2, d2.profile_advance(true).last)
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_add_result_other
|
121
|
+
d2 = $p1.add_dataset("ds_add_result_other")
|
122
|
+
Dir.mkdir(File.expand_path(
|
123
|
+
"data/07.annotation/01.function/01.essential/#{d2.name}.ess", $p1.path))
|
124
|
+
to_test = {
|
125
|
+
:trimmed_fasta => [
|
126
|
+
"data/04.trimmed_fasta/#{d2.name}.SingleReads.fa",
|
127
|
+
"data/04.trimmed_fasta/#{d2.name}.done"],
|
128
|
+
:assembly => [
|
129
|
+
"data/05.assembly/#{d2.name}.LargeContigs.fna",
|
130
|
+
"data/05.assembly/#{d2.name}.done"],
|
131
|
+
:cds => [
|
132
|
+
"data/06.cds/#{d2.name}.faa",
|
133
|
+
"data/06.cds/#{d2.name}.fna",
|
134
|
+
"data/06.cds/#{d2.name}.done"],
|
135
|
+
:essential_genes => %w[ess.faa ess/log done].map { |x|
|
136
|
+
"data/07.annotation/01.function/01.essential/#{d2.name}.#{x}" },
|
137
|
+
:ssu => [
|
138
|
+
"data/07.annotation/01.function/02.ssu/#{d2.name}.ssu.fa",
|
139
|
+
"data/07.annotation/01.function/02.ssu/#{d2.name}.done"],
|
140
|
+
:mytaxa_scan => %w[pdf wintax mytaxa reg done].map { |x|
|
141
|
+
"data/07.annotation/03.qa/02.mytaxa_scan/#{d2.name}.#{x}" },
|
142
|
+
:distances => [
|
143
|
+
"data/09.distances/01.haai/#{d2.name}.db",
|
144
|
+
"data/09.distances/#{d2.name}.done"]
|
145
|
+
}
|
146
|
+
to_test.each do |k,v|
|
147
|
+
assert_nil(d2.add_result(k), "Result for #{k} should be nil.")
|
148
|
+
v.each { |i| FileUtils.touch(File.expand_path(i, $p1.path)) }
|
149
|
+
FileUtils.touch(File.expand_path(
|
150
|
+
"data/04.trimmed_fasta/#{d2.name}.done",$p1.path))
|
151
|
+
assert_equal(MiGA::Result, d2.add_result(k).class,
|
152
|
+
"Result for #{k} should be MiGA::Result.")
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
require "miga/gui"
|
3
|
+
|
4
|
+
class GUITest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
$app = MiGA::GUI.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_status
|
11
|
+
assert_respond_to(MiGA::GUI, :status)
|
12
|
+
assert_equal("Initializing MiGA...", MiGA::GUI.status)
|
13
|
+
assert_equal(MiGA::GUI, $app.class)
|
14
|
+
MiGA::GUI.status = "Well well well..."
|
15
|
+
assert_equal("Well well well...", MiGA::GUI.status)
|
16
|
+
MiGA::GUI.reset_status
|
17
|
+
assert_equal("MiGA is ready to go!", MiGA::GUI.status)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
require "miga/metadata"
|
3
|
+
|
4
|
+
class MetadataTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
$tmp = Dir.mktmpdir
|
8
|
+
$gui_tests = !ENV["GUI_TESTS"].nil?
|
9
|
+
end
|
10
|
+
|
11
|
+
def teardown
|
12
|
+
FileUtils.rm_rf $tmp
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_save
|
16
|
+
omit_if($gui_tests, "JRuby doesn't implement fork.")
|
17
|
+
md1 = MiGA::Metadata.new(File.expand_path("md_save.json", $tmp))
|
18
|
+
FileUtils.touch(md1.lock_file)
|
19
|
+
fork do
|
20
|
+
sleep(1)
|
21
|
+
File.unlink(md1.lock_file)
|
22
|
+
end
|
23
|
+
t1 = Time.new
|
24
|
+
md1.save
|
25
|
+
t2 = Time.new
|
26
|
+
assert(! File.exist?(md1.lock_file))
|
27
|
+
assert(t2-t1 >= 1.0)
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_load
|
31
|
+
md1 = MiGA::Metadata.new(File.expand_path("md_load.json", $tmp), {:t=>1})
|
32
|
+
assert_equal(1, md1[:t])
|
33
|
+
omit_if($gui_tests, "JRuby doesn't implement fork.")
|
34
|
+
FileUtils.touch(md1.lock_file)
|
35
|
+
fork do
|
36
|
+
sleep(1)
|
37
|
+
File.open(md1.path, "w"){ |fh| fh.print '{"t": 2}' }
|
38
|
+
File.unlink(md1.lock_file)
|
39
|
+
end
|
40
|
+
t1 = Time.new
|
41
|
+
md1.load
|
42
|
+
t2 = Time.new
|
43
|
+
assert_equal(2, md1[:t])
|
44
|
+
assert(! File.exist?(md1.lock_file))
|
45
|
+
assert(t2-t1 >= 1.0)
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
require "miga/project"
|
3
|
+
|
4
|
+
class ProjectTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
$tmp = Dir.mktmpdir
|
8
|
+
ENV["MIGA_HOME"] = $tmp
|
9
|
+
FileUtils.touch("#{ENV["MIGA_HOME"]}/.miga_rc")
|
10
|
+
FileUtils.touch("#{ENV["MIGA_HOME"]}/.miga_daemon.json")
|
11
|
+
$p1 = MiGA::Project.new(File.expand_path("project1", $tmp))
|
12
|
+
end
|
13
|
+
|
14
|
+
def teardown
|
15
|
+
FileUtils.rm_rf $tmp
|
16
|
+
ENV["MIGA_HOME"] = nil
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_class_load
|
20
|
+
assert_nil(MiGA::Project.load($tmp + "/O_o"))
|
21
|
+
assert_equal(MiGA::Project, MiGA::Project.load($p1.path).class)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_create
|
25
|
+
assert_equal($tmp + "create", MiGA::Project.new($tmp + "create").path)
|
26
|
+
assert_raise do
|
27
|
+
ENV["MIGA_HOME"] = $tmp + "/chez-moi"
|
28
|
+
MiGA::Project.new($tmp + "/cuckoo")
|
29
|
+
end
|
30
|
+
ensure
|
31
|
+
ENV["MIGA_HOME"] = $tmp
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_load
|
35
|
+
p = MiGA::Project.new($tmp + "/load")
|
36
|
+
assert_equal(MiGA::Project, p.class)
|
37
|
+
File.unlink p.metadata.path
|
38
|
+
assert_raise do
|
39
|
+
p.load
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_datasets
|
44
|
+
p = MiGA::Project.new(File.expand_path("datasets", $tmp))
|
45
|
+
d = p.add_dataset("d1")
|
46
|
+
assert_equal(MiGA::Dataset, d.class)
|
47
|
+
assert_equal([d], p.datasets)
|
48
|
+
p.each_dataset{ |ds| assert_equal(d, ds) }
|
49
|
+
dr = p.unlink_dataset("d1")
|
50
|
+
assert_equal(d, dr)
|
51
|
+
assert_equal([], p.datasets)
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
require "miga/project"
|
3
|
+
require "miga/remote_dataset"
|
4
|
+
|
5
|
+
class RemoteDatasetTest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def setup
|
8
|
+
$tmp = Dir.mktmpdir
|
9
|
+
ENV["MIGA_HOME"] = $tmp
|
10
|
+
FileUtils.touch("#{ENV["MIGA_HOME"]}/.miga_rc")
|
11
|
+
FileUtils.touch("#{ENV["MIGA_HOME"]}/.miga_daemon.json")
|
12
|
+
$p1 = MiGA::Project.new(File.expand_path("project1", $tmp))
|
13
|
+
$remote_tests = !ENV["REMOTE_TESTS"].nil?
|
14
|
+
end
|
15
|
+
|
16
|
+
def teardown
|
17
|
+
FileUtils.rm_rf $tmp
|
18
|
+
ENV["MIGA_HOME"] = nil
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_class_universe
|
22
|
+
assert_respond_to(MiGA::RemoteDataset, :UNIVERSE)
|
23
|
+
assert(MiGA::RemoteDataset.UNIVERSE.keys.include? :ebi)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_bad_remote_dataset
|
27
|
+
assert_raise { MiGA::RemoteDataset.new("ids", :embl, :marvel) }
|
28
|
+
assert_raise { MiGA::RemoteDataset.new("ids", :google, :ebi) }
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_ebi
|
32
|
+
hiv2 = "M30502.1"
|
33
|
+
rd = MiGA::RemoteDataset.new(hiv2, :embl, :ebi)
|
34
|
+
assert_equal([hiv2], rd.ids)
|
35
|
+
omit_if(!$remote_tests, "Remote access is error-prone.")
|
36
|
+
tx = rd.get_ncbi_taxonomy
|
37
|
+
assert_equal(MiGA::Taxonomy, tx.class)
|
38
|
+
assert_equal("Lentivirus", tx[:g])
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
require "miga/tax_index"
|
3
|
+
|
4
|
+
class TaxIndexTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_initialization
|
7
|
+
ti = MiGA::TaxIndex.new
|
8
|
+
assert_equal(:root, ti.root.rank)
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_dataset
|
12
|
+
$tmp = Dir.mktmpdir
|
13
|
+
ENV["MIGA_HOME"] = $tmp
|
14
|
+
FileUtils.touch("#{ENV["MIGA_HOME"]}/.miga_rc")
|
15
|
+
FileUtils.touch("#{ENV["MIGA_HOME"]}/.miga_daemon.json")
|
16
|
+
p = MiGA::Project.new(File.expand_path("project1", $tmp))
|
17
|
+
d = p.add_dataset("dataset1")
|
18
|
+
|
19
|
+
ti = MiGA::TaxIndex.new
|
20
|
+
assert(ti.datasets.empty?)
|
21
|
+
ti << d
|
22
|
+
assert(ti.datasets.empty?, "Index should ignore datasets without tax.")
|
23
|
+
d.metadata[:tax] = MiGA::Taxonomy.new("k:Fantasia g:Unicornia")
|
24
|
+
ti << d
|
25
|
+
assert_equal(1, ti.datasets.size, "Index should have one dataset.")
|
26
|
+
assert_equal(1, ti.root.datasets_count)
|
27
|
+
ensure
|
28
|
+
FileUtils.rm_rf $tmp
|
29
|
+
ENV["MIGA_HOME"] = nil
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_to_json
|
33
|
+
js = JSON.parse(MiGA::TaxIndex.new.to_json)
|
34
|
+
assert(js.keys.include? "datasets")
|
35
|
+
assert_equal(2, js.keys.size)
|
36
|
+
assert(js["datasets"].empty?)
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_to_tab
|
40
|
+
ti = MiGA::TaxIndex.new
|
41
|
+
assert_equal("root:biota: 0\n", ti.to_tab)
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
require "miga/taxonomy"
|
3
|
+
|
4
|
+
class TaxonomyTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_ranks
|
7
|
+
assert_respond_to(MiGA::Taxonomy, :KNOWN_RANKS)
|
8
|
+
assert(MiGA::Taxonomy.KNOWN_RANKS.include? :s)
|
9
|
+
assert_nil(MiGA::Taxonomy.normalize_rank "No Rank")
|
10
|
+
assert_nil(MiGA::Taxonomy.normalize_rank "Captain")
|
11
|
+
assert_equal(:f, MiGA::Taxonomy.normalize_rank(:Family))
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_json
|
15
|
+
js = '{"json_class":"MiGA::Taxonomy",' +
|
16
|
+
'"str":"k:Fantasia f:Dragonaceae s:Dragonia_azura"}'
|
17
|
+
tx = JSON.parse(js, {:symbolize_names=>false, :create_additions=>true})
|
18
|
+
assert_equal(MiGA::Taxonomy, tx.class)
|
19
|
+
assert_equal("Dragonaceae", tx[:f])
|
20
|
+
assert_equal(js, tx.to_json)
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_append
|
24
|
+
tx = MiGA::Taxonomy.new ""
|
25
|
+
assert_equal("", "#{tx}")
|
26
|
+
tx << ["domain:Public","family:GNU"]
|
27
|
+
assert_equal("GNU", tx[:f])
|
28
|
+
tx << "class:ShareAlike"
|
29
|
+
assert_equal("ShareAlike", tx[:c])
|
30
|
+
tx << { :genus => "v3" }
|
31
|
+
assert_equal("v3", tx[:g])
|
32
|
+
tx << "s:v3_0"
|
33
|
+
assert(tx.is_in? MiGA::Taxonomy.new("species:v3_0"))
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require "codeclimate-test-reporter"
|
2
|
+
CodeClimate::TestReporter.start
|
3
|
+
|
4
|
+
require "rubygems"
|
5
|
+
require "test/unit"
|
6
|
+
require "miga/common"
|
7
|
+
require "stringio"
|
8
|
+
|
9
|
+
##
|
10
|
+
# Kernel extensions tp capture +$stdout+ and +$stderr+ based on
|
11
|
+
# http://thinkingdigitally.com/archive/capturing-output-from-puts-in-ruby/
|
12
|
+
module Kernel
|
13
|
+
|
14
|
+
def capture_stdout
|
15
|
+
out = StringIO.new
|
16
|
+
$stdout = out
|
17
|
+
yield
|
18
|
+
return out
|
19
|
+
ensure
|
20
|
+
$stdout = STDOUT
|
21
|
+
end
|
22
|
+
|
23
|
+
def capture_stderr
|
24
|
+
err = StringIO.new
|
25
|
+
$stderr = err
|
26
|
+
yield
|
27
|
+
return err
|
28
|
+
ensure
|
29
|
+
$stderr = STDERR
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|