miga-base 1.2.2.2 → 1.2.4.0

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: 4b1fb93676b3b4c48d2204f48a106575274ee50ab294bbf34a3790e7c9adb94b
4
- data.tar.gz: 629d74fd9c861b9afc99c9764b1990e8ea8c9b89e5d10780201828fd68ab3c7c
3
+ metadata.gz: 5a2b155a7dd169adddb5bc6c1470c252adb2357521e5df1cb37634a80031a123
4
+ data.tar.gz: dc99e9614989ea17bf173c8d1fc8c1f0dd5692030079d54197099471f8f17041
5
5
  SHA512:
6
- metadata.gz: 46d9ad97e0033b0c99e06476594148baaf2bc630f59c4775d763a2ab322a2ad449229fa9f342509fdfe6ca9a0949405f50b17c719fc817eb426f32a9dd287f54
7
- data.tar.gz: 4e6ae0abee96441ac65eb2e8e886f4c2f3d00cc9716205936563022d7858f0d966d28d110c3b18ecdaa8aa328ef58b3b53410e9c32560aa0368b88e7ea6604b8
6
+ metadata.gz: e4d1271135ba5c66a712f6ba7f19e14b351b367342d0a6f8e268ede58f7d85cc5bc2c4830040cdfa0e9bb742075ef61de4bf0cd086e075e9318ba4cd62eba4e2
7
+ data.tar.gz: 95d6881e9c0df6f5d2dbbef6f0ae144ac922a1e1a3b355785f78376cef1ed1e8b783ea08bf24674b6e17ca5543d90cc4555b11f11c261baa574398ddace9bb97
@@ -31,6 +31,7 @@ module MiGA::Cli::Action::Doctor::Base
31
31
  file = File.join(base, dir, file_db)
32
32
  blk[file, metric, result, rank] if File.exist? file
33
33
  end
34
+ # Query databases for reference databases refer to taxonomy runs
34
35
  base = File.join(base, '05.taxonomy')
35
36
  result = :taxonomy
36
37
  end
@@ -137,10 +138,11 @@ module MiGA::Cli::Action::Doctor::Base
137
138
  def save_bidirectional(a, dist)
138
139
  each_database_file(a) do |db_file, metric, result, rank|
139
140
  next if rank == :haai # No need for hAAI to be bidirectional
141
+ next if result == :taxonomy # Taxonomy is never bidirectional
140
142
 
141
143
  b2a = dist[rank].map { |b_name, v| b_name if v[a.name] }.compact
142
144
  a2b = dist[rank][a.name]&.keys || []
143
- SQLite3::Database.new(db_file) do |db|
145
+ MiGA::SQLite.new(db_file).run do |db|
144
146
  sql = <<~SQL
145
147
  insert into #{metric}(seq1, seq2, #{metric}, sd, n, omega) \
146
148
  values(?, ?, ?, ?, ?, ?);
@@ -5,7 +5,7 @@ require 'miga/cli/action'
5
5
 
6
6
  class MiGA::Cli::Action::Run < MiGA::Cli::Action
7
7
  def parse_cli
8
- cli.defaults = { try_load: false, thr: 1, env: false }
8
+ cli.defaults = { try_load: false, thr: 1, env: false, check_first: false }
9
9
  cli.parse do |opt|
10
10
  cli.opt_object(opt, [:project, :dataset_opt, :result_opt])
11
11
  opt.on(
@@ -25,6 +25,10 @@ class MiGA::Cli::Action::Run < MiGA::Cli::Action
25
25
  '-e', '--environment',
26
26
  'Load PROJECT, DATASET, and CORES from the environment'
27
27
  ) { |v| cli[:env] = v }
28
+ opt.on(
29
+ '--check-first',
30
+ 'Check if the result exists, and run only if it does not'
31
+ ) { |v| cli[:check_first] = v }
28
32
  end
29
33
  end
30
34
 
@@ -51,6 +55,15 @@ class MiGA::Cli::Action::Run < MiGA::Cli::Action
51
55
  # Load project
52
56
  p = cli.load_project
53
57
 
58
+ # Check if result already exists
59
+ if cli[:check_first]
60
+ obj = cli[:dataset] ? p.dataset(cli[:dataset]) : p
61
+ if obj.result(cli[:result])
62
+ cli.say 'Result already exists'
63
+ return
64
+ end
65
+ end
66
+
54
67
  # Prepare command
55
68
  miga = MiGA.root_path
56
69
  opts = {}
@@ -69,15 +69,20 @@ module MiGA::Cli::Action::Wf
69
69
  'By default: ~/.miga_daemon.json'
70
70
  ) { |v| cli[:daemon_json] = v }
