Class: BioDSL::WriteFastq

Inherits:
Object
  • Object
show all
Defined in:
lib/BioDSL/commands/write_fastq.rb

Overview

Write sequences from stream in FASTQ format.

Description

write_fastq writes sequence from the data stream in FASTQ format. However, a FASTQ entry will only be written if a SEQ key and a SEQ_NAME key is present. An example FASTQ entry:

>test1
TATGACGCGCATCGACAGCAGCACGAGCATGCATCGACTG
TGCACTGACTACGAGCATCACTATATCATCATCATAATCT
TACGACATCTAGGGACTAC

For more about the FASTQ format:

en.wikipedia.org/wiki/FASTQ_format

Usage

write_fastq([encoding: <:base_33|:base_64>[, output: <file>
            [, force: <bool>[, gzip: <bool> | bzip2: <bool>]]])

Options

  • encoding <base> - Encoding quality scores using :base_33 (default) or

    :base_64.
    
  • output <file> - Output file.

  • force <bool> - Force overwrite existing output file.

  • gzip <bool> - Write gzipped output file.

  • bzip2 <bool> - Write bzipped output file.

Examples

To write FASTQ entries to STDOUT.

write_fastq

To write FASTQ entries to a file ‘test.fq’.

write_fastq(output: "test.fq")

To overwrite output file if this exists use the force option:

write_fastq(output: "test.fq", force: true)

To write gzipped FASTQ entries to file ‘test.fq.gz’.

write_fastq(output: "test.fq.gz", gzip: true)

To write bzipped FASTQ entries to file ‘test.fq.bz2’.

write_fastq(output: "test.fq.bz2", bzip2: true)

Constant Summary collapse

STATS =
%i(records_in records_out sequences_in sequences_out residues_in
residues_out)

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ WriteFastq

Constructor for WriteFastq.

Parameters:

  • options (Hash)

    Options hash.

Options Hash (options):

  • :encoding (String, Symbol)
  • :force (Boolean)
  • :output (String)
  • :gzip (Boolean)
  • :bzip2 (Boolean)


93
94
95
96
97
98
99
# File 'lib/BioDSL/commands/write_fastq.rb', line 93

def initialize(options)
  @options = options
  check_options
  @options[:output] ||= $stdout
  @compress           = choose_compression
  @encoding           = choose_encoding
end

Instance Method Details

#lmbProc

Return command lambda for write_fastq.

Returns:

  • (Proc)

    Command lambda.



104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/BioDSL/commands/write_fastq.rb', line 104

def lmb
  lambda do |input, output, status|
    status_init(status, STATS)

    if @options[:output] == $stdout
      process_input(input, output, $stdout)
    else
      Fastq.open(@options[:output], 'w', compress: @compress) do |ios|
        process_input(input, output, ios)
      end
    end
  end
end