Class: Bioinform::MotifSplitter

Inherits:
Object
  • Object
show all
Defined in:
lib/bioinform/parsers/motif_splitter.rb

Overview

MotifSpliiter is designed to split text into chunks with separate motifs. It enumerates input line by line. One can supply two options:

* pattern for splitter `splitter_pattern`
* `start_motif_pattern` which can determine start of motif but doesn't
  match within motif

If specified pattern is nil, corresponding splitting is not applied. Paterns are applied by ‘#===` operator, thus both regexp or a Proc are valid options. Proc accepts a line and should return true if line is a splitter or is a motif start.

Splitter method ‘#split` returns an array of strings. Each of returned strings represents a motif. Motifs exclude splitter but include motif start, thus one can divide input both by lines which will be dismissed and by lines which will be retained.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ MotifSplitter

Returns a new instance of MotifSplitter.



22
23
24
25
# File 'lib/bioinform/parsers/motif_splitter.rb', line 22

def initialize(options={})
  @start_motif_pattern = options.fetch(:start_motif_pattern, /^\s*([^-+\s\d.]+|>.*)/)
  @splitter_pattern = options.fetch(:splitter_pattern, /^\s*$/)
end

Instance Attribute Details

#splitter_patternObject (readonly)

Returns the value of attribute splitter_pattern.



20
21
22
# File 'lib/bioinform/parsers/motif_splitter.rb', line 20

def splitter_pattern
  @splitter_pattern
end

#start_motif_patternObject (readonly)

Returns the value of attribute start_motif_pattern.



20
21
22
# File 'lib/bioinform/parsers/motif_splitter.rb', line 20

def start_motif_pattern
  @start_motif_pattern
end

Instance Method Details

#split(input) ⇒ Object



39
40
41
42
43
# File 'lib/bioinform/parsers/motif_splitter.rb', line 39

def split(input)
  parts_divided_by_splitter(input).map{|chunk|
    parts_divided_by_motif_starts(chunk)
  }.flatten.map(&:strip).reject(&:empty?)
end