Exemplo n.º 1
0
  def create(outdir, tc):
    grammar = tc.grammar
    c = adpc.Config
    os.chdir(c.workdir)
    shutil.copy(os.path.join(c.grammars, grammar), c.workdir)

    os.mkdir(grammar[:-4])

    out = tc.unique_filename() + Suffix.mf + Suffix.out
    testbox.checkFilename(out)
    err = tc.unique_filename() + Suffix.mf + Suffix.err
    testbox.checkFilename(err)
    f1 = os.path.join(outdir, out)
    f2 = os.path.join(outdir, err)
    i = sysext.sys(c.fe,
        [ grammar, '-p', c.fe_path, '--pure-prefix' ],
        f1, f2)
    if i != 0:
      raise cg.CallError('Metafrontend failed'
          + testbox.look_into([f1, f2]))
    out = tc.unique_filename() + Suffix.java + Suffix.out
    testbox.checkFilename(out)
    err = tc.unique_filename() + Suffix.java + Suffix.err
    testbox.checkFilename(err)
    f1 = os.path.join(outdir, out)
    f2 = os.path.join(outdir, err)
    i = sysext.sys(c.javac,
        [ '-cp', c.classpath,
          grammar[:-4] + os.path.sep + grammar[:-4] + '.java' ],
        f1, f2)
    if i != 0:
      raise cg.CallError('Java Compiler failed'
          + testbox.look_into([f1, f2]))
Exemplo n.º 2
0
  def extract(filename, algebra):
    pat_score = re.compile('^Optimal Score: ([-.0-9]+)')
    pat_algebra = re.compile('^Algebra: ([A-Za-z0-9]+)')
    pat_end = re.compile('^================================================================================')
    pat_begin = re.compile('^============================== Suboptimal Output ===============================')
    pat_cand = re.compile('^(.+) \(Score: ([-.0-9]+)\)')
    
    d = cg.Data()
    f = open(filename)
    look = testbox.look_into([filename])
    state = -1
    length = -1
    last_len = -1
    for i in f:
      if state == -1:
        match = pat_algebra.search(i)
        if match:
          if algebra == 'count' and match.group(1) == algebra:
            d.algebra = 'count'
            state = 0
          elif match.group(1) == 'count':
            pass
          elif algebra == '' or match.group(1) == algebra:
            d.algebra = match.group(1)
            state = 0
      elif state == 0:
        match = pat_score.search(i)
        if match:
            state = 1
            d.setScore(match.group(1))
      elif state == 1:
        match = pat_begin.search(i)
        if match:
          state = 2
      elif state == 2:
        match = pat_end.search(i)
        if match:
          state = 3
          break
        match = pat_cand.search(i)
        if match:
          if length == -1:
            length = last_len
          elif StdTranslate.test_length and length != len(match.group(1)):
            raise cg.TranslateError('Candidate structure deviates:\n'
                + '  ' + match.group(1) + ' (len: ' + str(len(match.group(1)))
                + ') vs. len: ' + str(length) + look)
          d.addCandidate( (match.group(2), match.group(1)) )
          last_len = len(match.group(1))
    f.close()

    if state == -1:
      raise cg.TranslateError('Algebra ' + algebra + ' not found.' + look)
    elif state != 3:
      raise cg.TranslateError('Missing begin and/or end.' + look)
    if len(d.candidates) == 0 and algebra != 'count':
      raise cg.TranslateError('Empty candidate list for algebra ' + algebra
          + '.' + look)
    f.close()
    return d
