miga-base 1.2.2.0 → 1.2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/miga/cli/action/add.rb +2 -1
- data/lib/miga/cli/action/doctor/base.rb +3 -1
- data/lib/miga/cli/action/init/files_helper.rb +1 -1
- data/lib/miga/cli/action/wf.rb +13 -7
- data/lib/miga/common/with_result.rb +1 -3
- data/lib/miga/common.rb +2 -3
- data/lib/miga/daemon.rb +6 -0
- data/lib/miga/sqlite.rb +18 -4
- data/lib/miga/version.rb +2 -2
- data/utils/core-pan-plot.R +37 -18
- data/utils/index_metadata.rb +2 -0
- data/utils/ref-tree.R +20 -15
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 94374ec5cc66632861a18159a8adf69591ce9d3d5249de5baacd636d7519bb9e
|
4
|
+
data.tar.gz: '0395e8ac95c1770b2ee859a4bc59d0ba806f1298cc271f4ff0b64a4c7363897d'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69667e9595a04b972865911b5c2e4204f879d8c8f7fee6cd68e5c4e7a84662d9c9d4018a4f533cbbb33eada796fc26faa4797b3c0c016d4ef34fc8c1d13138e2
|
7
|
+
data.tar.gz: 86aae6d82404516d2cbd8812eef539e00690fdf47ccecf7205bd4e4f301dc11f415f630111a40f22459a448579b4251698906e7e0380eb1631a1fae05915e183
|
data/lib/miga/cli/action/add.rb
CHANGED
@@ -57,6 +57,7 @@ class MiGA::Cli::Action::Add < MiGA::Cli::Action
|
|
57
57
|
|
58
58
|
def perform
|
59
59
|
p = cli.load_project
|
60
|
+
cli.ensure_par(type: '-t')
|
60
61
|
files, file_type = get_files_and_type
|
61
62
|
|
62
63
|
paired = cli[:input_type].to_s.include?('_paired')
|
@@ -113,7 +114,7 @@ class MiGA::Cli::Action::Add < MiGA::Cli::Action
|
|
113
114
|
cli.ensure_type(Dataset)
|
114
115
|
files = [nil]
|
115
116
|
else
|
116
|
-
|
117
|
+
cli.ensure_par({ input_type: '-i' }, 'Please specify input type (-i)')
|
117
118
|
|
118
119
|
file_type = self.class.INPUT_TYPES[cli[:input_type]]
|
119
120
|
raise "Unrecognized input type: #{cli[:input_type]}." if file_type.nil?
|
@@ -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
|
-
|
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(?, ?, ?, ?, ?, ?);
|
data/lib/miga/cli/action/wf.rb
CHANGED
@@ -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
|
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
|
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]]
|
188
|
-
cmd += ['--max-jobs', cli[:jobs]]
|
189
|
-
cmd += ['--ppn', cli[:threads]]
|
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)
|
@@ -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/common.rb
CHANGED
@@ -43,9 +43,8 @@ class MiGA::MiGA
|
|
43
43
|
# +ext+ values (Array of String).
|
44
44
|
def result_files_exist?(base, ext)
|
45
45
|
ext = [ext] unless ext.is_a? Array
|
46
|
-
|
47
|
-
|
48
|
-
end
|
46
|
+
MiGA::MiGA.DEBUG("Assserting files for result: #{ext}")
|
47
|
+
ext.all? { |f| File.exist?(base + f) or File.exist?("#{base}#{f}.gz") }
|
49
48
|
end
|
50
49
|
|
51
50
|
##
|
data/lib/miga/daemon.rb
CHANGED
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
|
-
|
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,
|
15
|
+
VERSION = [1.2, 3, 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(
|
23
|
+
VERSION_DATE = Date.new(2022, 2, 17)
|
24
24
|
|
25
25
|
##
|
26
26
|
# References of MiGA
|
data/utils/core-pan-plot.R
CHANGED
@@ -1,29 +1,48 @@
|
|
1
1
|
#!/usr/bin/env Rscript
|
2
2
|
|
3
|
-
argv <- commandArgs(trailingOnly=
|
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(
|
9
|
-
|
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(
|
12
|
-
|
13
|
-
|
14
|
-
|
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(
|
17
|
-
|
18
|
-
|
19
|
-
|
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("
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
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
|
+
|
data/utils/index_metadata.rb
CHANGED
@@ -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
|
data/utils/ref-tree.R
CHANGED
@@ -5,38 +5,43 @@
|
|
5
5
|
#
|
6
6
|
|
7
7
|
#= Load stuff
|
8
|
-
argv <- commandArgs(trailingOnly=
|
8
|
+
argv <- commandArgs(trailingOnly = TRUE)
|
9
9
|
suppressPackageStartupMessages(library(ape))
|
10
|
-
if(Sys.getenv(
|
10
|
+
if (Sys.getenv("MIGA") == "") {
|
11
11
|
suppressPackageStartupMessages(library(enveomics.R))
|
12
|
-
}else{
|
13
|
-
source(
|
14
|
-
|
12
|
+
} else {
|
13
|
+
source(
|
14
|
+
file.path(
|
15
|
+
Sys.getenv("MIGA"), "utils", "enveomics", "enveomics.R", "R", "df2dist.R"
|
16
|
+
)
|
17
|
+
)
|
15
18
|
}
|
16
19
|
inst <- c("phangorn", "phytools") %in% rownames(installed.packages())
|
17
|
-
if(inst[1]){
|
20
|
+
if (inst[1]) {
|
18
21
|
suppressPackageStartupMessages(library(phangorn))
|
19
22
|
reroot.fun <- midpoint
|
20
|
-
}else if(inst[2]){
|
23
|
+
} else if (inst[2]) {
|
21
24
|
suppressPackageStartupMessages(library(phytools))
|
22
25
|
reroot.fun <- midpoint.root
|
23
|
-
}else{
|
26
|
+
} else {
|
24
27
|
reroot.fun <- function(x) return(x)
|
25
28
|
}
|
26
29
|
|
27
30
|
#= Main function
|
28
31
|
ref_tree <- function(ani_file, out_base, q_dataset) {
|
29
|
-
a <- read.table(ani_file, sep="\t", header=TRUE, as.is=TRUE)
|
30
|
-
ani.d <- enve.df2dist(a[,1:3], default.d=0.9, max.sim=100)
|
32
|
+
a <- read.table(ani_file, sep = "\t", header = TRUE, as.is = TRUE)
|
33
|
+
ani.d <- enve.df2dist(a[, 1:3], default.d = 0.9, max.sim = 100)
|
31
34
|
ani.ph <- reroot.fun(bionj(ani.d))
|
32
|
-
write.tree(ani.ph, paste(out_base, ".nwk", sep=""))
|
33
|
-
pdf(paste(out_base, ".nwk.pdf", sep=""), 7, 7)
|
34
|
-
plot(
|
35
|
-
|
35
|
+
write.tree(ani.ph, paste(out_base, ".nwk", sep = ""))
|
36
|
+
pdf(paste(out_base, ".nwk.pdf", sep = ""), 7, 7)
|
37
|
+
plot(
|
38
|
+
ani.ph, cex = 1/3, type = "fan",
|
39
|
+
tip.color = c("red", "black")[ifelse(ani.ph$tip.label == q_dataset, 1, 2)]
|
40
|
+
)
|
36
41
|
add.scale.bar()
|
37
42
|
dev.off()
|
38
43
|
}
|
39
44
|
|
40
45
|
#= Main
|
41
|
-
ref_tree(ani_file=argv[1], out_base=argv[2], q_dataset=argv[3])
|
46
|
+
ref_tree(ani_file = argv[1], out_base = argv[2], q_dataset = argv[3])
|
42
47
|
|
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.
|
4
|
+
version: 1.2.3.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:
|
11
|
+
date: 2022-02-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: daemons
|