class CagnutGatk::AnalyzeCovariates

Public Class Methods

new(opts = {}) click to toggle source
# 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

Public Instance Methods

analyze_covariates_options() click to toggle source
# 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) click to toggle source
# 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_basename() click to toggle source
# File lib/cagnut_gatk/functions/analyze_covariates.rb, line 18
def file_basename
  @basename ||= File.basename @input
end
generate_script() click to toggle source
# 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) click to toggle source
# 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_array() click to toggle source
# 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_file() click to toggle source
# 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_combination() click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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