Mercurial > repos > jjohnson > find_in_reference
comparison find_in_reference.py @ 1:856033fb26e8
Add case insensitive option
| author | Jim Johnson <jj@umn.edu> |
|---|---|
| date | Fri, 17 Jan 2014 14:50:53 -0600 |
| parents | fe0327a3ba81 |
| children | 30975b3ff0dc |
comparison
equal
deleted
inserted
replaced
| 0:fe0327a3ba81 | 1:856033fb26e8 |
|---|---|
| 38 parser.add_option( '-r', '--reference', dest='reference', help='The reference file to filter against' ) | 38 parser.add_option( '-r', '--reference', dest='reference', help='The reference file to filter against' ) |
| 39 parser.add_option( '-o', '--output', dest='output', help='The output file for input lines filtered by reference') | 39 parser.add_option( '-o', '--output', dest='output', help='The output file for input lines filtered by reference') |
| 40 parser.add_option( '-f', '--filtered', dest='filtered', help='The output file for input lines not in the output') | 40 parser.add_option( '-f', '--filtered', dest='filtered', help='The output file for input lines not in the output') |
| 41 parser.add_option('-c','--input_column', dest='input_column', default=None, help='The column for the value in the input file. (first column = 1, default to last column)') | 41 parser.add_option('-c','--input_column', dest='input_column', default=None, help='The column for the value in the input file. (first column = 1, default to last column)') |
| 42 parser.add_option('-C','--reference_column', dest='reference_column', default=None, help='The column for the value in the reference file. (first column = 1, default to last column)') | 42 parser.add_option('-C','--reference_column', dest='reference_column', default=None, help='The column for the value in the reference file. (first column = 1, default to last column)') |
| 43 parser.add_option( '-I', '--case_insensitive', dest='ignore_case', action="store_true", default=False, help='case insensitive' ) | |
| 43 parser.add_option( '-k', '--keep', dest='keep', action="store_true", default=False, help='' ) | 44 parser.add_option( '-k', '--keep', dest='keep', action="store_true", default=False, help='' ) |
| 44 parser.add_option( '-d', '--debug', dest='debug', action='store_true', default=False, help='Turn on wrapper debugging to stdout' ) | 45 parser.add_option( '-d', '--debug', dest='debug', action='store_true', default=False, help='Turn on wrapper debugging to stdout' ) |
| 45 (options, args) = parser.parse_args() | 46 (options, args) = parser.parse_args() |
| 46 # Input files | 47 # Input files |
| 47 if options.input != None: | 48 if options.input != None: |
| 87 refFile = None | 88 refFile = None |
| 88 for ln,line in enumerate(inputFile): | 89 for ln,line in enumerate(inputFile): |
| 89 try: | 90 try: |
| 90 found = False | 91 found = False |
| 91 search_string = line.split('\t')[incol].rstrip('\r\n') | 92 search_string = line.split('\t')[incol].rstrip('\r\n') |
| 93 if options.ignore_case: | |
| 94 search_string = search_string.upper() | |
| 92 if options.debug: | 95 if options.debug: |
| 93 print >> sys.stderr, "search: %s" % (search_string) | 96 print >> sys.stderr, "search: %s" % (search_string) |
| 94 refFile = open(options.reference,'r') | 97 refFile = open(options.reference,'r') |
| 95 for tn,fline in enumerate(refFile): | 98 for tn,fline in enumerate(refFile): |
| 96 target_string = fline.split('\t')[refcol] | 99 target_string = fline.split('\t')[refcol] |
| 100 if options.ignore_case: | |
| 101 target_string = target_string.upper() | |
| 97 if options.debug: | 102 if options.debug: |
| 98 print >> sys.stderr, "in: %s %s %s" % (search_string,search_string in target_string,target_string) | 103 print >> sys.stderr, "in: %s %s %s" % (search_string,search_string in target_string,target_string) |
| 99 if search_string in target_string: | 104 if search_string in target_string: |
| 100 found = True | 105 found = True |
| 101 break | 106 break |
