Skip to content

Commit

Permalink
Merge pull request #468 from griffithlab/hotfix_netchop
Browse files Browse the repository at this point in the history
Fix bug in split_file function of net_chop.py and netmhc_stab.py
  • Loading branch information
susannasiebert authored Oct 25, 2019
2 parents b2a9f77 + 0df7b35 commit 5df179c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 26 deletions.
15 changes: 2 additions & 13 deletions lib/net_chop.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,11 @@
import os
from time import sleep
import collections
import lib.utils

cycle = ['|', '/', '-', '\\']
methods = ['cterm', '20s']

def split_file(reader, lines=400):
from itertools import islice, chain
for tmp in reader:
if tmp != "":
yield chain([tmp], islice(reader, lines-1))
try:
tmp = next(reader)
except StopIteration:
return
else:
break

def main(args_input = sys.argv[1:]):
parser = argparse.ArgumentParser("pvacseq net_chop", formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument(
Expand Down Expand Up @@ -64,7 +53,7 @@ def main(args_input = sys.argv[1:]):
i=1
print("Waiting for results from NetChop... |", end='')
sys.stdout.flush()
for chunk in split_file(reader, 100):
for chunk in lib.utils.split_file(reader, 100):
staging_file = tempfile.NamedTemporaryFile(mode='w+')
current_buffer = {}
for line in chunk:
Expand Down
15 changes: 2 additions & 13 deletions lib/netmhc_stab.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,11 @@
import re
import os
from time import sleep
import lib.utils

cycle = ['|', '/', '-', '\\']
methods = ['cterm', '20s']

def split_file(reader, lines=400):
from itertools import islice, chain
for tmp in reader:
if tmp != "":
yield chain([tmp], islice(reader, lines-1))
try:
tmp = next(reader)
except StopIteration:
return
else:
break

def main(args_input = sys.argv[1:]):
parser = argparse.ArgumentParser("pvacseq net_chop", formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument(
Expand Down Expand Up @@ -51,7 +40,7 @@ def main(args_input = sys.argv[1:]):
i=1
print("Waiting for results from NetMHCStabPan... |", end='')
sys.stdout.flush()
for chunk in split_file(reader, 100):
for chunk in lib.utils.split_file(reader, 100):
peptide_lengths = set()
staging_file = tempfile.NamedTemporaryFile(mode='w+')
current_buffer = {}
Expand Down
8 changes: 8 additions & 0 deletions lib/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import binascii
from itertools import islice

def is_gz_file(filepath):
with open(filepath, 'rb') as test_f:
return binascii.hexlify(test_f.read(2)) == b'1f8b'

def split_file(reader, lines):
i = iter(reader)
piece = list(islice(i, lines))
while piece:
yield piece
piece = list(islice(i, lines))

0 comments on commit 5df179c

Please sign in to comment.