You have opened the files in binary mode, so no newline translation will take place. Different platforms use different line endings, and if you are on Windows \n
is not enough.
The simplest method would be to write os.linesep
here:
destination.write(os.linesep + '...' + os.linesep)
but this could violate the actual newline convention used in the files.
The better approach would be to open the text files in text mode, read a line or two, then inspect the file.newlines
attribute to see what the convention is for that file:
def concatenate_fasta(file_1, file_2, newfile):
with open(file_1, 'r') as source:
next(source, None) # try and read a line
line_sep = source.newlines
if isinstance(line_sep, tuple):
# mixed newlines, lets just pick the first one
line_sep = line_sep[0]
with open(newfile,'wb') as destination
with open(file_1,'rb') as source:
shutil.copyfileobj(source, destination)
destination.write(line_sep + '...' + line_sep)
with open(file_2,'rb') as source:
shutil.copyfileobj(source, destination)
You may want to test file_2
as well, perhaps raising an exception if the newline convention used doesn't match the first file.