Class: Bioinform::MotifSplitter
- Inherits:
-
Object
- Object
- Bioinform::MotifSplitter
- 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
-
#splitter_pattern ⇒ Object
readonly
Returns the value of attribute splitter_pattern.
-
#start_motif_pattern ⇒ Object
readonly
Returns the value of attribute start_motif_pattern.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ MotifSplitter
constructor
A new instance of MotifSplitter.
- #split(input) ⇒ Object
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(={}) @start_motif_pattern = .fetch(:start_motif_pattern, /^\s*([^-+\s\d.]+|>.*)/) @splitter_pattern = .fetch(:splitter_pattern, /^\s*$/) end |
Instance Attribute Details
#splitter_pattern ⇒ Object (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_pattern ⇒ Object (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 |