Module: MiGA::Cli::Action::Doctor::Operations

Included in:
MiGA::Cli::Action::Doctor
Defined in:
lib/miga/cli/action/doctor/operations.rb

Instance Method Summary collapse

Instance Method Details

#check_cds(cli) ⇒ Object

Perform cds operation with MiGA::Cli cli



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/miga/cli/action/doctor/operations.rb', line 88

def check_cds(cli)
  cli.say 'Looking for unzipped genes or proteins'
  n, k = cli.load_project.dataset_names.size, 0
  cli.load_project.each_dataset do |d|
    cli.advance('Datasets:', k += 1, n, false)
    res = d.result(:cds) or next
    changed = false
    i[genes proteins gff3 gff2 tab].each do |f|
      file = res.file_path(f) or next
      if file !~ /\.gz/
        cli.say "  > Gzipping #{d.name} #{f}   "
        run_cmd(['gzip', '-9', file])
        changed = true
      end
    end
    if changed
      d.add_result(:cds, true, force: true)
      sr = d.result(:stats) and sr.remove!
    end
  end
  cli.say
end

#check_ess(cli) ⇒ Object

Perform essential-genes operation with MiGA::Cli cli



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/miga/cli/action/doctor/operations.rb', line 113

def check_ess(cli)
  cli.say 'Looking for outdated essential genes'
  cli.load_project.each_dataset do |d|
    res = d.result(:essential_genes)
    next if res.nil?

    dir = res.file_path(:collection)
    if dir.nil? || outdated_fastaai_ess(res)
      cli.say "  > Removing #{d.name}:essential_genes"
      res.remove!
      d.result(:stats)&.remove!
      next
    end
    next if Dir["#{dir}/*.faa"].empty?

    cli.say "  > Fixing #{d.name}"
    run_cmd "      cd \#{dir.shellescape} && tar -zcf proteins.tar.gz *.faa && rm *.faa\n    CMD\n  end\nend\n"

#check_files(cli) ⇒ Object

Perform files operation with MiGA::Cli cli



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/miga/cli/action/doctor/operations.rb', line 45

def check_files(cli)
  cli.say 'Looking for outdated files in results'
  n, k = cli.load_project.dataset_names.size, 0
  cli.load_project.each_dataset do |d|
    cli.advance('Datasets:', k += 1, n, false)
    d.each_result do |r_k, r|
      ok = true
      r.each_file do |_f_sym, _f_rel, f_abs|
        unless File.exist? f_abs
          ok = false
          break
        end
      end
      unless ok
        cli.say "  > Registering again #{d.name}:#{r_k}   "
        d.add_result(r_k, true, force: true)
        d.result(:stats)&.remove!
      end
    end
  end
  cli.say
end

#check_mdfiles(cli) ⇒ Object

Perform md-files operation with MiGA::Cli cli



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/miga/cli/action/doctor/operations.rb', line 70

def check_mdfiles(cli)
  cli.say 'Looking for unregistered files in the metadata folder'
  md = File.join(cli.load_project.path, 'metadata')
  Dir.each_child(md) do |file|
    expected_ds = File.basename(file, '.json')
    next if cli.load_project.dataset_names.include?(expected_ds)
    file_path = File.join(md, file)
    if Dir.exist?(file_path)
      cli.say "  > Ignoring directory: #{file}"
    else
      cli.say "  > Removing: #{file}"
      File.unlink(File.join(md, file))
    end
  end
end

#check_mts(cli) ⇒ Object

Perform mytaxa-scan operation with MiGA::Cli cli



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/miga/cli/action/doctor/operations.rb', line 137

def check_mts(cli)
  cli.say 'Looking for unarchived MyTaxa Scan runs'
  cli.load_project.each_dataset do |d|
    res = d.result(:mytaxa_scan)
    next if res.nil?

    dir = res.file_path(:regions)
    fix = false
    unless dir.nil?
      if Dir.exist? dir
        run_cmd "          cd \#{dir.shellescape}/.. \\\n              && tar -zcf '\#{d.name}.reg.tar.gz' '\#{d.name}.reg' \\\n              && rm -r '\#{d.name}.reg'\n        CMD\n      end\n      fix = true\n    end\n    %i[blast mytaxain wintax gene_ids region_ids].each do |ext|\n      file = res.file_path(ext)\n      unless file.nil?\n        FileUtils.rm(file) if File.exist? file\n        fix = true\n      end\n    end\n    if fix\n      cli.say \"  > Fixing \#{d.name}\"\n      d.add_result(:mytaxa_scan, true, force: true)\n    end\n  end\nend\n"

#check_refdb(cli) ⇒ Object

Perform refdb operation with MiGA::Cli cli



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/miga/cli/action/doctor/operations.rb', line 5

def check_refdb(cli)
  cli.say 'Checking index format of reference database'
  ref_dbs = File.join(ENV['MIGA_HOME'], '.miga_db')
  manif_file = File.join(ref_dbs, '_local_manif.json')
  return unless File.size?(manif_file)

  MiGA::Json.parse(manif_file)[:databases]&.keys&.each do |db|
    p = MiGA::Project.load(File.join(ref_dbs, db.to_s))
    md = p&.
  end
end

#check_start(cli) ⇒ Object

Perform start operation with MiGA::Cli cli



171
172
173
174
175
176
177
178
179
180
181
# File 'lib/miga/cli/action/doctor/operations.rb', line 171

def check_start(cli)
  cli.say 'Looking for legacy .start files lingering'
  cli.load_project.each_dataset do |d|
    d.each_result do |r_k, r|
      if File.exist? r.path(:start)
        cli.say "  > Registering again #{d.name}:#{r_k}"
        r.save
      end
    end
  end
end

#check_status(cli) ⇒ Object

Perform status operation with MiGA::Cli cli



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/miga/cli/action/doctor/operations.rb', line 19

def check_status(cli)
  cli.say 'Updating metadata status'
  p = cli.load_project
  n = p.dataset_names.size
  (0 .. cli[:threads] - 1).map do |i|
    Process.fork do
      k = 0
      cli.load_project.each_dataset do |d|
        k += 1
        cli.advance('Datasets:', k, n, false) if i == 0
        d.recalculate_status if k % cli[:threads] == i
      end
    end
  end
  Process.waitall
  cli.say
end

#check_tax(cli) ⇒ Object

Perform taxonomy operation with MiGA::Cli cli



185
186
187
188
189
190
# File 'lib/miga/cli/action/doctor/operations.rb', line 185

def check_tax(cli)
  # cli.say 'o Checking for taxonomy/distances consistency'
  # TODO: Find 95%ANI clusters with entries from different species
  # TODO: Find different 95%ANI clusters with genomes from the same species
  # TODO: Find AAI values too high or too low for each LCA rank
end