Exemplo n.º 1
0
def get_expr_info():
    if request.method == 'POST':
        info = request.form['info']
        info = json.loads(info)
        table = info['table']
        map_groupA = info['groupA']
        map_groupB = info['groupB']
        groupA = map_sample(map_groupA, map_dict=web2db_dict)
        groupB = map_sample(map_groupB, map_dict=web2db_dict)
        gene_str = info['gene_name']
        gene_ids = re.split(r'[\s,]', gene_str.strip())
        if len(gene_ids) > 10:
            return jsonify({'msg': 'query gene number not allowed > 10'})
        query_header, query_data = get_expr_table(table, gene_ids, groupA,
                                                  groupB, map_groupA,
                                                  map_groupB)
        if not query_data:
            return jsonify(
                {'msg': 'not search {0} in database!'.format(query_header)})

        return jsonify({
            'msg': 'ok',
            'headData': query_header,
            'bodyData': query_data
        })
Exemplo n.º 2
0
def test_mapSample():
    db2web_dict, web2db_dict = get_map()
    samples = get_samples_by_table(table='snp_mRNA_table', type='snp')
    test_web_sets = ['159_9_CS_P_2', '196_2_D_P', 'W3_14LL']
    test_db_sets = 'G097_0204_32bei1'
    web_samples = map_sample(samples, db2web_dict)
    db_samples = map_sample(test_web_sets, web2db_dict)
    assert test_db_sets in db_samples
    assert random.choice(test_web_sets) in web_samples
Exemplo n.º 3
0
def select_file_by_plot():
    filename = request.args.get('file', '')
    if filename:
        samples = get_samples_by_table(filename, type='snp')
        samples = map_sample(samples, db2web_dict)
        if not samples:
            return jsonify({'msg': 'error'})
        return jsonify({'msg': samples})
    return jsonify({'msg': 'error'})
Exemplo n.º 4
0
def generate_snp_plot():
    if request.method == 'POST':
        info = json.loads(request.form['info'])
        table = info['table']
        groupA = map_sample(info['groupA'], map_dict=web2db_dict)
        groupB = map_sample(info['groupB'], map_dict=web2db_dict)
        groupA_name = info['customGroupA']
        groupB_name = info['customGroupB']
        chrom = info['chrom']
        filename = "%svs%s" % (groupA_name, groupB_name)
        cmd, groupA_len, groupB_len = get_cmd_by_regin(table,
                                                       groupA,
                                                       groupB,
                                                       chrom=chrom,
                                                       get_all=True)
        query_data = calculate_table(cmd,
                                     groupA_len,
                                     groupB_len,
                                     filename,
                                     output=True,
                                     chrom=chrom)
        msg = run_snpplot_script(
            filepath=os.path.join(SNP_INDEX_PATH,
                                  '_'.join([groupA_name,
                                            groupB_name]), query_data),
            outdir=os.path.join(
                SNP_INDEX_PATH, '_'.join([groupA_name, groupB_name]),
                'vs'.join([groupA_name, groupB_name]) + '_plot'))
        files = glob.glob(
            os.path.join(SNP_INDEX_PATH, '_'.join([groupA_name, groupB_name]),
                         'vs'.join([groupA_name, groupB_name]) + '_plot') +
            '/*png')
        files_short = [each.rsplit('/', 1)[1] for each in files]

        path = os.path.join(RENDER_PATH, '_'.join([groupA_name, groupB_name]),
                            'vs'.join([groupA_name, groupB_name]) + '_plot')

        return jsonify({
            'msg':
            query_data,
            'name':
            'vs'.join([groupA_name, groupB_name]),
            'files': [os.path.join(path, each) for each in files_short]
        })