miga-base 0.7.3.1 → 0.7.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (120) hide show
  1. checksums.yaml +4 -4
  2. data/lib/miga/cli.rb +10 -8
  3. data/lib/miga/cli/action.rb +2 -3
  4. data/lib/miga/cli/action/about.rb +5 -6
  5. data/lib/miga/cli/action/add.rb +18 -12
  6. data/lib/miga/cli/action/add_result.rb +2 -3
  7. data/lib/miga/cli/action/archive.rb +1 -2
  8. data/lib/miga/cli/action/classify_wf.rb +8 -6
  9. data/lib/miga/cli/action/console.rb +0 -1
  10. data/lib/miga/cli/action/daemon.rb +7 -7
  11. data/lib/miga/cli/action/date.rb +0 -1
  12. data/lib/miga/cli/action/derep_wf.rb +5 -4
  13. data/lib/miga/cli/action/doctor.rb +71 -82
  14. data/lib/miga/cli/action/doctor/base.rb +102 -0
  15. data/lib/miga/cli/action/edit.rb +14 -2
  16. data/lib/miga/cli/action/files.rb +8 -8
  17. data/lib/miga/cli/action/find.rb +5 -6
  18. data/lib/miga/cli/action/generic.rb +7 -7
  19. data/lib/miga/cli/action/get.rb +20 -17
  20. data/lib/miga/cli/action/get_db.rb +8 -2
  21. data/lib/miga/cli/action/index_wf.rb +1 -1
  22. data/lib/miga/cli/action/init.rb +53 -41
  23. data/lib/miga/cli/action/init/daemon_helper.rb +65 -43
  24. data/lib/miga/cli/action/lair.rb +7 -7
  25. data/lib/miga/cli/action/ln.rb +6 -6
  26. data/lib/miga/cli/action/ls.rb +1 -2
  27. data/lib/miga/cli/action/ncbi_get.rb +11 -3
  28. data/lib/miga/cli/action/new.rb +4 -4
  29. data/lib/miga/cli/action/next_step.rb +0 -1
  30. data/lib/miga/cli/action/preproc_wf.rb +3 -3
  31. data/lib/miga/cli/action/quality_wf.rb +1 -1
  32. data/lib/miga/cli/action/rm.rb +2 -3
  33. data/lib/miga/cli/action/run.rb +8 -8
  34. data/lib/miga/cli/action/stats.rb +8 -4
  35. data/lib/miga/cli/action/summary.rb +7 -6
  36. data/lib/miga/cli/action/tax_dist.rb +8 -4
  37. data/lib/miga/cli/action/tax_index.rb +3 -4
  38. data/lib/miga/cli/action/tax_set.rb +7 -6
  39. data/lib/miga/cli/action/tax_test.rb +6 -5
  40. data/lib/miga/cli/action/wf.rb +25 -19
  41. data/lib/miga/cli/base.rb +34 -32
  42. data/lib/miga/cli/objects_helper.rb +27 -18
  43. data/lib/miga/cli/opt_helper.rb +3 -2
  44. data/lib/miga/common.rb +2 -5
  45. data/lib/miga/common/base.rb +15 -16
  46. data/lib/miga/common/format.rb +8 -5
  47. data/lib/miga/common/hooks.rb +1 -4
  48. data/lib/miga/common/path.rb +4 -9
  49. data/lib/miga/common/with_daemon.rb +5 -2
  50. data/lib/miga/common/with_daemon_class.rb +1 -1
  51. data/lib/miga/common/with_result.rb +2 -1
  52. data/lib/miga/daemon.rb +93 -44
  53. data/lib/miga/daemon/base.rb +30 -11
  54. data/lib/miga/dataset.rb +47 -37
  55. data/lib/miga/dataset/base.rb +52 -37
  56. data/lib/miga/dataset/hooks.rb +3 -4
  57. data/lib/miga/dataset/result.rb +17 -1
  58. data/lib/miga/dataset/status.rb +6 -5
  59. data/lib/miga/json.rb +5 -7
  60. data/lib/miga/lair.rb +4 -0
  61. data/lib/miga/metadata.rb +4 -3
  62. data/lib/miga/project.rb +29 -20
  63. data/lib/miga/project/base.rb +52 -37
  64. data/lib/miga/project/dataset.rb +33 -26
  65. data/lib/miga/project/hooks.rb +0 -3
  66. data/lib/miga/project/result.rb +14 -5
  67. data/lib/miga/remote_dataset.rb +85 -72
  68. data/lib/miga/remote_dataset/base.rb +11 -13
  69. data/lib/miga/remote_dataset/download.rb +34 -12
  70. data/lib/miga/result.rb +48 -53
  71. data/lib/miga/result/base.rb +0 -2
  72. data/lib/miga/result/dates.rb +1 -3
  73. data/lib/miga/result/source.rb +15 -16
  74. data/lib/miga/result/stats.rb +37 -27
  75. data/lib/miga/tax_dist.rb +6 -3
  76. data/lib/miga/tax_index.rb +17 -17
  77. data/lib/miga/taxonomy.rb +6 -1
  78. data/lib/miga/taxonomy/base.rb +19 -15
  79. data/lib/miga/version.rb +19 -16
  80. data/scripts/project_stats.bash +3 -0
  81. data/scripts/stats.bash +1 -1
  82. data/test/common_test.rb +3 -11
  83. data/test/daemon_helper.rb +38 -0
  84. data/test/daemon_test.rb +91 -99
  85. data/test/dataset_test.rb +63 -59
  86. data/test/format_test.rb +3 -11
  87. data/test/hook_test.rb +50 -55
  88. data/test/json_test.rb +7 -8
  89. data/test/lair_test.rb +22 -28
  90. data/test/metadata_test.rb +6 -14
  91. data/test/project_test.rb +33 -40
  92. data/test/remote_dataset_test.rb +26 -32
  93. data/test/result_stats_test.rb +17 -27
  94. data/test/result_test.rb +41 -34
  95. data/test/tax_dist_test.rb +2 -4
  96. data/test/tax_index_test.rb +4 -10
  97. data/test/taxonomy_test.rb +7 -9
  98. data/test/test_helper.rb +42 -1
  99. data/test/with_daemon_test.rb +14 -22
  100. data/utils/adapters.fa +13 -0
  101. data/utils/cleanup-databases.rb +6 -5
  102. data/utils/distance/base.rb +0 -1
  103. data/utils/distance/commands.rb +19 -12
  104. data/utils/distance/database.rb +24 -21
  105. data/utils/distance/pipeline.rb +23 -10
  106. data/utils/distance/runner.rb +20 -16
  107. data/utils/distance/temporal.rb +1 -3
  108. data/utils/distances.rb +1 -1
  109. data/utils/domain-ess-genes.rb +7 -7
  110. data/utils/index_metadata.rb +5 -4
  111. data/utils/mytaxa_scan.rb +18 -16
  112. data/utils/representatives.rb +5 -4
  113. data/utils/requirements.txt +1 -1
  114. data/utils/subclade/base.rb +0 -1
  115. data/utils/subclade/pipeline.rb +7 -6
  116. data/utils/subclade/runner.rb +9 -9
  117. data/utils/subclade/temporal.rb +0 -2
  118. data/utils/subclades-compile.rb +39 -37
  119. data/utils/subclades.rb +1 -1
  120. metadata +6 -4
