| Module | Bio::RestrictionEnzyme::StringFormatting |
| In: |
lib/bio/util/restriction_enzyme/string_formatting.rb
|
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
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, line 38
38: def add_spacing( seq, cs = cut_symbol )
39: str = ''
40: flag = false
41: seq.each_byte do |c|
42: c = c.chr
43: if c == cs
44: str += c
45: flag = false
46: elsif flag
47: str += ' ' + c
48: else
49: str += c
50: flag = true
51: end
52: end
53: str
54: end
Return the ‘n’ padding on the left side of the strand
Arguments
| Returns: | String the ‘n’ padding from the left side |
# File lib/bio/util/restriction_enzyme/string_formatting.rb, line 92
92: def left_padding( s )
93: s =~ %r{^n+}
94: ret = $&
95: ret ? ret : '' # Don't pass nil values
96: end
Return the ‘n’ padding on the right side of the strand
Arguments
| Returns: | String the ‘n’ padding from the right side |
# File lib/bio/util/restriction_enzyme/string_formatting.rb, line 104
104: def right_padding( s )
105: s =~ %r{n+$}
106: ret = $&
107: ret ? ret : '' # Don't pass nil values
108: end
Remove extraneous nucleic acid wildcards (‘n’ padding) from the left and right sides and remove cut symbols
Arguments
| Returns: | String sequence without ‘n’ padding on the sides or cut symbols |
# File lib/bio/util/restriction_enzyme/string_formatting.rb, line 82
82: def strip_cuts_and_padding( s )
83: strip_padding( s.tr(cut_symbol, '') )
84: end
Remove extraneous nucleic acid wildcards (‘n’ padding) from the left and right sides
Arguments
| Returns: | String sequence without ‘n’ padding on the sides |
# File lib/bio/util/restriction_enzyme/string_formatting.rb, line 63
63: def strip_padding( s )
64: if s[0].chr == 'n'
65: s =~ %r{(n+)(.+)}
66: s = $2
67: end
68: if s[-1].chr == 'n'
69: s =~ %r{(.+?)(n+)$}
70: s = $1
71: end
72: s
73: end