Class: Basil::CLI
- Inherits:
-
Object
- Object
- Basil::CLI
- Defined in:
- lib/basil/cli.rb
Class Method Summary collapse
- .parse_arguments ⇒ Object
- .parse_barcodes(barcodes) ⇒ Object
-
.parse_illumina_directory(dir) ⇒ Object
For parsing illumina-generated output directories containing paired QSEQ files.
- .run! ⇒ Object
Class Method Details
.parse_arguments ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/basil/cli.rb', line 79 def parse_arguments opts = Trollop:: do version "PRE-RELEASE" <<-EOS Basil is an HTPS demultiplexer Version: #{version} Usage: basil [options] -i <reads/directory> -o <output directory> where [options] are: EOS opt :barcodes, 'barcodes definition file', :short => 'b', :type => String opt :reads, 'reads (fastq/fasta/qseq)', :short => 'i', :type => String opt :illumina, 'Illumina output directory', :short => 'd' opt :out_fmt, 'Output format (default: same format as input)', :short => 'f' opt :pretrim, 'trim N nucleotides from start before searching for barcode', :type => Integer opt :out, 'output directory', :short => 'o', :type => String end filename = ARGV.shift Trollop::die :barcodes, "must specify barcodes" if opts[:barcodes].nil? Trollop::die :reads, "must specify reads or Illumina directory" if !(opts[:reads] || opts[:illumina]) Trollop::die "cannot specify both reads and Illumina directory" if opts[:reads] && opts[:illumina] Trollop::die :out, "must specify output directory" if !opts[:out] opts end |
.parse_barcodes(barcodes) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/basil/cli.rb', line 54 def = # barcodes included in barcodes/ directory? if Barcodes. Barcodes.() # barcodes specified by filename else end File.open() { |h| Basil. h } end |
.parse_illumina_directory(dir) ⇒ Object
For parsing illumina-generated output directories containing paired QSEQ files
70 71 72 73 74 75 76 77 |
# File 'lib/basil/cli.rb', line 70 def parse_illumina_directory dir files = Dir[File.join(dir, '*')] files.collect do |x| m = File.basename(x).match(/s_(\d)_(\d)_(\d*)_qseq\.txt/) { :lane => m[1], :pair => m[2], :n => m[3], :filename => File.join(dir, m[0]) } end.group_by { |x| x[:n] } end |
.run! ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/basil/cli.rb', line 5 def run! opts = parse_arguments = opts[:barcodes] out_dir = opts[:out] buffer = Buffer.new basil = Basil.new() handles = Array.new if opts[:illumina] if pretrim raise "pretrim is not supported with paired-end data" end else reads_handle = File.open(opts[:reads]) handles << reads_handle records_format = records.format pretrim = opts[:pretrim] || 0 afttrim = -1*opts[:afttrim] || -1 end if File.exist? out_dir $stderr.puts "#{out_dir} already exists -- delete or move!" exit else Dir.mkdir(out_dir) end records.each do |record| match = basil.recognize record.sequence , sequence = match if match unless match = 'unknown' trimmed_sequence = record.sequence end trimmed_sequence = record.sequence[pretrim..afttrim] new_record = Fasta.new :name => record.name, :sequence => trimmed_sequence buffer.add_to File.join(out_dir, + ".#{records_format}"), new_record end # Finish up buffer.finalize handles.collect { |x| x.close } end |