71
71
  opt.on(
72
- '-j', '--jobs INT',
72
+ '-j', '--jobs INT', Integer,
73
73
  'Number of parallel jobs to execute',
74
74
  'By default controlled by the daemon configuration (maxjobs)'
75
- ) { |v| cli[:jobs] = v.to_i }
75
+ ) { |v| cli[:jobs] = v }
76
76
  opt.on(
77
- '-t', '--threads INT',
77
+ '-t', '--threads INT', Integer,
78
78
  'Number of CPUs to use per job',
79
79
  'By default controlled by the daemon configuration (ppn)'
80
- ) { |v| cli[:threads] = v.to_i }
80
+ ) { |v| cli[:threads] = v }
81
+ opt.on(
82
+ '--threads-project INT', Integer,
83
+ 'Number of CPUs to use per project-wide job',
84
+ 'By default controlled by the daemon configuration (ppn_project or ppn)'
85
+ ) { |v| cli[:threads_project] = v }
81
86
  end
82
87
 
83
88
  def opts_for_wf_distances(opt)
@@ -184,9 +189,10 @@ module MiGA::Cli::Action::Wf
184
189
 
185
190
  def run_daemon
186
191
  cmd = ['daemon', 'run', '-P', cli[:outdir], '--shutdown-when-done']
187
- cmd += ['--json', cli[:daemon_json]] unless cli[:daemon_json].nil?
188
- cmd += ['--max-jobs', cli[:jobs]] unless cli[:jobs].nil?
189
- cmd += ['--ppn', cli[:threads]] unless cli[:threads].nil?
192
+ cmd += ['--json', cli[:daemon_json]] if cli[:daemon_json]
193
+ cmd += ['--max-jobs', cli[:jobs]] if cli[:jobs]
194
+ cmd += ['--ppn', cli[:threads]] if cli[:threads]
195
+ cmd += ['--ppn-project', cli[:threads_project]] if cli[:threads_project]
190
196
  cmd += ['--debug', MiGA::MiGA.debug_trace? ? '2' : '1'] if MiGA::MiGA.debug?
191
197
  cwd = Dir.pwd
192
198
  call_cli(cmd)
@@ -29,7 +29,7 @@ module MiGA::Common::WithDaemonClass
29
29
  return nil if c.nil? || c.empty?
30
30
 
31
31
  Time.parse(c)
32
- rescue Errno::ENOENT
32
+ rescue Errno::ENOENT, ArgumentError
33
33
  return nil
34
34
  end
35
35
  end
@@ -26,9 +26,7 @@ module MiGA::Common::WithResult
26
26
  task = task.to_sym
27
27
  return nil if result_dirs[task].nil?
28
28
 
29
- base = File.join(
30
- project.path, "data/#{result_dirs[task]}/#{result_base}"
31
- )
29
+ base = File.join(project.path, 'data', result_dirs[task], result_base)
32
30
  json = "#{base}.json"
33
31
  return MiGA::Result.load(json) unless save
34
32
 
data/lib/miga/sqlite.rb CHANGED
@@ -31,16 +31,30 @@ class MiGA::SQLite < MiGA::MiGA
31
31
  def initialize(path, opts = {})
32
32
  @opts = MiGA::SQLite.default_opts(opts)
33
33
  @path = File.absolute_path(path)
34
+ MiGA::MiGA.DEBUG("Accessing database: #{path}")
34
35
  end
35
36
 
36
37
  ##
37
- # Executes +cmd+ and returns the result
38
+ # Executes +cmd+ and returns the result. Alternatively, if a block is
39
+ # passed, the commands are ignored and the block is executed with a
40
+ # single parameter of the database connection
38
41
  def run(*cmd)
42
+ if block_given?
43
+ run_block { |conn| yield(conn) }
44
+ else
45
+ y = nil
46
+ run_block { |conn| y = conn.execute(*cmd) }
47
+ y
48
+ end
49
+ end
50
+
51
+ ##
52
+ # Executes +blk+ that accepts a single parameter for the database
53
+ # connection
54
+ def run_block(&blk)
39
55
  busy_attempts ||= 0
40
56
  io_attempts ||= 0
41
- y = nil
42
- SQLite3::Database.new(path) { |conn| y = conn.execute(*cmd) }
43
- y
57
+ SQLite3::Database.new(path) { |conn| blk[conn] }
44
58
  rescue SQLite3::BusyException => e
45
59
  busy_attempts += 1
46
60
  raise "Database busy #{path}: #{e.message}" if busy_attempts >= 3
data/lib/miga/version.rb CHANGED
@@ -12,7 +12,7 @@ module MiGA
12
12
  # - String indicating release status:
13
13
  # - rc* release candidate, not released as gem
14
14
  # - [0-9]+ stable release, released as gem
15
- VERSION = [1.2, 2, 2].freeze
15
+ VERSION = [1.2, 4, 0].freeze
16
16
 
17
17
  ##
18
18
  # Nickname for the current major.minor version.
@@ -20,7 +20,7 @@ module MiGA
20
20
 
21
21
  ##
22
22
  # Date of the current gem relese.
23
- VERSION_DATE = Date.new(2022, 2, 2)
23
+ VERSION_DATE = Date.new(2022, 2, 25)
24
24
 
25
25
  ##
26
26
  # References of MiGA
