Class: CagnutGatk::BaseRecalibrator

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

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ BaseRecalibrator

Returns a new instance of BaseRecalibrator.



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

def initialize opts = {}
  @order = sprintf '%02i', opts[:order]
  @csv_dir = opts[:dirs][:output]
  @has_bqsr_file = opts[:has_bqsr_file]
  @input = opts[:file_name].nil? ? "#{opts[:dirs][:input]}/#{sample_name}_realn.bam" : opts[:input]
  setup_output_and_bqsr_file
end

Instance Method Details

#base_recalibrator_optionsObject



62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/cagnut_gatk/functions/base_recalibrator.rb', line 62

def base_recalibrator_options
  dtag = snpdb.nil? ? "--run_without_dbsnp_potentially_ruining_quality" : "-knownSites #{snpdb}"
  array = base_recalibrator_params['params'].dup
  array << "-T BaseRecalibrator"
  array << "-R #{ref_fasta}"
  array << "-I #{@input}"
  array << "-o #{@output}"
  array << "#{dtag}"
  array << "-BQSR #{@bqsr_file}" if @has_bqsr_file
  array << "-L #{target_flanks_file}" if target_flanks_file
  array.uniq
end

#cluster_options(previous_job_id = nil) ⇒ Object



39
40
41
42
43
44
45
46
47
48
# File 'lib/cagnut_gatk/functions/base_recalibrator.rb', line 39

def cluster_options previous_job_id = nil
  core_num = 6
  {
    previous_job_id: previous_job_id,
    var_env: [core_num],
    adjust_memory: ["h_vmem=adjustWorkingMem 7G #{core_num}"],
    parallel_env: [core_num],
    tools: ['gatk', 'base_recalibrator']
  }
end

#generate_scriptObject



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/cagnut_gatk/functions/base_recalibrator.rb', line 50

def generate_script
  script_name = @has_bqsr_file ? "#{@order}_gatk_base_recalibrator_post" : "#{@order}_gatk_base_recalibrator"
  file = File.join jobs_dir, "#{script_name}.sh"
  path = File.expand_path "../templates/base_recalibrator.sh", __FILE__
  template = Tilt.new path
  File.open(file, 'w') do |f|
    f.puts template.render Object.new, job_params(script_name)
  end
  File.chmod(0700, file)
  script_name
end

#job_params(script_name) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
# File 'lib/cagnut_gatk/functions/base_recalibrator.rb', line 87

def job_params script_name
  {
    jobs_dir: jobs_dir,
    script_name: script_name,
    magic28: magic28,
    input: @input,
    output: @output,
    base_recalibrator_params: params_combination,
    run_local: ::Cagnut::JobManage.run_local
  }
end

#modified_java_arrayObject



75
76
77
78
# File 'lib/cagnut_gatk/functions/base_recalibrator.rb', line 75

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

#params_combinationObject



80
81
82
83
84
85
# File 'lib/cagnut_gatk/functions/base_recalibrator.rb', line 80

def params_combination
  {
    'java' => modified_java_array,
    'params' => base_recalibrator_options
  }
end

#run(previous_job_id = nil) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/cagnut_gatk/functions/base_recalibrator.rb', line 30

def run previous_job_id = nil
  message = @has_bqsr_file ? 'with BQSR' : ''
  puts "Submitting BaseRecalibrator #{sample_name} #{message}"
  script_name = generate_script
  job_name = "#{prefix_name}_#{script_name}"
  ::Cagnut::JobManage.submit script_name, job_name, cluster_options(previous_job_id)
  job_name
end

#setup_output_and_bqsr_fileObject



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/cagnut_gatk/functions/base_recalibrator.rb', line 18

def setup_output_and_bqsr_file
  file_name = File.basename @input
  if @has_bqsr_file
    output = file_name.gsub '_realn.bam', '_recal_post.csv'
    bqsr_file = file_name.gsub '_realn.bam', '_recal.csv'
  else
    output = file_name.gsub '_realn.bam', '_recal.csv'
  end
  @output = "#{@csv_dir}/#{output}"
  @bqsr_file = "#{@csv_dir}/#{bqsr_file}" if @has_bqsr_file
end