From f3e16aec55ea74f4203f6f703cfc855d52c89340 Mon Sep 17 00:00:00 2001 From: h-j-han <19178967+h-j-han@users.noreply.github.com> Date: Tue, 19 Jul 2022 12:13:36 -0400 Subject: [PATCH 1/2] Add command option for print align score --- src/force_align.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/force_align.py b/src/force_align.py index 7eba63c..824ac91 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): From 8bdef1fdd842a5e51992de16363b0d4d5ee574a4 Mon Sep 17 00:00:00 2001 From: h-j-han <19178967+h-j-han@users.noreply.github.com> Date: Tue, 19 Jul 2022 12:23:32 -0400 Subject: [PATCH 2/2] Add description --- src/force_align.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/force_align.py b/src/force_align.py index 824ac91..92b2085 100755 --- a/src/force_align.py +++ b/src/force_align.py @@ -82,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:])