miga-base 1.2.0.1 → 1.2.2.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 27068ded9d2ff63c3575a5aafd3fa68374f4bcf8aef924354e0c9cbde7dc1f6d
4
- data.tar.gz: ef438e828180d304a9e3449d49551ace933a5e5a46128970b3c8bc385c836d58
3
+ metadata.gz: 4b1fb93676b3b4c48d2204f48a106575274ee50ab294bbf34a3790e7c9adb94b
4
+ data.tar.gz: 629d74fd9c861b9afc99c9764b1990e8ea8c9b89e5d10780201828fd68ab3c7c
5
5
  SHA512:
6
- metadata.gz: 894cbeca2aa4f5e29c6bd6e1c23c9c358b9f3b497960998116169fa62d7122da78417e357789dc9b9b7bfdfad824f835b3daa035d1320cb948e5cdc4b1d74bb3
7
- data.tar.gz: 8bea4585b36855195f3a2d76005a6ff664133c1df639a677402907c88fd8f6b0a25fb34cc4bd0e9e38bc7666dbe3a382644137dcf5cddd4005c93256d2c75c05
6
+ metadata.gz: 46d9ad97e0033b0c99e06476594148baaf2bc630f59c4775d763a2ab322a2ad449229fa9f342509fdfe6ca9a0949405f50b17c719fc817eb426f32a9dd287f54
7
+ data.tar.gz: 4e6ae0abee96441ac65eb2e8e886f4c2f3d00cc9716205936563022d7858f0d966d28d110c3b18ecdaa8aa328ef58b3b53410e9c32560aa0368b88e7ea6604b8
@@ -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
- raise 'Please specify input type (-i).' if cli[:input_type].nil?
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?
@@ -112,7 +112,7 @@ module MiGA::Cli::Action::Init::FilesHelper
112
112
  && tar zxf #{arch.shellescape} \
113
113
  && rm #{arch.shellescape}
114
114
  CMD
115
- run_cmd(cmd, source: nil)
115
+ run_cmd(cli, cmd, source: nil)
116
116
  cli.puts
117
117
  end
118
118
  end
@@ -1,5 +1,4 @@
1
- # @package MiGA
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
- if !cli[:datum].nil?
57
+
58
+ head = nil
59
+ fun = nil
60
+ if cli[:datum]
52
61
  cli[:tabular] = true
53
- format_table(ds, [nil, nil]) { |d| [d.name, d.metadata[cli[:datum]]] }
54
- elsif !cli[:fields].nil?
55
- format_table(ds, [:name] + cli[:fields]) do |d|
56
- [d.name] + cli[:fields].map { |f| d.metadata[f] }
57
- end
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
- format_table(ds, Dataset.INFO_FIELDS) { |d| d.info }
68
+ head = Dataset.INFO_FIELDS
69
+ fun = proc(&:info)
60
70
  elsif cli[:processing]
61
- comp = %w[- done queued]
62
- format_table(ds, [:name] + MiGA::Dataset.PREPROCESSING_TASKS) do |d|
63
- [d.name] + d.profile_advance.map { |i| comp[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
- format_table(ds, [:name] + MiGA::Dataset.PREPROCESSING_TASKS) do |d|
67
- [d.name] + d.results_status.values
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
- format_table(ds, [nil]) { |d| [d.name] }
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
- # @package MiGA
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 an MiGA project',
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 an MiGA project',
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',
@@ -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 = "#{self}"
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
- # @package MiGA
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
- ext.all? do |f|
48
- File.exist?(base + f) or File.exist?("#{base}#{f}.gz")
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
@@ -66,6 +66,12 @@ class MiGA::Daemon < MiGA::MiGA
66
66
  "MiGA:#{project.name}"
67
67
  end
68
68
 
69
+ ##
70
+ # Alias to +project.path+ for compatibility with lairs
71
+ def path
72
+ project.path
73
+ end
74
+
69
75
  ##
70
76
  # Run only in the first loop
71
77
  def daemon_first_loop
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, 0, 1].freeze
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(2021, 12, 11)
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
@@ -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
- fh.puts target_asm if target_asm
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}"
@@ -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=T)
8
+ argv <- commandArgs(trailingOnly = TRUE)
9
9
  suppressPackageStartupMessages(library(ape))
10
- if(Sys.getenv('MIGA') == ''){
10
+ if (Sys.getenv("MIGA") == "") {
11
11
  suppressPackageStartupMessages(library(enveomics.R))
12
- }else{
13
- source(file.path(Sys.getenv('MIGA'),
14
- 'utils', 'enveomics', 'enveomics.R', 'R', 'df2dist.R'))
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(ani.ph, cex=1/3, type='fan',
35
- tip.color=c('red', 'black')[ifelse(ani.ph$tip.label==q_dataset, 1, 2)])
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.0.1
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: 2021-12-11 00:00:00.000000000 Z
11
+ date: 2022-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: daemons