예제 #1
0
파일: tst_single.py 프로젝트: dials/cctbx
  def test(self):

    tree = single.tree()
    result = list( single.matching_statistics( tree, list( "ABC" ) ) )
    self.assertEqual( result, [ ( 0, ( tree.root, 0 ) ) ] * 3 )

    builder = single.ukkonen( tree = tree )

    for c in "TTAGC$":
      builder.append( c )

    builder.detach()
    leaf_indices_below = suffixtree.calculate_leaf_indices( root = tree.root )

    root = tree.root
    branch_t = root[ "T" ]
    leaf_0 = branch_t[ "T" ]
    leaf_1 = branch_t[ "A" ]
    leaf_2 = root[ "A" ]
    leaf_3 = root[ "G" ]
    leaf_4 = root[ "C" ]
    leaf_5 = root[ "$" ]

    self.assertEqual( leaf_indices_below[ leaf_0 ], [ 0 ] )
    self.assertEqual( leaf_indices_below[ leaf_1 ], [ 1 ] )
    self.assertEqual( leaf_indices_below[ leaf_2 ], [ 2 ] )
    self.assertEqual( leaf_indices_below[ leaf_3 ], [ 3 ] )
    self.assertEqual( leaf_indices_below[ leaf_4 ], [ 4 ] )
    self.assertEqual( leaf_indices_below[ leaf_5 ], [ 5 ] )

    self.assertEqual( sorted( leaf_indices_below[ branch_t ] ), [ 0, 1 ] )
    self.assertEqual( sorted( leaf_indices_below[ root ] ), list(range( 6)) )
예제 #2
0
  def test(self):

    tree = single.tree()
    result = list( single.matching_statistics( tree, list( "ABC" ) ) )
    self.assertEqual( result, [ ( 0, ( tree.root, 0 ) ) ] * 3 )

    builder = single.ukkonen( tree = tree )

    for c in "TTAGC$":
      builder.append( c )

    builder.detach()
    leaf_indices_below = suffixtree.calculate_leaf_indices( root = tree.root )

    root = tree.root
    branch_t = root[ "T" ]
    leaf_0 = branch_t[ "T" ]
    leaf_1 = branch_t[ "A" ]
    leaf_2 = root[ "A" ]
    leaf_3 = root[ "G" ]
    leaf_4 = root[ "C" ]
    leaf_5 = root[ "$" ]

    self.assertEqual( leaf_indices_below[ leaf_0 ], [ 0 ] )
    self.assertEqual( leaf_indices_below[ leaf_1 ], [ 1 ] )
    self.assertEqual( leaf_indices_below[ leaf_2 ], [ 2 ] )
    self.assertEqual( leaf_indices_below[ leaf_3 ], [ 3 ] )
    self.assertEqual( leaf_indices_below[ leaf_4 ], [ 4 ] )
    self.assertEqual( leaf_indices_below[ leaf_5 ], [ 5 ] )

    self.assertEqual( sorted( leaf_indices_below[ branch_t ] ), [ 0, 1 ] )
    self.assertEqual( sorted( leaf_indices_below[ root ] ), range( 6 ) )
예제 #3
0
파일: tst_single.py 프로젝트: dials/cctbx
  def test_tree(self):

    tree = single.tree()
    self.assertEqual( tree.in_construction, False )
    w = tree.word
    self.assertTrue( isinstance( w, single.word ) )
    self.assertEqual( w.length_descriptor()(), 0 )
    r = tree.root
    self.assertTrue( isinstance( r, single.edge ) )
    self.assertEqual( r.keys(), [] )
예제 #4
0
  def test_tree(self):

    tree = single.tree()
    self.assertEqual( tree.in_construction, False )
    w = tree.word
    self.assertTrue( isinstance( w, single.word ) )
    self.assertEqual( w.length_descriptor()(), 0 )
    r = tree.root
    self.assertTrue( isinstance( r, single.const_edge ) )
    self.assertEqual( r.keys(), [] )