@@ -2,31 +2,26 @@ require 'test_helper'
2
2
  require 'miga/lair'
3
3
 
4
4
  class LairTest < Test::Unit::TestCase
5
+ include TestHelper
5
6
 
6
7
  def setup
7
- $jruby_tests = !ENV['JRUBY_TESTS'].nil?
8
- $tmp = Dir.mktmpdir
9
- ENV['MIGA_HOME'] = $tmp
10
- FileUtils.touch(File.expand_path('.miga_rc', ENV['MIGA_HOME']))
11
- daemon_json = File.expand_path('.miga_daemon.json', ENV['MIGA_HOME'])
12
- File.open(daemon_json, 'w') do |fh|
13
- fh.puts '{"maxjobs":1,"ppn":1,"latency":1,"varsep":" ",
14
- "var":"{{key}}={{value}}","cmd":"echo {{task_name}} >/dev/null",
15
- "alive":"echo 1 # {{pid}}","type":"bash","format_version":1}'
16
- end
17
- Dir.mkdir(File.join($tmp, 'sub'))
18
- $p1 = MiGA::Project.new(File.join($tmp, 'project1'))
19
- $p2 = MiGA::Project.new(File.join($tmp, 'project2'))
20
- $p3 = MiGA::Project.new(File.join($tmp, 'sub/project3'))
21
- end
8
+ initialize_miga_home(
9
+ <<~DAEMON
10
+ { "maxjobs": 1, "ppn": 1, "latency": 1, "varsep": " ",
11
+ "var": "{{key}}={{value}}", "cmd": "echo {{task_name}} >/dev/null",
12
+ "alive": "echo 1 # {{pid}}", "type": "bash", "format_version": 1 }
13
+ DAEMON
14
+ )
22
15
 
