Sha256: 1d8fc3974e197a46c3bd30f50e78dc5a19a305e0910a20578efaab04450fae22

Contents?: true

Size: 737 Bytes

Versions: 7

Compression:

Stored size: 737 Bytes

Contents

require 'genomer'

class GenomerPluginView::Fasta < Genomer::Plugin

  def run
    if flags[:contigs]
      flags.delete(:contigs)

      sequence.
        split(/[Nn]+/).
        map{|s| Bio::Sequence.new(s) }.
        each_with_index.
        map{|s,i| s.output(:fasta,:header => header(sprintf("contig%05d",i+1))) }.
        join
    else
      Bio::Sequence.new(sequence).output(:fasta,:header => header(identifier))
    end
  end

  def header(identifier)
    (identifier + ' ' + header_flags).strip
  end

  def identifier
    flags[:identifier] ? flags.delete(:identifier) : '.'
  end

  def header_flags
    flags.map{|k,v| "[#{k}=#{v}]" }.join(' ')
  end

  def sequence
    scaffold.map{|entry| entry.sequence}.join
  end

end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
genomer-plugin-view-0.1.0 lib/genomer-plugin-view/fasta.rb
genomer-plugin-view-0.0.7 lib/genomer-plugin-view/fasta.rb
genomer-plugin-view-0.0.6 lib/genomer-plugin-view/fasta.rb
genomer-plugin-view-0.0.5 lib/genomer-plugin-view/fasta.rb
genomer-plugin-view-0.0.4 lib/genomer-plugin-view/fasta.rb
genomer-plugin-view-0.0.3 lib/genomer-plugin-view/fasta.rb
genomer-plugin-view-0.0.2 lib/genomer-plugin-view/fasta.rb