Exemplo n.º 1
0
def add_variant(variant, db=None):
    global hotspot_name
    if db is None:
        client, db = mongo.get_connection()

    variants_coll = db[hotspot_name]

    final_qc_inc = 0
    cov_qc_inc = 0
    af_qc_inc = 0
    multi_allele_inc = 0

    if variant['FINAL_QC'] == 'PASS':
        final_qc_inc = 1
    if variant['COV_QC'] == 'PASS':
        cov_qc_inc = 1
    if variant['AF_QC'] == 'PASS':
        af_qc_inc = 1
    if variant['MULTI_ALLELE_QC'] == 'PASS':
        multi_allele_inc = 1

    wt_inc = 0
    het_alt_inc = 0
    het_inc = 0
    hom_inc = 0
    nocall_inc = 0

    zygos = genotypetools.get_zygosity(variant['GT_calc'])

    if 'NOCALL' in variant['FILTER']:
        nocall_inc = 1
    elif zygos == 'wt':
        wt_inc = 1
    elif zygos == 'het_alt':
        het_alt_inc = 1
    elif zygos == 'het':
        het_inc = 1
    elif zygos == 'hom':
        hom_inc = 1
    elif zygos == 'nocall':
        nocall_inc = 1

    entry = {'CHROM': variant['CHROM'], 'POS': variant['POS'], 'REF': variant['REF'], 'ALT': variant['ALT']}

    variants_coll.update_one(entry, {'$inc': {'orig_stats.qc.total_count': 1,
                                              'orig_stats.qc.final_qc_count': final_qc_inc,
                                              'orig_stats.qc.cov_qc_count': cov_qc_inc,
                                              'orig_stats.qc.af_qc_count': af_qc_inc,
                                              'orig_stats.qc.multi_allele_qc_count': multi_allele_inc,
                                              'orig_stats.zygosity.wt_count': wt_inc,
                                              'orig_stats.zygosity.het_count': het_inc,
                                              'orig_stats.zygosity.het_alt_count': het_alt_inc,
                                              'orig_stats.zygosity.hom_count': hom_inc,
                                              'orig_stats.zygosity.nocall_count': nocall_inc},
                                     '$addToSet': {'orig_samples': variant['SAMPLE']}},
                             upsert=True)

    if db is None:
        client.close()
Exemplo n.º 2
0
def add_new_sample(new_sample, db=None):
    if db is None:
        client, db = mongo.get_connection()

    sampleinfo_coll = db['sample_info']
    sampleinfo_coll.update_one(new_sample, {'$set': new_sample}, upsert=True)

    if db is None:
        client.close()
Exemplo n.º 3
0
def delete_sample(sample, db=None):
    if db is None:
        client, db = mongo.get_connection()

    sampleinfo_coll = db['sample_info']
    sampleinfo_coll.remove_one({"project_name": project_name, "SAMPLE": sample})

    if db is None:
        client.close()
Exemplo n.º 4
0
def get_sample_vars(sample, type, db=None):
    global variants_name
    if db is None:
        client, db = mongo.get_connection()

    variants_coll = db[variants_name]

    sample_vars = variants_coll.find({'TYPE': type, 'SAMPLE': sample})

    return sample_vars
Exemplo n.º 5
0
def count_samples(db=None):
    global variants_name
    if db is None:
        client, db = mongo.get_connection()

    variants_coll = db[variants_name]

    sample_vars = variants_coll.distinct('SAMPLE')

    return len(sample_vars)
Exemplo n.º 6
0
def add_variant(variant, db=None):
    global variants_name
    if db is None:
        client, db = mongo.get_connection()

    variants_coll = db[variants_name]
    variants_coll.insert(variant)

    if db is None:
        client.close()
Exemplo n.º 7
0
def drop_variants_index(db=None):
    global project_name, variants_name

    if db is None:
        client, db = mongo.get_connection()

    variants_coll = db[variants_name]
    variants_coll.drop_indexes()

    if db is None:
        client.close()
