<s> import re <EOL> import os <EOL> import sys <EOL> import GeminiQuery <EOL> from GeminiQuery import select_formatter <EOL> def _report_results ( args , query , gq ) : <EOL> gq . run ( query , show_variant_samples = args . show_variant_samples ) <EOL> if args . use_header and gq . header : <EOL> print gq . header <EOL> for row in gq : <EOL> print row <EOL> def get_region ( args , gq ) : <EOL> region_regex = re . compile ( "<STR_LIT>" ) <EOL> try : <EOL> region = region_regex . findall ( args . region ) [ <NUM_LIT:0> ] <EOL> except IndexError : <EOL> sys . exit ( "<STR_LIT>" ) <EOL> if len ( region ) != <NUM_LIT:3> : <EOL> sys . exit ( "<STR_LIT>" ) <EOL> chrom = region [ <NUM_LIT:0> ] <EOL> start = region [ <NUM_LIT:1> ] <EOL> end = region [ <NUM_LIT:2> ] <EOL> if args . columns is not None : <EOL> query = "<STR_LIT>" + str ( args . columns ) + "<STR_LIT>" <EOL> else : <EOL> query = "<STR_LIT>" <EOL> query += "<STR_LIT>" + "<STR_LIT:'>" + chrom + "<STR_LIT:'>" + "<STR_LIT>" + start + "<STR_LIT>" + end + "<STR_LIT:)>" + "<STR_LIT>" + start + "<STR_LIT>" + end + "<STR_LIT>" <EOL> if args . filter : <EOL> query += "<STR_LIT>" + args . filter <EOL> query += "<STR_LIT>" <EOL> _report_results ( args , query , gq ) <EOL> def get_gene ( args , gq ) : <EOL> """<STR_LIT>""" <EOL> if args . columns is not None : <EOL> query = "<STR_LIT>" + str ( args . columns ) + "<STR_LIT>" <EOL> else : <EOL> query = "<STR_LIT>" <EOL> query += "<STR_LIT>" + "<STR_LIT:'>" + args . gene + "<STR_LIT>" <EOL> if args . filter : <EOL> query += "<STR_LIT>" + args . filter <EOL> query += "<STR_LIT>" <EOL> _report_results ( args , query , gq ) <EOL> def add_region_to_query ( args ) : <EOL> region_regex = re . compile ( "<STR_LIT>" ) <EOL> try : <EOL> region = region_regex . findall ( args . region ) [ <NUM_LIT:0> ] <EOL> except IndexError : <EOL> sys . exit ( "<STR_LIT>" ) <EOL> if len ( region ) != <NUM_LIT:3> : <EOL> sys . exit ( "<STR_LIT>" ) <EOL> chrom = region [ <NUM_LIT:0> ] <EOL> start = region [ <NUM_LIT:1> ] <EOL> end = region [ <NUM_LIT:2> ] <EOL> where_clause = "<STR_LIT>" + "<STR_LIT:'>" + chrom + "<STR_LIT:'>" + "<STR_LIT>" + start + "<STR_LIT>" + end + "<STR_LIT:)>" + "<STR_LIT>" + start + "<STR_LIT>" + end + "<STR_LIT>" <EOL> args . query = _add_to_where_clause ( args . query , where_clause ) <EOL> def _add_to_where_clause ( query , where_clause ) : <EOL> where_index = query . lower ( ) . find ( "<STR_LIT>" ) <EOL> prefix = query [ <NUM_LIT:0> : where_index ] <EOL> suffix = query [ where_index + len ( "<STR_LIT>" ) : ] <EOL> if where_index == - <NUM_LIT:1> : <EOL> query += "<STR_LIT>" + where_clause <EOL> else : <EOL> query = "<STR_LIT>" . format ( prefix , suffix , where_clause ) <EOL> return query <EOL> def region ( parser , args ) : <EOL> if os . path . exists ( args . db ) : <EOL> formatter = select_formatter ( args ) <EOL> gq = GeminiQuery . GeminiQuery ( args . db , out_format = formatter ) <EOL> if args . region is not None and args . gene is not None : <EOL> sys . exit ( '<STR_LIT>' ) <EOL> elif args . region is not None : <EOL> get_region ( args , gq ) <EOL> elif args . gene is not None : <EOL> get_gene ( args , gq ) </s>
