Class: CagnutSamtools::MgBamSoftLink

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

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ MgBamSoftLink

Returns a new instance of MgBamSoftLink.



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

def initialize opts = {}
  @order = sprintf '%02i', opts[:order]
  @job_name = "#{prefix_name}_mgBam_#{sample_name}"
  @input = opts[:input].nil? ? "#{opts[:dirs][:input]}/#{sample_name}_rg.bam" : opts[:input]
  @output = "#{opts[:dirs][:output]}/#{sample_name}_merged.bam"
  @output_bai = "#{opts[:dirs][:output]}/#{sample_name}_merged.bai"
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/cagnut_samtools/functions/mg_bam_soft_link.rb', line 31

def generate_script
  script_name = "#{@order}_samtools_mg_bam_soft_link"
  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"
      rm -f #{@output} #{@output_bai}
      ln -s #{@input}  #{@output}

      # Check BAM EOF
      BAM_28=$(tail -c 28 #{@output}|xxd -p)
      if [ "#{magic28}" != "$BAM_28" ]
      then
        echo "Error with BAM EOF" 1>&2
        exit 100
      fi

      #{samtools_path} index #{@output} \\
        #{::Cagnut::JobManage.run_local}
      mv #{output}.bai #{@output_bai}

      if [ !  -s "#{@output_bai}" ]
      then
        echo "Incorrect Output!"
        exit 100
      fi
      echo "#{script_name} is finished at $(date +%Y%m%d%H%M%S)" >> "#{jobs_dir}/finished_jobs"

      exit $EXITSTATUS
    BASH
  end
  File.chmod(0700, file)
  script_name
end

#queuing_options(previous_job_id = nil) ⇒ Object



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

def queuing_options previous_job_id = nil
  {
    previous_job_id: previous_job_id,
    tools: ['samtools', 'mg_bam_soft_link']
  }
end

#run(previous_job_id = nil) ⇒ Object



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

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