Пример #1
0
def create_datasets_list():
    if USE_REDIS:
        key = "all_datasets"
        result = Redis.get(key)

        if result:
            logger.debug("Redis cache hit")
            datasets = pickle.loads(result)

    if result is None:
        datasets = list()
        with Bench("Creating DataSets object"):
            type_dict = {'Publish': 'PublishFreeze',
                         'ProbeSet': 'ProbeSetFreeze',
                         'Geno': 'GenoFreeze'}

            for dataset_type in type_dict:
                query = "SELECT Name FROM {}".format(type_dict[dataset_type])
                for result in fetchall(query):
                    #The query at the beginning of this function isn't
                    #necessary here, but still would rather just reuse
                    #it logger.debug("type: {}\tname:
                    #{}".format(dataset_type, result.Name))
                    dataset = create_dataset(result.Name, dataset_type)
                    datasets.append(dataset)

        if USE_REDIS:
            Redis.set(key, pickle.dumps(datasets, pickle.HIGHEST_PROTOCOL))
            Redis.expire(key, 60*60)

    return datasets
Пример #2
0
def create_datasets_list():
    if USE_REDIS:
        key = "all_datasets"
        result = Redis.get(key)

        if result:
            logger.debug("Redis cache hit")
            datasets = pickle.loads(result)

    if result is None:
        datasets = list()
        with Bench("Creating DataSets object"):
            type_dict = {'Publish': 'PublishFreeze',
                         'ProbeSet': 'ProbeSetFreeze',
                         'Geno': 'GenoFreeze'}

            for dataset_type in type_dict:
                query = "SELECT Name FROM {}".format(type_dict[dataset_type])
                for result in fetchall(query):
                    #The query at the beginning of this function isn't
                    #necessary here, but still would rather just reuse
                    #it logger.debug("type: {}\tname:
                    #{}".format(dataset_type, result.Name))
                    dataset = create_dataset(result.Name, dataset_type)
                    datasets.append(dataset)

        if USE_REDIS:
            Redis.set(key, pickle.dumps(datasets, pickle.HIGHEST_PROTOCOL))
            Redis.expire(key, 60*60)

    return datasets
Пример #3
0
def datasets(group_name, this_group = None):
    key = "group_dataset_menu:v2:" + group_name
    logger.debug("key is2:", key)
    dataset_menu = []
    logger.debug("[tape4] webqtlConfig.PUBLICTHRESH:", webqtlConfig.PUBLICTHRESH)
    logger.debug("[tape4] type webqtlConfig.PUBLICTHRESH:", type(webqtlConfig.PUBLICTHRESH))
    the_results = fetchall('''
         (SELECT '#PublishFreeze',PublishFreeze.FullName,PublishFreeze.Name
          FROM PublishFreeze,InbredSet
          WHERE PublishFreeze.InbredSetId = InbredSet.Id
            and InbredSet.Name = '%s'
            and PublishFreeze.public > %s)
         UNION
         (SELECT '#GenoFreeze',GenoFreeze.FullName,GenoFreeze.Name
          FROM GenoFreeze, InbredSet
          WHERE GenoFreeze.InbredSetId = InbredSet.Id
            and InbredSet.Name = '%s'
            and GenoFreeze.public > %s)
         UNION
         (SELECT Tissue.Name, ProbeSetFreeze.FullName,ProbeSetFreeze.Name
          FROM ProbeSetFreeze, ProbeFreeze, InbredSet, Tissue
          WHERE ProbeSetFreeze.ProbeFreezeId = ProbeFreeze.Id
            and ProbeFreeze.TissueId = Tissue.Id
            and ProbeFreeze.InbredSetId = InbredSet.Id
            and InbredSet.Name like %s
            and ProbeSetFreeze.public > %s
          ORDER BY Tissue.Name, ProbeSetFreeze.CreateTime desc, ProbeSetFreeze.AvgId)
        ''' % (group_name, webqtlConfig.PUBLICTHRESH,
              group_name, webqtlConfig.PUBLICTHRESH,
              "'" + group_name + "'", webqtlConfig.PUBLICTHRESH))

    #for tissue_name, dataset in itertools.groupby(the_results, itemgetter(0)):
    for dataset_item in the_results:
        tissue_name = dataset_item[0]
        dataset = dataset_item[1]
        dataset_short = dataset_item[2]
        if tissue_name in ['#PublishFreeze', '#GenoFreeze']:
            dataset_menu.append(dict(tissue=None, datasets=[(dataset, dataset_short)]))
        else:
            dataset_sub_menu = [item[1:] for item in dataset]

            tissue_already_exists = False
            tissue_position = None
            for i, tissue_dict in enumerate(dataset_menu):
                if tissue_dict['tissue'] == tissue_name:
                    tissue_already_exists = True
                    tissue_position = i
                    break

            if tissue_already_exists:
                #logger.debug("dataset_menu:", dataset_menu[i]['datasets'])
                dataset_menu[i]['datasets'].append((dataset, dataset_short))
            else:
                dataset_menu.append(dict(tissue=tissue_name,
                                    datasets=[(dataset, dataset_short)]))

    if USE_REDIS:
        Redis.set(key, pickle.dumps(dataset_menu, pickle.HIGHEST_PROTOCOL))
        Redis.expire(key, 60*5)

    if this_group != None:
        this_group._datasets = dataset_menu
        return this_group._datasets
    else:
        return dataset_menu
