Class: GenomerPluginView::Fasta

Inherits:
Genomer::Plugin
  • Object
show all
Defined in:
lib/genomer-plugin-view/fasta.rb

Instance Method Summary collapse

Instance Method Details

#header(identifier) ⇒ Object



20
21
22
# File 'lib/genomer-plugin-view/fasta.rb', line 20

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

#header_flagsObject



28
29
30
# File 'lib/genomer-plugin-view/fasta.rb', line 28

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

#identifierObject



24
25
26
# File 'lib/genomer-plugin-view/fasta.rb', line 24

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

#runObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/genomer-plugin-view/fasta.rb', line 5

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

#sequenceObject



32
33
34
# File 'lib/genomer-plugin-view/fasta.rb', line 32

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