Esempio n. 1
0
def variant_json(variant_str):
    variant = orm.Variant(variant_id=variant_str, db=get_db())
    if session['user'] == 'demo':
        variant.__dict__['wt_samples'] = []
        variant.__dict__['het_samples'] = []
        variant.__dict__['hom_samples'] = []
    return jsonify(result=variant.__dict__)
Esempio n. 2
0
def common_rare_variants(individual, individual2, AC=1):
    pv = []
    s = subprocess.check_output([
        "bgt view -s," + individual + " -s," + individual2 + " -s 'name!=\"" +
        individual + "\"&&name!=\"" + individual2 +
        "\"' -f 'AC1>0&&AC2>0&&AC3<%s' " % AC +
        "-G /slms/gee/research/vyplab/UCLex/mainset_July2016/bgt/mainset_July2016.bgt"
    ],
                                shell=True)
    #bgt view -s,IRDC_batch6_LON_2055 -s,WebsterURMD_Sample_06G02870 -s 'name!="IRDC_batch6_LON_2055"&&name!="WebsterURMD_Sample_06G02870"' -f 'AC1>0&&AC2>0&&AC3==0' -G mainset_July2016_chr1.bgt
    for l in s.split('\n'):
        if len(l) < 5: continue
        if l.startswith('##'): continue
        if l.startswith('#'):
            headers = l.split('\t')
            continue
        d = dict(zip(headers, l.split('\t')))
        d.update(dict([x.split('=') for x in d['INFO'].split(';')]))
        del d['INFO']
        #d['variant_id']='-'.join([d['#CHROM'],d['POS'],d['REF'],d['ALT']])
        #pv.append(d)
        d['variant_id'] = '-'.join([d['#CHROM'], d['POS'], d['REF'], d['ALT']])
        try:
            var = orm.Variant(variant_id=d['variant_id'], db=get_db())
        except Exception, e:
            print(e)
            print(d)
            continue
        pv.append(var.__dict__)
Esempio n. 3
0
def variant_page(variant_str):
    try:
        variant = orm.Variant(variant_id=variant_str, db=get_db())
    except:
        return 'Variant does not exist'
    if not variant: return 'Variant does not exist'
    variant = variant.__dict__
    if session['user'] == 'demo':
        del variant['wt_samples']
        del variant['het_samples']
        del variant['hom_samples']
    return render_template('variant.html', title=variant_str, variant=variant)
Esempio n. 4
0
def put_variant(variant):
    """
    Add a new variant
    """
    vid = variant['id'] if 'id' in variant else None
    if vid is not None:
        if db_session.query(orm.Variant).filter(orm.Variant.id == vid).one_or_none():
            logging.info('Attempting to update existing variant %d..', vid)
            return NoContent, 405

    logging.info('Creating variant...')
    variant['created'] = datetime.datetime.utcnow()
    db_session.add(orm.Variant(**variant))
    db_session.commit()
    return NoContent, 201
Esempio n. 5
0
 def generate():
     for l in iter(proc.stdout.readline, ''):
         l = l.strip()
         print(l)
         if len(l) < 5: continue
         if l.startswith('##'): continue
         if l.startswith('#'):
             headers = l.split('\t')
             continue
         d = dict(zip(headers, l.split('\t')))
         d.update(dict([x.split('=') for x in d['INFO'].split(';')]))
         del d['INFO']
         if ',' in d['ALT']: d['ALT'] = d['ALT'].split(',')[0]
         d['variant_id'] = '-'.join(
             [d['#CHROM'], d['POS'], d['REF'], d['ALT']])
         try:
             var = orm.Variant(variant_id=d['variant_id'], db=get_db())
         except Exception, e:
             print(e)
             print(d)
             continue
         yield flask.json.dumps(var.__dict__) + '\n'
Esempio n. 6
0
def variant_json_db_new(variant_str):
    if session['user'] == 'demo': return ''
    variant = orm.Variant(variant_id=variant_str, db=get_db())
    return jsonify(result=variant.__dict__)