<s> '''<STR_LIT>''' <EOL> import sys <EOL> import csv <EOL> import _csv <EOL> import CGAT . Experiment as E <EOL> import CGAT . CSV as CSV <EOL> class CommentStripper : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , file ) : <EOL> self . mFile = file <EOL> def __iter__ ( self ) : <EOL> return self <EOL> def next ( self ) : <EOL> while <NUM_LIT:1> : <EOL> line = self . mFile . readline ( ) <EOL> if not line : <EOL> raise StopIteration <EOL> if line [ <NUM_LIT:0> ] != "<STR_LIT:#>" : <EOL> return line <EOL> def main ( argv = None ) : <EOL> """<STR_LIT>""" <EOL> if argv is None : <EOL> argv = sys . argv <EOL> parser = E . OptionParser ( version = "<STR_LIT>" , <EOL> usage = globals ( ) [ "<STR_LIT>" ] ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , action = "<STR_LIT:store_true>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , action = "<STR_LIT:store_true>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , action = "<STR_LIT:store_true>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , type = "<STR_LIT:string>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . set_defaults ( <EOL> remove = False , <EOL> unique = False , <EOL> filename_fields = None , <EOL> ) <EOL> ( options , args ) = E . Start ( parser , <EOL> add_csv_options = True , <EOL> quiet = True ) <EOL> statement = "<STR_LIT:U+0020>" . join ( args ) <EOL> if options . large : <EOL> reader = CSV . DictReaderLarge ( CommentStripper ( sys . stdin ) , <EOL> dialect = options . csv_dialect ) <EOL> else : <EOL> reader = csv . DictReader ( CommentStripper ( sys . stdin ) , <EOL> dialect = options . csv_dialect ) <EOL> exec "<STR_LIT>" % statement in locals ( ) <EOL> counter = E . Counter ( ) <EOL> writer = csv . DictWriter ( options . stdout , <EOL> reader . fieldnames , <EOL> dialect = options . csv_dialect , <EOL> lineterminator = options . csv_lineterminator ) <EOL> writer . writerow ( dict ( ( fn , fn ) for fn in reader . fieldnames ) ) <EOL> while <NUM_LIT:1> : <EOL> counter . input += <NUM_LIT:1> <EOL> try : <EOL> row = reader . next ( ) <EOL> except _csv . Error , msg : <EOL> options . stderr . write ( "<STR_LIT>" % ( msg ) ) <EOL> counter . errors += <NUM_LIT:1> <EOL> continue <EOL> except StopIteration : <EOL> break <EOL> if not row : <EOL> break <EOL> if f ( row ) : <EOL> writer . writerow ( row ) <EOL> counter . output += <NUM_LIT:1> <EOL> else : <EOL> counter . filtered += <NUM_LIT:1> <EOL> E . info ( "<STR_LIT:%s>" % counter ) <EOL> E . Stop ( ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> sys . exit ( main ( sys . argv ) ) </s>
