From f89ddd55f8c36a5a3f2504bd45f95727dd9e375a Mon Sep 17 00:00:00 2001 From: Kevin Murray Date: Mon, 17 Aug 2015 20:36:48 +1000 Subject: [PATCH 1/6] load-into-coungraph.py: put version into .info --- scripts/load-into-counting.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/scripts/load-into-counting.py b/scripts/load-into-counting.py index c616d5a8d0..1d7a3ff41e 100755 --- a/scripts/load-into-counting.py +++ b/scripts/load-into-counting.py @@ -117,16 +117,17 @@ def main(): check_space_for_graph(args.output_countgraph_filename, tablesize, args.force) + info_filename = base + ".info" check_file_writable(base) - check_file_writable(base + ".info") + check_file_writable(info_filename) print('Saving k-mer countgraph to %s' % base, file=sys.stderr) print('Loading kmers from sequences in %s' % repr(filenames), file=sys.stderr) # clobber the '.info' file now, as we always open in append mode below - if os.path.exists(base + '.info'): - os.remove(base + '.info') + with open(info_filename, 'w') as info_fh: + print('khmer version:', khmer.__version__, file=info_fh) print('making countgraph', file=sys.stderr) countgraph = khmer_args.create_countgraph(args) @@ -159,13 +160,13 @@ def main(): print('mid-save', base, file=sys.stderr) countgraph.save(base) - with open(base + '.info', 'a') as info_fh: + with open(info_filename, 'a') as info_fh: print('through', filename, file=info_fh) total_num_reads += rparser.num_reads n_kmers = countgraph.n_unique_kmers() print('Total number of unique k-mers:', n_kmers, file=sys.stderr) - with open(base + '.info', 'a') as info_fp: + with open(info_filename, 'a') as info_fp: print('Total number of unique k-mers:', n_kmers, file=info_fp) print('saving', base, file=sys.stderr) @@ -176,7 +177,7 @@ def main(): khmer.calc_expected_collisions( countgraph, args.force, max_false_pos=.2) - with open(base + '.info', 'a') as info_fp: + with open(info_filename, 'a') as info_fp: print('fp rate estimated to be %1.3f\n' % fp_rate, file=info_fp) if args.summary_info: @@ -209,7 +210,7 @@ def main(): print('fp rate estimated to be %1.3f' % fp_rate, file=sys.stderr) print('DONE.', file=sys.stderr) - print('wrote to:', base + '.info', file=sys.stderr) + print('wrote to:', info_filename, file=sys.stderr) if __name__ == '__main__': main() From 0aa86f5c0017316c59a191ade8358e5f8dd7bd80 Mon Sep 17 00:00:00 2001 From: Kevin Murray Date: Mon, 17 Aug 2015 20:37:40 +1000 Subject: [PATCH 2/6] be consistent with variable names --- scripts/load-into-counting.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/load-into-counting.py b/scripts/load-into-counting.py index 1d7a3ff41e..77c7f12d0c 100755 --- a/scripts/load-into-counting.py +++ b/scripts/load-into-counting.py @@ -126,7 +126,7 @@ def main(): repr(filenames), file=sys.stderr) # clobber the '.info' file now, as we always open in append mode below - with open(info_filename, 'w') as info_fh: + with open(info_filename, 'w') as info_fp: print('khmer version:', khmer.__version__, file=info_fh) print('making countgraph', file=sys.stderr) From b5a6474f322b77c1f63fd0e4f578ac23cee24791 Mon Sep 17 00:00:00 2001 From: Kevin Murray Date: Mon, 15 Feb 2016 10:36:59 -0800 Subject: [PATCH 3/6] Fix info file variable name --- scripts/load-into-counting.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/load-into-counting.py b/scripts/load-into-counting.py index 77c7f12d0c..90c88e3bce 100755 --- a/scripts/load-into-counting.py +++ b/scripts/load-into-counting.py @@ -127,7 +127,7 @@ def main(): # clobber the '.info' file now, as we always open in append mode below with open(info_filename, 'w') as info_fp: - print('khmer version:', khmer.__version__, file=info_fh) + print('khmer version:', khmer.__version__, file=info_fp) print('making countgraph', file=sys.stderr) countgraph = khmer_args.create_countgraph(args) From eec60bd3c3dd083f1c05fdd836e6f6ab2bd68704 Mon Sep 17 00:00:00 2001 From: Kevin Murray Date: Mon, 15 Feb 2016 10:47:33 -0800 Subject: [PATCH 4/6] Document #1260 in CL --- ChangeLog | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ChangeLog b/ChangeLog index 75c6d0f3b9..5355cdc397 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2016-02-15 Kevin Murray + + * scripts/load-into-counting.py: Insert khmer's version into .info files + 2015-08-14 Luiz Irber * lib/subset.cc: check iterator before decrementing in From 4ce7980cf9b7bf1df60208e23abbf9f7238bc8fe Mon Sep 17 00:00:00 2001 From: Kevin Murray Date: Mon, 15 Feb 2016 10:50:01 -0800 Subject: [PATCH 5/6] Bump copyright year of load-into-counting.py Per checklist item --- scripts/load-into-counting.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/load-into-counting.py b/scripts/load-into-counting.py index 90c88e3bce..4a56537882 100755 --- a/scripts/load-into-counting.py +++ b/scripts/load-into-counting.py @@ -1,7 +1,7 @@ #! /usr/bin/env python # This file is part of khmer, https://github.com/dib-lab/khmer/, and is # Copyright (C) 2011-2015, Michigan State University. -# Copyright (C) 2015, The Regents of the University of California. +# Copyright (C) 2015-2016, The Regents of the University of California. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are From 46e491d67d3a210f8c9301b7310b4b128dff9ad3 Mon Sep 17 00:00:00 2001 From: Kevin Murray Date: Mon, 15 Feb 2016 10:59:42 -0800 Subject: [PATCH 6/6] Add test for load-into-counting info version --- tests/test_scripts.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/test_scripts.py b/tests/test_scripts.py index edc3abbc1e..829fe33a6a 100644 --- a/tests/test_scripts.py +++ b/tests/test_scripts.py @@ -333,6 +333,29 @@ def test_load_into_counting_bad_summary_fmt(): assert "invalid choice: 'badfmt'" in err, err +def test_load_into_counting_info_version(): + script = 'load-into-counting.py' + args = ['-x', '1e5', '-N', '2', '-k', '20'] # use small HT + + outfile = utils.get_temp_filename('out') + infile = utils.get_test_data('random-20-a.fa') + + args.extend([outfile, infile]) + + (status, out, err) = utils.runscript(script, args) + + ht_file = outfile + assert os.path.exists(ht_file), ht_file + + info_file = outfile + '.info' + assert os.path.exists(info_file), info_file + with open(info_file) as info_fp: + versionline = info_fp.readline() + version = versionline.split(':')[1].strip() + assert versionline.startswith('khmer version:'), versionline + assert version == khmer.__version__, version + + def _make_counting(infilename, SIZE=1e7, N=2, K=20, BIGCOUNT=True): script = 'load-into-counting.py' args = ['-x', str(SIZE), '-N', str(N), '-k', str(K)]