title: sqlalchemy: query by variable attribute
body: <p>Here is my current code:</p>
  
  <pre><code>def hypergeometric(query_genes, filename, input_format):
  
      if input_format == 'ENSEMBLID':
          OCRs = OpenChromatinRegion.query
                  .filter(OpenChromatinRegion.filename == filename)
                  .filter(OpenChromatinRegion.ENSEMBLID.in_(query_genes))
                  .filter(OpenChromatinRegion.ENSEMBLID != 'NA')
                  .all()
  
      elif input_format == 'gene_symbol':
          OCRs = OpenChromatinRegion.query
                  .filter(OpenChromatinRegion.filename == filename)
                  .filter(OpenChromatinRegion.gene_symbol.in_(query_genes))
                  .filter(OpenChromatinRegion.gene_symbol != 'NA')
                  .all()
  </code></pre>
  
  <p>For obvious reasons, this is very painful. Is there some way of interpolating the <code>input_format</code> variable into the query? </p>