#!/usr/bin/env python
# 
# Copyright 2009 Mark Fiers, Plant & Food Research
# 
# This file is part of Moa - http://github.com/mfiers/Moa
# 
# Moa is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your
# option) any later version.
# 
# Moa is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
# License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with Moa.  If not, see <http://www.gnu.org/licenses/>.
# 
"""
Filters an r2 stream

Example:

  return all sequences longer than a 100 nt
  r2cut len>100  < input > out

  possible filters:
    len

"""

import os
import sys
import optparse

parser = optparse.OptionParser()
parser.add_option('-l', dest='len', help = 'len filter: 200, 200-, -200, 200-300')

(options, args) = parser.parse_args()

def len_filter(fval, sid, seq):
    x = fval.split(':')
    if len(x) == 1:
        mn = mx = int(x)
    elif len(x) == 2:
        if not x[0]: x[0] = 0
        if not x[1]: x[1] = 1e78
        mn, mx = map(int, x)
    else:
        raise Exception("Invalid filter")
    if len(seq) < mn: return False
    if len(seq) > mx: return False
    return True

while True:
    line = sys.stdin.readline()
    if not line: break
    line = line.strip()
    if not line: continue
    sid,seq = line.split()
    if not len_filter(options.len, sid, seq):
        continue
    print "%s %s" % (sid, seq)
    
