Class: CagnutGatk::AnalyzeCovariates

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

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ AnalyzeCovariates

Returns a new instance of AnalyzeCovariates.



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

def initialize opts = {}
  @order = sprintf '%02i', opts[:order]
  @job_name = "#{prefix_name}_AnalyzeCovariates_#{sample_name}"
  @input = opts[:input].nil? ? "#{opts[:dirs][:input]}/#{sample_name}_realn.bam" : opts[:input]
  @recal_csv = "#{opts[:dirs][:contrast]}/#{replace_filename('_recal.csv')}"
  @recal_bqsr_csv = "#{opts[:dirs][:contrast]}/#{replace_filename('_recal_post.csv')}"
  @output = "#{opts[:dirs][:output]}/#{output_file}"
end

Instance Method Details

#analyze_covariates_optionsObject



68
69
70
71
72
73
74
75
76
# File 'lib/cagnut_gatk/functions/analyze_covariates.rb', line 68

def analyze_covariates_options
  array = analyze_covariates_params['params'].dup
  array << "-T AnalyzeCovariates"
  array << "-R #{ref_fasta}"
  array << "-before #{@recal_csv}"
  array << "-after #{@recal_bqsr_csv}"
  array << "-plots #{@output}"
  array.uniq
end

#cluster_options(previous_job_id = nil) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/cagnut_gatk/functions/analyze_covariates.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}"],
    tools: ['gatk', 'analyze_covariates']
  }
end

#file_basenameObject



18
19
20
# File 'lib/cagnut_gatk/functions/analyze_covariates.rb', line 18

def file_basename
  @basename ||= File.basename @input
end

#generate_scriptObject



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

def generate_script
  script_name = "#{@order}_gatk_analyze_covariates"
  file = File.join jobs_dir, "#{script_name}.sh"
  path = File.expand_path '../templates/analyze_covariates.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



83
84
85
86
87
88
89
90
91
92
# File 'lib/cagnut_gatk/functions/analyze_covariates.rb', line 83

def job_params script_name
  {
    jobs_dir: jobs_dir,
    script_name: script_name,
    after: @after,
    output: @output,
    analyze_covariates_params: params_combination,
    run_local: "#{::Cagnut::JobManage.run_local}"
  }
end

#modified_java_arrayObject



78
79
80
81
# File 'lib/cagnut_gatk/functions/analyze_covariates.rb', line 78

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

#output_fileObject



26
27
28
29
30
# File 'lib/cagnut_gatk/functions/analyze_covariates.rb', line 26

def output_file
  output = replace_filename '_recalibration_plots.pdf'
  return output unless output == file_basename
  abort 'Input file is not correctly'
end

#params_combinationObject



61
62
63
64
65
66
# File 'lib/cagnut_gatk/functions/analyze_covariates.rb', line 61

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

#replace_filename(target_name) ⇒ Object



22
23
24
# File 'lib/cagnut_gatk/functions/analyze_covariates.rb', line 22

def replace_filename target_name
  file_basename.gsub '_realn.bam', target_name
end

#run(previous_job_id = nil) ⇒ Object



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

def run previous_job_id = nil
  puts "Submitting AnalyzeCovariates #{sample_name}"
  script_name = generate_script
  ::Cagnut::JobManage.submit script_name, @job_name, cluster_options(previous_job_id)
  @job_name
end