Exemplo n.º 3
0
  def execute(outdir, progname, filename, tc, sys_fn = sysext.sys):
    c = adpc.Config
    os.chdir(c.workdir)

    para = []
    if tc.flavour == 'rna' or tc.flavour == 'window':
      para += Call.default_opts_rna
    else:
      para += Call.default_opts
    if hasattr(tc, 'parameter'):
      para += tc.parameter.split()

    out = tc.unique_filename() + Suffix.out
    testbox.checkFilename(out)
    err = tc.unique_filename() + Suffix.err
    testbox.checkFilename(err)
    f1 = os.path.join(outdir, out)
    f2 = os.path.join(outdir, err)
    i = sys_fn(c.java,
        [ '-cp', c.classpath,
          progname + '.' + progname, "-f", os.path.join(c.input, filename)]
        + tc.default_parameter + para,
        f1, f2)
    if i != 0:
      raise cg.CallError("error executing adp program (exit status: " + str(i) + ")"
        + testbox.look_into([f1, f2]))
Exemplo n.º 4
0
Arquivo: call.py Projeto: u-u-h/adpc
 def clean(outdir, tc):
   c = adpc.Config
   os.chdir(c.workdir)
   out = tc.unique_filename() + Suffix.clean + Suffix.out
   testbox.checkFilename(out)
   err = tc.unique_filename() + Suffix.clean + Suffix.err
   testbox.checkFilename(err)
   f1 = os.path.join(outdir, out)
   f2 = os.path.join(outdir, err)
   i = sysext.sys(c.make, ["clean"], f1, f2)
   if i != 0:
     raise cg.CallError("make clean failed" + testbox.look_into([f1, f2]))
   os.unlink(tc.grammar)
   ls = os.listdir(c.workdir)
   if not (ls == [] or ls == ['.svn'] or ls == ['.hg']):
     raise cg.CallError("make clean doesn't clean everything"
         + testbox.look_into([c.workdir]))
Exemplo n.º 5
0
  def clean(outdir, tc):
    grammar = tc.grammar
    c = adpc.Config
    os.chdir(c.workdir)

    for i in os.listdir(grammar[:-4]):
      os.unlink(grammar[:-4] + os.path.sep + i)
    os.rmdir(grammar[:-4])
    os.unlink(grammar)
    ls = os.listdir(c.workdir)
    if not (ls == [] or ls == ['.svn'] or ls == ['.hg']):
      raise cg.CallError("not everything is clean" + 
          testbox.look_into([c.workdir]))
Exemplo n.º 6
0
    def extract(filename, algebra):
        pat_score = re.compile('^Algebra: ([A-Za-z0-9]+), score: ([-.0-9]+)')
        pat_end = re.compile(
            '^================================================================='
        )
        pat_begin = re.compile(
            '^-----------------------------------------------------------------'
        )
        pat_cand = re.compile('^[ \t]+([-0-9.]+) \| (.+)$')

        d = cg.Data()

        f = open(filename)
        state = 0
        for i in f:
            if state == 0:
                match = pat_score.search(i)
                if match:
                    if algebra == 'count' and match.group(1) == algebra:
                        d.setScore(match.group(2))
                        d.algebra = 'count'
                        state = 2
                    elif match.group(1) == 'count':
                        pass
                    elif algebra == '' or match.group(1) == algebra:
                        state = 1
                        d.algebra = match.group(1)
                        d.setScore(match.group(2))
            elif state == 1:
                match = pat_begin.search(i)
                if match:
                    state = 2
            elif state == 2:
                match = pat_end.search(i)
                if match:
                    state = 3
                    break
                match = pat_cand.search(i)
                if match:
                    d.addCandidate(match.groups())
        f.close()
        look = testbox.look_into([filename])
        if state == 0:
            raise cg.TranslateError('Algebra ' + algebra + ' not found.' +
                                    look)
        elif state != 3:
            raise cg.TranslateError('Missing begin and/or end.' + look)
        if len(d.candidates) == 0 and algebra != 'count':
            raise cg.TranslateError('Empty candidate list.' + look)
        f.close()
        return d
Exemplo n.º 7
0
 def design(self, dest):
   os.chdir(self.config.cwd)
   out = self.unique_filename() + Suffix.out
   testbox.checkFilename(out)
   err = self.unique_filename() + Suffix.err
   testbox.checkFilename(err)
   f1 = os.path.join(dest, out)
   f2 = os.path.join(dest, err)
   i = sysext.sys(self.config.hand,
       self.hand_opts + [ os.path.join(self.config.state,
         self.grammar + Suffix.i + Suffix.out) ],
       f1, f2)
   self.failIf(i != 0, "Couldn't generate hand output"
       + testbox.look_into([f1, f2]))
