diff --git a/src/force_align.py b/src/force_align.py index 7eba63c..92b2085 100755 --- a/src/force_align.py +++ b/src/force_align.py @@ -9,7 +9,7 @@ # Use the version in realtime for development class Aligner: - def __init__(self, fwd_params, fwd_err, rev_params, rev_err, heuristic='grow-diag-final-and'): + def __init__(self, fwd_params, fwd_err, rev_params, rev_err, heuristic='grow-diag-final-and', addscore='None'): build_root = os.path.dirname(os.path.abspath(__file__)) fast_align = os.path.join(build_root, 'fast_align') @@ -25,16 +25,23 @@ def __init__(self, fwd_params, fwd_err, rev_params, rev_err, heuristic='grow-dia self.fwd_align = popen_io(fwd_cmd) self.rev_align = popen_io(rev_cmd) self.tools = popen_io(tools_cmd) + self.addscore = addscore def align(self, line): self.fwd_align.stdin.write('{}\n'.format(line)) self.rev_align.stdin.write('{}\n'.format(line)) # f words ||| e words ||| links ||| score - fwd_line = self.fwd_align.stdout.readline().split('|||')[2].strip() - rev_line = self.rev_align.stdout.readline().split('|||')[2].strip() + fwd_wholeline = self.fwd_align.stdout.readline() + fwd_line = fwd_wholeline.split('|||')[2].strip() + fwd_score = fwd_wholeline.split('|||')[3].strip() + rev_wholeline = self.rev_align.stdout.readline() + rev_line = rev_wholeline.split('|||')[2].strip() + rev_score = rev_wholeline.split('|||')[3].strip() self.tools.stdin.write('{}\n'.format(fwd_line)) self.tools.stdin.write('{}\n'.format(rev_line)) al_line = self.tools.stdout.readline().strip() + if self.addscore == 'fwdbwd': + return al_line + '\t' + str(fwd_score) + '\t' + str(rev_score) return al_line def close(self): @@ -75,6 +82,10 @@ def main(): sys.stderr.write(' {} fwd_params fwd_err rev_params rev_err [heuristic] out.f-e.gdfa\n'.format(sys.argv[0])) sys.stderr.write('\n') sys.stderr.write('where heuristic is one of: (intersect union grow-diag grow-diag-final grow-diag-final-and) default=grow-diag-final-and\n') + sys.stderr.write('To see alignment scores, run:\n') + sys.stderr.write(' {} fwd_params fwd_err rev_params rev_err heuristic fwdbwd out.f-e.gdfa\n'.format(sys.argv[0])) + sys.stderr.write('\n') + sys.stderr.write('This will show fwd and bwd align score seperated with tab following the alignment pairs.\n') sys.exit(2) aligner = Aligner(*sys.argv[1:])