<s> from decimal import Decimal <EOL> import logging <EOL> import json <EOL> from django . db import connection <EOL> from django . db . models import Q <EOL> from django . http import HttpResponse <EOL> from annotation_server import utils <EOL> logger = logging . getLogger ( __name__ ) <EOL> def search_genes ( request , genome , search_string ) : <EOL> """<STR_LIT>""" <EOL> logger . debug ( "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> genome , search_string ) <EOL> if genome in utils . SUPPORTED_GENOMES : <EOL> current_table = eval ( genome + "<STR_LIT>" ) <EOL> curr_vals = current_table . objects . filter ( <EOL> Q ( name__contains = search_string ) | Q ( name2__contains = search_string ) <EOL> ) . values ( '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> data = ValuesQuerySetToDict ( curr_vals ) <EOL> return HttpResponse ( data , '<STR_LIT:application/json>' ) <EOL> else : <EOL> return HttpResponse ( status = <NUM_LIT> ) <EOL> return HttpResponse ( status = <NUM_LIT> ) <EOL> def search_extended_genes ( request , genome , search_string ) : <EOL> """<STR_LIT>""" <EOL> logger . debug ( "<STR_LIT>" <EOL> "<STR_LIT>" , genome , search_string ) <EOL> def get_sequence ( request , genome , chrom , start , end ) : <EOL> """<STR_LIT>""" <EOL> logger . debug ( "<STR_LIT>" <EOL> "<STR_LIT>" , genome , chrom ) <EOL> offset = int ( end ) - int ( start ) <EOL> if genome in utils . SUPPORTED_GENOMES : <EOL> cursor = connection . cursor ( ) <EOL> query = ( "<STR_LIT>" <EOL> "<STR_LIT>" ) . format ( start , offset , genome , chrom ) <EOL> cursor . execute ( query ) <EOL> return HttpResponse ( cursor_to_json ( cursor ) , '<STR_LIT>' ) <EOL> else : <EOL> return HttpResponse ( status = <NUM_LIT> ) <EOL> def get_length ( request , genome ) : <EOL> """<STR_LIT>""" <EOL> logger . debug ( "<STR_LIT>" , genome ) <EOL> if genome in utils . SUPPORTED_GENOMES : <EOL> current_table = eval ( genome + "<STR_LIT>" ) <EOL> data = ValuesQuerySetToDict ( <EOL> current_table . objects . values ( '<STR_LIT>' , '<STR_LIT:size>' ) ) <EOL> return HttpResponse ( data , '<STR_LIT:application/json>' ) <EOL> else : <EOL> return HttpResponse ( status = <NUM_LIT> ) <EOL> def get_chrom_length ( request , genome , chrom ) : <EOL> """<STR_LIT>""" <EOL> logger . debug ( "<STR_LIT>" <EOL> "<STR_LIT>" , genome , chrom ) <EOL> if genome in utils . SUPPORTED_GENOMES : <EOL> current_table = eval ( genome + "<STR_LIT>" ) <EOL> curr_vals = current_table . objects . filter ( chrom__iexact = chrom ) . values ( <EOL> '<STR_LIT>' , '<STR_LIT:size>' ) <EOL> data = ValuesQuerySetToDict ( curr_vals ) <EOL> return HttpResponse ( data , '<STR_LIT:application/json>' ) <EOL> else : <EOL> return HttpResponse ( status = <NUM_LIT> ) <EOL> def get_cytoband ( request , genome , chrom ) : <EOL> """<STR_LIT>""" <EOL> logger . debug ( "<STR_LIT>" <EOL> "<STR_LIT>" , genome , chrom ) <EOL> if genome in utils . SUPPORTED_GENOMES : <EOL> current_table = eval ( genome + "<STR_LIT>" ) <EOL> curr_vals = current_table . objects . filter ( chrom__iexact = chrom ) . values ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:name>' , '<STR_LIT>' ) <EOL> data = ValuesQuerySetToDict ( curr_vals ) <EOL> return HttpResponse ( data , '<STR_LIT:application/json>' ) <EOL> else : <EOL> return HttpResponse ( status = <NUM_LIT> ) <EOL> def get_genes ( request , genome , chrom , start , end ) : <EOL> """<STR_LIT>""" <EOL> logger . debug ( "<STR_LIT>" <EOL> "<STR_LIT>" , genome , chrom ) <EOL> if genome in utils . SUPPORTED_GENOMES : <EOL> current_table = eval ( genome + "<STR_LIT>" ) <EOL> curr_vals = current_table . objects . filter ( <EOL> Q ( chrom__iexact = chrom ) , <EOL> Q ( cdsStart__range = ( start , end ) ) | Q ( cdsEnd__range = ( start , end ) ) <EOL> ) . values ( '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> data = ValuesQuerySetToDict ( curr_vals ) <EOL> return HttpResponse ( data , '<STR_LIT:application/json>' ) <EOL> else : <EOL> return HttpResponse ( status = <NUM_LIT> ) <EOL> def get_gc ( request , genome , chrom , start , end ) : <EOL> """<STR_LIT>""" <EOL> logger . debug ( "<STR_LIT>" <EOL> "<STR_LIT>" , genome , chrom , start , end ) <EOL> if genome in utils . SUPPORTED_GENOMES : <EOL> current_table = eval ( genome + "<STR_LIT>" ) <EOL> curr_vals = current_table . objects . filter ( <EOL> Q ( chrom__iexact = chrom ) , <EOL> Q ( position__range = ( start , end ) ) , <EOL> ) . values ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:value>' ) <EOL> data = ValuesQuerySetToDict ( curr_vals ) <EOL> return HttpResponse ( data , '<STR_LIT:application/json>' ) <EOL> else : <EOL> return HttpResponse ( status = <NUM_LIT> ) <EOL> def get_maptheo ( request , genome , chrom , start , end ) : <EOL> """<STR_LIT>""" <EOL> logger . debug ( "<STR_LIT>" <EOL> "<STR_LIT>" , genome , chrom , start , end ) <EOL> if genome in utils . MAPPABILITY_THEORETICAL : <EOL> current_table = eval ( genome + "<STR_LIT>" ) <EOL> curr_vals = current_table . objects . filter ( <EOL> Q ( chrom__iexact = chrom ) , <EOL> Q ( chromStart__range = ( start , end ) ) | Q ( chromEnd__range = ( start , end ) ) <EOL> ) . values ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> data = ValuesQuerySetToDict ( curr_vals ) <EOL> return HttpResponse ( data , '<STR_LIT:application/json>' ) <EOL> else : <EOL> return HttpResponse ( status = <NUM_LIT> ) <EOL> def get_mapemp ( request , genome , chrom , start , end ) : <EOL> """<STR_LIT>""" <EOL> logger . debug ( "<STR_LIT>" <EOL> "<STR_LIT>" , genome , chrom , start , end ) <EOL> if genome in utils . SUPPORTED_GENOMES : <EOL> current_table = eval ( genome + "<STR_LIT>" ) <EOL> curr_vals = current_table . objects . filter ( <EOL> Q ( chrom__iexact = chrom ) , <EOL> Q ( chromStart__range = ( start , end ) ) | Q ( chromEnd__range = ( start , end ) ) <EOL> ) . values ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> data = ValuesQuerySetToDict ( curr_vals ) <EOL> return HttpResponse ( data , '<STR_LIT:application/json>' ) <EOL> else : <EOL> return HttpResponse ( status = <NUM_LIT> ) <EOL> def get_conservation ( request , genome , chrom , start , end ) : <EOL> """<STR_LIT>""" <EOL> logger . debug ( "<STR_LIT>" <EOL> "<STR_LIT>" , genome , chrom , start , end ) <EOL> if genome in utils . SUPPORTED_GENOMES : <EOL> current_table = eval ( genome + "<STR_LIT>" ) <EOL> curr_vals = current_table . objects . filter ( <EOL> Q ( chrom__iexact = chrom ) , <EOL> Q ( position__range = ( start , end ) ) , <EOL> ) . values ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:value>' ) <EOL> data = ValuesQuerySetToDict ( curr_vals ) <EOL> return HttpResponse ( data , '<STR_LIT:application/json>' ) <EOL> else : <EOL> return HttpResponse ( status = <NUM_LIT> ) <EOL> def get_gapregion ( request , genome , chrom , start , end ) : <EOL> """<STR_LIT>""" <EOL> logger . debug ( "<STR_LIT>" <EOL> "<STR_LIT>" , genome , chrom , start , end ) <EOL> if genome in utils . GAP_REGIONS : <EOL> current_table = eval ( genome + "<STR_LIT>" ) <EOL> curr_vals = current_table . objects . filter ( <EOL> Q ( chrom__iexact = chrom ) , <EOL> Q ( chromStart__gte = start ) , <EOL> Q ( chromStart__range = ( start , end ) ) | Q ( chromEnd__range = ( start , end ) ) <EOL> ) . values ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:n>' , '<STR_LIT:size>' , '<STR_LIT:type>' , <EOL> '<STR_LIT>' ) <EOL> data = ValuesQuerySetToDict ( curr_vals ) <EOL> return HttpResponse ( data , '<STR_LIT:application/json>' ) <EOL> else : <EOL> return HttpResponse ( status = <NUM_LIT> ) <EOL> def cursor_to_json ( cursor_in ) : <EOL> cols = [ x [ <NUM_LIT:0> ] for x in cursor_in . description ] <EOL> out = [ ] <EOL> for r in cursor_in . fetchall ( ) : <EOL> row = { } <EOL> for prop , val in zip ( cols , r ) : <EOL> if isinstance ( val , Decimal ) : <EOL> val = float ( val ) <EOL> row [ prop ] = val <EOL> out . append ( row ) <EOL> return json . dumps ( out ) <EOL> def ValuesQuerySetToDict ( vqs ) : <EOL> """<STR_LIT>""" <EOL> ret = [ item for item in vqs ] <EOL> return json . dumps ( ret , indent = <NUM_LIT:4> ) </s>