Exemplo n.º 8
0
 def serialize(self, out_dir):
   c = self.config
   os.chdir(c.grammars)
   out = self.grammar + Suffix.i + Suffix.out
   testbox.checkFilename(out)
   err = self.grammar + Suffix.i + Suffix.err
   testbox.checkFilename(err)
   f1 = os.path.join(out_dir, out)
   f2 = os.path.join(out_dir, err)
   i = sysext.sys(c.adpcompile,
       ['-iuc', '-te', os.path.join(c.grammars, self.grammar) ], f1, f2)
   self.failIf(i != 0, "Couldn't create serialized output."
       + testbox.look_into([f1, f2]))
   return i
Exemplo n.º 9
0
Arquivo: call.py Projeto: u-u-h/adpc
 def _create_b(outdir, tc):
   c = adpc.Config
   out = tc.unique_filename() + Suffix.make + Suffix.out
   testbox.checkFilename(out)
   err = tc.unique_filename() + Suffix.make + Suffix.err
   testbox.checkFilename(err)
   f1 = os.path.join(outdir, out)
   f2 = os.path.join(outdir, err)
   i = sysext.sys(c.make, ["BINPATH=" + c.binpath,
       "ADPCOMPILE=" + c.adpcompile,
       "ADPC=" + c.adpc_bin + " " + c.binpath],
       f1, f2)
   if i != 0:
     raise cg.CallError('making adp program failed' + 
         testbox.look_into([f1, f2]))
Exemplo n.º 10
0
Arquivo: call.py Projeto: u-u-h/adpc
 def _create_a(outdir, tc):
   c = adpc.Config
   os.chdir(c.workdir)
   shutil.copy(os.path.join(c.grammars, tc.grammar), c.workdir)
   out = tc.unique_filename() + Suffix.adp + Suffix.out
   testbox.checkFilename(out)
   err = tc.unique_filename() + Suffix.adp + Suffix.err
   testbox.checkFilename(err)
   f1 = os.path.join(outdir, out)
   f2 = os.path.join(outdir, err)
   i = sysext.sys(c.adpc_bin, [c.binpath, tc.grammar],
       f1, f2)
   if i != 0:
     raise cg.CallError('generating c src from adp program failed'
         + testbox.look_into([f1, f2]))
Exemplo n.º 11
0
 def serialize(self, out_dir):
     c = self.config
     os.chdir(c.grammars)
     out = self.grammar + Suffix.i + Suffix.out
     testbox.checkFilename(out)
     err = self.grammar + Suffix.i + Suffix.err
     testbox.checkFilename(err)
     f1 = os.path.join(out_dir, out)
     f2 = os.path.join(out_dir, err)
     i = sysext.sys(c.adpcompile,
                    ['-iuc', '-te',
                     os.path.join(c.grammars, self.grammar)], f1, f2)
     self.failIf(
         i != 0,
         "Couldn't create serialized output." + testbox.look_into([f1, f2]))
     return i
Exemplo n.º 12
0
 def test(self):
     filename_out = self.unique_filename() + Suffix.out
     self.call(self.config.output)
     a = self.unpickle()
     f1 = self.config.state + os.path.sep + filename_out
     # uncomment this to debug the Translators
     #a = self.extract(f1)
     f2 = os.path.join(self.config.output, filename_out)
     b = self.extract(f2)
     try:
         a.compare(b)
     except cg.DataError, (message):
         self.fail(
             'Different program output:\n' + str(message) +
             testbox.look_into([f1, f2]) +
             '\nor into the corresponding default language state-file\n')
