cagnut_gatk 0.3.0

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.
Files changed (35) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.rspec +2 -0
  4. data/.ruby-version +1 -0
  5. data/.travis.yml +5 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +35 -0
  9. data/Rakefile +6 -0
  10. data/bin/console +14 -0
  11. data/bin/setup +8 -0
  12. data/cagnut_gatk.gemspec +27 -0
  13. data/lib/cagnut_gatk/base.rb +82 -0
  14. data/lib/cagnut_gatk/check_tools.rb +16 -0
  15. data/lib/cagnut_gatk/configuration.rb +56 -0
  16. data/lib/cagnut_gatk/functions/analyze_covariates.rb +94 -0
  17. data/lib/cagnut_gatk/functions/base_recalibrator.rb +99 -0
  18. data/lib/cagnut_gatk/functions/count_read.rb +77 -0
  19. data/lib/cagnut_gatk/functions/depth_of_coverage.rb +81 -0
  20. data/lib/cagnut_gatk/functions/haplotype_caller.rb +89 -0
  21. data/lib/cagnut_gatk/functions/indel_realigner.rb +101 -0
  22. data/lib/cagnut_gatk/functions/print_reads.rb +92 -0
  23. data/lib/cagnut_gatk/functions/realigner_target_creator.rb +92 -0
  24. data/lib/cagnut_gatk/functions/templates/analyze_covariates.sh +26 -0
  25. data/lib/cagnut_gatk/functions/templates/base_recalibrator.sh +30 -0
  26. data/lib/cagnut_gatk/functions/templates/count_read.sh +23 -0
  27. data/lib/cagnut_gatk/functions/templates/depth_of_coverage.sh +19 -0
  28. data/lib/cagnut_gatk/functions/templates/print_reads.sh +25 -0
  29. data/lib/cagnut_gatk/functions/unified_genotyper.rb +89 -0
  30. data/lib/cagnut_gatk/functions/variant_eval.rb +88 -0
  31. data/lib/cagnut_gatk/functions/variant_filtration.rb +88 -0
  32. data/lib/cagnut_gatk/util.rb +118 -0
  33. data/lib/cagnut_gatk/version.rb +3 -0
  34. data/lib/cagnut_gatk.rb +16 -0
  35. metadata +135 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fe5eb1cd0ec1bce7070824c57593e870b3bcb088