예제 #5
0
파일: tst_single.py 프로젝트: dials/cctbx
  def test(self):

    tree = single.tree()
    result = list( single.matching_statistics( tree, list( "ABC" ) ) )
    self.assertEqual( result, [ ( 0, ( tree.root, 0 ) ) ] * 3 )

    builder = single.ukkonen( tree = tree )

    for c in "TTAGC$":
      builder.append( c )

    self.assertRaises( RuntimeError, single.matching_statistics, tree, list() );

    builder.detach()
    root = tree.root
    branch_t = root[ "T" ]
    leaf_0 = branch_t[ "T" ]
    leaf_1 = branch_t[ "A" ]
    leaf_2 = root[ "A" ]
    leaf_3 = root[ "G" ]
    leaf_4 = root[ "C" ]

    result = list( single.matching_statistics( tree, [] ) )
    self.assertEqual( result, [] )

    result = list( single.matching_statistics( tree, list( "QTTATTATTTAGCQWTTAGFK" ) ) )

    self.assertEqual(
      result,
      [
        ( 0, (   root, 0 ) ),
        ( 3, ( leaf_0, 3 ) ),
        ( 2, ( leaf_1, 3 ) ),
        ( 1, ( leaf_2, 3 ) ),
        ( 3, ( leaf_0, 3 ) ),
        ( 2, ( leaf_1, 3 ) ),
        ( 1, ( leaf_2, 3 ) ),
        ( 2, ( leaf_0, 2 ) ),
        ( 5, ( leaf_0, 5 ) ),
        ( 4, ( leaf_1, 5 ) ),
        ( 3, ( leaf_2, 5 ) ),
        ( 2, ( leaf_3, 5 ) ),
        ( 1, ( leaf_4, 5 ) ),
        ( 0, (   root, 0 ) ),
        ( 0, (   root, 0 ) ),
        ( 4, ( leaf_0, 4 ) ),
        ( 3, ( leaf_1, 4 ) ),
        ( 2, ( leaf_2, 4 ) ),
        ( 1, ( leaf_3, 4 ) ),
        ( 0, (   root, 0 ) ),
        ( 0, (   root, 0 ) ),
        ]
      )
예제 #6
0
  def test(self):

    tree = single.tree()
    result = list( single.matching_statistics( tree, list( "ABC" ) ) )
    self.assertEqual( result, [ ( 0, ( tree.root, 0 ) ) ] * 3 )

    builder = single.ukkonen( tree = tree )

    for c in "TTAGC$":
      builder.append( c )

    self.assertRaises( RuntimeError, single.matching_statistics, tree, list() );

    builder.detach()
    root = tree.root
    branch_t = root[ "T" ]
    leaf_0 = branch_t[ "T" ]
    leaf_1 = branch_t[ "A" ]
    leaf_2 = root[ "A" ]
    leaf_3 = root[ "G" ]
    leaf_4 = root[ "C" ]

    result = list( single.matching_statistics( tree, [] ) )
    self.assertEqual( result, [] )

    result = list( single.matching_statistics( tree, list( "QTTATTATTTAGCQWTTAGFK" ) ) )

    self.assertEqual(
      result,
      [
        ( 0, (   root, 0 ) ),
        ( 3, ( leaf_0, 3 ) ),
        ( 2, ( leaf_1, 3 ) ),
        ( 1, ( leaf_2, 3 ) ),
        ( 3, ( leaf_0, 3 ) ),
        ( 2, ( leaf_1, 3 ) ),
        ( 1, ( leaf_2, 3 ) ),
        ( 2, ( leaf_0, 2 ) ),
        ( 5, ( leaf_0, 5 ) ),
        ( 4, ( leaf_1, 5 ) ),
        ( 3, ( leaf_2, 5 ) ),
        ( 2, ( leaf_3, 5 ) ),
        ( 1, ( leaf_4, 5 ) ),
        ( 0, (   root, 0 ) ),
        ( 0, (   root, 0 ) ),
        ( 4, ( leaf_0, 4 ) ),
        ( 3, ( leaf_1, 4 ) ),
        ( 2, ( leaf_2, 4 ) ),
        ( 1, ( leaf_3, 4 ) ),
        ( 0, (   root, 0 ) ),
        ( 0, (   root, 0 ) ),
        ]
      )