Пример #4
0
def datasets(group_name, this_group = None):
    key = "group_dataset_menu:v2:" + group_name
    logger.debug("key is2:", key)
    dataset_menu = []
    logger.debug("[tape4] webqtlConfig.PUBLICTHRESH:", webqtlConfig.PUBLICTHRESH)
    logger.debug("[tape4] type webqtlConfig.PUBLICTHRESH:", type(webqtlConfig.PUBLICTHRESH))
    the_results = fetchall('''
         (SELECT '#PublishFreeze',PublishFreeze.FullName,PublishFreeze.Name
          FROM PublishFreeze,InbredSet
          WHERE PublishFreeze.InbredSetId = InbredSet.Id
            and InbredSet.Name = '%s'
            and PublishFreeze.public > %s
            and PublishFreeze.confidentiality < 1)
         UNION
         (SELECT '#GenoFreeze',GenoFreeze.FullName,GenoFreeze.Name
          FROM GenoFreeze, InbredSet
          WHERE GenoFreeze.InbredSetId = InbredSet.Id
            and InbredSet.Name = '%s'
            and GenoFreeze.public > %s
            and GenoFreeze.confidentiality < 1)
         UNION
         (SELECT Tissue.Name, ProbeSetFreeze.FullName,ProbeSetFreeze.Name
          FROM ProbeSetFreeze, ProbeFreeze, InbredSet, Tissue
          WHERE ProbeSetFreeze.ProbeFreezeId = ProbeFreeze.Id
            and ProbeFreeze.TissueId = Tissue.Id
            and ProbeFreeze.InbredSetId = InbredSet.Id
            and InbredSet.Name like %s
            and ProbeSetFreeze.public > %s
            and ProbeSetFreeze.confidentiality < 1
          ORDER BY Tissue.Name, ProbeSetFreeze.CreateTime desc, ProbeSetFreeze.AvgId)
        ''' % (group_name, webqtlConfig.PUBLICTHRESH,
              group_name, webqtlConfig.PUBLICTHRESH,
              "'" + group_name + "'", webqtlConfig.PUBLICTHRESH))

    #for tissue_name, dataset in itertools.groupby(the_results, itemgetter(0)):
    for dataset_item in the_results:
        tissue_name = dataset_item[0]
        dataset = dataset_item[1]
        dataset_short = dataset_item[2]
        if tissue_name in ['#PublishFreeze', '#GenoFreeze']:
            dataset_menu.append(dict(tissue=None, datasets=[(dataset, dataset_short)]))
        else:
            dataset_sub_menu = [item[1:] for item in dataset]

            tissue_already_exists = False
            tissue_position = None
            for i, tissue_dict in enumerate(dataset_menu):
                if tissue_dict['tissue'] == tissue_name:
                    tissue_already_exists = True
                    tissue_position = i
                    break

            if tissue_already_exists:
                #logger.debug("dataset_menu:", dataset_menu[i]['datasets'])
                dataset_menu[i]['datasets'].append((dataset, dataset_short))
            else:
                dataset_menu.append(dict(tissue=tissue_name,
                                    datasets=[(dataset, dataset_short)]))

    if USE_REDIS:
        Redis.set(key, pickle.dumps(dataset_menu, pickle.HIGHEST_PROTOCOL))
        Redis.expire(key, 60*5)

    if this_group != None:
        this_group._datasets = dataset_menu
        return this_group._datasets
    else:
        return dataset_menu
