8 | 8 |
'from a mates file. Ouptut is interleaved if mates file given',
|
9 | 9 |
usage = 'fastaq to_random_subset [options] <infile> <outfile> <percent>')
|
10 | 10 |
parser.add_argument('--mate_file', help='Name of mates file')
|
|
11 |
parser.add_argument('--seed', help='Seed for random number generator. If not given, python\'s default is used', metavar='INT')
|
11 | 12 |
parser.add_argument('infile', help='Name of input file')
|
12 | 13 |
parser.add_argument('outfile', help='Name of output file')
|
13 | |
parser.add_argument('percent', type=int, help='Per cent probability of keeping any given read (pair) in [0,100]', metavar='INT')
|
|
14 |
parser.add_argument('percent', type=float, help='Per cent probability of keeping any given read (pair) in [0,100]', metavar='FLOAT')
|
14 | 15 |
options = parser.parse_args()
|
15 | 16 |
|
|
17 |
random.seed(a=options.seed)
|
16 | 18 |
seq_reader = sequences.file_reader(options.infile)
|
17 | 19 |
fout = utils.open_file_write(options.outfile)
|
18 | 20 |
|
|
26 | 28 |
except StopIteration:
|
27 | 29 |
print('Error! Didn\'t get mate for read', seq.id, file=sys.stderr)
|
28 | 30 |
sys.exit(1)
|
29 | |
if random.randint(0, 100) <= options.percent:
|
|
31 |
if 100 * random.random() <= options.percent:
|
30 | 32 |
print(seq, file=fout)
|
31 | 33 |
if options.mate_file:
|
32 | 34 |
print(mate_seq, file=fout)
|