Class: BioDSL::WriteFasta

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

Overview

Write sequences from stream in FASTA format.

Description

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

>test1
TATGACGCGCATCGACAGCAGCACGAGCATGCATCGACTG
TGCACTGACTACGAGCATCACTATATCATCATCATAATCT
TACGACATCTAGGGACTAC

For more about the FASTA format:

en.wikipedia.org/wiki/FASTA_format

Usage

write_fasta([wrap: <uin>[, output: <file>[, force: <bool>
            [, gzip: <bool> | bzip2: <bool>]]]])

Options

  • output <file> - Output file.

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

  • wrap <uint> - Wrap sequence into lines of wrap length.

  • gzip <bool> - Write gzipped output file.

  • bzip2 <bool> - Write bzipped output file.

Examples

To write FASTA entries to STDOUT.

write_fasta

To write FASTA entries wrapped in lines of length of 80 to STDOUT.

write_fasta(wrap: 80)

To write FASTA entries to a file 'test.fna'.

write_fasta(output: "test.fna")

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

write_fasta(output: "test.fna", force: true)

To write gzipped FASTA entries to file 'test.fna.gz'.

write_fasta(output: "test.fna.gz", gzip: true)

To write bzipped FASTA entries to file 'test.fna.bz2'.

write_fasta(output: "test.fna.bz2", bzip2: true)

Constant Summary

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

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ WriteFasta

Constructor for the WriteFasta class.

Parameters:

  • options (Hash)

    Options hash.

Options Hash (options):

  • :force (Bool)

    Flag allowing overwriting files.

  • :output (String)

    Output file path.

  • :wrap (Integer)

    Wrap sequences at this length (default no wrap)

  • :gzip (Bool)

    Output will be gzip'ed.

  • :bzip2 (Bool)

    Output will be bzip2'ed.



97
98
99
100
101
# File 'lib/BioDSL/commands/write_fasta.rb', line 97

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

Instance Method Details

#lmbProc

Return a lambda for the write_fasta command.

Returns:

  • (Proc)

    Returns the write_fasta command lambda.



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

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

    if @options[:output] == $stdout
      write_stdout(input, output)
    else
      write_file(input, output)
    end
  end
end