Exemplo n.º 8
0
def get_collection(db=None):
    global hotspot_name
    if db is None:
        client, db = mongo.get_connection()

    hotspot_coll = db[hotspot_name]

    if db is None:
        client.close()

    return hotspot_coll
Exemplo n.º 9
0
def get_collection(db=None):
    global variants_name
    if db is None:
        client, db = mongo.get_connection()

    variants_coll = db[variants_name]

    if db is None:
        client.close()

    return variants_coll
Exemplo n.º 10
0
def add_new_hist(number, db=None):
    global project_name

    if db is None:
        client, db = mongo.get_connection()

    new_hist = {"PROJECT": project_name, "NUMBER": number}
    hotspothist_coll = db['hotspot_history']
    hotspothist_coll.update_one(new_hist, {'$set': new_hist}, upsert=True)

    if db is None:
        client.close()
Exemplo n.º 11
0
def change_config_field(field, value, db=None):
    global project_name

    if db is None:
        client, db = mongo.get_connection()

    config_coll = db['configs']

    config_coll.update_one({'project_name': project_name}, {'$set': {field: value}})

    if db is None:
        client.close()
Exemplo n.º 12
0
def create_project_config(config, db=None):
    if db is None:
        client, db = mongo.get_connection()

    configs_coll = db['configs']

    configs_coll.replace_one(config, config, upsert=True)

    if db is None:
        client.close()

    return config
Exemplo n.º 13
0
def change_sample_field(sample, field, value, db=None):
    global project_name

    if db is None:
        client, db = mongo.get_connection()

    sample_info_coll = db['sample_info']

    sample_info_coll.update_one({'PROJECT': project_name, 'SAMPLE': sample}, {'$set': {field: value}})

    if db is None:
        client.close()
Exemplo n.º 14
0
def get_affected(sample_name, db=None):
    global project_name

    if db is None:
        client, db = mongo.get_connection()

    sample_info_coll = db['sample_info']
    info_doc = sample_info_coll.find_one({"project_name": project_name, "SAMPLE": sample_name})

    if db is None:
        client.close()

    return info_doc['AFFECTED']
Exemplo n.º 15
0
def index_hotspot(db=None):
    global project_name, hotspot_name

    index = [("CHROM", ASCENDING), ("POS", ASCENDING)]

    if db is None:
        client, db = mongo.get_connection()

    hotspot_coll = db[hotspot_name]
    hotspot_coll.create_index(index)

    if db is None:
        client.close()
Exemplo n.º 16
0
def get_next_number(db=None):
    global project_name

    if db is None:
        client, db = mongo.get_connection()

    hotspothist_coll = db['hotspot_history']
    total_count = hotspothist_coll.find({"PROJECT": project_name}).count()

    if db is None:
        client.close()

    return total_count + 1
Exemplo n.º 17
0
def get_variant(chrom, pos, ref, alt, db=None):
    global hotspot_name
    if db is None:
        client, db = mongo.get_connection()

    hotspot_coll = db[hotspot_name]

    hotspot = hotspot_coll.find_one({"CHROM": chrom, "POS": pos, "REF": ref, "ALT": alt})

    if db is None:
        client.close()

    return hotspot
Exemplo n.º 18
0
def index_variants(db=None):
    global project_name, variants_name

    index = [("TYPE", ASCENDING), ("CHROM", ASCENDING), ("POS", ASCENDING)]

    if db is None:
        client, db = mongo.get_connection()

    variants_coll = db[variants_name]
    variants_coll.create_index(index)

    if db is None:
        client.close()
Exemplo n.º 19
0
def is_fully_annotated(sample, db=None):
    global project_name

    if db is None:
        client, db = mongo.get_connection()

    proj_collection = db['sample_info']
    result = proj_collection.find_one({"PROJECT": project_name, "SAMPLE": sample})

    if "FULLY_ANNOTATED" in result.keys() and result['FULLY_ANNOTATED'] is True:
        return True
    else:
        return False
Exemplo n.º 20
0
def is_sample(sample, db=None):
    global project_name

    if db is None:
        client, db = mongo.get_connection()

    proj_collection = db['sample_info']
    result = proj_collection.find_one({"PROJECT": project_name, "SAMPLE": sample})

    if result is not None:
        return True
    else:
        return False
