Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed github issues 14 and 15 #20

Open
wants to merge 1 commit into
base: version-2.0.1
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/crackling/utils/extractOfftargets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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:
Expand All @@ -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}')
Expand All @@ -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')
Expand Down