Class: CagnutSnpeff::SnpAnnotation

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

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ SnpAnnotation

Returns a new instance of SnpAnnotation.



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

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

Instance Method Details

#annotation_optionsObject



31
32
33
34
35
# File 'lib/cagnut_snpeff/functions/snp_annotation.rb', line 31

def annotation_options
  array = annotation_params['params'].dup
  array << "#{@input} > #{@output}"
  array.uniq
end

#cluster_options(previous_job_id = nil) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/cagnut_snpeff/functions/snp_annotation.rb', line 23

def cluster_options previous_job_id = nil
  {
    previous_job_id: previous_job_id,
    adjust_memory: ['h_stack=256M', 'h_vmem=8G'],
    tools: ['snpeff', 'annotation']
  }
end

#generate_scriptObject



49
50
51
52
53
54
55
56
57
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
# File 'lib/cagnut_snpeff/functions/snp_annotation.rb', line 49

def generate_script
  script_name = "#{@order}_snpeff_snp_annotation"
  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_hash['java'].join("\s")} \\
        #{params_combination_hash['params'].join(" \\\n            ")} \\
        #{::Cagnut::JobManage.run_local}

      EXITSTATUS=$?

      #force error when missing output
      if [ ! -s "#{@output}" ]; then exit 100;fi;
      if [ $(grep -cv "^#" "#{@output}") -eq "0" ]
      then
        echo "No variants!"
        exit 100;
      fi

      if [ $EXITSTATUS -eq 1 ];then
        echo "Error in Java"
        exit 100
      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

#modified_java_arrayObject



37
38
39
40
# File 'lib/cagnut_snpeff/functions/snp_annotation.rb', line 37

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

#params_combination_hashObject



42
43
44
45
46
47
# File 'lib/cagnut_snpeff/functions/snp_annotation.rb', line 42

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

#run(previous_job_id = nil) ⇒ Object



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

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