@@ -1,29 +1,48 @@
1
1
  #!/usr/bin/env Rscript
2
2
 
3
- argv <- commandArgs(trailingOnly=T)
3
+ argv <- commandArgs(trailingOnly = TRUE)
4
4
 
5
- plot_core_pan <- function(core_pan, pdf){
6
- a <- read.table(core_pan, sep="\t", header=TRUE)
5
+ plot_core_pan <- function (core_pan, pdf) {
6
+ a <- read.table(core_pan, sep = "\t", header = TRUE)
7
+ col <- c(
8
+ rgb(96, 11, 64, max = 255),
9
+ rgb(0, 121, 166, max = 255),
10
+ rgb(0.5, 0.5, 0.5, 1/3),
11
+ rep(rgb(0.5, 0.5, 0.5), 2)
12
+ )
7
13
  pdf(pdf, 7, 5)
8
- plot(1, type="n", xlim=c(0, max(a$genomes)*1.05), xaxs="i", yaxs="i",
9
- ylim=c(0, max(a$pan_q3)*1.05), xlab="Genomes", ylab="Orthologous Groups")
14
+ plot(
15
+ 1, type = "n", xlim = c(0, max(a$genomes) * 1.05), xaxs = "i", yaxs = "i",
16
+ ylim = c(0, max(a$pan_q3) * 1.05)/1e3, xlab = "Genomes",
17
+ ylab = "Orthologous Groups (thousands)"
18
+ )
19
+
10
20
  # Core
11
- polygon(c(a$genomes, rev(a$genomes)), c(a$core_q1, rev(a$core_q3)),
12
- border=NA, col=rgb(0, 121, 166, 128/2, max=255))
13
- lines(a$genomes, a$core_avg, col=rgb(0,121,166,max=255), lty=2)
14
- lines(a$genomes, a$core_q2, col=rgb(0,121,166,max=255), lty=1)
21
+ polygon(
22
+ c(a$genomes, rev(a$genomes)), c(a$core_q1, rev(a$core_q3))/1e3,
23
+ border = NA, col = rgb(0, 121, 166, 256/4, max = 255)
24
+ )
25
+ lines(a$genomes, a$core_avg/1e3, col = col[2], lty = 2)
26
+ lines(a$genomes, a$core_q2/1e3, col = col[2], lty = 1)
27
+
15
28
  # Pan
16
- polygon(c(a$genomes, rev(a$genomes)), c(a$pan_q1, rev(a$pan_q3)),
17
- border=NA, col=rgb(96, 11, 64, 128/2, max=255))
18
- lines(a$genomes, a$pan_avg, col=rgb(96,11,64,max=255), lty=2)
19
- lines(a$genomes, a$pan_q2, col=rgb(96,11,64,max=255), lty=1)
29
+ polygon(
30
+ c(a$genomes, rev(a$genomes)), c(a$pan_q1, rev(a$pan_q3))/1e3,
31
+ border = NA, col = rgb(96, 11, 64, 256/4, max = 255)
32
+ )
33
+ lines(a$genomes, a$pan_avg/1e3, col = col[1], lty = 2)
34
+ lines(a$genomes, a$pan_q2/1e3, col = col[1], lty = 1)
35
+
20
36
  # Legend
21
- legend("topleft",
22
- legend=c("pangenome","core genome","Inter-Quartile","Median","Average"),
23
- pch=c(16,16,15,NA,NA),lty=c(NA,NA,NA,1,2), pt.cex=c(1,1,2,NA,NA),
24
- col=c(rgb(96,11,64,max=255), rgb(0,121,166,max=255),
25
- rgb(0.5,0.5,0.5,166/255), rep(rgb(0.5,0.5,0.5),2)), bty="n")
37
+ legend <- c("pangenome", "core genome", "Inter-Quartile", "Median", "Average")
38
+ legend(
39
+ "topleft", legend = legend, col = col, bty = "n",
40
+ pch = c(16, 16, 15, NA, NA),
41
+ lty = c(NA, NA, NA, 1, 2),
42
+ pt.cex = c(1, 1, 2, NA, NA),
43
+ )
26
44
  dev.off()
27
45
  }
28
46
 
29
47
  plot_core_pan(argv[1], argv[2])
48
+
@@ -19,6 +19,7 @@ end
19
19
  p.each_dataset do |d|
20
20
  next unless d.ref? && d.active?
21
21
 
22
+ db.execute('BEGIN TRANSACTION')
22
23
  searchable(db, d, :name, d.name)
23
24
  d.metadata.each do |k, v|
24
25
  next if [:created, :updated].include? k
@@ -26,4 +27,5 @@ p.each_dataset do |d|
26
27
  v = v.sorted_ranks.map { |r| r[1] }.join(' ') if k == :tax
27
28
  searchable(db, d, k, v)
28
29
  end
30
+ db.execute('COMMIT')
29
31
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: miga-base
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2.2
4
+ version: 1.2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luis M. Rodriguez-R
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-02-02 00:00:00.000000000 Z
11
+ date: 2022-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: daemons