Exemplo n.º 13
0
 def testSerialize(self):
   """serialized output from adpc"""
   i = self.serialize(self.config.output)
   suff = self.grammar + Suffix.i + Suffix.out
   f1 = os.path.join(self.config.state, suff)
   f2 = os.path.join(self.config.output, suff)
   f = open(f1)
   g = open(f2)
   l1 = f.readline().split(';')
   l2 = g.readline().split(';')
   f.close()
   g.close()
   look = testbox.look_into([f1, f2])
   self.failIf(len(l1) != len(l2),
     "Length of serialized array is different" + look)
   self.failIf(l1 != l2, "Serialized arrays are not equal" + look)
Exemplo n.º 14
0
  def extract(filename, algebra):
    pat_score = re.compile('^Algebra: ([A-Za-z0-9]+), score: ([-.0-9]+)')
    pat_end = re.compile('^=================================================================')
    pat_begin = re.compile('^-----------------------------------------------------------------')
    pat_cand = re.compile('^[ \t]+([-0-9.]+) \| (.+)$')

    d = cg.Data()
    
    f = open(filename)
    state = 0
    for i in f:
      if state == 0:
        match = pat_score.search(i)
        if match:
          if algebra == 'count' and match.group(1) == algebra:
            d.setScore(match.group(2))
            d.algebra = 'count'
            state = 2
          elif match.group(1) == 'count':
            pass
          elif algebra == '' or match.group(1) == algebra:
            state = 1
            d.algebra = match.group(1)
            d.setScore(match.group(2))
      elif state == 1:
        match = pat_begin.search(i)
        if match:
          state = 2
      elif state == 2:
        match = pat_end.search(i)
        if match:
          state = 3
          break
        match = pat_cand.search(i)
        if match:
          d.addCandidate(match.groups())
    f.close()
    look = testbox.look_into([filename])
    if state == 0:
      raise cg.TranslateError('Algebra ' + algebra + ' not found.' + look)
    elif state != 3:
      raise cg.TranslateError('Missing begin and/or end.' + look)
    if len(d.candidates) == 0 and algebra != 'count':
      raise cg.TranslateError('Empty candidate list.' + look)
    f.close()
    return d
Exemplo n.º 15
0
 def testSerialize(self):
     """serialized output from adpc"""
     i = self.serialize(self.config.output)
     suff = self.grammar + Suffix.i + Suffix.out
     f1 = os.path.join(self.config.state, suff)
     f2 = os.path.join(self.config.output, suff)
     f = open(f1)
     g = open(f2)
     l1 = f.readline().split(';')
     l2 = g.readline().split(';')
     f.close()
     g.close()
     look = testbox.look_into([f1, f2])
     self.failIf(
         len(l1) != len(l2),
         "Length of serialized array is different" + look)
     self.failIf(l1 != l2, "Serialized arrays are not equal" + look)
Exemplo n.º 16
0
    def extract(filename, algebra):
        pat_bounds = re.compile('^([0-9]+) +([0-9]+)')
        pat_cand = re.compile('^([.()\\[\\]]+)  \(([-.0-9]+)\)')

        f = open(filename)
        look = testbox.look_into([filename])
        d = cg.WindowData()
        e = cg.Data()
        bounds = None
        for i in f:
            match = pat_bounds.search(i)
            if match:
                e.optimal_score = Equal()
                e.algebra = algebra
                d.addWindow(bounds, e)
                e = cg.Data()
                g = match.groups()
                bounds = (int(g[0]), int(g[1]))
                length = len(i) - 1
            else:
                match = pat_cand.search(i)
                if match:
                    g = match.groups()
                    if len(g[0]) != length:
                        raise cg.TranslateError(
                            'Length of candidate structure does not match in window '
                            + str(bounds) + ':\n"' + '  ' + g[0] + ' (len: ' +
                            str(len(g[0])) + ') vs len: ' + str(length) + look)
                    e.addCandidate((g[1], g[0]))
                else:
                    if len(i) - 1 != length:
                        raise cg.TranslateError(
                            'Length of sequence does not match in window ' +
                            str(bounds) + ':\n' + '  ' + i + ' (len: ' +
                            str(len(i) - 1) + ') vs. len: ' + str(length) +
                            look)

        f.close()

        e.optimal_score = Equal()
        e.algebra = algebra
        d.addWindow(bounds, e)
        d.windows.pop(0)
        return d
