Class: CagnutBwa::Mem

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

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Mem

Returns a new instance of Mem.



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

def initialize opts = {}
  @order = sprintf '%02i', opts[:order]
  @input = opts[:input].nil? ? "#{seqs_path}" : opts[:input]
  @input2 = File.expand_path fetch_filename, File.dirname(@input)
  abort('Cant recognized sequence files') if @input2.nil?
  @output = "#{opts[:dirs][:output]}/#{sample_name}_mem.sam"
  @job_name = "#{prefix_name}_#{sample_name}_mem*"
end

Instance Method Details

#fetch_filenameObject



18
19
20
21
22
23
24
25
# File 'lib/cagnut_bwa/functions/mem.rb', line 18

def fetch_filename
  filename = File.basename(@input)
  if filename.match '_R1_'
    filename.gsub '_R1_', '_R2_'
  elsif filename.match '_1_'
    filename.gsub '_1_', '_2_'
  end
end

#generate_scriptObject



53
54
55
56
57
58
59
60
61
62
# File 'lib/cagnut_bwa/functions/mem.rb', line 53

def generate_script
  script_name = "#{@order}_bwa_mem"
  file = File.join jobs_dir, "#{script_name}.sh"
  template = Tilt.new(File.expand_path '../templates/mem.sh', __FILE__)
  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



64
65
66
67
68
69
70
71
72
# File 'lib/cagnut_bwa/functions/mem.rb', line 64

def job_params script_name
  {
    jobs_dir: jobs_dir,
    script_name: script_name,
    output: @output,
    mem_params: mem_options,
    run_local: ::Cagnut::JobManage.run_local
  }
end

#mem_optionsObject



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/cagnut_bwa/functions/mem.rb', line 41

def mem_options
  array = mem_params.dup
  array.insert 1, 'mem'
  array << "-M"
  array << "-R \"#{rg_str}\""
  array << "#{ref_fasta}"
  array << "#{@input}"
  array << "#{@input2}"
  array << "> #{@output}"
  array.uniq
end

#queuing_options(previous_job_id = nil) ⇒ Object



34
35
36
37
38
39
# File 'lib/cagnut_bwa/functions/mem.rb', line 34

def queuing_options previous_job_id = nil
  {
    previous_job_id: previous_job_id,
    tools: ['bwa', 'mem']
  }
end

#run(previous_job_id = nil) ⇒ Object



27
28
29
30
31
32
# File 'lib/cagnut_bwa/functions/mem.rb', line 27

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