예제 #7
0
파일: tst_single.py 프로젝트: dials/cctbx
  def test_ukkonen1(self):

    tree = single.tree()
    self.assertEqual( tree.in_construction, False )

    builder = single.ukkonen( tree )
    self.assertTrue( tree.in_construction )
    self.assertTrue( builder.is_attached )
    self.assertTrue( builder.is_valid )

    self.assertRaises( RuntimeError, single.ukkonen, tree )

    builder.detach()
    self.assertFalse( builder.is_attached )
    self.assertTrue( builder.is_valid )
    self.assertFalse( tree.in_construction )
    self.assertRaises( RuntimeError, builder.append, "a" )
예제 #8
0
  def test_ukkonen1(self):

    tree = single.tree()
    self.assertEqual( tree.in_construction, False )

    builder = single.ukkonen( tree )
    self.assertTrue( tree.in_construction )
    self.assertTrue( builder.is_attached )
    self.assertTrue( builder.is_valid )

    self.assertRaises( RuntimeError, single.ukkonen, tree )

    builder.detach()
    self.assertFalse( builder.is_attached )
    self.assertTrue( builder.is_valid )
    self.assertFalse( tree.in_construction )
    self.assertRaises( RuntimeError, builder.append, "a" )
예제 #9
0
파일: tst_single.py 프로젝트: dials/cctbx
  def test_ukkonen2(self):

    tree = single.tree()
    builder = single.ukkonen( tree )

    builder.append( glyph = "a" )
    self.assertTrue( builder.is_valid )

    builder.append( glyph = "n" )
    self.assertTrue( builder.is_valid )

    builder.detach()
    self.assertFalse( builder.is_attached )
    self.assertFalse( tree.in_construction )

    builder = single.ukkonen( tree )
    self.assertTrue( builder.is_valid )
    self.assertTrue( builder.is_attached )
    self.assertTrue( tree.in_construction )

    builder.append( glyph = "a" )
    self.assertFalse( builder.is_valid )
    self.assertRaises( RuntimeError, builder.detach )

    builder.append( glyph = "n" )
    self.assertFalse( builder.is_valid )
    self.assertRaises( RuntimeError, builder.detach )

    builder.append( glyph = "a" )
    self.assertFalse( builder.is_valid )
    self.assertRaises( RuntimeError, builder.detach )

    builder.append( glyph = "s" )
    self.assertTrue( builder.is_valid )

    builder.detach()
    self.assertFalse( builder.is_attached )
    self.assertFalse( tree.in_construction )

    builder = single.ukkonen( tree )
    self.assertTrue( builder.is_valid )
    self.assertTrue( builder.is_attached )
    self.assertTrue( tree.in_construction )

    builder.append( glyph = "$" )
    self.assertTrue( builder.is_valid )

    builder.detach()

    root = tree.root
    self.assertTrue( root.is_root() )
    self.assertEqual( set( root.keys() ), set( [ "a", "n", "s", "$" ] ) )

    b_a = root[ "a" ]
    self.assertFalse( b_a.is_root() )
    self.assertFalse( b_a.is_leaf() )
    self.assertEqual( b_a.start, 0 )
    self.assertEqual( b_a.stop, 1 )
    self.assertEqual( set( b_a.keys() ), set( [ "n", "s" ] ) )
    self.assertEqual( b_a.parent, root )

    b_a_n = b_a[ "n" ]
    self.assertFalse( b_a_n.is_root() )
    self.assertFalse( b_a_n.is_leaf() )
    self.assertEqual( b_a_n.start, 1 )
    self.assertEqual( b_a_n.stop, 3 )
    self.assertEqual( set( b_a_n.keys() ), set( [ "n", "s" ] ) )
    self.assertEqual( b_a_n.parent, b_a )

    b_a_n_n = b_a_n[ "n" ]
    self.assertTrue( b_a_n_n.is_leaf() )
    self.assertEqual( b_a_n_n.start, 3 )
    self.assertEqual( b_a_n_n.stop, 7 )
    self.assertEqual( b_a_n_n.label, 0 )
    self.assertEqual( b_a_n_n.parent, b_a_n )

    b_a_n_s = b_a_n[ "s" ]
    self.assertTrue( b_a_n_s.is_leaf() )
    self.assertEqual( b_a_n_s.start, 5 )
    self.assertEqual( b_a_n_s.stop, 7 )
    self.assertEqual( b_a_n_s.label, 2 )
    self.assertEqual( b_a_n_s.parent, b_a_n )

    b_a_s = b_a[ "s" ]
    self.assertTrue( b_a_s.is_leaf() )
    self.assertEqual( b_a_s.start, 5 )
    self.assertEqual( b_a_s.stop, 7 )
    self.assertEqual( b_a_s.label, 4 )
    self.assertEqual( b_a_s.parent, b_a )

    b_n = root[ "n" ]
    self.assertFalse( b_n.is_root() )
    self.assertFalse( b_n.is_leaf() )
    self.assertEqual( b_n.start, 1 )
    self.assertEqual( b_n.stop, 3 )
    self.assertEqual( set( b_n.keys() ), set( [ "n", "s" ] ) )
    self.assertEqual( b_n.parent, root )

    b_n_n = b_n[ "n" ]
    self.assertTrue( b_n_n.is_leaf() )
    self.assertEqual( b_n_n.start, 3 )
    self.assertEqual( b_n_n.stop, 7 )
    self.assertEqual( b_n_n.label, 1 )
    self.assertEqual( b_n_n.parent, b_n )

    b_n_s = b_n[ "s" ]
    self.assertTrue( b_n_s.is_leaf() )
    self.assertEqual( b_n_s.start, 5 )
    self.assertEqual( b_n_s.stop, 7 )
    self.assertEqual( b_n_s.label, 3 )
    self.assertEqual( b_n_s.parent, b_n )

    b_s = root[ "s" ]
    self.assertTrue( b_s.is_leaf() )
    self.assertEqual( b_s.start, 5 )
    self.assertEqual( b_s.stop, 7 )
    self.assertEqual( b_s.label, 5 )
    self.assertEqual( b_s.parent, root )

    b_dl = root[ "$" ]
    self.assertTrue( b_dl.is_leaf() )
    self.assertEqual( b_dl.start, 6 )
    self.assertEqual( b_dl.stop, 7 )
    self.assertEqual( b_dl.label, 6 )
    self.assertEqual( b_dl.parent, root )

    self.assertEqual( b_a.suffix, root )
    self.assertEqual( b_n.suffix, b_a )
    self.assertEqual( b_a_n.suffix, b_n )
