Here is my current 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()
For obvious reasons, this is very painful. Is there some way of interpolating the input_format variable into the query?