/usr/bin/grepseq is in python3-biotools 1.2.12-2.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | #! /usr/bin/python
from optparse import OptionParser
import biotools.IO as io
import re
def search(regex, filename, options):
pfn = options.print_filename
snm = options.search_name
ssq = options.search_seq
inv = options.invert_results
cnt = options.count
cmx = options.max_count
if pfn and not cnt:
print('\n=======>', filename, '<=======\n')
for seq in io.open(filename, 'r'):
in_name = snm and regex.search(seq.name + ' ' + seq.defline)
in_seq = ssq and regex.search(seq.seq)
if not inv and (in_name or in_seq):
options.curr_count += 1
if not cnt:
print(seq)
elif inv and not (in_name or in_seq):
options.curr_count += 1
if not cnt:
print(seq)
if cmx and options.curr_count > cmx:
break
if cnt:
print(options.curr_count)
if __name__ == '__main__':
optp = OptionParser(usage="%prog [options] <pattern> <files ...>")
optp.add_option('-c', '--count',
action='store_true', dest='count', default=False,
help='''Suppress normal output; instead print a count of
matching lines for each input file. With the -v,
--invert-match option (see below), count non-matching
lines.''')
optp.add_option('-H', '--with-filename',
action='store_true', dest='print_filename', default=False,
help='Print the filename for each match.')
optp.add_option('-i', '--ignore-case',
action='store_true', dest='ignore_case', default=False,
help='''Ignore case distinctions in both the pattern and
input files.''')
optp.add_option('-m', '--max-count', metavar='NUM',
action='store', dest='max_count', default=None, type='int',
help='''Stop reading a file after NUM matching lines. When
the -c or --count option is also used, grepseq does
not output a count greater than NUM. When the -v or
--invert-match option is also used, grep stops after
outputting NUM non-matching lines.''')
optp.add_option('-N', '--names-only',
action='store_false', dest='search_seq', default=True,
help='Search only sequence names. Cannot be used with -S.')
optp.add_option('-S', '--sequences-only',
action='store_false', dest='search_name', default=True,
help='Search only sequences. Cannot be used with -N.')
optp.add_option('-v', '--invert-match',
action='store_true', dest='invert_results', default=False,
help='''Invert the sense of matching, to select non-matching
lines.''')
opts, args = optp.parse_args()
if len(args) < 2:
optp.print_help()
exit(1)
if opts.max_count is not None and opts.max_count < 1:
exit(0)
flags = 0
if opts.ignore_case:
flags |= re.I
try:
pattern = re.compile(args[0], flags)
except:
exit(1)
files = args[1:]
opts.curr_count = 0
if len(files) > 1 or opts.print_filename:
opts.print_filename = True
for f in files:
search(pattern, f, opts)
|