23
- def teardown
24
- FileUtils.rm_rf $tmp
25
- ENV['MIGA_HOME'] = nil
16
+ # Make sure projects already exist
17
+ Dir.mkdir(tmpfile('sub'))
18
+ project(1)
19
+ project(2)
20
+ project('sub/project3')
26
21
  end
27
-
22
+
28
23
  def test_lair_init
29
- path = $tmp
24
+ path = tmpdir
30
25
  lair = MiGA::Lair.new(path, name: 'Alt-X')
31
26
  assert_equal(MiGA::Lair, lair.class)
32
27
  assert_equal(path, lair.path)
@@ -36,9 +31,8 @@ class LairTest < Test::Unit::TestCase
36
31
  end
37
32
 
38
33
  def test_in_loop
39
- omit_if($jruby_tests, 'JRuby doesn\'t implement fork.')
40
- lair = MiGA::Lair.new($tmp, name: 'Oh')
41
- omit_if($jruby_tests, 'JRuby doesn\'t implement fork.')
34
+ declare_forks
35
+ lair = MiGA::Lair.new(tmpdir, name: 'Oh')
42
36
  child = lair.start(['--shush'])
43
37
  assert_not_nil(child)
44
38
  assert_gt(child, 0, 'The daemon process should have non-zero PID')
@@ -53,13 +47,13 @@ class LairTest < Test::Unit::TestCase
53
47
  end
54
48
 
55
49
  def test_first_loop
56
- lair = MiGA::Lair.new($tmp, name: 'Ew')
50
+ lair = MiGA::Lair.new(tmpdir, name: 'Ew')
57
51
  out = capture_stderr { lair.daemon_first_loop }.string
58
52
  assert_match(/-{20}/, out)
59
53
  end
60
54
 
61
55
  def test_loop
62
- lair = MiGA::Lair.new($tmp, name: 'Ew', latency: 1, dry: true)
56
+ lair = MiGA::Lair.new(tmpdir, name: 'Ew', latency: 1, dry: true)
63
57
  out = capture_stderr { assert { !lair.daemon_loop } }.string
64
58
  assert_match(/Launching daemon: \S*project1/, out)
65
59
  assert_match(/Launching daemon: \S*project2/, out)
@@ -67,13 +61,13 @@ class LairTest < Test::Unit::TestCase
67
61
  end
68
62
 
69
63
  def test_daemon_launch
70
- lair = MiGA::Lair.new(File.join($tmp, 'sub'), latency: 1)
64
+ lair = MiGA::Lair.new(tmpfile('sub'), latency: 1)
71
65
  p = MiGA::Project.load(File.join(lair.path, 'project3'))
72
66
  d = MiGA::Daemon.new(p)
73
67
  assert_not_predicate(d, :active?)
74
68
  assert_path_exist(d.daemon_home)
75
69
 
76
- omit_if($jruby_tests, 'JRuby doesn\'t implement fork.')
70
+ declare_forks
77
71
  capture_stdout do
78
72
  FileUtils.touch(d.output_file) # <- To prevent test racing
79
73
  out = capture_stderr { lair.check_directories }.string
@@ -92,7 +86,7 @@ class LairTest < Test::Unit::TestCase
92
86
  end
93
87
 
94
88
  def test_each_project
95
- lair = MiGA::Lair.new($tmp)
89
+ lair = MiGA::Lair.new(tmpdir)
96
90
  y = []
97
91
  lair.each_project { |p| y << p }
98
92
  assert_equal(3, y.size)
@@ -2,19 +2,11 @@ require 'test_helper'
2
2
  require 'miga/metadata'
3
3
 
4
4
  class MetadataTest < Test::Unit::TestCase
5
-
6
- def setup
7
- $tmp = Dir.mktmpdir
8
- $jruby_tests = !ENV['JRUBY_TESTS'].nil?
9
- end
10
-
11
- def teardown
12
- FileUtils.rm_rf $tmp
13
- end
5
+ include TestHelper
14
6
 
15
7
  def test_save
16
- omit_if($jruby_tests, 'JRuby doesn\'t implement fork.')
17
- md1 = MiGA::Metadata.new(File.expand_path('md_save.json', $tmp))
8
+ declare_forks
9
+ md1 = MiGA::Metadata.new(tmpfile('md_save.json'))
18
10
  FileUtils.touch(md1.lock_file)
19
11
  fork do
20
12
  sleep(1)
@@ -28,9 +20,10 @@ class MetadataTest < Test::Unit::TestCase
28
20
  end
29
21
 
30
22
  def test_load
31
- md1 = MiGA::Metadata.new(File.expand_path('md_load.json', $tmp), {t: 1})
23
+ md1 = MiGA::Metadata.new(tmpfile('md_load.json'), { t: 1 })
32
24
  assert_equal(1, md1[:t])