Exemplo n.º 17
0
  def extract(filename, algebra):
    pat_bounds = re.compile('^([0-9]+) +([0-9]+)')
    pat_cand = re.compile('^([.()\\[\\]]+)  \(([-.0-9]+)\)')

   
    f = open(filename)
    look = testbox.look_into([filename])
    d = cg.WindowData()
    e = cg.Data()
    bounds = None
    for i in f:
      match = pat_bounds.search(i)
      if match:
        e.optimal_score = Equal()
        e.algebra = algebra
        d.addWindow(bounds, e)
        e = cg.Data()
        g = match.groups()
        bounds = (int(g[0]), int(g[1]))
        length = len(i) - 1
      else:
        match = pat_cand.search(i)
        if match:
          g = match.groups()
          if len(g[0]) !=  length:
            raise cg.TranslateError('Length of candidate structure does not match in window ' + str(bounds) + ':\n"'
                + '  ' + g[0] + ' (len: ' + str(len(g[0])) + ') vs len: '
                + str(length) + look)
          e.addCandidate((g[1], g[0]))
        else:
          if len(i) - 1 != length:
            raise cg.TranslateError('Length of sequence does not match in window ' + str(bounds) + ':\n'
                + '  ' + i + ' (len: ' + str(len(i)-1) + ') vs. len: '
                + str(length) + look)

    f.close()

    e.optimal_score = Equal()
    e.algebra = algebra
    d.addWindow(bounds, e)
    d.windows.pop(0)
    return d
Exemplo n.º 18
0
Arquivo: call.py Projeto: u-u-h/adpc
  def execute(outdir, progname, filename, tc, sys_fn = sysext.sys):
    c = adpc.Config
    os.chdir(c.workdir)

    if hasattr(tc, 'parameter'):
      para = tc.parameter.split()
    else:
      para = []

    out = tc.unique_filename() + Suffix.out
    testbox.checkFilename(out)
    err = tc.unique_filename() + Suffix.err
    testbox.checkFilename(err)
    f1 = os.path.join(outdir, out)
    f2 = os.path.join(outdir, err)
    i = sys_fn('./' + progname,
       [ "-f", c.input + os.path.sep + filename] + para,
       f1, f2)
    if i != 0:
      raise cg.CallError("error executing adp program (exit status: " + str(i) + ")" 
          + testbox.look_into([f1, f2]))
Exemplo n.º 19
0
    def extract(filename, algebra):
        pat_score = re.compile('^([A-Za-z0-9]+): ([-.0-9]+)')
        pat_cand = re.compile('^([.()\\[\\]]+)  \(([-.0-9]+)\)')
        look = testbox.look_into([filename])

        d = cg.Data()

        f = open(filename)
        state = 0
        length = -1
        last_len = -1
        for i in f:
            if state == 0:
                match = pat_score.search(i)
                if match:
                    state = 1
                    d.algebra = match.group(1)
                    d.setScore(match.group(2))
            elif state == 1:
                match = pat_cand.search(i)
                if match:
                    if length == -1:
                        length = last_len
                    d.addCandidate((match.group(2), match.group(1)))
                    if length != -1 and length != len(match.group(1)):
                        raise cg.TranslateError(
                            'Candidate structure length deviates:\n' + '  ' +
                            match.group(1) + ' (len: ' +
                            str(len(match.group(1))) + ') vs. len: ' +
                            str(length) + look)
                    last_len = len(match.group(1))
        f.close()
        if state == 0:
            raise cg.TranslateError('Found no algebra at all.' + look)
        if len(d.candidates) == 0 and algebra != 'count':
            raise cg.TranslateError('Empty candidate list.' + look)
        f.close()
        return d
