def test_repeat_masker_alignment_iterator(self):
    """Test roundtrip of repeatmasker alignment."""
    debug = False
    s_io = StringIO.StringIO(self.rm_rc_1_input)
    alig_iter = repeat_masker_alignment_iterator(s_io)
    results = [r for r in alig_iter]
    self.failUnlessEqual(len(results), len(self.rm_tc1_records))
    for i, trail_meta_size, c_width, m_width in [(0, 4, 29, None),
                                                 (1, 4, 30, None),
                                                 (2, 3, 31, 13),
                                                 (3, 0, 22, 13)]:
      rm_str = _to_repeatmasker_string(results[i], column_width=c_width,
                                       m_name_width=m_width)
      if debug:
        sys.stderr.write("===============================\n")
        sys.stderr.write(rm_str + "\n")
        sys.stderr.write("*******************************\n")
        sys.stderr.write(self.rm_tc1_records[i] + "\n")
        sys.stderr.write("===============================\n")

      # strip out the last few lines; these should all be their, but order
      # isn't important.
      alig_actual = [x for x in map(str.rstrip,
                     self.rm_tc1_records[i].split("\n")[:-trail_meta_size])
                     if x.strip() != ""]
      meta_actual = map(str.rstrip,
                        self.rm_tc1_records[i].split("\n")[-trail_meta_size:])
      alig_result = [x for x in map(str.rstrip,
                                    rm_str.split("\n")[:-trail_meta_size])
                     if x.strip() != ""]
      meta_result = map(str.rstrip, rm_str.split("\n")[-trail_meta_size:])

      if debug:
        sys.stderr.write(str(alig_actual) + "\n")
        sys.stderr.write(str(alig_result) + "\n")
      self.failUnlessEqual(alig_actual, alig_result)
      self.failUnlessEqual(set(meta_actual), set(meta_result))
def test_repeat_masker_alignment_iterator ( self ) : debug = False s_io = StringIO . StringIO ( self . rm_rc_1_input ) alig_iter = repeat_masker_alignment_iterator ( s_io ) results = [ r for r in alig_iter ] self . failUnlessEqual ( len ( results ) , len ( self . rm_tc1_records ) ) for i , trail_meta_size , c_width , m_width in [ ( 0 , 4 , 29 , None ) , ( 1 , 4 , 30 , None ) , ( 2 , 3 , 31 , 13 ) , ( 3 , 0 , 22 , 13 ) ] : rm_str = _to_repeatmasker_string ( results [ i ] , column_width = c_width , m_name_width = m_width ) if debug : sys . stderr . write ( "===============================\n" ) sys . stderr . write ( rm_str + "\n" ) sys . stderr . write ( "*******************************\n" ) sys . stderr . write ( self . rm_tc1_records [ i ] + "\n" ) sys . stderr . write ( "===============================\n" ) alig_actual = [ x for x in map ( str . rstrip , self . rm_tc1_records [ i ] . split ( "\n" ) [ : - trail_meta_size ] ) if x . strip ( ) != "" ] meta_actual = map ( str . rstrip , self . rm_tc1_records [ i ] . split ( "\n" ) [ - trail_meta_size : ] ) alig_result = [ x for x in map ( str . rstrip , rm_str . split ( "\n" ) [ : - trail_meta_size ] ) if x . strip ( ) != "" ] meta_result = map ( str . rstrip , rm_str . split ( "\n" ) [ - trail_meta_size : ] ) if debug : sys . stderr . write ( str ( alig_actual ) + "\n" ) sys . stderr . write ( str ( alig_result ) + "\n" ) self . failUnlessEqual ( alig_actual , alig_result ) self . failUnlessEqual ( set ( meta_actual ) , set ( meta_result ) )
Test roundtrip of repeatmasker alignment.