33
- omit_if($jruby_tests, 'JRuby doesn\'t implement fork.')
25
+
26
+ declare_forks
34
27
  FileUtils.touch(md1.lock_file)
35
28
  fork do
36
29
  sleep(1)
@@ -44,5 +37,4 @@ class MetadataTest < Test::Unit::TestCase
44
37
  assert_path_not_exist(md1.lock_file)
45
38
  assert_ge(t2 - t1, 1.0)
46
39
  end
47
-
48
40
  end
@@ -2,17 +2,10 @@ require 'test_helper'
2
2
  require 'miga/project'
3
3
 
4
4
  class ProjectTest < Test::Unit::TestCase
5
- def setup
6
- $tmp = Dir.mktmpdir
7
- ENV['MIGA_HOME'] = $tmp
8
- FileUtils.touch(File.expand_path('.miga_rc', ENV['MIGA_HOME']))
9
- FileUtils.touch(File.expand_path('.miga_daemon.json', ENV['MIGA_HOME']))
10
- $p1 = MiGA::Project.new(File.expand_path('project1', $tmp))
11
- end
5
+ include TestHelper
12
6
 
13
- def teardown
14
- FileUtils.rm_rf $tmp
15
- ENV['MIGA_HOME'] = nil
7
+ def setup
8
+ initialize_miga_home
16
9
  end
17
10
 
18
11
  def create_result_files(project, res, exts)
@@ -22,28 +15,26 @@ class ProjectTest < Test::Unit::TestCase
22
15
  project.add_result(res),
23
16
  "Premature registration of result #{res} at extension #{x}"
24
17
  )
25
- FileUtils.touch(File.join(project.path, "data/#{d}/miga-project#{x}"))
18
+ FileUtils.touch(File.join(project.path, 'data', d, "miga-project#{x}"))
26
19
  end
27
20
  end
28
21
 
29
22
  def test_class_load
30
- assert_nil(MiGA::Project.load($tmp + '/O_o'))
31
- assert_equal(MiGA::Project, MiGA::Project.load($p1.path).class)
23
+ assert_nil(MiGA::Project.load(tmpfile('O_o')))
24
+ assert_instance_of(MiGA::Project, MiGA::Project.load(project.path))
32
25
  end
33
26
 
34
27
  def test_create
35
- assert_equal("#{$tmp}/create", MiGA::Project.new("#{$tmp}/create").path)
36
- assert_path_exist("#{$tmp}/create")
28
+ assert_equal(tmpfile('create'), project('create').path)
29
+ assert_path_exist(tmpfile('create'))
37
30
  assert_raise do
38
- ENV['MIGA_HOME'] = $tmp + '/chez-moi'
39
- MiGA::Project.new($tmp + '/cuckoo')
31
+ ENV['MIGA_HOME'] = tmpfile('chez-moi')
32
+ project('cuckoo')
40
33
  end
41
- ensure
42
- ENV['MIGA_HOME'] = $tmp
43
34
  end
44
35
 
45
36
  def test_load
46
- p = MiGA::Project.new($tmp + '/load')
37
+ p = project('load')
47
38
  assert_equal(MiGA::Project, p.class)
48
39
  File.unlink p.metadata.path
49
40
  assert_raise do
@@ -52,13 +43,12 @@ class ProjectTest < Test::Unit::TestCase
52
43
  end
53
44
 
54
45
  def test_datasets
55
- p = $p1
56
- d = p.add_dataset('d1')
46
+ p = project
47
+ d = dataset(0, 'd1')
57
48
  assert_equal(MiGA::Dataset, d.class)
58
49
  assert_equal([d], p.datasets)
59
50
  assert_equal(['d1'], p.dataset_names)
60
51
  p.each_dataset { |ds| assert_equal(d, ds) }
61
- p.each_dataset { |n, ds| assert_equal(n, ds.name) }
62
52
  dr = p.unlink_dataset('d1')
63
53
  assert_equal(d, dr)
64
54
  assert_equal([], p.datasets)
@@ -66,55 +56,58 @@ class ProjectTest < Test::Unit::TestCase
66
56
  end
67
57
 
68
58
  def test_import_dataset
69
- p1 = $p1
59
+ p1 = project
70
60
  d = p1.add_dataset('d1')
71
61
  File.open(
72
- "#{p1.path}/data/01.raw_reads/#{d.name}.1.fastq", 'w'
62
+ File.join(p1.path, 'data', '01.raw_reads', "#{d.name}.1.fastq"), 'w'
73
63
  ) { |f| f.puts ':-)' }