예제 #10
0
  def test_ukkonen2(self):

    tree = single.tree()
    builder = single.ukkonen( tree )

    builder.append( glyph = "a" )
    self.assertTrue( builder.is_valid )

    builder.append( glyph = "n" )
    self.assertTrue( builder.is_valid )

    builder.detach()
    self.assertFalse( builder.is_attached )
    self.assertFalse( tree.in_construction )

    builder = single.ukkonen( tree )
    self.assertTrue( builder.is_valid )
    self.assertTrue( builder.is_attached )
    self.assertTrue( tree.in_construction )

    builder.append( glyph = "a" )
    self.assertFalse( builder.is_valid )
    self.assertRaises( builder.detach )

    builder.append( glyph = "n" )
    self.assertFalse( builder.is_valid )
    self.assertRaises( builder.detach )

    builder.append( glyph = "a" )
    self.assertFalse( builder.is_valid )
    self.assertRaises( builder.detach )

    builder.append( glyph = "s" )
    self.assertTrue( builder.is_valid )

    builder.detach()
    self.assertFalse( builder.is_attached )
    self.assertFalse( tree.in_construction )

    builder = single.ukkonen( tree )
    self.assertTrue( builder.is_valid )
    self.assertTrue( builder.is_attached )
    self.assertTrue( tree.in_construction )

    builder.append( glyph = "$" )
    self.assertTrue( builder.is_valid )

    builder.detach()

    root = tree.root
    self.assertTrue( root.is_root() )
    self.assertEqual( set( root.keys() ), set( [ "a", "n", "s", "$" ] ) )

    b_a = root[ "a" ]
    self.assertFalse( b_a.is_root() )
    self.assertFalse( b_a.is_leaf() )
    self.assertEqual( b_a.start, 0 )
    self.assertEqual( b_a.stop, 1 )
    self.assertEqual( set( b_a.keys() ), set( [ "n", "s" ] ) )
    self.assertEqual( b_a.parent, root )

    b_a_n = b_a[ "n" ]
    self.assertFalse( b_a_n.is_root() )
    self.assertFalse( b_a_n.is_leaf() )
    self.assertEqual( b_a_n.start, 1 )
    self.assertEqual( b_a_n.stop, 3 )
    self.assertEqual( set( b_a_n.keys() ), set( [ "n", "s" ] ) )
    self.assertEqual( b_a_n.parent, b_a )

    b_a_n_n = b_a_n[ "n" ]
    self.assertTrue( b_a_n_n.is_leaf() )
    self.assertEqual( b_a_n_n.start, 3 )
    self.assertEqual( b_a_n_n.stop, 7 )
    self.assertEqual( b_a_n_n.label, 0 )
    self.assertEqual( b_a_n_n.parent, b_a_n )

    b_a_n_s = b_a_n[ "s" ]
    self.assertTrue( b_a_n_s.is_leaf() )
    self.assertEqual( b_a_n_s.start, 5 )
    self.assertEqual( b_a_n_s.stop, 7 )
    self.assertEqual( b_a_n_s.label, 2 )
    self.assertEqual( b_a_n_s.parent, b_a_n )

    b_a_s = b_a[ "s" ]
    self.assertTrue( b_a_s.is_leaf() )
    self.assertEqual( b_a_s.start, 5 )
    self.assertEqual( b_a_s.stop, 7 )
    self.assertEqual( b_a_s.label, 4 )
    self.assertEqual( b_a_s.parent, b_a )

    b_n = root[ "n" ]
    self.assertFalse( b_n.is_root() )
    self.assertFalse( b_n.is_leaf() )
    self.assertEqual( b_n.start, 1 )
    self.assertEqual( b_n.stop, 3 )
    self.assertEqual( set( b_n.keys() ), set( [ "n", "s" ] ) )
    self.assertEqual( b_n.parent, root )

    b_n_n = b_n[ "n" ]
    self.assertTrue( b_n_n.is_leaf() )
    self.assertEqual( b_n_n.start, 3 )
    self.assertEqual( b_n_n.stop, 7 )
    self.assertEqual( b_n_n.label, 1 )
    self.assertEqual( b_n_n.parent, b_n )

    b_n_s = b_n[ "s" ]
    self.assertTrue( b_n_s.is_leaf() )
    self.assertEqual( b_n_s.start, 5 )
    self.assertEqual( b_n_s.stop, 7 )
    self.assertEqual( b_n_s.label, 3 )
    self.assertEqual( b_n_s.parent, b_n )

    b_s = root[ "s" ]
    self.assertTrue( b_s.is_leaf() )
    self.assertEqual( b_s.start, 5 )
    self.assertEqual( b_s.stop, 7 )
    self.assertEqual( b_s.label, 5 )
    self.assertEqual( b_s.parent, root )

    b_dl = root[ "$" ]
    self.assertTrue( b_dl.is_leaf() )
    self.assertEqual( b_dl.start, 6 )
    self.assertEqual( b_dl.stop, 7 )
    self.assertEqual( b_dl.label, 6 )
    self.assertEqual( b_dl.parent, root )

    self.assertEqual( b_a.suffix, root )
    self.assertEqual( b_n.suffix, b_a )
    self.assertEqual( b_a_n.suffix, b_n )