rbbt-util 5.17.73 → 5.17.74

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
  SHA1:
3
- metadata.gz: a4fda440967a1a2af0ca8818045e4a1dd1d09c93
4
- data.tar.gz: 1a49bd9b10e32462295e9d3467e05b0883f72d9b
3
+ metadata.gz: 60cd54c17004ef80456c9a69b1c2f5f9b8c5f175
4
+ data.tar.gz: d7e91f9c4beeda66383edb73e5c1db647d30af59
5
5
  SHA512:
6
- metadata.gz: fa61d113310f26ff43331250c84be4b9b1f154347baec120f7930f8e351c187e961802a113ea9dc55e3a2e958922c4db69f6dc03d0f35c867dc858e3092ef3e3
7
- data.tar.gz: c46d922a4e0ef0d56b19bc2aee57820e57f46e590b7d3ab754cb2c074dc8d1b3a145271f25b45328a44e9e960af7d4caf1008f8801a895c241a3a78275c4d85d
6
+ metadata.gz: 69c7cbb4d618f5830df5bf91e8927712884bb83ca7f95e0179522e9c0a49e694d85de0efc6c28ed40d3faecc9f3dbc6932944bd703fdfa67faa9fb08894b6061
7
+ data.tar.gz: 27a0fdd194de5180300fe37d0b888130c23a91132ebef7c84ddd6d62954575a7f173cab3f46a984b4bd0cdbc5392ee8bf668642f9678a057870f4165af23433c
@@ -0,0 +1,82 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rbbt-util'
4
+ require 'rbbt/util/simpleopt'
5
+
6
+ $0 = "rbbt #{$previous_commands*""} #{ File.basename(__FILE__) }" if $previous_commands
7
+
8
+ options = SOPT.setup <<EOF
9
+
10
+ Optimize the files in a directory.
11
+
12
+ $ rbbt system optimize [options] <directory>
13
+
14
+ Compresses the chromosome files with BGZ and optimizes TokyoCabinet databases. Some files
15
+ do not compress correctly with BGZ and are left un-compressed.
16
+
17
+ -h--help Print this help
18
+ -k--keep Keep original files
19
+
20
+ EOF
21
+ if options[:help]
22
+ if defined? rbbt_usage
23
+ rbbt_usage
24
+ else
25
+ puts SOPT.usage
26
+ end
27
+ exit 0
28
+ end
29
+
30
+ directory = ARGV.shift
31
+ raise ParameterException, "No directory given" if directory.nil?
32
+
33
+ raise ParameterException, "Not a valid directory" unless File.directory? directory
34
+
35
+ directory = Path.setup directory.dup
36
+ keep = options[:keep]
37
+
38
+ Log.info Log.color(:magenta, "Processing chromosomes")
39
+ chromosome_files = directory.glob('**/chromosome_*')
40
+ TSV.traverse chromosome_files, :type => :array, :bar => "Processing chromosomes" do |chr_file|
41
+ next if chr_file =~ /.bgz$/
42
+ compressed_file = chr_file + '.bgz'
43
+ Log.info "Compressing #{ chr_file } into #{ compressed_file }"
44
+ CMD.cmd("bgzip '#{ chr_file }' -c > #{ compressed_file }")
45
+ begin
46
+ Open.read(compressed_file)
47
+ if keep
48
+ Log.info "File #{ chr_file } was correctly compressed. Keeping original"
49
+ else
50
+ Log.info "File #{ chr_file } was correctly compressed. Removing original"
51
+ FileUtils.rm chr_file
52
+ end
53
+ rescue
54
+ Log.warn "File #{ chr_file } was not correctly compressed. Removing compressed version and leaving original"
55
+ FileUtils.rm compressed_file
56
+ end
57
+ end
58
+
59
+ Log.info Log.color(:magenta, "Processing Tokyo Cabinet files")
60
+
61
+ all_files = directory.glob('**/*')
62
+ TSV.traverse all_files, :type => :array, :bar => "Processing Tokyo Cabinet files" do |file|
63
+ cmd = 'file "' << file << '"'
64
+ file_type = CMD.cmd(cmd).read.strip.partition(/:\s+/).last
65
+ next unless file_type =~ /Tokyo/
66
+ type = file_type.split(", ")[1]
67
+ case type
68
+ when "Hash"
69
+ cmd = 'tchmgr optimize "' << file << '"'
70
+ when "B+ tree"
71
+ cmd = 'tcbmgr optimize "' << file << '"'
72
+ else
73
+ next
74
+ end
75
+ size = File.size(file)
76
+ cmd << ' -td -tl' if size > 2_000_000_000 or file_type =~ /deflate/
77
+ Log.info "Optimizing #{type} database #{file}"
78
+ io = CMD.cmd(cmd)
79
+ while line = io.gets
80
+ Log.debug line
81
+ end
82
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbbt-util
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.17.73
4
+ version: 5.17.74
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miguel Vazquez
@@ -308,6 +308,7 @@ files:
308
308
  - share/rbbt_commands/study/task
309
309
  - share/rbbt_commands/system/clean
310
310
  - share/rbbt_commands/system/deleted_files
311
+ - share/rbbt_commands/system/optimize
311
312
  - share/rbbt_commands/system/purge
312
313
  - share/rbbt_commands/system/report
313
314
  - share/rbbt_commands/system/status