74
64
  File.open(
75
- "#{p1.path}/data/01.raw_reads/#{d.name}.done", 'w'
65
+ File.join(p1.path, 'data', '01.raw_reads', "#{d.name}.done"), 'w'
76
66
  ) { |f| f.puts ':-)' }
77
67
  d.next_preprocessing(true)
78
- p2 = MiGA::Project.new(File.expand_path('import_dataset', $tmp))
68
+ p2 = project('import_dataset')
79
69
  assert_empty(p2.datasets)
80
70
  assert_nil(p2.dataset('d1'))
81
71
  p2.import_dataset(d)
82
72
  assert_equal(1, p2.datasets.size)
83
73
  assert_equal(MiGA::Dataset, p2.dataset('d1').class)
84
74
  assert_equal(1, p2.dataset('d1').results.size)
85
- assert_path_exist(File.join(p2.path, "data/01.raw_reads/#{d.name}.1.fastq"))
86
- assert_path_exist(File.join(p2.path, "metadata/#{d.name}.json"))
75
+ assert_path_exist(
76
+ File.join(p2.path, 'data', '01.raw_reads', "#{d.name}.1.fastq")
77
+ )
78
+ assert_path_exist(File.join(p2.path, 'metadata', "#{d.name}.json"))
87
79
  end
88
80
 
89
81
  def test_add_result
90
- p1 = $p1
82
+ p1 = project
91
83
  assert_nil(p1.add_result(:doom))
92
84
  %w[.Rdata .log .txt .done].each do |x|
93
85
  assert_nil(p1.add_result(:haai_distances))
94
86
  FileUtils.touch(
95
- File.join(p1.path, "data/09.distances/01.haai/miga-project#{x}")
87
+ File.join(
88
+ p1.path, 'data', '09.distances', '01.haai', "miga-project#{x}"
89
+ )
96
90
  )
97
91
  end
98
92
  assert_equal(MiGA::Result, p1.add_result(:haai_distances).class)
99
93
  end
100
94
 
101
95
  def test_result
102
- p1 = $p1
96
+ p1 = project
103
97
  assert_nil(p1.result(:n00b))
104
98
  assert_nil(p1.result(:project_stats))
105
- File.open(
106
- File.expand_path('data/90.stats/miga-project.json', p1.path), 'w'
107
- ) { |fh| fh.puts '{}' }
99
+ json = File.join(p1.path, 'data', '90.stats', 'miga-project.json')
100
+ File.open(json, 'w') { |fh| fh.puts '{}' }
108
101
  assert_not_nil(p1.result(:project_stats))
109
102
  assert_equal(1, p1.results.size)
110
103
  end
111
104
 
112
105
  def test_preprocessing
113
- p1 = $p1
106
+ p1 = project
114
107
  assert_predicate(p1, :done_preprocessing?)
115
108
  d1 = p1.add_dataset('BAH')
116
109
  assert_not_predicate(p1, :done_preprocessing?)
117
- FileUtils.touch(File.expand_path("data/90.stats/#{d1.name}.done", p1.path))
110
+ FileUtils.touch(File.join(p1.path, 'data', '90.stats', "#{d1.name}.done"))
118
111
  assert_predicate(p1, :done_preprocessing?)
119
112
  assert_nil(p1.next_inclade)
120
113
  p1.metadata[:type] = :clade
@@ -127,7 +120,7 @@ class ProjectTest < Test::Unit::TestCase
127
120
  aai_distances: %w[.Rdata .log .txt],
128
121
  ani_distances: %w[.Rdata .log .txt],
129
122
  clade_finding: %w[.pdf .classif .medoids
130
- .class.tsv .class.nwk .proposed-clades],
123
+ .class.tsv .class.nwk .proposed-clades],
131
124
  subclades: %w[.pdf .classif .medoids .class.tsv .class.nwk],
132
125
  ogs: %w[.ogs .stats]
133
126
  }
@@ -141,7 +134,7 @@ class ProjectTest < Test::Unit::TestCase
141
134
  end
142
135
 
143
136
  def test_empty_results
144
- p1 = $p1
137
+ p1 = project
145
138
  p1.metadata[:type] = :clade
146
139
  %i[clade_finding subclades ogs].each do |r|
147
140
  assert_nil(p1.add_result(r), "Unexpected result exists: #{r}")
@@ -151,7 +144,7 @@ class ProjectTest < Test::Unit::TestCase
151
144
  end
152
145
 
153
146
  def test_force_result
154
- p1 = $p1
147
+ p1 = project
155
148
  create_result_files(p1, :ogs, %w[.empty])