4
+ data.tar.gz: 0b74a7f00a8a7ecc9f9a4be0cf3f88a87de2fc57
5
+ SHA512:
6
+ metadata.gz: 4a32007bb842e9ee92d779817a4c6730ae3d27b47f012609dc65db54bf0adb09718abbe8da668e6220f7bf0792d7502fa2b5adc94200e08cc93bf1915bf74773
7
+ data.tar.gz: f8d03e201a08dc188203a46b8517fa8527e604c1980587ebb5d7bada9f8ca9727dba489cad031b61986268638f9c17c40764bf0470ca312024946bc753cdb26b
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_gatk.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,35 @@
1
+ # CagnutGatk
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem 'cagnut_gatk'
9
+ ```
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install cagnut_gatk
18
+
19
+ ## Usage
20
+
21
+ ## Development
22
+
23
+ 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.
24
+
25
+ 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).
26
+
27
+ ## Contributing
28
+
29
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/cagnut_gatk.
30
+
31
+
32
+ ## License
33
+
34
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
35
+
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_gatk"
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_gatk/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "cagnut_gatk"
8
+ spec.version = CagnutGatk::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 Gatk tools}
13
+ spec.description = %q{Cagnut Gatk tools}
14
+ spec.homepage = "https://github.com/CAGNUT/cagnut_gatk"
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,82 @@
1
+ require 'cagnut_gatk/functions/count_read'
2
+ require 'cagnut_gatk/functions/realigner_target_creator'
3
+ require 'cagnut_gatk/functions/indel_realigner'
4
+ require 'cagnut_gatk/functions/base_recalibrator'
5
+ require 'cagnut_gatk/functions/analyze_covariates'
6
+ require 'cagnut_gatk/functions/print_reads'
7
+ require 'cagnut_gatk/functions/depth_of_coverage'
8
+ require 'cagnut_gatk/functions/unified_genotyper'
9
+ require 'cagnut_gatk/functions/haplotype_caller'
10
+ require 'cagnut_gatk/functions/variant_filtration'
11
+ require 'cagnut_gatk/functions/variant_eval'
12
+
13
+ module CagnutGatk
14
+ class Base
15
+
16
+ def count_read dirs, order, previous_job_id, opts = {}
17
+ opts = { dirs: dirs, order: order }.merge opts
18
+ count_read = CagnutGatk::CountRead.new opts
19
+ count_read.run previous_job_id
20
+ end
21
+
22
+ def realigner_target_creator dirs, order, previous_job_id, input = nil
23
+ opts = { input: input, dirs: dirs, order: order }
24
+ realigner_target_creator = CagnutGatk::RealignerTargetCreator.new opts
25
+ realigner_target_creator.run previous_job_id
26
+ end
27
+
28
+ def indel_realigner dirs, order, previous_job_id, input, interval_list
29
+ opts = { input: input, interval_list: interval_list, dirs: dirs, order: order }
30
+ indel_realigner = CagnutGatk::IndelRealigner.new opts
31
+ indel_realigner.run previous_job_id
32
+ end
33
+
34
+ def base_recalibrator dirs, order, previous_job_id, input, opts
35
+ opts = { input: input, dirs: dirs, order: order }.merge opts
36
+ base_recalibrator = CagnutGatk::BaseRecalibrator.new opts
37
+ base_recalibrator.run previous_job_id
38
+ end
39
+
40
+ def analyze_covariates dirs, order, previous_job_id, input
41
+ opts = { input: input, dirs: dirs, order: order }
42
+ analyze_covariates = CagnutGatk::AnalyzeCovariates.new opts
43
+ analyze_covariates.run previous_job_id
44
+ end
45
+
46
+ def print_reads dirs, order, previous_job_id, input
47
+ opts = { input: input, dirs: dirs, order: order}
48
+ print_reads = CagnutGatk::PrintReads.new opts
49
+ print_reads.run previous_job_id
50
+ end
51
+
52
+ def depth_of_coverage dirs, order, previous_job_id, input, opts
53
+ opts = { input: input, dirs: dirs, order: order }.merge opts
54
+ depth_of_coverage = CagnutGatk::DepthOfCoverage.new opts
55
+ depth_of_coverage.run previous_job_id
56
+ end
57
+
58
+ def haplotype_caller dirs, order, previous_job_id, input
59
+ opts = { input: input, dirs: dirs, order: order }
60
+ haplotype_caller = CagnutGatk::HaplotypeCaller.new opts
61
+ haplotype_caller.run previous_job_id
62
+ end
63
+
64
+ def unified_genotyper dirs, order, previous_job_id, input
65
+ opts = { input: input, dirs: dirs, order: order }
66
+ unifiedgenotyper = CagnutGatk::UnifiedGenotyper.new opts
67
+ unifiedgenotyper.run previous_job_id
68
+ end
69
+
70
+ def variant_filtration dirs, order, previous_job_id, input
71
+ opts = { input: input, dirs: dirs, order: order }
72
+ variant_filtration = CagnutGatk::VariantFiltration.new opts
73
+ variant_filtration.run previous_job_id
74
+ end
75
+
76
+ def variant_eval dirs, order, previous_job_id, input
77
+ opts = { input: input, dirs: dirs, order: order }
78
+ variant_eval = CagnutGatk::VariantEval.new opts
79
+ variant_eval.run previous_job_id
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,16 @@
1
+ module CagnutGatk
2
+ module CheckTools
3
+ def check_tool tools_path
4
+ super if defined?(super)
5
+ check_gatk tools_path['gatk'] if @java
6
+ end
7
+
8
+ def check_gatk path
9
+ check_tool_ver 'GATK' do
10
+ `#{@java} -jar #{path} --version` if path
11
+ end
12
+ end
13
+ end
14
+ end
15
+
16
+ Cagnut::Configuration::Checks::Tools.prepend CagnutGatk::CheckTools
@@ -0,0 +1,56 @@
1
+ require 'singleton'
2
+
3
+ module CagnutGatk
4
+ class Configuration
5
+
6
+ include Singleton
7
+ attr_accessor :analyze_covariates_params, :base_recalibrator_params,
8
+ :count_reads_params, :depth_of_coverage_params,
9
+ :haplotype_caller_params, :indel_realigner_params,
10
+ :print_reads_params, :realigner_target_creator_params,
11
+ :unified_genotyper_params, :variant_eval_params,
12
+ :variant_filtration_params
13
+
14
+ class << self
15
+ def load config, params
16
+ instance.load config, params
17
+ end
18
+ end
19
+
20
+ def load config, params
21
+ @config = config
22
+ @params = params
23
+ attributes.each do |name, value|
24
+ send "#{name}=", value if respond_to? "#{name}="
25
+ end
26
+ end
27
+
28
+ def attributes
29
+ {
30
+ analyze_covariates_params: add_java_params(@params['analyze_covariates']),
31
+ base_recalibrator_params: add_java_params(@params['base_recalibrator']),
32
+ count_reads_params: add_java_params(@params['count_reads']),
33
+ depth_of_coverage_params: add_java_params(@params['depth_of_coverage'], true),
34
+ haplotype_caller_params: add_java_params(@params['haplotype_caller']),
35
+ indel_realigner_params: add_java_params(@params['indel_realigner']),
36
+ print_reads_params: add_java_params(@params['print_reads']),
37
+ realigner_target_creator_params: add_java_params(@params['realigner_target_creator']),
38
+ unified_genotyper_params: add_java_params(@params['unified_genotyper']),
39
+ variant_eval_params: add_java_params(@params['variant_eval']),
40
+ variant_filtration_params: add_java_params(@params['variant_filtration'])
41
+ }
42
+ end
43
+
44
+ def add_java_params method_params, verbose=false
45
+ return if method_params.blank?
46
+ array = method_params['java'].dup
47
+ array << "-verbose:sizes" if verbose
48
+ array << "-jar #{@config['tools']['gatk']}"
49
+ {
50
+ 'java' => array,
51
+ 'params' => method_params['params']
52
+ }
53
+ end
54
+
55
+ end
56
+ end
@@ -0,0 +1,94 @@
1
+ module CagnutGatk
2
+ class AnalyzeCovariates
3
+ extend Forwardable
4
+
5
+ def_delegators :'Cagnut::Configuration.base', :sample_name, :jobs_dir, :prefix_name,
6
+ :ref_fasta, :dodebug, :java_path, :magic28
7
+ def_delegators :'CagnutGatk.config', :analyze_covariates_params
8
+
9
+ def initialize opts = {}
10
+ @order = sprintf '%02i', opts[:order]
11
+ @job_name = "#{prefix_name}_AnalyzeCovariates_#{sample_name}"
12
+ @input = opts[:input].nil? ? "#{opts[:dirs][:input]}/#{sample_name}_realn.bam" : opts[:input]
13
+ @recal_csv = "#{opts[:dirs][:contrast]}/#{replace_filename('_recal.csv')}"
14
+ @recal_bqsr_csv = "#{opts[:dirs][:contrast]}/#{replace_filename('_recal_post.csv')}"
15
+ @output = "#{opts[:dirs][:output]}/#{output_file}"
16
+ end
17
+
18
+ def file_basename
19
+ @basename ||= File.basename @input
20
+ end
21
+
22
+ def replace_filename target_name
23
+ file_basename.gsub '_realn.bam', target_name
24
+ end
25
+
26
+ def output_file
27
+ output = replace_filename '_recalibration_plots.pdf'
28
+ return output unless output == file_basename
29
+ abort 'Input file is not correctly'
30
+ end
31
+
32
+ def run previous_job_id = nil
33
+ puts "Submitting AnalyzeCovariates #{sample_name}"
34
+ script_name = generate_script
35
+ ::Cagnut::JobManage.submit script_name, @job_name, cluster_options(previous_job_id)
36
+ @job_name
37
+ end
38
+
39
+ def cluster_options previous_job_id = nil
40
+ core_num = 6
41
+ {
42
+ previous_job_id: previous_job_id,
43
+ var_env: ["#{core_num}"],
44
+ adjust_memory: ["h_vmem=adjustWorkingMem 7G #{core_num}"],
45
+ tools: ['gatk', 'analyze_covariates']
46
+ }
47
+ end
48
+
49
+ def generate_script
50
+ script_name = "#{@order}_gatk_analyze_covariates"
51
+ file = File.join jobs_dir, "#{script_name}.sh"
52
+ path = File.expand_path '../templates/analyze_covariates.sh', __FILE__
53
+ template = Tilt.new path
54
+ File.open(file, 'w') do |f|
55
+ f.puts template.render Object.new, job_params(script_name)
56
+ end
57
+ File.chmod(0700, file)
58
+ script_name
59
+ end
60
+
61
+ def params_combination
62
+ {
63
+ 'java' => modified_java_array,
64
+ 'params' => analyze_covariates_options
65
+ }
66
+ end
67
+
68
+ def analyze_covariates_options
69
+ array = analyze_covariates_params['params'].dup
70
+ array << "-T AnalyzeCovariates"
71
+ array << "-R #{ref_fasta}"
72
+ array << "-before #{@recal_csv}"
73
+ array << "-after #{@recal_bqsr_csv}"
74
+ array << "-plots #{@output}"
75
+ array.uniq
76
+ end
77
+
78
+ def modified_java_array
79
+ array = analyze_covariates_params['java'].dup
80
+ array.unshift(java_path).uniq
81
+ end
82
+
83
+ def job_params script_name
84
+ {
85
+ jobs_dir: jobs_dir,
86
+ script_name: script_name,
87
+ after: @after,
88
+ output: @output,
89
+ analyze_covariates_params: params_combination,
90
+ run_local: "#{::Cagnut::JobManage.run_local}"
91
+ }
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,99 @@
1
+ module CagnutGatk
2
+ class BaseRecalibrator
3
+ extend Forwardable
4
+
5
+ def_delegators :'Cagnut::Configuration.base', :sample_name, :jobs_dir, :prefix_name,
6
+ :ref_fasta, :snpdb, :target_flanks_file, :dodebug,
7
+ :magic28, :java_path
8
+ def_delegators :'CagnutGatk.config', :base_recalibrator_params
9
+
10
+ def initialize opts = {}
11
+ @order = sprintf '%02i', opts[:order]
12
+ @csv_dir = opts[:dirs][:output]
13
+ @has_bqsr_file = opts[:has_bqsr_file]
14
+ @input = opts[:file_name].nil? ? "#{opts[:dirs][:input]}/#{sample_name}_realn.bam" : opts[:input]
15
+ setup_output_and_bqsr_file
16
+ end
17
+
18
+ def setup_output_and_bqsr_file
19
+ file_name = File.basename @input
20
+ if @has_bqsr_file
21
+ output = file_name.gsub '_realn.bam', '_recal_post.csv'
22
+ bqsr_file = file_name.gsub '_realn.bam', '_recal.csv'
23
+ else
24
+ output = file_name.gsub '_realn.bam', '_recal.csv'
25
+ end
26
+ @output = "#{@csv_dir}/#{output}"
27
+ @bqsr_file = "#{@csv_dir}/#{bqsr_file}" if @has_bqsr_file
28
+ end
29
+
30
+ def run previous_job_id = nil
31
+ message = @has_bqsr_file ? 'with BQSR' : ''
32
+ puts "Submitting BaseRecalibrator #{sample_name} #{message}"
33
+ script_name = generate_script
34
+ job_name = "#{prefix_name}_#{script_name}"
35
+ ::Cagnut::JobManage.submit script_name, job_name, cluster_options(previous_job_id)
36
+ job_name
37
+ end
38
+
39
+ def cluster_options previous_job_id = nil
40
+ core_num = 6
41
+ {
42
+ previous_job_id: previous_job_id,
43
+ var_env: [core_num],
44
+ adjust_memory: ["h_vmem=adjustWorkingMem 7G #{core_num}"],
45
+ parallel_env: [core_num],
46
+ tools: ['gatk', 'base_recalibrator']
47
+ }
48
+ end
49
+
50
+ def generate_script
51
+ script_name = @has_bqsr_file ? "#{@order}_gatk_base_recalibrator_post" : "#{@order}_gatk_base_recalibrator"
52
+ file = File.join jobs_dir, "#{script_name}.sh"
53
+ path = File.expand_path "../templates/base_recalibrator.sh", __FILE__
54
+ template = Tilt.new path
55
+ File.open(file, 'w') do |f|
56
+ f.puts template.render Object.new, job_params(script_name)
57
+ end
58
+ File.chmod(0700, file)
59
+ script_name
60
+ end
61
+
62
+ def base_recalibrator_options
63
+ dtag = snpdb.nil? ? "--run_without_dbsnp_potentially_ruining_quality" : "-knownSites #{snpdb}"
64
+ array = base_recalibrator_params['params'].dup
65
+ array << "-T BaseRecalibrator"
66
+ array << "-R #{ref_fasta}"
67
+ array << "-I #{@input}"
68
+ array << "-o #{@output}"
69
+ array << "#{dtag}"
70
+ array << "-BQSR #{@bqsr_file}" if @has_bqsr_file
71
+ array << "-L #{target_flanks_file}" if target_flanks_file
72
+ array.uniq
73
+ end
74
+
75
+ def modified_java_array
76
+ array = base_recalibrator_params['java'].dup
77
+ array.unshift(java_path).uniq
78
+ end
79
+
80
+ def params_combination
81
+ {
82
+ 'java' => modified_java_array,
83
+ 'params' => base_recalibrator_options
84
+ }
85
+ end
86
+
87
+ def job_params script_name
88
+ {
89
+ jobs_dir: jobs_dir,
90
+ script_name: script_name,
91
+ magic28: magic28,
92
+ input: @input,
93
+ output: @output,
94
+ base_recalibrator_params: params_combination,
95
+ run_local: ::Cagnut::JobManage.run_local
96
+ }
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,77 @@
1
+ module CagnutGatk
2
+ class CountRead
3
+ extend Forwardable
4
+
5
+ def_delegators :'Cagnut::Configuration.base', :sample_name, :jobs_dir, :java_path,
6
+ :ref_fasta, :prefix_name, :dodebug
7
+ def_delegators :'CagnutGatk.config', :count_reads_params
8
+
9
+ def initialize opts = {}
10
+ @order = sprintf '%02i', opts[:order]
11
+ @target = opts[:target]
12
+ @suffix = @target.nil? ? 'genome.readct' : 'target.readct'
13
+ @input = opts[:input].nil? ? "#{opts[:dirs][:input]}/#{sample_name}_markdup.bam" : opts[:input]
14
+ @output = "#{opts[:dirs][:output]}/#{sample_name}_markdup_#{@suffix}"
15
+ @job_name = "#{prefix_name}_countRead_#{sample_name}_#{@suffix}"
16
+ end
17
+
18
+ def run previous_job_id = nil
19
+ puts "Submitting countRead #{@suffix}"
20
+ script_name = generate_script
21
+ ::Cagnut::JobManage.submit script_name, @job_name, cluster_options(previous_job_id)
22
+ @job_name
23
+ end
24
+
25
+ def cluster_options previous_job_id = nil
26
+ {
27
+ previous_job_id: previous_job_id,
28
+ var_env: [ref_fasta],
29
+ adjust_memory: ['h_vmem=5G'],
30
+ tools: ['gatk', 'count_reads']
31
+ }
32
+ end
33
+
34
+ def generate_script
35
+ script_name = "#{@order}_gatk_count_reads_#{@suffix}"
36
+ file = File.join jobs_dir, "#{script_name}.sh"
37
+ path = File.expand_path '../templates/count_read.sh', __FILE__
38
+ template = Tilt.new path
39
+ File.open(file, 'w') do |f|
40
+ f.puts template.render Object.new, job_params(script_name)
41
+ end
42
+ File.chmod(0700, file)
43
+ script_name
44
+ end
45
+
46
+ def count_reads_options
47
+ array = count_reads_params['params'].dup
48
+ array << "-T CountReads"
49
+ array << "-R #{ref_fasta}"
50
+ array << "-I #{@input} > #{@output}"
51
+ array << "-L #{@target}" if @target
52
+ array.uniq
53
+ end
54
+
55
+ def modified_java_array
56
+ array = count_reads_params['java'].dup
57
+ array.unshift(java_path).uniq
58
+ end
59
+
60
+ def params_combination
61
+ {
62
+ 'java' => modified_java_array,
63
+ 'params' => count_reads_options
64
+ }
65
+ end
66
+
67
+ def job_params script_name
68
+ {
69
+ jobs_dir: jobs_dir,
70
+ script_name: script_name,
71
+ output: @output,
72
+ count_reads_params: params_combination,
73
+ run_local: ::Cagnut::JobManage.run_local
74
+ }
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,81 @@
1
+ module CagnutGatk
2
+ class DepthOfCoverage
3
+ extend Forwardable
4
+
5
+ def_delegators :'Cagnut::Configuration.base', :sample_name, :jobs_dir, :java_path,
6
+ :ref_fasta, :prefix_name, :dodebug
7
+ def_delegators :'CagnutGatk.config', :depth_of_coverage_params
8
+
9
+ def initialize opts = {}
10
+ @order = sprintf '%02i', opts[:order]
11
+ @suffix = opts[:suffix]
12
+ @target_file = opts[:target]
13
+ @job_name = "#{prefix_name}_#{sample_name}_#{@suffix}_depthofcoverage"
14
+ @input = opts[:input].nil? ? "#{opts[:dirs][:input]}/#{sample_name}_recal.bam" : opts[:input]
15
+ @output = "#{opts[:dirs][:output]}/#{sample_name}_#{@suffix}_depthofcoverage"
16
+ end
17
+
18
+ def run previous_job_id = nil
19
+ puts "Submitting #{sample_name} #{@suffix} depth of coverage Jobs"
20
+ script_name = generate_script
21
+ ::Cagnut::JobManage.submit script_name, @job_name, cluster_options(previous_job_id)
22
+ [@job_name, @output]
23
+ end
24
+
25
+ def cluster_options previous_job_id = nil
26
+ core_num = 6
27
+ {
28
+ previous_job_id: previous_job_id,
29
+ var_env: [core_num],
30
+ adjust_memory: ['h_stack=256M', 'h_vmem=8G'],
31
+ parallel_env: [core_num],
32
+ tools: ['gatk', 'depth_of_coverage']
33
+ }
34
+ end
35
+
36
+ def generate_script
37
+ file_name = "#{@order}_gatk_depth_of_coverage_#{@suffix}"
38
+ file = File.join jobs_dir, "#{file_name}.sh"
39
+ path = File.expand_path '../templates/depth_of_coverage.sh', __FILE__
40
+ template = Tilt.new path
41
+ File.open(file, 'w') do |f|
42
+ f.puts template.render Object.new, job_params(file_name)
43
+ end
44
+ File.chmod(0700, file)
45
+ file_name
46
+ end
47
+
48
+ def depth_of_coverage_options
49
+ target = @target_file.blank? ? '-omitIntervals' : "-L #{@target_file}"
50
+ array = depth_of_coverage_params['params'].dup
51
+ array << "-T DepthOfCoverage"
52
+ array << "-R #{ref_fasta}"
53
+ array << "-I #{@input}"
54
+ array << "-o #{@output}"
55
+ array << target
56
+ array.uniq
57
+ end
58
+
59
+ def modified_java_array
60
+ array = depth_of_coverage_params['java'].dup
61
+ array.unshift(java_path).uniq
62
+ end
63
+
64
+ def params_combination_hash
65
+ {
66
+ 'java' => modified_java_array,
67
+ 'params' => depth_of_coverage_options
68
+ }
69
+ end
70
+
71
+ def job_params script_name
72
+ {
73
+ jobs_dir: jobs_dir,
74
+ script_name: script_name,
75
+ output: @output,
76
+ depth_of_coverage_params: params_combination_hash,
77
+ run_local: ::Cagnut::JobManage.run_local
78
+ }
79
+ end
80
+ end
81
+ end