Class: CagnutSamtools::DoFlagStat

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

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ DoFlagStat

Returns a new instance of DoFlagStat.



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

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

Instance Method Details

#generate_scriptObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/cagnut_samtools/functions/do_flag_stat.rb', line 31

def generate_script
  script_name = "#{@order}_samtools_do_flag_stat"
  file = File.join jobs_dir, "#{script_name}.sh"
  File.open(file, 'w') do |f|
    f.puts <<-BASH.strip_heredoc
      #!/bin/bash
      echo "#{script_name} is starting at $(date +%Y%m%d%H%M%S)" >> "#{jobs_dir}/finished_jobs"
      #{samtools_path} flagstat #{@input} > #{@output} \\
        #{::Cagnut::JobManage.run_local}

      if [ ! -s #{@output} ]
      then
        echo "Incomplete output file #{@output}"
        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

#queuing_options(previous_job_id = nil) ⇒ Object



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

def queuing_options previous_job_id = nil
  {
    previous_job_id: previous_job_id,
    adjust_memory: ['h_vmem=500M'],
    tools: ['samtools', 'do_flag_stat']
  }
end

#run(previous_job_id = nil) ⇒ Object



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

def run previous_job_id = nil
  puts "Submitting doFlagStat for #{sample_name}_markdup suffix"
  script_name = generate_script
  ::Cagnut::JobManage.submit script_name, @job_name, queuing_options(previous_job_id)
  @job_name
end