Class: CagnutGatk::HaplotypeCaller

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

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ HaplotypeCaller

Returns a new instance of HaplotypeCaller.



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

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

Instance Method Details

#cluster_options(previous_job_id = nil) ⇒ Object



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

def cluster_options previous_job_id = nil
  core_num = 6
  job_mem1 = "adjustWorkingMem 256M #{core_num}"
  job_mem2 = "adjustWorkingMem 10G #{core_num}"
  {
    previous_job_id: previous_job_id,
    var_env: [core_num, target],
    adjust_memory: ["h_stack=#{job_mem1}", "h_vmem=#{job_mem2}"],
    parallel_env: [core_num],
    tools: ['gatk', 'haplotype_caller']
  }
end

#generate_scriptObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/cagnut_gatk/functions/haplotype_caller.rb', line 58

def generate_script
  script_name = "#{@order}_gatk_haplotype_caller"
  file = File.join jobs_dir, "#{script_name}.sh"
  File.open(file, 'w') do |f|
    f.puts <<-BASH.strip_heredoc
      #!/bin/bash

      cd "#{jobs_dir}/../"
      echo "#{script_name} is starting at $(date +%Y%m%d%H%M%S)" >> "#{jobs_dir}/finished_jobs"

      #{params_combination['java'].join("\s")} \\
        #{params_combination['params'].join(" \\\n            ")} \\
        #{::Cagnut::JobManage.run_local}

      EXITSTATUS=$?

      if [ ! -s "#{@output}" ]
      then
        echo "vcf incomplete!"
        exit 100;
      fi

      if [ $EXITSTATUS -ne 0 ];then exit $EXITSTATUS;fi
      echo "#{script_name} is finished at $(date +%Y%m%d%H%M%S)" >> "#{jobs_dir}/finished_jobs"

    BASH
  end
  File.chmod(0700, file)
  script_name
end

#haplotype_caller_optionsObject



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

def haplotype_caller_options
  array = haplotype_caller_params['params'].dup
  array << "-T HaplotypeCaller"
  array << "-R #{ref_fasta}"
  array << "-I #{@input}"
  array << "-o #{@output}"
  array << "-L #{target_flanks_file}" if target_flanks_file
  array.uniq
end

#modified_java_arrayObject



46
47
48
49
# File 'lib/cagnut_gatk/functions/haplotype_caller.rb', line 46

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

#params_combinationObject



51
52
53
54
55
56
# File 'lib/cagnut_gatk/functions/haplotype_caller.rb', line 51

def params_combination
  @params_combination_hash ||= {
    'java' => modified_java_array,
    'params' => haplotype_caller_options
  }
end

#run(previous_job_id = nil) ⇒ Object



16
17
18
19
20
21
# File 'lib/cagnut_gatk/functions/haplotype_caller.rb', line 16

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