156
149
  date1 = p1.add_result(:ogs)[:created]
157
150
  sleep(1)
@@ -3,19 +3,10 @@ require 'miga/project'
3
3
  require 'miga/remote_dataset'
4
4
 
5
5
  class RemoteDatasetTest < Test::Unit::TestCase
6
+ include TestHelper
6
7
 
7
8
  def setup
8
- $tmp = Dir.mktmpdir
9
- ENV['MIGA_HOME'] = $tmp
10
- FileUtils.touch(File.expand_path('.miga_rc', ENV["MIGA_HOME"]))
11
- FileUtils.touch(File.expand_path('.miga_daemon.json', ENV["MIGA_HOME"]))
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
9
+ initialize_miga_home
19
10
  end
20
11
 
21
12
  def test_class_universe
@@ -33,19 +24,22 @@ class RemoteDatasetTest < Test::Unit::TestCase
33
24
  { embl: :ebi, nuccore: :ncbi }.each do |db, universe|
34
25
  rd = MiGA::RemoteDataset.new(hiv2, db, universe)
35
26
  assert_equal([hiv2], rd.ids)
36
- omit_if(!$remote_tests, 'Remote access is error-prone')
27
+
28
+ declare_remote_access
37
29
  tx = rd.get_ncbi_taxonomy
38
30
  msg = "Failed on #{universe}:#{db}"
39
31
  assert_equal(MiGA::Taxonomy, tx.class, msg)
40
32
  assert_equal('Lentivirus', tx[:g], msg)
41
33
  assert_equal(
42
- 'ns:ncbi o:Ortervirales f:Retroviridae ' \
43
- 'g:Lentivirus s:Human_immunodeficiency_virus_2',
34
+ 'ns:ncbi k:Pararnavirae p:Artverviricota c:Revtraviricetes ' \
35
+ 'o:Ortervirales f:Retroviridae g:Lentivirus ' \
36
+ 's:Human_immunodeficiency_virus_2',
44
37
  tx.to_s, msg
45
38
  )
46
39
  assert_equal(
47
- 'ns:ncbi d: k: p: c: o:Ortervirales f:Retroviridae ' \
48
- 'g:Lentivirus s:Human_immunodeficiency_virus_2 ssp: str: ds:',
40
+ 'ns:ncbi d: k:Pararnavirae p:Artverviricota c:Revtraviricetes ' \
41
+ 'o:Ortervirales f:Retroviridae g:Lentivirus ' \
42
+ 's:Human_immunodeficiency_virus_2 ssp: str: ds:',
49
43
  tx.to_s(true), msg
50
44
  )
51
45
  assert_equal('ncbi', tx.namespace, msg)
@@ -57,8 +51,9 @@ class RemoteDatasetTest < Test::Unit::TestCase
57
51
  n = 'Cjac_L14'
58
52
  rd = MiGA::RemoteDataset.new(cjac, :assembly_gz, :web)
59
53
  assert_equal([cjac], rd.ids)
60
- omit_if(!$remote_tests, 'Remote access is error-prone')
61
- p = $p1
54
+
55
+ declare_remote_access
56
+ p = project
62
57
  assert_nil(p.dataset(n))
63
58
  rd.save_to(p, n)
64
59
  p.add_dataset(n)
@@ -67,7 +62,7 @@ class RemoteDatasetTest < Test::Unit::TestCase
67
62
  end
68
63
 
69
64
  def test_asm_acc2id
70
- omit_if(!$remote_tests, 'Remote access is error-prone')
65
+ declare_remote_access
71
66
  assert_nil(MiGA::RemoteDataset.ncbi_asm_acc2id('NotAnAccession'))
72
67
  id = MiGA::RemoteDataset.ncbi_asm_acc2id('GCA_004684205.1')
73
68
  assert_equal('2514661', id)
@@ -75,9 +70,9 @@ class RemoteDatasetTest < Test::Unit::TestCase
75
70
  end
76
71
 
77
72
  def test_update_metadata
78
- omit_if(!$remote_tests, 'Remote access is error-prone')
73
+ declare_remote_access
79
74
  hiv1 = 'GCF_000856385.1'
80
- d1 = MiGA::Dataset.new($p1, 'd1')
75
+ d1 = MiGA::Dataset.new(project, 'd1')
81
76
  assert_nil(d1.metadata[:ncbi_assembly])
82
77
  rd = MiGA::RemoteDataset.new(hiv1, :assembly, :ncbi)
83
78
  rd.update_metadata(d1, passthrough: 123, metadata_only: true)
@@ -87,36 +82,35 @@ class RemoteDatasetTest < Test::Unit::TestCase
87
82
  end
