Class: CagnutGatk::DepthOfCoverage

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/cagnut_gatk/functions/depth_of_coverage.rb

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ DepthOfCoverage

Returns a new instance of DepthOfCoverage.



9
10
11
12
13
14
15
16
# File 'lib/cagnut_gatk/functions/depth_of_coverage.rb', line 9

def initialize opts = {}
  @order = sprintf '%02i', opts[:order]
  @suffix = opts[:suffix]
  @target_file = opts[:target]
  @job_name = "#{prefix_name}_#{sample_name}_#{@suffix}_depthofcoverage"
  @input = opts[:input].nil? ? "#{opts[:dirs][:input]}/#{sample_name}_recal.bam" : opts[:input]
  @output = "#{opts[:dirs][:output]}/#{sample_name}_#{@suffix}_depthofcoverage"
end

Instance Method Details

#cluster_options(previous_job_id = nil) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/cagnut_gatk/functions/depth_of_coverage.rb', line 25

def cluster_options previous_job_id = nil
  core_num = 6
  {
    previous_job_id: previous_job_id,
    var_env: [core_num],
    adjust_memory: ['h_stack=256M', 'h_vmem=8G'],
    parallel_env: [core_num],
    tools: ['gatk', 'depth_of_coverage']
  }
end

#depth_of_coverage_optionsObject



48
49
50
51
52
53
54
55
56
57
# File 'lib/cagnut_gatk/functions/depth_of_coverage.rb', line 48

def depth_of_coverage_options
  target = @target_file.blank? ? '-omitIntervals' : "-L #{@target_file}"
  array = depth_of_coverage_params['params'].dup
  array << "-T DepthOfCoverage"
  array << "-R #{ref_fasta}"
  array << "-I #{@input}"
  array << "-o #{@output}"
  array << target
  array.uniq
end

#generate_scriptObject



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/cagnut_gatk/functions/depth_of_coverage.rb', line 36

def generate_script
  file_name = "#{@order}_gatk_depth_of_coverage_#{@suffix}"
  file = File.join jobs_dir, "#{file_name}.sh"
  path = File.expand_path '../templates/depth_of_coverage.sh', __FILE__
  template = Tilt.new path
  File.open(file, 'w') do |f|
    f.puts template.render Object.new, job_params(file_name)
  end
  File.chmod(0700, file)
  file_name
end

#job_params(script_name) ⇒ Object



71
72
73
74
75
76
77
78
79
# File 'lib/cagnut_gatk/functions/depth_of_coverage.rb', line 71

def job_params script_name
  {
    jobs_dir: jobs_dir,
    script_name: script_name,
    output: @output,
    depth_of_coverage_params: params_combination_hash,
    run_local: ::Cagnut::JobManage.run_local
  }
end

#modified_java_arrayObject



59
60
61
62
# File 'lib/cagnut_gatk/functions/depth_of_coverage.rb', line 59

def modified_java_array
  array = depth_of_coverage_params['java'].dup
  array.unshift(java_path).uniq
end

#params_combination_hashObject



64
65
66
67
68
69
# File 'lib/cagnut_gatk/functions/depth_of_coverage.rb', line 64

def params_combination_hash
  {
    'java' => modified_java_array,
    'params' => depth_of_coverage_options
  }
end

#run(previous_job_id = nil) ⇒ Object



18
19
20
21
22
23
# File 'lib/cagnut_gatk/functions/depth_of_coverage.rb', line 18

def run previous_job_id = nil
  puts "Submitting #{sample_name} #{@suffix} depth of coverage Jobs"
  script_name = generate_script
  ::Cagnut::JobManage.submit script_name, @job_name, cluster_options(previous_job_id)
  [@job_name, @output]
end