Class: CagnutGatk::CountRead

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

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ CountRead

Returns a new instance of CountRead.



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

def initialize opts = {}
  @order = sprintf '%02i', opts[:order]
  @target = opts[:target]
  @suffix = @target.nil? ? 'genome.readct' : 'target.readct'
  @input = opts[:input].nil? ? "#{opts[:dirs][:input]}/#{sample_name}_markdup.bam" : opts[:input]
  @output = "#{opts[:dirs][:output]}/#{sample_name}_markdup_#{@suffix}"
  @job_name = "#{prefix_name}_countRead_#{sample_name}_#{@suffix}"
end

Instance Method Details

#cluster_options(previous_job_id = nil) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/cagnut_gatk/functions/count_read.rb', line 25

def cluster_options previous_job_id = nil
  {
    previous_job_id: previous_job_id,
    var_env: [ref_fasta],
    adjust_memory: ['h_vmem=5G'],
    tools: ['gatk', 'count_reads']
  }
end

#count_reads_optionsObject



46
47
48
49
50
51
52
53
# File 'lib/cagnut_gatk/functions/count_read.rb', line 46

def count_reads_options
  array = count_reads_params['params'].dup
  array << "-T CountReads"
  array << "-R #{ref_fasta}"
  array << "-I #{@input} > #{@output}"
  array << "-L #{@target}" if @target
  array.uniq
end

#generate_scriptObject



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

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



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

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

#modified_java_arrayObject



55
56
57
58
# File 'lib/cagnut_gatk/functions/count_read.rb', line 55

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

#params_combinationObject



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

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

#run(previous_job_id = nil) ⇒ Object



18
19
20
21
22
23
# File 'lib/cagnut_gatk/functions/count_read.rb', line 18

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