| Class | Bio::RestrictionEnzyme::DoubleStranded::AlignedStrands |
| In: |
lib/bio/util/restriction_enzyme/double_stranded/aligned_strands.rb
|
| Parent: | Object |
Align two SingleStrand objects and return a Result object with primary and complement accessors.
| Result | = | Struct.new(:primary, :complement) | The object returned for alignments |
Pad and align two String objects without cut symbols.
This will look for the sub-sequence without left and right ‘n’ padding and re-apply ‘n’ padding to both strings on both sides equal to the maximum previous padding on that side.
The sub-sequences stripped of left and right ‘n’ padding must be of equal length.
Example:
AlignedStrands.align('nngattacannnnn', 'nnnnnctaatgtnn') # =>
<struct Bio::RestrictionEnzyme::DoubleStranded::AlignedStrands::Result
primary="nnnnngattacannnnn",
complement="nnnnnctaatgtnnnnn">
Arguments
| Returns: | Result object with equal padding on both strings |
# File lib/bio/util/restriction_enzyme/double_stranded/aligned_strands.rb, line 47
47: def self.align(a, b)
48: a = a.to_s
49: b = b.to_s
50: validate_input( strip_padding(a), strip_padding(b) )
51: left = [left_padding(a), left_padding(b)].sort.last
52: right = [right_padding(a), right_padding(b)].sort.last
53:
54: p = left + strip_padding(a) + right
55: c = left + strip_padding(b) + right
56: Result.new(p,c)
57: end
Pad and align two String objects with cut symbols.
Example:
AlignedStrands.with_cuts('nngattacannnnn', 'nnnnnctaatgtnn', [0, 10, 12], [0, 2, 12]) # =>
<struct Bio::RestrictionEnzyme::DoubleStranded::AlignedStrands::Result
primary="n n n n^n g a t t a c a n n^n n^n",
complement="n^n n^n n c t a a t g t n^n n n n">
Notes:
The sequences stripped of left and right ‘n’ padding must be of equal length.
Arguments
| Returns: | Result object with equal padding on both strings and spacing between bases |
# File lib/bio/util/restriction_enzyme/double_stranded/aligned_strands.rb, line 83
83: def self.align_with_cuts(a,b,a_cuts,b_cuts)
84: a = a.to_s
85: b = b.to_s
86: validate_input( strip_padding(a), strip_padding(b) )
87:
88: a_left, a_right = left_padding(a), right_padding(a)
89: b_left, b_right = left_padding(b), right_padding(b)
90:
91: left_diff = a_left.length - b_left.length
92: right_diff = a_right.length - b_right.length
93:
94: (right_diff > 0) ? (b_right += 'n' * right_diff) : (a_right += 'n' * right_diff.abs)
95:
96: a_adjust = b_adjust = 0
97:
98: if left_diff > 0
99: b_left += 'n' * left_diff
100: b_adjust = left_diff
101: else
102: a_left += 'n' * left_diff.abs
103: a_adjust = left_diff.abs
104: end
105:
106: a = a_left + strip_padding(a) + a_right
107: b = b_left + strip_padding(b) + b_right
108:
109: a_cuts.sort.reverse.each { |c| a.insert(c+1+a_adjust, cut_symbol) }
110: b_cuts.sort.reverse.each { |c| b.insert(c+1+b_adjust, cut_symbol) }
111:
112: Result.new( add_spacing(a), add_spacing(b) )
113: end
# File lib/bio/util/restriction_enzyme/double_stranded/aligned_strands.rb, line 119
119: def self.validate_input(a,b)
120: unless a.size == b.size
121: err = "Result sequences are not the same size. Does not align sequences with differing lengths after strip_padding.\n"
122: err += "#{a.size}, #{a.inspect}\n"
123: err += "#{b.size}, #{b.inspect}"
124: raise ArgumentError, err
125: end
126: end