From 364f5c654cde2ebe84b56b08e96e784c269a3d30 Mon Sep 17 00:00:00 2001 From: Jake Bradford Date: Thu, 11 Jan 2024 15:38:39 +1000 Subject: [PATCH] fixed github issues 14 and 15 --- src/crackling/utils/extractOfftargets.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/crackling/utils/extractOfftargets.py b/src/crackling/utils/extractOfftargets.py index a96dd79..0ae53ac 100644 --- a/src/crackling/utils/extractOfftargets.py +++ b/src/crackling/utils/extractOfftargets.py @@ -32,6 +32,9 @@ def explodeMultiFastaFile(fpInput, fpOutputTempDir): for line in fRead: line = line.strip() + if len(line) == 0: + continue + # just found a new fasta segment. open a new file if line[0] == '>': fpTemp = tempfile.NamedTemporaryFile( @@ -161,6 +164,7 @@ def paginatedSort(filesToSort, fpOutput, mpPool, maxNumOpenFiles=400): while len(sortedFiles) > 1: # A file to write the merged sequences to mergedFile = tempfile.NamedTemporaryFile(delete = False) + mergedFile.close() # Select the files to merge while True: @@ -169,6 +173,12 @@ def paginatedSort(filesToSort, fpOutput, mpPool, maxNumOpenFiles=400): break except OSError as e: if e.errno == 24: + for file in sortedFilesPointers: + try: + file.close() + except Exception as e: + pass + printer(f'Attempted to open too many files at once (OSError errno 24)') maxNumOpenFiles = max(1, int(maxNumOpenFiles / 2)) printer(f'Reducing the number of files that can be opened by half to {maxNumOpenFiles}') @@ -187,8 +197,8 @@ def paginatedSort(filesToSort, fpOutput, mpPool, maxNumOpenFiles=400): # prepare for the next set to be merged sortedFiles = sortedFiles[maxNumOpenFiles:] + [mergedFile.name] - - shutil.move(mergedFile.name, fpOutput) + + shutil.move(sortedFiles[0], fpOutput) def startMultiprocessing(fpInputs, fpOutput, mpPool, numThreads, maxOpenFiles): printer('Extracting off-targets using multiprocessing approach')