Skip to content

Commit

Permalink
Rerun tests using shared constants.
Browse files Browse the repository at this point in the history
  • Loading branch information
cmnbroad committed Sep 21, 2018
1 parent 623a528 commit 455b058
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
21 changes: 8 additions & 13 deletions src/main/python/org/broadinstitute/hellbender/gatktool/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import os
import cProfile, pstats, io
import traceback
from gatktool import toolconstants

_ackFIFO = None
_dataFIFO = None
Expand Down Expand Up @@ -152,9 +153,6 @@ class AckFIFO:
Manage the FIFO used to notify GATK (via an ack) that a command has
completed, or failed due to an unhandled exception (via a nck).
"""
_ackString = "ack"
_nackString = "nck"
_nkmString = "nkm"

def __init__(self, ackFIFOName: str) -> None:
"""Open the ack fifo stream for writing only"""
Expand All @@ -168,7 +166,7 @@ def writeAck(self):
"""
if self.fileWriter is None:
raise RuntimeError("ack FIFO has not been initialized")
self.fileWriter.write(AckFIFO._ackString)
self.fileWriter.write(toolconstants._ackString)
self.fileWriter.flush()

def writeNack(self):
Expand All @@ -180,7 +178,7 @@ def writeNack(self):
"""
if self.fileWriter is None:
raise RuntimeError("ack FIFO has not been initialized")
self.fileWriter.write(AckFIFO._nackString)
self.fileWriter.write(toolconstants._nackString)
self.fileWriter.flush()

def writeNackWithMessage(self, message: str) -> None:
Expand All @@ -197,21 +195,18 @@ def writeNackWithMessage(self, message: str) -> None:
Calling this method will result in an exception being thrown
in the GATK tool on whose behalf this module is running.
"""
"""The length of the message to be written must be 4 bytes long when serialized as a string"""
nckMaxMessageLength = 9999
nckMessageLengthSerializedSize = 4
if self.fileWriter is None:
raise RuntimeError("ack FIFO has not been initialized")
self.fileWriter.write(AckFIFO._nkmString)
self.fileWriter.write(toolconstants._nkmString)
actualMessageLength = len(message)
"""The message length must be exactly 4 bytes"""
if len(str(actualMessageLength)) <= nckMessageLengthSerializedSize:
self.fileWriter.write(str(actualMessageLength).zfill(nckMessageLengthSerializedSize))
if len(str(actualMessageLength)) <= toolconstants.nckMessageLengthSerializedSize:
self.fileWriter.write(str(actualMessageLength).zfill(toolconstants.nckMessageLengthSerializedSize))
self.fileWriter.write(message)
else:
"""Message is too long, trim to 9999 bytes"""
self.fileWriter.write(str(nckMaxMessageLength))
self.fileWriter.write(message[:nckMaxMessageLength])
self.fileWriter.write(str(toolconstants.nckMaxMessageLength))
self.fileWriter.write(message[:toolconstants.nckMaxMessageLength])
self.fileWriter.flush()


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""
Constants that must remain in sync with the companion Java code in GATK.
"""

"""
Command acknowledgement messages used to signal positive acknowledgement ('ack',
negative acknowledgement ('nck'), and negative acknowledgement with an accompanying
message ('nkm').
"""
_ackString = "ack"
_nackString = "nck"
_nkmString = "nkm"


"""
The length of a message written with a negative ack (nkm) must be 4 bytes long when
serialized as a string, and cannot have a value > 9999.
"""
_nckMessageLengthSerializedSize = 4
_nckMaxMessageLength = 9999

0 comments on commit 455b058

Please sign in to comment.