Sha256: 3c6834dbd8c952136de97bf2d72acab0fcf1a5d367ad6e1187ee5df14c202109

Contents?: true

Size: 990 Bytes

Versions: 1

Compression:

Stored size: 990 Bytes

Contents

module Lederhosen
  class CLI

    ##
    # PAIRED-END READ WORK-AROUND (JOIN THEM)
    #
    desc "join reads end-to-end",
         "--trimmed=trimmed/*.fasta --output=joined.fasta"

    method_option :trimmed, :type => :string, :default => 'trimmed/*.fasta'
    method_option :output,  :type => :string, :default => 'joined.fasta'

    def join

      trimmed = Dir[options[:trimmed]]
      output = options[:output]

      fail "no reads in #{trimmed}" if trimmed.length == 0

      output = File.open(output, 'w')

      pbar = ProgressBar.new "joining", trimmed.length

      trimmed.each do |fasta_file|
        pbar.inc

        begin
          records = Dna.new File.open(fasta_file)
        rescue
          ohai "skipping #{fasta_file} (empty?)"
          next
        end

        records.each_slice(2) do |r, l|
          output.puts ">#{r.name}:#{File.basename(fasta_file, '.fasta')}\n#{r.sequence.reverse+l.sequence}"
        end
      end
      pbar.finish
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lederhosen-0.0.8 lib/lederhosen/tasks/join.rb