Debian Codegraph @

pyfastaq/runners/chunker.py

raw
1 import argparse
2 from pyfastaq import tasks
3
4 def run(description):
5 parser = argparse.ArgumentParser(
6 description = 'Splits a multi sequence file into separate files. Splits sequences into chunks of a fixed size. Aims for chunk_size chunks in each file, but allows a little extra, so chunk can be up to (chunk_size + tolerance), to prevent tiny chunks made from the ends of sequences',
7 usage = 'fastaq chunker [options] <infile> <out> <chunk size> <tolerance>')
8 parser.add_argument('infile', help='Name of input file to be split')
9 parser.add_argument('out', help='Prefix of output file. If --onefile used, then name of single output file')
10 parser.add_argument('chunk_size', type=int, help='Size of each chunk')
11 parser.add_argument('tolerance', type=int, help='Tolerance allowed in chunk size')
12 parser.add_argument('--onefile', action='store_true', help='Output all the sequences in one file')
13 parser.add_argument('--skip_all_Ns', action='store_true', help='Do not output any sequence that consists of all Ns')
14 options = parser.parse_args()
15 if options.onefile:
16 tasks.split_by_fixed_size_onefile(
17 options.infile,
18 options.out,
19 options.chunk_size,
20 options.tolerance,
21 skip_if_all_Ns=options.skip_all_Ns
22 )
23 else:
24 tasks.split_by_fixed_size(
25 options.infile,
26 options.out,
27 options.chunk_size,
28 options.tolerance,
29 skip_if_all_Ns=options.skip_all_Ns
30 )