miga-base 1.2.1.0 → 1.2.2.3
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/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/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/distance/commands.rb +6 -1
- data/utils/distance/pipeline.rb +4 -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: 3b3fd16e90667560b5cba41046eb92613187279fd7194d1825cc3dee9690273d
|
4
|
+
data.tar.gz: 84043b09c234b825ba0b89ca057b4301a97d5234a87282583516abffbc377e05
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e0d76139cfd93f77a91ee266bd596d74e8881da94fb750d97b03bb6c491424e75af208177687525d284ae3fe96e77f1e373f0bdce0583445a4070f3ed09cac0
|
7
|
+
data.tar.gz: 5bd98ea9eb89bcb4af4b74128c2d84ac1f32047322bb2177f7d47543efcc4122a4f8c23f463e8ae8291c8e6dff753182a39fd11fbdf42679975e5b2dba0ca571
|
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(?, ?, ?, ?, ?, ?);
|
@@ -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, 2, 3].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, 9)
|
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/distance/commands.rb
CHANGED
@@ -111,12 +111,17 @@ module MiGA::DistanceRunner::Commands
|
|
111
111
|
return unless File.size?(f1)
|
112
112
|
|
113
113
|
# Run FastANI
|
114
|
+
empty = true
|
114
115
|
File.open(f2 = tmp_file, 'w') do |fh|
|
115
116
|
targets.each do |target|
|
116
117
|
target_asm = target&.result(:assembly)&.file_path(:largecontigs)
|
117
|
-
|
118
|
+
if target_asm
|
119
|
+
fh.puts target_asm
|
120
|
+
empty = false
|
121
|
+
end
|
118
122
|
end
|
119
123
|
end
|
124
|
+
return if empty
|
120
125
|
run_cmd <<~CMD
|
121
126
|
fastANI -q "#{f1}" --rl "#{f2}" -t #{opts[:thr]} \
|
122
127
|
-o "#{f3 = tmp_file}"
|
data/utils/distance/pipeline.rb
CHANGED
@@ -33,6 +33,10 @@ module MiGA::DistanceRunner::Pipeline
|
|
33
33
|
|
34
34
|
# Builds a tree with all visited medoids from any classification level
|
35
35
|
def build_medoids_tree(metric)
|
36
|
+
# TODO Reduce impact and bring back the medoids tree
|
37
|
+
$stderr.puts 'Bypassing medoids tree'
|
38
|
+
return
|
39
|
+
|
36
40
|
$stderr.puts "Building medoids tree (metric = #{metric})"
|
37
41
|
db = query_db(metric)
|
38
42
|
return unless File.size? db
|
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.2.3
|
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-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: daemons
|