Exemplo n.º 20
0
  def extract(filename, algebra):
    pat_score = re.compile('^([A-Za-z0-9]+): ([-.0-9]+)')
    pat_cand = re.compile('^([.()\\[\\]]+)  \(([-.0-9]+)\)')
    look = testbox.look_into([filename])

    d = cg.Data()
   
    f = open(filename)
    state = 0
    length = -1
    last_len = -1
    for i in f:
      if state == 0:
        match = pat_score.search(i)
        if match:
          state = 1
          d.algebra = match.group(1)
          d.setScore(match.group(2))
      elif state == 1:
        match = pat_cand.search(i)
        if match:
          if length == -1:
            length = last_len
          d.addCandidate( (match.group(2), match.group(1)) )
          if length != -1 and length != len(match.group(1)):
            raise cg.TranslateError('Candidate structure length deviates:\n'
                + '  ' + match.group(1) + ' (len: ' + str(len(match.group(1)))
                + ') vs. len: ' + str(length) + look)
          last_len = len(match.group(1))
    f.close()
    if state == 0:
      raise cg.TranslateError('Found no algebra at all.' + look)
    if len(d.candidates) == 0 and algebra != 'count':
      raise cg.TranslateError('Empty candidate list.' + look)
    f.close()
    return d
Exemplo n.º 21
0
Arquivo: call.py Projeto: u-u-h/adpc
 def create(outdir, tc):
   grammar = tc.grammar
   c = adpc.Config
   Call._create_a(outdir, tc)
   out = tc.unique_filename() + Suffix.make + 'tup.' + Suffix.out
   testbox.checkFilename(out)
   err = tc.unique_filename() + Suffix.make + 'tup.' + Suffix.err
   f1 = os.path.join(outdir, out)
   f2 = os.path.join(outdir, err)
   i = sysext.sys(c.make, ["BINPATH=" + c.binpath,
       "ADPCOMPILE=" + c.adpcompile,
       "ADPC=" + c.adpc_bin + " " + c.binpath,
       grammar[:-4] + '.c'], f1, f2)
   if i != 0:
     raise cg.CallError('making tupel step failed'
         + testbox.look_into([f1, f2]))
   sed_file = grammar[:-4] + '_' + CallTuple.algebra + '.sed'
   tmp = sed_file + '.tmp'
   pat = re.compile('result_score')
   pat_head = re.compile('int maxloop;\\\\')
   shutil.move(sed_file, tmp)
   f = open(tmp)
   g = open(sed_file, 'w')
   for i in f:
     if pat.search(i):
       j = pat.sub('result_score.tup1', i)
     elif pat_head.match(i):
       j = i
       g.write('#undef is_suboptimal\\\n#define is_suboptimal(a, b, c) abs(a.tup1 - b) <= c\\\n')
     else:
       j = i
     g.write(j)
   f.close()
   g.close()
   os.unlink(tmp)
   Call._create_b(outdir, tc)
