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.

### Methods

align align_with_cuts new validate_input

### Constants

Result | = | Struct.new(:primary, :complement) |  | The object returned for alignments

### Public Class methods

align(a, b)

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

- `a`: Primary strand
- `b`: Complementary strand

Returns: | `Result` object with equal padding on both strings

[Source]

        # File lib/bio/util/restriction_enzyme/double_stranded/aligned_strands.rb, line 52
    52:   def self.align(a, b)
    53:     a = a.to_s
    54:     b = b.to_s
    55:     validate_input( strip_padding(a), strip_padding(b) )
    56:     left = [left_padding(a), left_padding(b)].sort.last
    57:     right = [right_padding(a), right_padding(b)].sort.last
    58:
    59:     p = left + strip_padding(a) + right
    60:     c = left + strip_padding(b) + right
    61:     Result.new(p,c)
    62:   end

align_with_cuts(a,b,a_cuts,b_cuts)

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:

- To make room for the cut symbols each nucleotide is spaced out.
- This is meant to be able to handle multiple cuts and completely unrelated cutsites on the two strands, therefore no biological algorithm assumptions (shortcuts) are made.

The sequences stripped of left and right ‘n’ padding must be of equal length.

Arguments

- `a`: Primary sequence
- `b`: Complementary sequence
- `a_cuts`: Primary strand cut locations in 0-based index notation
- `b_cuts`: Complementary strand cut locations in 0-based index notation

Returns: | `Result` object with equal padding on both strings and spacing between bases

[Source]

         # File lib/bio/util/restriction_enzyme/double_stranded/aligned_strands.rb, line 88
     88:   def self.align_with_cuts(a,b,a_cuts,b_cuts)
     89:     a = a.to_s
     90:     b = b.to_s
     91:     validate_input( strip_padding(a), strip_padding(b) )
     92:
     93:     a_left, a_right = left_padding(a), right_padding(a)
     94:     b_left, b_right = left_padding(b), right_padding(b)
     95:
     96:     left_diff = a_left.length - b_left.length
     97:     right_diff = a_right.length - b_right.length
     98:
     99:     (right_diff > 0) ? (b_right += 'n' * right_diff) : (a_right += 'n' * right_diff.abs)
    100:
    101:     a_adjust = b_adjust = 0
    102:
    103:     if left_diff > 0
    104:       b_left += 'n' * left_diff
    105:       b_adjust = left_diff
    106:     else
    107:       a_left += 'n' * left_diff.abs
    108:       a_adjust = left_diff.abs
    109:     end
    110:
    111:     a = a_left + strip_padding(a) + a_right
    112:     b = b_left + strip_padding(b) + b_right
    113:
    114:     a_cuts.sort.reverse.each { |c| a.insert(c+1+a_adjust, cut_symbol) }
    115:     b_cuts.sort.reverse.each { |c| b.insert(c+1+b_adjust, cut_symbol) }
    116:
    117:     Result.new( add_spacing(a), add_spacing(b) )
    118:   end

new()

Creates a new object.

Returns: | Bio::RestrictionEnzyme::DoubleStranded::AlignedStrands object

[Source]

        # File lib/bio/util/restriction_enzyme/double_stranded/aligned_strands.rb, line 27
    27:   def initialize; super; end

### Protected Class methods

validate_input(a,b)

[Source]

         # File lib/bio/util/restriction_enzyme/double_stranded/aligned_strands.rb, line 124
    124:   def self.validate_input(a,b)
    125:     unless a.size == b.size
    126:       err = "Result sequences are not the same size.  Does not align sequences with differing lengths after strip_padding.\n"
    127:       err += "#{a.size}, #{a.inspect}\n"
    128:       err += "#{b.size}, #{b.inspect}"
    129:       raise ArgumentError, err
    130:     end
    131:   end

[Validate]