Exemplo n.º 21
0
def get_project_config(db=None):
    global project_name

    if db is None:
        client, db = mongo.get_connection()

    configs_coll = db['configs']

    project_config = configs_coll.find_one({'project_name': project_name})

    if db is None:
        client.close()

    return project_config
Exemplo n.º 22
0
def get_samples(db=None):
    if db is None:
        client, db = mongo.get_connection()

    sample_info = get_sample_info(db)

    samples = []
    for id in sample_info:
        samples.append(id)

    if db is None:
        client.close()

    return samples
Exemplo n.º 23
0
def get_hotspot_vars(db=None):
    global hotspot_name
    if db is None:
        client, db = mongo.get_connection()

    hotspot_coll = db[hotspot_name]

    sortby = [('CHROM', ASCENDING), ('POS', ASCENDING)]
    hotspot_cursor = hotspot_coll.find().sort(sortby)

    if db is None:
        client.close()

    return hotspot_cursor
Exemplo n.º 24
0
def has_loaded_hotspots(number, db=None):
    global project_name, variants_name
    if db is None:
        client, db = mongo.get_connection()

    variants_coll = db[variants_name]
    var_match = variants_coll.find_one({"PROJECT": project_name, "TYPE": "hotspot", "NUMBER": number})

    if db is None:
        client.close()

    if var_match is None:
        return False
    else:
        return True
Exemplo n.º 25
0
def is_hotspot_hist(number, db=None):
    global project_name

    if db is None:
        client, db = mongo.get_connection()

    hotspothist_coll = db['hotspot_history']
    hotspot_hist = hotspothist_coll.find_one({"PROJECT": project_name, "NUMBER": number})

    if db is None:
        client.close()

    if hotspot_hist is None:
        return False
    else:
        return True
Exemplo n.º 26
0
def save_annotation(chrom, pos, ref, alt, annotations, db=None):
    global hotspot_name
    if db is None:
        client, db = mongo.get_connection()

    hotspot_coll = db[hotspot_name]

    search = {'CHROM': chrom, 'POS': pos, 'REF': ref, 'ALT': alt}
    update = {'$set': {'ANNOTATION': annotations}}
    matched_count = hotspot_coll.update_one(search, update).matched_count

    if matched_count != 1:
        print 'Variant not found in hotspot'

    if db is None:
        client.close()
Exemplo n.º 27
0
def is_sample_loaded(sample, type, db=None):
    global variants_name
    if db is None:
        client, db = mongo.get_connection()

    variants_coll = db[variants_name]

    sample_var = variants_coll.find_one({'TYPE': type, 'SAMPLE': sample})

    if db is None:
        client.close()

    if sample_var is not None:
        return True
    else:
        return False
Exemplo n.º 28
0
def has_annotation(chrom, pos, ref, alt, db=None):
    global hotspot_name
    if db is None:
        client, db = mongo.get_connection()

    hotspot_coll = db[hotspot_name]

    hotspot = hotspot_coll.find_one({"CHROM": chrom, "POS": pos, "REF": ref, "ALT": alt})

    if db is None:
        client.close()

    if 'ANNOTATION' in hotspot.keys():
        return True
    else:
        return False
Exemplo n.º 29
0
def is_hotspot(chrom, pos, ref, alt, db=None):
    global hotspot_name
    if db is None:
        client, db = mongo.get_connection()

    query = {'CHROM': chrom, 'POS': pos, 'REF': ref, 'ALT': alt}
    hotspot_coll = db[hotspot_name]
    match = hotspot_coll.find_one(query)

    if db is None:
        client.close()

    if match:
        return True
    else:
        return False
Exemplo n.º 30
0
def has_sample_info(db=None):
    global project_name

    if db is None:
        client, db = mongo.get_connection()

    sample_info_coll = db['sample_info']
    info_doc = sample_info_coll.find_one({"PROJECT": project_name})

    if db is None:
        client.close()

    if info_doc is not None:
        return True
    else:
        return False