Exemplo n.º 22
0
    def extract(filename, algebra):
        pat_score = re.compile('^Optimal Score: ([-.0-9]+)')
        pat_algebra = re.compile('^Algebra: ([A-Za-z0-9]+)')
        pat_end = re.compile(
            '^================================================================================'
        )
        pat_begin = re.compile(
            '^============================== Suboptimal Output ==============================='
        )
        pat_cand = re.compile('^(.+) \(Score: ([-.0-9]+)\)')
        pat_bounds = re.compile('^([0-9]+) +([0-9]+)')

        f = open(filename)
        look = testbox.look_into([filename])
        d = cg.WindowData()
        bounds = None
        length = -1
        state = -1
        for i in f:
            if state == -1:
                match = pat_algebra.search(i)
                if match:
                    if algebra == '' or algebra == match.group(1):
                        al = algebra
                    else:
                        raise cg.TranslateError(
                            'Wrong algebra in window mode: ' + algebra +
                            ' vs. ' + match.group(1) + look)
                    state = 0
            elif state == 0:
                match = pat_score.search(i)
                if match:
                    e = cg.Data()
                    e.algebra = al
                    e.optimal_score = float(match.group(1)) / 100
                    state = 1
                    continue
                else:
                    match = pat_bounds.search(i)
                    if match:
                        bounds = (int(match.group(1)), int(match.group(2)))
                if length < 0:
                    length = len(i) - 1
                elif len(i) - 1 != length:
                    raise cg.TranslateError(
                        'Length of sequence/bounds differs in window ' +
                        str(bounds) + ':\n' + '  ' + i + ' (len: ' +
                        str(len(i) - 1) + ' vs. len: ' + str(length) + look)
            elif state == 1:
                match = pat_begin.search(i)
                if match:
                    state = 2
                else:
                    raise cg.TranslateError('Found no start in window ' +
                                            str(bounds) + '.' + look)
            elif state == 2:
                match = pat_cand.search(i)
                if match:
                    (cand, score) = match.groups()
                    if len(cand) != length:
                        raise cg.TranslateError(
                            'Length of candidate structures does not match in window '
                            + str(bounds) + ':\n' + cand + ' (len: ' +
                            str(len(cand)) + ') vs. len: ' + str(length) +
                            look)
                    e.candidates.append((float(score) / 100, cand))
                else:
                    match = pat_end.search(i)
                    d.addWindow(bounds, e)
                    if match:
                        state = 0
                    else:
                        raise cg.TranslateError(
                            'Found no end or candidate in window ' +
                            str(bounds) + '.' + look)

        f.close()
        if state != 0:
            raise cg.TranslateError('Found no end at the end.' + look)
        return d
Exemplo n.º 23
0
  def extract(filename, algebra):
    pat_score = re.compile('^Optimal Score: ([-.0-9]+)')
    pat_algebra = re.compile('^Algebra: ([A-Za-z0-9]+)')
    pat_end = re.compile('^================================================================================')
    pat_begin = re.compile('^============================== Suboptimal Output ===============================')
    pat_cand = re.compile('^(.+) \(Score: ([-.0-9]+)\)')
    pat_bounds = re.compile('^([0-9]+) +([0-9]+)')

   
    f = open(filename)
    look = testbox.look_into([filename])
    d = cg.WindowData()
    bounds = None
    length = -1
    state = -1
    for i in f:
      if state == -1:
        match = pat_algebra.search(i)
        if match:
          if algebra == '' or algebra == match.group(1):
            al = algebra
          else:
            raise cg.TranslateError('Wrong algebra in window mode: ' + algebra
              + ' vs. ' + match.group(1) + look)
          state = 0
      elif state == 0:
        match = pat_score.search(i)
        if match:
          e = cg.Data()
          e.algebra = al
          e.optimal_score = float(match.group(1)) / 100
          state = 1
          continue
        else:
          match =  pat_bounds.search(i)
          if match:
            bounds = ( int(match.group(1)), int(match.group(2)) )
        if length < 0:
          length = len(i) - 1
        elif len(i) - 1 != length:
          raise cg.TranslateError('Length of sequence/bounds differs in window '
              + str(bounds) + ':\n'
              + '  ' + i + ' (len: ' + str(len(i) - 1) + ' vs. len: ' 
              + str(length) + look)
      elif state == 1:
        match = pat_begin.search(i)
        if match:
          state = 2
        else:
          raise cg.TranslateError('Found no start in window '
              + str(bounds) +  '.' + look)
      elif state == 2:
        match = pat_cand.search(i)
        if match:
          (cand, score) = match.groups()
          if len(cand) != length:
            raise cg.TranslateError('Length of candidate structures does not match in window '
                + str(bounds) +  ':\n'
                + cand + ' (len: ' + str(len(cand)) + ') vs. len: '
                + str(length) + look)
          e.candidates.append((float(score) / 100, cand))
        else:
          match = pat_end.search(i)
          d.addWindow(bounds, e)
          if match:
            state = 0
          else:
            raise cg.TranslateError('Found no end or candidate in window '
                + str(bounds) + '.' + look)

    f.close()
    if state != 0:
      raise cg.TranslateError('Found no end at the end.' + look)
    return d