Пример #5
0
def datasets(group_name, this_group=None):
    key = "group_dataset_menu:v2:" + group_name
    logger.debug("key is2:", key)
    dataset_menu = []
    logger.debug("[tape4] webqtlConfig.PUBLICTHRESH:",
                 webqtlConfig.PUBLICTHRESH)
    logger.debug("[tape4] type webqtlConfig.PUBLICTHRESH:",
                 type(webqtlConfig.PUBLICTHRESH))
    the_results = fetchall('''
         (SELECT '#PublishFreeze',PublishFreeze.FullName,PublishFreeze.Name
          FROM PublishFreeze,InbredSet
          WHERE PublishFreeze.InbredSetId = InbredSet.Id
            and InbredSet.Name = '%s'
            and PublishFreeze.public > %s
            and PublishFreeze.confidentiality < 1
          ORDER BY PublishFreeze.Id ASC)
         UNION
         (SELECT '#GenoFreeze',GenoFreeze.FullName,GenoFreeze.Name
          FROM GenoFreeze, InbredSet
          WHERE GenoFreeze.InbredSetId = InbredSet.Id
            and InbredSet.Name = '%s'
            and GenoFreeze.public > %s
            and GenoFreeze.confidentiality < 1)
         UNION
         (SELECT Tissue.Name, ProbeSetFreeze.FullName,ProbeSetFreeze.Name
          FROM ProbeSetFreeze, ProbeFreeze, InbredSet, Tissue
          WHERE ProbeSetFreeze.ProbeFreezeId = ProbeFreeze.Id
            and ProbeFreeze.TissueId = Tissue.Id
            and ProbeFreeze.InbredSetId = InbredSet.Id
            and InbredSet.Name like %s
            and ProbeSetFreeze.public > %s
            and ProbeSetFreeze.confidentiality < 1
          ORDER BY Tissue.Name, ProbeSetFreeze.OrderList DESC)
        ''' % (group_name, webqtlConfig.PUBLICTHRESH, group_name,
               webqtlConfig.PUBLICTHRESH, "'" + group_name + "'",
               webqtlConfig.PUBLICTHRESH))

    sorted_results = sorted(the_results, key=lambda kv: kv[0])

    pheno_inserted = False  #ZS: This is kind of awkward, but need to ensure Phenotypes show up before Genotypes in dropdown
    geno_inserted = False
    for dataset_item in sorted_results:
        tissue_name = dataset_item[0]
        dataset = dataset_item[1]
        dataset_short = dataset_item[2]
        if tissue_name in ['#PublishFreeze', '#GenoFreeze']:
            if tissue_name == '#PublishFreeze' and (dataset_short
                                                    == group_name + 'Publish'):
                dataset_menu.insert(
                    0, dict(tissue=None, datasets=[(dataset, dataset_short)]))
                pheno_inserted = True
            elif pheno_inserted and tissue_name == '#GenoFreeze':
                dataset_menu.insert(
                    1, dict(tissue=None, datasets=[(dataset, dataset_short)]))
                geno_inserted = True
            else:
                dataset_menu.append(
                    dict(tissue=None, datasets=[(dataset, dataset_short)]))
        else:
            tissue_already_exists = False
            for i, tissue_dict in enumerate(dataset_menu):
                if tissue_dict['tissue'] == tissue_name:
                    tissue_already_exists = True
                    break

            if tissue_already_exists:
                #logger.debug("dataset_menu:", dataset_menu[i]['datasets'])
                dataset_menu[i]['datasets'].append((dataset, dataset_short))
            else:
                dataset_menu.append(
                    dict(tissue=tissue_name,
                         datasets=[(dataset, dataset_short)]))

    if USE_REDIS:
        Redis.set(key, pickle.dumps(dataset_menu, pickle.HIGHEST_PROTOCOL))
        Redis.expire(key, 60 * 5)

    if this_group != None:
        this_group._datasets = dataset_menu
        return this_group._datasets
    else:
        return dataset_menu