miga-base 1.2.0.1 → 1.2.2.2
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/init/files_helper.rb +1 -1
- data/lib/miga/cli/action/ls.rb +35 -16
- data/lib/miga/cli/base.rb +3 -4
- data/lib/miga/common/format.rb +5 -3
- data/lib/miga/common.rb +3 -5
- data/lib/miga/daemon.rb +6 -0
- data/lib/miga/version.rb +2 -2
- data/test/format_test.rb +21 -0
- 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: 4b1fb93676b3b4c48d2204f48a106575274ee50ab294bbf34a3790e7c9adb94b
|
4
|
+
data.tar.gz: 629d74fd9c861b9afc99c9764b1990e8ea8c9b89e5d10780201828fd68ab3c7c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 46d9ad97e0033b0c99e06476594148baaf2bc630f59c4775d763a2ab322a2ad449229fa9f342509fdfe6ca9a0949405f50b17c719fc817eb426f32a9dd287f54
|
7
|
+
data.tar.gz: 4e6ae0abee96441ac65eb2e8e886f4c2f3d00cc9716205936563022d7858f0d966d28d110c3b18ecdaa8aa328ef58b3b53410e9c32560aa0368b88e7ea6604b8
|
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?
|
data/lib/miga/cli/action/ls.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
#
|
2
|
-
# @license Artistic-2.0
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
3
|
require 'miga/cli/action'
|
5
4
|
|
@@ -42,33 +41,53 @@ class MiGA::Cli::Action::Ls < MiGA::Cli::Action
|
|
42
41
|
'-s', '--silent',
|
43
42
|
'No output and exit with non-zero status if the dataset list is empty'
|
44
43
|
) { |v| cli[:silent] = v }
|
44
|
+
opt.on(
|
45
|
+
'--exec CMD',
|
46
|
+
'Command to execute per dataset, with the following token variables:',
|
47
|
+
'~ {{dataset}}: Name of the dataset',
|
48
|
+
'~ {{project}}: Path to the project'
|
49
|
+
) { |v| cli[:exec] = v }
|
45
50
|
end
|
46
51
|
end
|
47
52
|
|
48
53
|
def perform
|
49
54
|
ds = cli.load_and_filter_datasets(cli[:silent])
|
55
|
+
p = cli.load_project
|
50
56
|
exit(ds.empty? ? 1 : 0) if cli[:silent]
|
51
|
-
|
57
|
+
|
58
|
+
head = nil
|
59
|
+
fun = nil
|
60
|
+
if cli[:datum]
|
52
61
|
cli[:tabular] = true
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
62
|
+
head = [nil, nil]
|
63
|
+
fun = proc { |d| [d.name, d.metadata[cli[:datum]]] }
|
64
|
+
elsif cli[:fields]
|
65
|
+
head = [:name] + cli[:fields]
|
66
|
+
fun = proc { |d| [d.name] + cli[:fields].map { |f| d.metadata[f] } }
|
58
67
|
elsif cli[:info]
|
59
|
-
|
68
|
+
head = Dataset.INFO_FIELDS
|
69
|
+
fun = proc(&:info)
|
60
70
|
elsif cli[:processing]
|
61
|
-
|
62
|
-
|
63
|
-
[d.name] + d.profile_advance.map { |i|
|
71
|
+
head = [:name] + MiGA::Dataset.PREPROCESSING_TASKS
|
72
|
+
fun = proc do |d|
|
73
|
+
[d.name] + d.profile_advance.map { |i| %w[- done queued][i] }
|
64
74
|
end
|
65
75
|
elsif cli[:taskstatus]
|
66
|
-
|
67
|
-
|
68
|
-
end
|
76
|
+
head = [:name] + MiGA::Dataset.PREPROCESSING_TASKS
|
77
|
+
fun = proc { |d| [d.name] + d.results_status.values }
|
69
78
|
else
|
70
79
|
cli[:tabular] = true
|
71
|
-
|
80
|
+
head = [nil]
|
81
|
+
fun = proc { |d| [d.name] }
|
82
|
+
end
|
83
|
+
|
84
|
+
format_table(ds, head) do |d|
|
85
|
+
if cli[:exec]
|
86
|
+
MiGA::MiGA.run_cmd(
|
87
|
+
cli[:exec].miga_variables(dataset: d.name, project: p.path)
|
88
|
+
)
|
89
|
+
end
|
90
|
+
fun[d]
|
72
91
|
end
|
73
92
|
end
|
74
93
|
|
data/lib/miga/cli/base.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
#
|
2
|
-
# @license Artistic-2.0
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
3
|
module MiGA::Cli::Base
|
5
4
|
@@TASK_DESC = {
|
@@ -20,10 +19,10 @@ module MiGA::Cli::Base
|
|
20
19
|
add: 'Create a dataset in a MiGA project',
|
21
20
|
get: 'Download a dataset from public databases into a MiGA project',
|
22
21
|
ncbi_get: 'Download all genomes in a taxon from NCBI into a MiGA project',
|
23
|
-
rm: 'Remove a dataset from
|
22
|
+
rm: 'Remove a dataset from a MiGA project',
|
24
23
|
find: 'Find unregistered datasets based on result files',
|
25
24
|
ln: 'Link datasets (including results) from one project to another',
|
26
|
-
ls: 'List all registered datasets in
|
25
|
+
ls: 'List all registered datasets in a MiGA project',
|
27
26
|
archive: 'Generate a tar-ball with all files from select datasets',
|
28
27
|
# Results
|
29
28
|
add_result: 'Register a result',
|
data/lib/miga/common/format.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'tempfile'
|
2
4
|
|
3
5
|
##
|
@@ -37,13 +39,13 @@ module MiGA::Common::Format
|
|
37
39
|
tmp_path = tmp_fh.path
|
38
40
|
fh = File.open(file, 'r')
|
39
41
|
end
|
40
|
-
buffer = ''
|
42
|
+
buffer = ''.dup
|
41
43
|
fh.each_line do |ln|
|
42
44
|
ln.chomp!
|
43
45
|
if ln =~ /^>\s*(\S+)(.*)/
|
44
46
|
id, df = $1, $2
|
45
47
|
tmp_fh.print buffer.wrap_width(80)
|
46
|
-
buffer = ''
|
48
|
+
buffer = ''.dup
|
47
49
|
tmp_fh.puts ">#{id.gsub(/[^A-Za-z0-9_\|\.]/, '_')}#{df}"
|
48
50
|
else
|
49
51
|
buffer << ln.gsub(/[^A-Za-z\.\-]/, '')
|
@@ -165,7 +167,7 @@ class String
|
|
165
167
|
##
|
166
168
|
# Replace {{variables}} using the +vars+ hash
|
167
169
|
def miga_variables(vars)
|
168
|
-
o =
|
170
|
+
o = self.dup
|
169
171
|
vars.each { |k, v| o.gsub!("{{#{k}}}", v.to_s) }
|
170
172
|
o
|
171
173
|
end
|
data/lib/miga/common.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
#
|
2
|
-
# @license Artistic-2.0
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
3
|
require 'zlib'
|
5
4
|
require 'stringio'
|
@@ -44,9 +43,8 @@ class MiGA::MiGA
|
|
44
43
|
# +ext+ values (Array of String).
|
45
44
|
def result_files_exist?(base, ext)
|
46
45
|
ext = [ext] unless ext.is_a? Array
|
47
|
-
|
48
|
-
|
49
|
-
end
|
46
|
+
MiGA::MiGA.DEBUG("Assserting files for result: #{ext}")
|
47
|
+
ext.all? { |f| File.exist?(base + f) or File.exist?("#{base}#{f}.gz") }
|
50
48
|
end
|
51
49
|
|
52
50
|
##
|
data/lib/miga/daemon.rb
CHANGED
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, 2].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, 2)
|
24
24
|
|
25
25
|
##
|
26
26
|
# References of MiGA
|
data/test/format_test.rb
CHANGED
@@ -58,6 +58,9 @@ class FormatTest < Test::Unit::TestCase
|
|
58
58
|
assert_equal(50.0, o[:gc])
|
59
59
|
assert_equal(5, o[:n50])
|
60
60
|
assert_equal(4.0, o[:med])
|
61
|
+
o = MiGA::MiGA.seqs_length(f, :fasta, skew: true)
|
62
|
+
assert_equal(-50.0, o[:at_skew])
|
63
|
+
assert_equal(-25.0, o[:gc_skew])
|
61
64
|
end
|
62
65
|
|
63
66
|
def test_seqs_length_fastq
|
@@ -77,4 +80,22 @@ class FormatTest < Test::Unit::TestCase
|
|
77
80
|
assert_equal('123 45', tab[2])
|
78
81
|
assert_equal('678 90', tab[3])
|
79
82
|
end
|
83
|
+
|
84
|
+
def test_miga_name
|
85
|
+
assert_not('a-bad-name'.miga_name?)
|
86
|
+
assert('a_good_one'.miga_name?)
|
87
|
+
|
88
|
+
assert('After_it_s_fixed_', 'After it\'s fixed!'.miga_name)
|
89
|
+
|
90
|
+
assert('A sp.', 'A_sp_'.unmiga_name)
|
91
|
+
assert('B str. C', 'B_sp_C'.unmiga_name)
|
92
|
+
assert('The X content', 'The_x_content'.unmiga_name)
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_miga_variables
|
96
|
+
assert_equal(
|
97
|
+
'1 a box!',
|
98
|
+
'{{n}} {{my}} {{secret}}!'.miga_variables(my: 'a', secret: :box, n: 1)
|
99
|
+
)
|
100
|
+
end
|
80
101
|
end
|
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.2
|
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-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: daemons
|