parameters: (db, query)
return_statement: return 'not_found', query
docstring: Similar to the above, but this is after a user types enter
      We need to figure out what they meant - could be gene, variant, region
  
      Return tuple of (datatype, identifier)
      Where datatype is one of 'gene', 'variant', or 'region'
      And identifier is one of:
      - ensembl ID for gene
      - variant ID string for variant (eg. 1-1000-A-T)
      - region ID string for region (eg. 1-1000-2000)
  
      Follow these steps:
      - if query is an ensembl ID, return it
      - if a gene symbol, return that gene's ensembl ID
      - if an RSID, return that variant's string
  
  
      Finally, note that we don't return the whole object here - only it's identifier.
      This could be important for performance later
docstring_summary: Similar to the above, but this is after a user types enter
      We need to figure out what they meant - could be gene, variant, region
docstring_tokens: Similar to the above but this is after a user types enter We need to figure out what they meant - could be gene variant region
function: def get_awesomebar_result(db, query):
      """
      Similar to the above, but this is after a user types enter
      We need to figure out what they meant - could be gene, variant, region
  
      Return tuple of (datatype, identifier)
      Where datatype is one of 'gene', 'variant', or 'region'
      And identifier is one of:
      - ensembl ID for gene
      - variant ID string for variant (eg. 1-1000-A-T)
      - region ID string for region (eg. 1-1000-2000)
  
      Follow these steps:
      - if query is an ensembl ID, return it
      - if a gene symbol, return that gene's ensembl ID
      - if an RSID, return that variant's string
  
  
      Finally, note that we don't return the whole object here - only it's identifier.
      This could be important for performance later
  
      """
      query = query.strip()
      print 'Query: %s' % query
  
      # Variant
      variant = get_variants_by_rsid(db, query.lower())
      if variant:
          if len(variant) == 1:
              return 'variant', variant[0]['variant_id']
          else:
              return 'dbsnp_variant_set', variant[0]['rsid']
      variant = get_variants_from_dbsnp(db, query.lower())
      if variant:
          return 'variant', variant[0]['variant_id']
      # variant = get_variant(db, )
      # TODO - https://github.com/brettpthomas/exac_browser/issues/14
  
      gene = get_gene_by_name(db, query)
      if gene:
          return 'gene', gene['gene_id']
  
      # From here out, all should be uppercase (gene, tx, region, variant_id)
      query = query.upper()
      gene = get_gene_by_name(db, query)
      if gene:
          return 'gene', gene['gene_id']
  
      # Ensembl formatted queries
      if query.startswith('ENS'):
          # Gene
          gene = get_gene(db, query)
          if gene:
              return 'gene', gene['gene_id']
  
          # Transcript
          transcript = get_transcript(db, query)
          if transcript:
              return 'transcript', transcript['transcript_id']
  
      # From here on out, only region queries
      if query.startswith('CHR'):
          query = query.lstrip('CHR')
      # Region
      m = R1.match(query)
      if m:
          if int(m.group(3)) < int(m.group(2)):
              return 'region', 'invalid'
          return 'region', '{}-{}-{}'.format(m.group(1), m.group(2), m.group(3))
      m = R2.match(query)
      if m:
          return 'region', '{}-{}-{}'.format(m.group(1), m.group(2), m.group(2))
      m = R3.match(query)
      if m:
          return 'region', '{}'.format(m.group(1))
      m = R4.match(query)
      if m:
          return 'variant', '{}-{}-{}-{}'.format(m.group(1), m.group(2), m.group(3), m.group(4))
  
      return 'not_found', query
function_tokens: def get_awesomebar_result ( db , query ) : query = query . strip ( ) print 'Query: %s' % query # Variant variant = get_variants_by_rsid ( db , query . lower ( ) ) if variant : if len ( variant ) == 1 : return 'variant' , variant [ 0 ] [ 'variant_id' ] else : return 'dbsnp_variant_set' , variant [ 0 ] [ 'rsid' ] variant = get_variants_from_dbsnp ( db , query . lower ( ) ) if variant : return 'variant' , variant [ 0 ] [ 'variant_id' ] # variant = get_variant(db, ) # TODO - https://github.com/brettpthomas/exac_browser/issues/14 gene = get_gene_by_name ( db , query ) if gene : return 'gene' , gene [ 'gene_id' ] # From here out, all should be uppercase (gene, tx, region, variant_id) query = query . upper ( ) gene = get_gene_by_name ( db , query ) if gene : return 'gene' , gene [ 'gene_id' ] # Ensembl formatted queries if query . startswith ( 'ENS' ) : # Gene gene = get_gene ( db , query ) if gene : return 'gene' , gene [ 'gene_id' ] # Transcript transcript = get_transcript ( db , query ) if transcript : return 'transcript' , transcript [ 'transcript_id' ] # From here on out, only region queries if query . startswith ( 'CHR' ) : query = query . lstrip ( 'CHR' ) # Region m = R1 . match ( query ) if m : if int ( m . group ( 3 ) ) < int ( m . group ( 2 ) ) : return 'region' , 'invalid' return 'region' , '{}-{}-{}' . format ( m . group ( 1 ) , m . group ( 2 ) , m . group ( 3 ) ) m = R2 . match ( query ) if m : return 'region' , '{}-{}-{}' . format ( m . group ( 1 ) , m . group ( 2 ) , m . group ( 2 ) ) m = R3 . match ( query ) if m : return 'region' , '{}' . format ( m . group ( 1 ) ) m = R4 . match ( query ) if m : return 'variant' , '{}-{}-{}-{}' . format ( m . group ( 1 ) , m . group ( 2 ) , m . group ( 3 ) , m . group ( 4 ) ) return 'not_found' , query