Skip to content

Commit

Permalink
Merge pull request #1163 from dib-lab/fix/silent_fifo_check
Browse files Browse the repository at this point in the history
No more complaining about FIFO's being empty (addresses #1147)
  • Loading branch information
ctb committed Jul 17, 2015
2 parents f775830 + 006f715 commit 283063a
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
6 changes: 6 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
2015-07-09 Jacob Fenton <bocajnotnef@gmail.com>

* khmer/kfile.py: changed check_valid_file_exists to recognize fifos as
non-empty
* tests/test_normalize_by_median.py: added test

2015-07-10 Jacob Fenton <bocajnotnef@gmail.com>

* oxli/functions.py: changed estimate functions to use correct letter
Expand Down
3 changes: 2 additions & 1 deletion khmer/kfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ def check_valid_file_exists(in_files):
"""
for in_file in in_files:
if os.path.exists(in_file):
if os.stat(in_file).st_size > 0:
mode = os.stat(in_file).st_mode
if os.stat(in_file).st_size > 0 or S_ISBLK(mode) or S_ISFIFO(mode):
return
else:
print('WARNING: Input file %s is empty' %
Expand Down
42 changes: 41 additions & 1 deletion tests/test_normalize_by_median.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@ def test_normalize_by_median_indent():
assert os.path.exists(outfile)


def test_normalize_by_median_empty_file():
infile = utils.get_temp_filename('empty')
shutil.copyfile(utils.get_test_data('empty-file'), infile)
script = 'normalize-by-median.py'
in_dir = os.path.dirname(infile)

args = [infile]
(status, out, err) = utils.runscript(script, args, in_dir)

assert 'WARNING:' in err, err
assert 'is empty' in err, err
assert 'SKIPPED' in err, err


def test_normalize_by_median():
CUTOFF = '1'

Expand Down Expand Up @@ -495,7 +509,7 @@ def write_by_chunks(infile, outfile, CHUNKSIZE=8192):
ofile.close()


def test_normalize_by_median_streaming():
def test_normalize_by_median_streaming_0():
CUTOFF = '20'

infile = utils.get_test_data('100-reads.fq.gz')
Expand All @@ -522,6 +536,32 @@ def test_normalize_by_median_streaming():
assert linecount == 400


def test_normalize_by_median_streaming_1():
CUTOFF = '20'

infile = utils.get_test_data('test-filter-abund-Ns.fq')
in_dir = os.path.dirname(infile)
fifo = utils.get_temp_filename('fifo')
outfile = utils.get_temp_filename('outfile')

# Use a fifo to copy stdout to a file for checking
os.mkfifo(fifo)
thread = threading.Thread(target=write_by_chunks, args=(infile, fifo))
thread.start()

# Execute diginorm
script = 'normalize-by-median.py'
args = ['-C', CUTOFF, '-k', '17', '-o', outfile, fifo]
(status, out, err) = utils.runscript(script, args, in_dir)

# Merge the thread
thread.join()

assert os.path.exists(outfile), outfile
assert 'Total number of unique k-mers: 98' in err, err
assert 'fifo is empty' not in err, err


def test_diginorm_basic_functionality_1():
# each of these pairs has both a multicopy sequence ('ACTTCA...') and
# a random sequence. With 'C=1' and '-p', all should be kept.
Expand Down

0 comments on commit 283063a

Please sign in to comment.