| 1 |
import argparse |
| 2 |
from pyfastaq import tasks |
| 3 |
|
| 4 |
def run(description): |
| 5 |
parser = argparse.ArgumentParser( |
| 6 |
description = 'Filters a sequence file by sequence length and/or by name matching a regular expression', |
| 7 |
usage = 'fastaq filter [options] <infile> <outfile>') |
| 8 |
parser.add_argument('--min_length', type=int, help='Minimum length of sequence to keep [%(default)s]', default=0, metavar='INT') |
| 9 |
parser.add_argument('--max_length', type=float, help='Maximum length of sequence to keep [%(default)s]', default=float('inf'), metavar='INT') |
| 10 |
parser.add_argument('--regex', help='If given, only reads with a name matching the regular expression will be kept') |
| 11 |
parser.add_argument('--ids_file', help='If given, only reads whose ID is in th given file will be used. One ID per line of file.', metavar='FILENAME') |
| 12 |
parser.add_argument('-v', '--invert', action='store_true', help='Only keep sequences that do not match the filters') |
| 13 |
|
| 14 |
mate_group = parser.add_argument_group('Mate file for read pairs options') |
| 15 |
mate_group.add_argument('--mate_in', help='Name of mates input file. If used, must also provide --mate_out', metavar='FILENAME') |
| 16 |
mate_group.add_argument('--mate_out', help='Name of mates output file', metavar='FILENAME') |
| 17 |
mate_group.add_argument('--both_mates_pass', action='store_true', help='By default, if either mate passes filter, then both reads output. Use this flag to require that both reads of a pair pass the filter') |
| 18 |
|
| 19 |
parser.add_argument('infile', help='Name of input file to be filtered') |
| 20 |
parser.add_argument('outfile', help='Name of output file') |
| 21 |
options = parser.parse_args() |
| 22 |
tasks.filter(options.infile, |
| 23 |
options.outfile, |
| 24 |
minlength=options.min_length, |
| 25 |
maxlength=options.max_length, |
| 26 |
regex=options.regex, |
| 27 |
ids_file=options.ids_file, |
| 28 |
invert=options.invert, |
| 29 |
mate_in=options.mate_in, |
| 30 |
mate_out=options.mate_out, |
| 31 |
both_mates_pass=options.both_mates_pass, |
| 32 |
) |