88
83
 
89
84
  def test_type_status_asm
90
- omit_if(!$remote_tests, 'Remote access is error-prone')
85
+ declare_remote_access
91
86
  rd = MiGA::RemoteDataset.new('GCF_000018105.1', :assembly, :ncbi)
92
87
  assert { rd.get_metadata[:is_type] }
93
88
  end
94
89
 
95
90
  def test_nontype_status_asm
96
- omit_if(!$remote_tests, 'Remote access is error-prone')
91
+ declare_remote_access
97
92
  rd = MiGA::RemoteDataset.new('GCA_004684205.1', :assembly, :ncbi)
98
93
  assert { !rd.get_metadata[:is_type] }
99
94
  end
100
95
 
101
96
  def test_type_status_nuccore
102
- omit_if(!$remote_tests, 'Remote access is error-prone')
97
+ declare_remote_access
103
98
  rd = MiGA::RemoteDataset.new('NC_019748.1', :nuccore, :ncbi)
104
99
  assert { rd.get_metadata[:is_type] }
105
100
  end
106
101
 
107
102
  def test_ref_type_status
108
- omit_if(!$remote_tests, 'Remote access is error-prone')
103
+ declare_remote_access
109
104
  rd = MiGA::RemoteDataset.new('GCA_002849345', :assembly, :ncbi)
110
105
  assert { !rd.get_metadata[:is_type] }
111
106
  assert { rd.get_metadata[:is_ref_type] }
112
107
  end
113
108
 
114
109
  # This test is too expensive (too much time to run it!)
115
- #def test_net_timeout
116
- # omit_if(!$remote_tests, "Remote access is error-prone")
117
- # bad = "ftp://example.com/miga"
118
- # rd = MiGA::RemoteDataset.new(bad, :assembly, :web)
119
- # assert_raise(Net::ReadTimeout) { rd.save_to($p1, "bad") }
120
- #end
121
-
110
+ # def test_net_timeout
111
+ # declare_remote_access
112
+ # bad = "ftp://example.com/miga"
113
+ # rd = MiGA::RemoteDataset.new(bad, :assembly, :web)
114
+ # assert_raise(Net::ReadTimeout) { rd.save_to(project, "bad") }
115
+ # end
122
116
  end
@@ -3,23 +3,14 @@ require 'miga/project'
3
3
  require 'zlib'
4
4
 
5
5
  class ResultStatsTest < Test::Unit::TestCase
6
+ include TestHelper
6
7
 
7
8
  def setup
8
- $tmp = Dir.mktmpdir
9
- ENV['MIGA_HOME'] = $tmp
10
- FileUtils.touch(File.expand_path('.miga_rc', ENV['MIGA_HOME']))
11
- FileUtils.touch(File.expand_path('.miga_daemon.json', ENV['MIGA_HOME']))
12
- $p = MiGA::Project.new(File.expand_path('project1', $tmp))
13
- $d = $p.add_dataset('dataset1')
14
- end
15
-
16
- def teardown
17
- FileUtils.rm_rf $tmp
18
- ENV['MIGA_HOME'] = nil
9
+ initialize_miga_home
19
10
  end
20
11
 
21
12
  def file_path(dir, ext)
22
- File.join($p.path, dir, "#{$d.name}#{ext}")
13
+ File.join(project.path, dir, "#{dataset.name}#{ext}")
23
14
  end
24
15
 
25
16
  def touch_done(dir)
@@ -29,9 +20,9 @@ class ResultStatsTest < Test::Unit::TestCase
29
20
  def test_single_raw_reads
30
21
  dir = 'data/01.raw_reads'
31
22
  fq = file_path(dir, '.1.fastq')
32
- File.open(fq, 'w') { |fh| fh.puts '@1','ACTAC','+','####' }
23
+ File.open(fq, 'w') { |fh| fh.puts '@1', 'ACTAC', '+', '####' }
33
24
  touch_done(dir)
34
- r = $d.add_result(:raw_reads)
25
+ r = dataset.add_result(:raw_reads)
35
26
  assert_equal({}, r[:stats])
36
27
  r.compute_stats
37
28
  assert_not_empty(r[:stats])
@@ -43,11 +34,11 @@ class ResultStatsTest < Test::Unit::TestCase
43
34
  def test_coupled_raw_reads
44
35
  dir = 'data/01.raw_reads'
45
36
  fq = file_path(dir, '.1.fastq')
46
- File.open(fq, 'w') { |fh| fh.puts '@1','ACTAC','+','####' }
37
+ File.open(fq, 'w') { |fh| fh.puts '@1', 'ACTAC', '+', '####' }
47
38
  fq = file_path(dir, '.2.fastq')
