module Bio::RestrictionEnzyme::StringFormatting
Public Instance Methods
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 ofCutSymbol
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
# File lib/bio/util/restriction_enzyme/string_formatting.rb 37 def add_spacing( seq, cs = cut_symbol ) 38 str = '' 39 flag = false 40 seq.each_byte do |c| 41 c = c.chr 42 if c == cs 43 str += c 44 flag = false 45 elsif flag 46 str += ' ' + c 47 else 48 str += c 49 flag = true 50 end 51 end 52 str 53 end
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
# File lib/bio/util/restriction_enzyme/string_formatting.rb 91 def left_padding( s ) 92 s =~ %r{^n+} 93 ret = $& 94 ret ? ret : '' # Don't pass nil values 95 end
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
# File lib/bio/util/restriction_enzyme/string_formatting.rb 103 def right_padding( s ) 104 s =~ %r{n+$} 105 ret = $& 106 ret ? ret : '' # Don't pass nil values 107 end
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
# File lib/bio/util/restriction_enzyme/string_formatting.rb 81 def strip_cuts_and_padding( s ) 82 strip_padding( s.tr(cut_symbol, '') ) 83 end
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
# File lib/bio/util/restriction_enzyme/string_formatting.rb 62 def strip_padding( s ) 63 if s[0].chr == 'n' 64 s =~ %r{(n+)(.+)} 65 s = $2 66 end 67 if s[-1].chr == 'n' 68 s =~ %r{(.+?)(n+)$} 69 s = $1 70 end 71 s 72 end