diff --git a/Bio/Align/bigbed.py b/Bio/Align/bigbed.py index bec88217f91..6903b3c1aa5 100644 --- a/Bio/Align/bigbed.py +++ b/Bio/Align/bigbed.py @@ -217,7 +217,7 @@ class AlignmentWriter(interfaces.AlignmentWriter): """Alignment file writer for the bigBed file format.""" fmt = "bigBed" - mode = "wb" + mode = "b" def __init__( self, diff --git a/Bio/Align/interfaces.py b/Bio/Align/interfaces.py index be188a72a32..de40ce9a954 100644 --- a/Bio/Align/interfaces.py +++ b/Bio/Align/interfaces.py @@ -208,11 +208,11 @@ class AlignmentWriter(ABC): # noqa: B024 followed finally by write_footer(). Subclasses may define the following class attributes: - - mode - 'w' or 'wb' for text or binary files, respectively + - mode - 't' or 'b' for text or binary files, respectively - fmt - a human-readable name for the file format. """ - mode = "w" # assume text files by default + mode = "t" # assume text files by default fmt: Optional[str] = None # to be defined in the subclass def __init__(self, target): @@ -229,7 +229,7 @@ def __init__(self, target): """ if target is not None: # target is None if we only use the writer to format strings. - if self.mode == "w": + if self.mode == "t": try: target.write("") except TypeError: @@ -237,10 +237,10 @@ def __init__(self, target): raise StreamModeError("File must be opened in text mode.") from None except AttributeError: # target is a path - stream = open(target, self.mode) + stream = open(target, "w" + self.mode) else: stream = target - elif self.mode == "wb": + elif self.mode == "b": try: target.write(b"") except TypeError: @@ -250,13 +250,12 @@ def __init__(self, target): ) from None except AttributeError: # target is a path - stream = open(target, self.mode) + stream = open(target, "w" + self.mode) else: stream = target else: raise RuntimeError("Unknown mode '%s'" % self.mode) self._stream = stream - self._target = target def write_header(self, stream, alignments): @@ -280,9 +279,11 @@ def format_alignment(self, alignment): alignment - an Alignment object """ - raise NotImplementedError("This method should be implemented") + if self.mode == "t": + raise NotImplementedError("This method should be implemented") ################################################### # You MUST implement this method in the subclass. # + # if the file mode is text. # ################################################### def write_single_alignment(self, stream, alignments): @@ -318,7 +319,7 @@ def write_multiple_alignments(self, stream, alignments): write_alignments = write_multiple_alignments def write_file(self, stream, alignments): - """Write the alignments to the file strenm, and return the number of alignments. + """Write the alignments to the file stream, and return the number of alignments. alignments - A list or iterator returning Alignment objects stream - Output file stream.