cagnut_toolbox 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 255142762a855c9e25cc84f803f895e6ce44c739
4
+ data.tar.gz: 5c392e8edf6aeeefe014fa77c75ba200b371d898
5
+ SHA512:
6
+ metadata.gz: 0d96dd1570c6eb5a9bb9beee9deadbfeebd96fec4ed830ae21e758daa2aaa4a49ec99fb2fb98c00de44bc5b55dd3435397050167dd0abea1a72ef87968a6a7e2
7
+ data.tar.gz: a09fe04f8f4c9b9856f2e3f6935b21cb5267b40953dc9d54e6e330e10f5671f6c1b519f8fe6e82d9cbed29c222116504e7ed61354741fa65f1e04770d5379e76
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.3.1
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.12.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cagnut_toolbox.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Goldenio Technology
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # CagnutToolbox
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem 'cagnut_toolbox'
9
+ ```
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install cagnut_toolbox
18
+
19
+ ## Usage
20
+
21
+
22
+ ## Development
23
+
24
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
25
+
26
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
27
+
28
+ ## Contributing
29
+
30
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/cagnut_toolbox.
31
+
32
+
33
+ ## License
34
+
35
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
36
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "cagnut_toolbox"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cagnut_toolbox/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "cagnut_toolbox"
8
+ spec.version = CagnutToolbox::VERSION
9
+ spec.authors = ['Shi-Gang Wang', 'Tse-Ching Ho']
10
+ spec.email = ['seanwang@goldenio.com', 'tsechingho@goldenio.com']
11
+
12
+ spec.summary = %q{Cagnut Toolbox tools}
13
+ spec.description = %q{Cagnut Toolbox tools}
14
+ spec.homepage = "https://github.com/CAGNUT/cagnut_toolbox"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency 'cagnut_core'
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.12"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.0"
27
+ end
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+ require 'zlib'
3
+
4
+ File.open(ARGV[0], 'w') do |f|
5
+ STDIN.each_line do |line|
6
+ part = line.gsub!(/\n/, '').split(/\t/)
7
+ f.puts "@#{part[2..7].join(':')}\n"
8
+ f.puts "#{part[8]}\n"
9
+ f.puts "+\n"
10
+ f.puts "#{part[9]}\n"
11
+ end
12
+ end
@@ -0,0 +1,20 @@
1
+ require "cagnut_toolbox/version"
2
+
3
+ module CagnutToolbox
4
+ class << self
5
+ def config
6
+ @config ||= begin
7
+ CagnutToolbox::Configuration.load(Cagnut::Configuration.config, Cagnut::Configuration.params['toolbox'])
8
+ CagnutToolbox::Configuration.instance
9
+ end
10
+ end
11
+
12
+ def root
13
+ ::Pathname.new File.expand_path '../..', __FILE__
14
+ end
15
+ end
16
+ end
17
+
18
+ require 'cagnut_toolbox/configuration'
19
+ require 'cagnut_toolbox/base'
20
+ require 'cagnut_toolbox/util'
@@ -0,0 +1,11 @@
1
+ require 'cagnut_toolbox/functions/qseq_to_fastq'
2
+
3
+ module CagnutToolbox
4
+ class Base
5
+ def qseq2fastq dirs
6
+ opts = { dirs: dirs, order: order }
7
+ qseq2fastq = CagnutToolbox::QseqToFastq.new opts
8
+ qseq2fastq.run
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,31 @@
1
+ require 'singleton'
2
+
3
+ module CagnutToolbox
4
+ class Configuration
5
+ include Singleton
6
+ attr_accessor :exe_path
7
+
8
+ class << self
9
+ def load config, params
10
+ instance.load config, params
11
+ end
12
+ end
13
+
14
+ def load config, params
15
+ @config = config
16
+ attributes.each do |name, value|
17
+ send "#{name}=", value if respond_to? "#{name}="
18
+ end
19
+ end
20
+
21
+ def attributes
22
+ {
23
+ exe_path: exe_path
24
+ }
25
+ end
26
+
27
+ def exe_path
28
+ CagnutToolbox.root.join('exe')
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,79 @@
1
+ module CagnutToolbox
2
+ class QseqToFastq
3
+ extend Forwardable
4
+
5
+ def_delegators :'Cagnut::Configuration.base', :sample_name, :dodebug,
6
+ :jobs_dir, :ref_fasta, :seqs_path, :prefix_name
7
+ def_delegators :'CagnutToolbox.config', :exe_path
8
+
9
+ def initialize opts = {}
10
+ @order = sprintf '%02i', opts[:order]
11
+ @input = opts[:input].nil? ? "#{seqs_path}" : opts[:input]
12
+ @input.gsub! '.gz', ''
13
+ @input2 = File.expand_path fetch_filename, File.dirname(@input)
14
+ abort('Cant recognized sequence files') if @input2.nil?
15
+ @output = "#{opts[:dirs][output]}/#{sample_name}_1_qtf.fastq"
16
+ @output2 = "#{opts[:dirs][output]}/s_#{sample_name}_2_qtf.fastq"
17
+ @job_name = "#{prefix_name}_qseq_to_fastq_#{sample_name}"
18
+ end
19
+
20
+ def fetch_filename
21
+ filename = File.basename(@input)
22
+ if filename.match '_R1_'
23
+ filename.gsub '_R1_', '_R2_'
24
+ elsif filename.match '_1_'
25
+ filename.gsub '_1_', '_2_'
26
+ end
27
+ end
28
+
29
+ def run previous_job_id = nil
30
+ puts "Submitting #{sample_name} qseqToFastq"
31
+ script_name = generate_script task
32
+ ::Cagnut::JobManage.submit script_name, @job_name, queuing_options(previous_job_id)
33
+ [@job_name, @output]
34
+ end
35
+
36
+ def queuing_options previous_job_id = nil
37
+ {
38
+ previous_job_id: previous_job_id,
39
+ tools: ['toolbox', 'qseq_to_fastq']
40
+ }
41
+ end
42
+
43
+ def generate_script
44
+ script_name = "#{@order}_toolbox_qseq2fastq"
45
+ exe_qseq_to_fastq = "ruby #{exe_path}/qseq_to_fastq.rb"
46
+ file = File.join jobs_dir, "#{script_name}.sh"
47
+ File.open(file, 'w') do |f|
48
+ f.puts <<-BASH.strip_heredoc
49
+ #!/bin/bash
50
+
51
+ cd "#{jobs_dir}/../"
52
+ echo "#{script_name} is starting at $(date +%Y%m%d%H%M%S)" >> "#{jobs_dir}/finished_jobs"
53
+ if [ -s "#{@input}.gz" ]
54
+ then
55
+ gunzip -c #{@input}.gz | #{exe_qseq_to_fastq} #{@output} \\
56
+ #{::Cagnut::JobManage.run_local}
57
+ gunzip -c #{@input2}.gz | #{exe_qseq_to_fastq} #{@output2} \\
58
+ #{::Cagnut::JobManage.run_local}
59
+ else
60
+ cat #{@input} | #{exe_qseq_to_fastq} #{@output} \\
61
+ #{::Cagnut::JobManage.run_local}
62
+ cat #{@input2} | #{exe_qseq_to_fastq} #{@output2} \\
63
+ #{::Cagnut::JobManage.run_local}
64
+ fi
65
+
66
+ #force error when missing/empty fastq . Would prevent continutation of pipeline
67
+ if [ ! -s "#{@output2}" ]
68
+ then
69
+ echo "Missing FASTQ: #{@output2} file!"
70
+ exit 100
71
+ fi
72
+ echo "#{script_name} is finished at $(date +%Y%m%d%H%M%S)" >> "#{jobs_dir}/finished_jobs"
73
+
74
+ BASH
75
+ end
76
+ File.chmod(0700, file)
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,43 @@
1
+ module CagnutToolbox
2
+ class Util
3
+ attr_accessor :toolbox, :config
4
+
5
+ def initialize configure
6
+ @config = configure
7
+ @toolbox = CagnutToolbox::Base.new
8
+ end
9
+
10
+ def qseq2fastq dirs, order=1
11
+ if check_files
12
+ job_name, filename = toolbox.qseq2fastq dirs, order
13
+ [job_name, filename, order+1]
14
+ else
15
+ [nil, nil, order]
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def check_files
22
+ tilesqseq? && check_incomplete_fastq
23
+ end
24
+
25
+ def tilesqseq?
26
+ @config['data_type'] == 'TILESQSEQ'
27
+ end
28
+
29
+ def check_incomplete_fastq
30
+ file = fetch_filename @config['seqs_path'][sample]
31
+ !File.size? file
32
+ end
33
+
34
+ def fetch_filename file
35
+ filename = File.basename(@file)
36
+ if filename.match '_R1_'
37
+ filename.gsub '_R1_', '_R2_'
38
+ elsif filename.match '_1_'
39
+ filename.gsub '_1_', '_2_'
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,3 @@
1
+ module CagnutToolbox
2
+ VERSION = "0.3.0"
3
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cagnut_toolbox
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ platform: ruby
6
+ authors:
7
+ - Shi-Gang Wang
8
+ - Tse-Ching Ho
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2016-11-01 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: cagnut_core
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: bundler
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '1.12'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '1.12'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rake
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '10.0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '10.0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rspec
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '3.0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '3.0'
70
+ description: Cagnut Toolbox tools
71
+ email:
72
+ - seanwang@goldenio.com
73
+ - tsechingho@goldenio.com
74
+ executables:
75
+ - qseq_to_fastq.rb
76
+ extensions: []
77
+ extra_rdoc_files: []
78
+ files:
79
+ - ".gitignore"
80
+ - ".rspec"
81
+ - ".ruby-version"
82
+ - ".travis.yml"
83
+ - Gemfile
84
+ - LICENSE.txt
85
+ - README.md
86
+ - Rakefile
87
+ - bin/console
88
+ - bin/setup
89
+ - cagnut_toolbox.gemspec
90
+ - exe/qseq_to_fastq.rb
91
+ - lib/cagnut_toolbox.rb
92
+ - lib/cagnut_toolbox/base.rb
93
+ - lib/cagnut_toolbox/configuration.rb
94
+ - lib/cagnut_toolbox/functions/qseq_to_fastq.rb
95
+ - lib/cagnut_toolbox/util.rb
96
+ - lib/cagnut_toolbox/version.rb
97
+ homepage: https://github.com/CAGNUT/cagnut_toolbox
98
+ licenses:
99
+ - MIT
100
+ metadata: {}
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubyforge_project:
117
+ rubygems_version: 2.5.1
118
+ signing_key:
119
+ specification_version: 4
120
+ summary: Cagnut Toolbox tools
121
+ test_files: []