Class: CagnutBwa::Samp

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

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Samp

Returns a new instance of Samp.



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

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

Instance Method Details

#fetch_filename(file) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/cagnut_bwa/functions/samp.rb', line 20

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

#generate_scriptObject



56
57
58
59
60
61
62
63
64
65
# File 'lib/cagnut_bwa/functions/samp.rb', line 56

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



67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/cagnut_bwa/functions/samp.rb', line 67

def job_params script_name
  {
    jobs_dir: jobs_dir,
    script_name: script_name,
    input: @input,
    input2: @input2,
    fastq: @fastq,
    fastq2: @fastq2,
    output: @output,
    samp_options: samp_options,
    run_local: ::Cagnut::JobManage.run_local
  }
end

#queuing_options(previous_job_id = nil) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/cagnut_bwa/functions/samp.rb', line 36

def queuing_options previous_job_id = nil
  {
    previous_job_id: previous_job_id,
    adjust_memory: ['h_vmem=5G'],
    tools: ['bwa', 'samp']
  }
end

#run(previous_job_id = nil) ⇒ Object



29
30
31
32
33
34
# File 'lib/cagnut_bwa/functions/samp.rb', line 29

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

#samp_optionsObject



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/cagnut_bwa/functions/samp.rb', line 44

def samp_options
  array = samp_params.dup
  array.insert 1, 'sampe'
  array << "-r \"#{rg_str}\""
  array << "#{ref_fasta}"
  array << "#{@input}"
  array << "#{@input2}"
  array << "#{@fastq}"
  array << "#{@fastq2} | gzip > #{@output}"
  array.uniq.compact
end