Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/force_align.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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):
Expand Down Expand Up @@ -75,6 +82,10 @@ def main():
sys.stderr.write(' {} fwd_params fwd_err rev_params rev_err [heuristic] <in.f-e >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 <in.f-e >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:])
Expand Down