Class: CagnutToolbox::QseqToFastq
- Inherits:
-
Object
- Object
- CagnutToolbox::QseqToFastq
- Extended by:
- Forwardable
- Defined in:
- lib/cagnut_toolbox/functions/qseq_to_fastq.rb
Instance Method Summary collapse
- #fetch_filename ⇒ Object
- #generate_script ⇒ Object
-
#initialize(opts = {}) ⇒ QseqToFastq
constructor
A new instance of QseqToFastq.
- #queuing_options(previous_job_id = nil) ⇒ Object
- #run(previous_job_id = nil) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ QseqToFastq
Returns a new instance of QseqToFastq.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/cagnut_toolbox/functions/qseq_to_fastq.rb', line 9 def initialize opts = {} @order = sprintf '%02i', opts[:order] @input = opts[:input].nil? ? "#{seqs_path}" : opts[:input] @input.gsub! '.gz', '' @input2 = File. fetch_filename, File.dirname(@input) abort('Cant recognized sequence files') if @input2.nil? @output = "#{opts[:dirs][output]}/#{sample_name}_1_qtf.fastq" @output2 = "#{opts[:dirs][output]}/s_#{sample_name}_2_qtf.fastq" @job_name = "#{prefix_name}_qseq_to_fastq_#{sample_name}" end |
Instance Method Details
#fetch_filename ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/cagnut_toolbox/functions/qseq_to_fastq.rb', line 20 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_script ⇒ Object
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 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/cagnut_toolbox/functions/qseq_to_fastq.rb', line 43 def generate_script script_name = "#{@order}_toolbox_qseq2fastq" exe_qseq_to_fastq = "ruby #{exe_path}/qseq_to_fastq.rb" 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" if [ -s "#{@input}.gz" ] then gunzip -c #{@input}.gz | #{exe_qseq_to_fastq} #{@output} \\ #{::Cagnut::JobManage.run_local} gunzip -c #{@input2}.gz | #{exe_qseq_to_fastq} #{@output2} \\ #{::Cagnut::JobManage.run_local} else cat #{@input} | #{exe_qseq_to_fastq} #{@output} \\ #{::Cagnut::JobManage.run_local} cat #{@input2} | #{exe_qseq_to_fastq} #{@output2} \\ #{::Cagnut::JobManage.run_local} fi #force error when missing/empty fastq . Would prevent continutation of pipeline if [ ! -s "#{@output2}" ] then echo "Missing FASTQ: #{@output2} file!" 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) end |
#queuing_options(previous_job_id = nil) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/cagnut_toolbox/functions/qseq_to_fastq.rb', line 36 def previous_job_id = nil { previous_job_id: previous_job_id, tools: ['toolbox', 'qseq_to_fastq'] } end |
#run(previous_job_id = nil) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/cagnut_toolbox/functions/qseq_to_fastq.rb', line 29 def run previous_job_id = nil puts "Submitting #{sample_name} qseqToFastq" script_name = generate_script task ::Cagnut::JobManage.submit script_name, @job_name, (previous_job_id) [@job_name, @output] end |