bio-gadget 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gthorfile CHANGED
@@ -1,46 +1,2 @@
1
- module Bio
2
- class Gadget < Thor
3
-
4
- namespace :bio
5
-
6
- desc 'qvstat QUAL', 'statistics of quality values in *.qual file'
7
- def qvstat(qualfile)
8
- stat = Hash.new
9
- myopen(qualfile) { |fp|
10
- fp.each { |line|
11
- next if /^[\#\>]/ =~ line
12
- qvs = line.rstrip.split
13
- qvs.each_index { |i|
14
- qv = qvs[i]
15
- stat[qv] = Array.new unless stat.key?(qv)
16
- if stat[qv][i].nil?
17
- stat[qv][i] = 1
18
- else
19
- stat[qv][i] += 1
20
- end
21
- }
22
- }
23
- }
24
- statfile = qualfile.sub(/.qual(.gz)?$/, '.qvstat')
25
- open(statfile, 'w') { |out|
26
- qvs = stat.keys.sort { |a, b| a.to_i <=> b.to_i }
27
- qvs.each { |qv|
28
- out.puts "#{qv} #{stat[qv].join(' ')}"
29
- }
30
- }
31
- end
32
-
33
- private
34
-
35
- def myopen(file, &block)
36
- # how to write?
37
- f = (/\|/ !~ file && /\.gz$/ =~ file) ? "| gunzip -c #{file}" : file
38
- unless block.nil?
39
- o = open(f); block.call(o); o.close
40
- else
41
- open(f)
42
- end
43
- end
44
-
45
- end
46
- end
1
+ $:.unshift File.expand_path('../lib', __FILE__)
2
+ require 'bio-gadget'
data/README.org CHANGED
@@ -8,9 +8,18 @@
8
8
 
9
9
  * Usage
10
10
 
11
+ To check all commands in this package,
12
+
11
13
  : gthor help bio
12
14
  : gthor list bio
13
15
 
16
+ Currently available commands are
17
+
18
+ : bio
19
+ : ---
20
+ : gthor bio:fqlzma # automatic (re)compression of *.fq(.gz|.bz2) files
21
+ : gthor bio:qvstat QUAL # statistics of quality values in *.qual file
22
+
14
23
  * Contributing
15
24
 
16
25
  1. Fork it
data/bio-gadget.gemspec CHANGED
@@ -16,4 +16,5 @@ Gem::Specification.new do |gem|
16
16
  gem.version = Bio::Gadget::VERSION
17
17
 
18
18
  gem.add_dependency 'gthor'
19
+ gem.add_dependency 'parallel'
19
20
  end
data/lib/bio-gadget.rb CHANGED
@@ -1,7 +1,3 @@
1
- require "bio-gadget/version"
2
-
3
- module Bio
4
- module Gadget
5
- # Your code goes here...
6
- end
7
- end
1
+ require 'bio-gadget/version'
2
+ require 'bio-gadget/fqlzma'
3
+ require 'bio-gadget/qvstat'
@@ -0,0 +1,30 @@
1
+ require 'parallel'
2
+ require 'pathname'
3
+
4
+ module Bio
5
+ class Gadget < Thor
6
+
7
+ namespace :bio
8
+
9
+ desc 'fqlzma', 'automatic (re)compression of *.fq(.gz|.bz2) files'
10
+ def fqlzma
11
+ Parallel.map(Pathname.glob('*.fq{.gz,.bz2,}')) { |fqfilename|
12
+ lzmafilename = fqfilename.sub(/\.fq(\.(gz|bz2))*$/, '.fq.lzma')
13
+ if !lzmafilename.exist?
14
+ case fqfilename.extname
15
+ when '.gz'
16
+ decompressor = 'gunzip -c'
17
+ when '.bz2'
18
+ decompressor = 'bunzip2 -c'
19
+ else
20
+ decompressor = 'cat'
21
+ end
22
+ puts "compressing #{lzmafilename}..."
23
+ system "#{decompressor} #{fqfilename} | lzma -c > #{lzmafilename} 2> #{lzmafilename}.log"
24
+ system "lzma -t #{lzmafilename} >> #{lzmafilename}.log 2>&1"
25
+ end
26
+ }
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,46 @@
1
+ module Bio
2
+ class Gadget < Thor
3
+
4
+ namespace :bio
5
+
6
+ desc 'qvstat QUAL', 'statistics of quality values in *.qual file'
7
+ def qvstat(qualfile)
8
+ stat = Hash.new
9
+ myopen(qualfile) { |fp|
10
+ fp.each { |line|
11
+ next if /^[\#\>]/ =~ line
12
+ qvs = line.rstrip.split
13
+ qvs.each_index { |i|
14
+ qv = qvs[i]
15
+ stat[qv] = Array.new unless stat.key?(qv)
16
+ if stat[qv][i].nil?
17
+ stat[qv][i] = 1
18
+ else
19
+ stat[qv][i] += 1
20
+ end
21
+ }
22
+ }
23
+ }
24
+ statfile = qualfile.sub(/.qual(.gz)?$/, '.qvstat')
25
+ open(statfile, 'w') { |out|
26
+ qvs = stat.keys.sort { |a, b| a.to_i <=> b.to_i }
27
+ qvs.each { |qv|
28
+ out.puts "#{qv} #{stat[qv].join(' ')}"
29
+ }
30
+ }
31
+ end
32
+
33
+ private
34
+
35
+ def myopen(file, &block)
36
+ # how to write?
37
+ f = (/\|/ !~ file && /\.gz$/ =~ file) ? "| gunzip -c #{file}" : file
38
+ unless block.nil?
39
+ o = open(f); block.call(o); o.close
40
+ else
41
+ open(f)
42
+ end
43
+ end
44
+
45
+ end
46
+ end
@@ -1,5 +1,9 @@
1
+ require 'thor'
2
+
1
3
  module Bio
2
- module Gadget
3
- VERSION = "0.1.0"
4
+ class Gadget < Thor
5
+
6
+ VERSION = "0.1.1"
7
+
4
8
  end
5
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bio-gadget
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-20 00:00:00.000000000 Z
12
+ date: 2012-10-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: gthor
@@ -27,6 +27,22 @@ dependencies:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: parallel
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
30
46
  description: Gadgets for bioinformatics
31
47
  email:
32
48
  - shintaro.katayama@gmail.com
@@ -42,6 +58,8 @@ files:
42
58
  - Rakefile
43
59
  - bio-gadget.gemspec
44
60
  - lib/bio-gadget.rb
61
+ - lib/bio-gadget/fqlzma.rb
62
+ - lib/bio-gadget/qvstat.rb
45
63
  - lib/bio-gadget/version.rb
46
64
  homepage: https://github.com/shka/ruby-bio-gadget
47
65
  licenses: []