Example #1
0
 def data_for_heatmap(self, request):
     """ Get hitmap data. Parameters need to be included in the filters. Check the FAQ for details on the filters."""
         # Usage: chrom = indicate the chromosome(s) of interest ('all' or any chromosome),
         #     region_width = indicate the size of the bins for which to count hits,
         #     threshold = indicate the type of threshold to look at (FDR, Bonferroni, permutation or none, default='FDR')
         #     region = indicate a specific window in which to aggregate for, default = ('','') looks at entire chromosome
         #     maf = indicate a minimum maf (default=0)
         #     mac = indicate a minimum mac (default=0)
     # Load studies from regular db
     recompute = request.query_params.getlist('recompute')
     if recompute == []:
         # import requests
         file_name = "%s/heatmap_data.json" % (settings.HDF5_FILE_PATH)
     #     url = 'https://gist.githubusercontent.com/mtog/95d29b45e0f58e5c11dc61818f4c57fb/raw/b5bf20b80d168e6d3a3a261e204c34a97c72ba5b/pre_loaded_heatmap_data.json'
     #     return Response(requests.get(url).json())
         import json
         with open(file_name) as data_file: # There seems to be a displaying problem when loading from file: the histograms are loaded and displayed twice
             data = json.load(data_file)
         return Response(data)
     studies = Study.objects.all()
     studies_data = []
     for study in studies:
         studies_data.append(
             {'id': study.id, 'name': study.phenotype.name})  # For now only add phenotype name for shorted strings
     # get the rest of the data
     filters = dict()
     # Get region params for zoomed regions...
     filters['chrom'] = request.query_params.get('chromosome')
     region = request.query_params.getlist('region')
     filters['region']=(int(region[0]),int(region[1]))
     filters['region_width'] = request.query_params.get('regionwidth')
     results = elastic.get_gwas_overview_heatmap_data(filters, len(studies))
     results['studies'] = studies_data
     return Response(results)
Example #2
0
def generate_hitmap_json():
    studies = Study.objects.all()
    studies_data = []
    for study in studies:
        studies_data.append(
            {'id': study.id, 'name': study.phenotype.name})  # For now only add phenotype name for shorted strings
    filters = dict()
    results = elastic.get_gwas_overview_heatmap_data(filters)
    results['studies'] = studies_data
    file_name = "%s/heatmap_data.json" % (settings.HDF5_FILE_PATH)
    with open(file_name, 'w') as out_file:
        json.dump(results, out_file)
Example #3
0
def generate_hitmap_json():
    abs_filename = os.path.join(settings.HDF5_FILE_PATH,"heatmap_data.json")
    if not _check_modifed(abs_filename):
        logger.info('Hitmap already up2date. Skipping generation')
        return
    Path('%s.run' % abs_filename).touch()
    studies = Study.objects.all()
    studies_data = []
    for study in studies:
        studies_data.append(
            {'id': study.id, 'name': study.phenotype.name})  # For now only add phenotype name for shorted strings
    num_studies = len(studies)
    filters = dict()
    results = elastic.get_gwas_overview_heatmap_data(filters, num_studies)
    results['studies'] = studies_data
    with open('%s.tmp' % abs_filename, 'w') as out_file:
        json.dump(results, out_file)
    os.rename('%s.tmp' % abs_filename, abs_filename)
    logger.info('Finished generating hitmap')