コード例 #1
0
def exercise(request):
    '''Get SNP data for an exercise.'''
    exercise = request.GET.get('exercise', None)

    # Defaults
    fields = '*'
    where_clause = ''
    db = 'interpretome_exercises'
    table = exercise

    # Supported exercises
    exercises = [
        'ashley_cad', 'tang_ancestry', 'altman_pgx', 'butte_diabetes',
        'assimes_cad', 'snyder_binding', 'class_writeups', 'mignot_narcolepsy',
        'kim_aging', 'eqtl', 'longevity', 'selection', 'neandertal'
    ]
    if exercise not in exercises:
        return http.HttpResponseBadRequest()

    # Set query parameters
    if exercise == 'longevity':
        where_clause = 'ORDER BY log10_bf DESC'
    elif exercise == 'selection':
        pop = request.REQUEST.get('population')
        where_clause = "WHERE pop = '%s' AND selected IS NOT NULL" % pop

    query = '''SELECT %(fields)s FROM %(db)s.%(table)s %(where)s
  ''' % {
        'fields': fields,
        'db': db,
        'table': table,
        'where': where_clause
    }

    # Get type of snp_dict
    cursor = connections['default'].dict_cursor()
    cursor.execute(query)
    snps = {}
    if exercise in ('snyder_binding'):
        result = cursor.fetchall()
        snps['snps'] = helpers.create_multi_snp_dict(result)
    else:
        result = cursor.fetchall()
        snps['snps'] = helpers.create_snp_dict(result)

    # Post-processing
    if exercise == 'longevity':
        snps['sorted_dbsnps'] = [e['dbsnp'] for e in result]

    return http.HttpResponse(simplejson.dumps(snps),
                             mimetype='application/json')
コード例 #2
0
ファイル: views.py プロジェクト: konradjk/Interpretome
def exercise(request):
  '''Get SNP data for an exercise.'''
  exercise = request.GET.get('exercise', None)
    
  # Defaults
  fields = '*'
  where_clause = ''
  db = 'interpretome_exercises'
  table = exercise
  
  # Supported exercises
  exercises = ['ashley_cad', 'tang_ancestry', 'altman_pgx', 'butte_diabetes',
               'assimes_cad', 'snyder_binding', 'class_writeups',
               'mignot_narcolepsy', 'kim_aging',
               'eqtl', 'longevity', 'selection', 'neandertal']
  if exercise not in exercises:
    return http.HttpResponseBadRequest()
  
  # Set query parameters
  if exercise == 'longevity':
    where_clause = 'ORDER BY log10_bf DESC'
  elif exercise == 'selection':
    pop = request.REQUEST.get('population')
    where_clause = "WHERE pop = '%s' AND selected IS NOT NULL" % pop
  
  query = '''SELECT %(fields)s FROM %(db)s.%(table)s %(where)s
  ''' % {'fields': fields, 'db': db, 'table': table, 'where': where_clause}
  
  # Get type of snp_dict
  cursor = connections['default'].dict_cursor()
  cursor.execute(query)
  snps = {}
  if exercise in ('snyder_binding'):
    result = cursor.fetchall()
    snps['snps'] = helpers.create_multi_snp_dict(result)
  else:
    result = cursor.fetchall()
    snps['snps'] = helpers.create_snp_dict(result)
  
  # Post-processing
  if exercise == 'longevity':
    snps['sorted_dbsnps'] = [e['dbsnp'] for e in result]
  
  return http.HttpResponse(simplejson.dumps(snps), mimetype = 'application/json')
コード例 #3
0
ファイル: views.py プロジェクト: konradjk/Interpretome
def get_individuals(request):
  numsnps = helpers.check_int(request.GET.get('numsnps', None))
  if numsnps is None:
    return http.HttpResponseBadRequest()
  individuals = helpers.sanitize(request.GET.get('individuals', None)).split(',')
  individual_select = set()
  for individual in individuals:
    if individual == '210-2011-staff':
      individual_select.update(['Konrad', 'Nick', 'Noah', 'Rob', 'Stuart'])
    else:
      individual_select.add(individual)
  if len(individual_select) == 0:
    return http.HttpResponseBadRequest()
  cursor = connections['default'].dict_cursor()
  query = '''
    SELECT dbsnp, %s FROM interpretome_ancestry.similarity LIMIT %s;
  ''' % (",".join([str(i) for i in individual_select]), numsnps)
  cursor.execute(query)
  output = helpers.create_snp_dict(cursor.fetchall())
  return http.HttpResponse(simplejson.dumps(output), mimetype = 'application/json')
コード例 #4
0
def get_individuals(request):
    numsnps = helpers.check_int(request.GET.get('numsnps', None))
    if numsnps is None:
        return http.HttpResponseBadRequest()
    individuals = helpers.sanitize(request.GET.get('individuals',
                                                   None)).split(',')
    individual_select = set()
    for individual in individuals:
        if individual == '210-2011-staff':
            individual_select.update(
                ['Konrad', 'Nick', 'Noah', 'Rob', 'Stuart'])
        else:
            individual_select.add(individual)
    if len(individual_select) == 0:
        return http.HttpResponseBadRequest()
    cursor = connections['default'].dict_cursor()
    query = '''
    SELECT dbsnp, %s FROM interpretome_ancestry.similarity LIMIT %s;
  ''' % (",".join([str(i) for i in individual_select]), numsnps)
    cursor.execute(query)
    output = helpers.create_snp_dict(cursor.fetchall())
    return http.HttpResponse(simplejson.dumps(output),
                             mimetype='application/json')