48
- File.open(fq, 'w') { |fh| fh.puts '@1','ACTAC','+','####' }
39
+ File.open(fq, 'w') { |fh| fh.puts '@1', 'ACTAC', '+', '####' }
49
40
  touch_done(dir)
50
- r = $d.add_result(:raw_reads)
41
+ r = dataset.add_result(:raw_reads)
51
42
  r.compute_stats
52
43
  assert_not_empty(r[:stats])
53
44
  assert_nil(r[:stats][:reads])
@@ -59,7 +50,7 @@ class ResultStatsTest < Test::Unit::TestCase
59
50
  dir = 'data/02.trimmed_reads'
60
51
  FileUtils.touch(file_path(dir, '.1.clipped.fastq'))
61
52
  touch_done(dir)
62
- r = $d.add_result(:trimmed_reads)
53
+ r = dataset.add_result(:trimmed_reads)
63
54
  assert_equal({}, r[:stats])
64
55
  r.compute_stats
65
56
  assert_equal({}, r[:stats])
@@ -70,7 +61,7 @@ class ResultStatsTest < Test::Unit::TestCase
70
61
  Dir.mkdir(file_path(dir, '.solexaqa'))
71
62
  Dir.mkdir(file_path(dir, '.fastqc'))
72
63
  touch_done(dir)
73
- r = $d.add_result(:read_quality)
64
+ r = dataset.add_result(:read_quality)
74
65
  assert_equal({}, r[:stats])
75
66
  r.compute_stats
76
67
  assert_equal({}, r[:stats])
@@ -79,9 +70,9 @@ class ResultStatsTest < Test::Unit::TestCase
79
70
  def test_trimmed_fasta
80
71
  dir = 'data/04.trimmed_fasta'
81
72
  fa = file_path(dir, '.CoupledReads.fa')
82
- File.open(fa, 'w') { |fh| fh.puts '>1','ACTAC' }
73
+ File.open(fa, 'w') { |fh| fh.puts '>1', 'ACTAC' }
83
74
  touch_done(dir)
84
- r = $d.add_result(:trimmed_fasta)
75
+ r = dataset.add_result(:trimmed_fasta)
85
76
  assert_equal({}, r[:stats])
86
77
  r.compute_stats
87
78
  assert_equal(1, r[:stats][:reads])
@@ -92,9 +83,9 @@ class ResultStatsTest < Test::Unit::TestCase
92
83
  # Prepare result
93
84
  dir = 'data/05.assembly'
94
85
  fa = file_path(dir, '.LargeContigs.fna')
95
- File.open(fa, 'w') { |fh| fh.puts '>1','ACTAC' }
86
+ File.open(fa, 'w') { |fh| fh.puts '>1', 'ACTAC' }
96
87
  touch_done(dir)
97
- r = $d.add_result(:assembly)
88
+ r = dataset.add_result(:assembly)
98
89
 
99
90
  # Test assertions
100
91
  assert_equal({}, r[:stats])
@@ -108,13 +99,13 @@ class ResultStatsTest < Test::Unit::TestCase
108
99
  # Prepare result
109
100
  dir = 'data/06.cds'
110
101
  fa = file_path(dir, '.faa')
111
- File.open(fa, 'w') { |fh| fh.puts '>1','M' }
102
+ File.open(fa, 'w') { |fh| fh.puts '>1', 'M' }
112
103
  gff = file_path(dir, '.gff3.gz')
113
104
  Zlib::GzipWriter.open(gff) do |fh|
114
105
  fh.puts '# Model Data: a=b;transl_table=11;'
115
106
  end
116
107
  touch_done(dir)
117
- r = $d.add_result(:cds)
108
+ r = dataset.add_result(:cds)
118
109
 
119
110
  # Test assertions
120
111
  assert_equal({}, r[:stats])
@@ -139,7 +130,7 @@ class ResultStatsTest < Test::Unit::TestCase
139
130
  fh.puts ' phylum Abc 0.0 **** '
140
131
  end
141
132
  touch_done(dir)
142
- r = $d.add_result(:taxonomy)
133
+ r = dataset.add_result(:taxonomy)
143
134
 
144
135
  # Test assertions
145
136
  assert_nil(r[:stats][:closest_relative])
@@ -148,5 +139,4 @@ class ResultStatsTest < Test::Unit::TestCase
148
139
  assert_equal([100.0, '%'], r[:stats][:aai])
149
140
  assert_equal(0.0, r[:stats][:phylum_pvalue])
150
141
  end
151
-
152
142
  end