Skip to content

Commit

Permalink
Merge pull request #61 from martinghunt/random_reads_use_float
Browse files Browse the repository at this point in the history
Random reads use float
  • Loading branch information
martinghunt authored Aug 12, 2016
2 parents e473b2d + dba1b55 commit 0f00fdf
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions pyfastaq/runners/to_random_subset.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ def run(description):
'from a mates file. Ouptut is interleaved if mates file given',
usage = 'fastaq to_random_subset [options] <infile> <outfile> <percent>')
parser.add_argument('--mate_file', help='Name of mates file')
parser.add_argument('--seed', help='Seed for random number generator. If not given, python\'s default is used', metavar='INT')
parser.add_argument('infile', help='Name of input file')
parser.add_argument('outfile', help='Name of output file')
parser.add_argument('percent', type=int, help='Per cent probability of keeping any given read (pair) in [0,100]', metavar='INT')
parser.add_argument('percent', type=float, help='Per cent probability of keeping any given read (pair) in [0,100]', metavar='FLOAT')
options = parser.parse_args()

random.seed(a=options.seed)
seq_reader = sequences.file_reader(options.infile)
fout = utils.open_file_write(options.outfile)

Expand All @@ -27,7 +29,7 @@ def run(description):
except StopIteration:
print('Error! Didn\'t get mate for read', seq.id, file=sys.stderr)
sys.exit(1)
if random.randint(0, 100) <= options.percent:
if 100 * random.random() <= options.percent:
print(seq, file=fout)
if options.mate_file:
print(mate_seq, file=fout)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

setup(
name='pyfastaq',
version='3.12.1',
version='3.13.0',
description='Script to manipulate FASTA and FASTQ files, plus API for developers',
packages = find_packages(),
author='Martin Hunt',
Expand Down

0 comments on commit 0f00fdf

Please sign in to comment.