Module: Bio::RestrictionEnzyme::StringFormatting
- Extended by:
- CutSymbol
- Includes:
- CutSymbol
- Included in:
- DoubleStranded, DoubleStranded, DoubleStranded::AlignedStrands, Range::SequenceRange::CalculatedCuts, SingleStrand
- Defined in:
- lib/bio/util/restriction_enzyme/string_formatting.rb
Instance Method Summary collapse
-
#add_spacing(seq, cs = cut_symbol) ⇒ Object
Return the sequence with spacing for alignment.
-
#left_padding(s) ⇒ Object
Return the ‘n’ padding on the left side of the strand.
-
#right_padding(s) ⇒ Object
Return the ‘n’ padding on the right side of the strand.
-
#strip_cuts_and_padding(s) ⇒ Object
Remove extraneous nucleic acid wildcards (‘n’ padding) from the left and right sides and remove cut symbols.
-
#strip_padding(s) ⇒ Object
Remove extraneous nucleic acid wildcards (‘n’ padding) from the left and right sides.
Methods included from CutSymbol
cut_symbol, escaped_cut_symbol, re_cut_symbol, re_cut_symbol_adjacent, set_cut_symbol
Instance Method Details
#add_spacing(seq, cs = cut_symbol) ⇒ Object
Return the sequence with spacing for alignment. Does not add whitespace around cut symbols.
Example:
pattern = 'n^ng^arraxt^n'
add_spacing( pattern ) # => "n^n g^a r r a x t^n"
Arguments
-
seq
: sequence with cut symbols -
cs
: (optional) Cut symbol along the string. The reason this is definable outside of CutSymbol is that this is a utility function used to form vertical and horizontal cuts such as:a|t g c +---+ t a c|g
- Returns
-
String
sequence with single character distance between bases
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/bio/util/restriction_enzyme/string_formatting.rb', line 30 def add_spacing( seq, cs = cut_symbol ) str = '' flag = false seq.each_byte do |c| c = c.chr if c == cs str += c flag = false elsif flag str += ' ' + c else str += c flag = true end end str end |
#left_padding(s) ⇒ Object
Return the ‘n’ padding on the left side of the strand
Arguments
-
s
: sequence with extraneous ‘n’ padding on the left side of the strand
- Returns
-
String
the ‘n’ padding from the left side
84 85 86 87 88 |
# File 'lib/bio/util/restriction_enzyme/string_formatting.rb', line 84 def left_padding( s ) s =~ %r{^n+} ret = $& ret ? ret : '' # Don't pass nil values end |
#right_padding(s) ⇒ Object
Return the ‘n’ padding on the right side of the strand
Arguments
-
s
: sequence with extraneous ‘n’ padding on the right side of the strand
- Returns
-
String
the ‘n’ padding from the right side
96 97 98 99 100 |
# File 'lib/bio/util/restriction_enzyme/string_formatting.rb', line 96 def right_padding( s ) s =~ %r{n+$} ret = $& ret ? ret : '' # Don't pass nil values end |
#strip_cuts_and_padding(s) ⇒ Object
Remove extraneous nucleic acid wildcards (‘n’ padding) from the left and right sides and remove cut symbols
Arguments
-
s
: sequence with extraneous ‘n’ padding and cut symbols
- Returns
-
String
sequence without ‘n’ padding on the sides or cut symbols
74 75 76 |
# File 'lib/bio/util/restriction_enzyme/string_formatting.rb', line 74 def strip_cuts_and_padding( s ) strip_padding( s.tr(cut_symbol, '') ) end |
#strip_padding(s) ⇒ Object
Remove extraneous nucleic acid wildcards (‘n’ padding) from the left and right sides
Arguments
-
s
: sequence with extraneous ‘n’ padding
- Returns
-
String
sequence without ‘n’ padding on the sides
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/bio/util/restriction_enzyme/string_formatting.rb', line 55 def strip_padding( s ) if s[0].chr == 'n' s =~ %r{(n+)(.+)} s = $2 end if s[-1].chr == 'n' s =~ %r{(.+?)(n+)$} s = $1 end s end |