def main(argv):
    out_folder = '/home/jkb4y/cphgdesk_share/Yan/UBASH3A'
    eurmeta_out = os.path.join(out_folder, 'eurmeta_UBASH3A_122112.txt')
    eurmeta_in = '/home/jkb4y/work/data/2012Feb1/eurmeta_Oct2012/eurmeta_lz_hg19_intersect.tbl'
    eurmeta_dict, thing = pc_toolbox.create_index_dict(eurmeta_in, 'meta')
    family_out = os.path.join(out_folder, 'eurgdtscan_UBASH3A_122112.txt')
    family_in = '/home/jkb4y/work/data/2012Feb1/Family_Nov2012/eurgdtscan_lz_hg19_intersect.txt'
    family_dict, thing = pc_toolbox.create_index_dict(family_in, 'family')
    region_loc ='/home/jkb4y/work/data/Region_Lists/hg19/T1D_regions_hg19_09202012.txt'
    region_list = pc_toolbox.create_bp_region_list(region_loc)
    for region in region_list:
        if region.ID == '21q22.3_a':
            print region
            filter_by_region(region, eurmeta_in,eurmeta_out, eurmeta_dict)
            filter_by_region(region, family_in, family_out, family_dict)
def main():
    build = 'hg19'
    table_loc = '/home/jkb4y/ubs/work/results/July2012/Logistic_pc8/AA_8.assoc.logistic'
    
    annot_dict = pc_toolbox.create_annot_dict(build,'LOG')
    base, ext = os.path.splitext(table_loc)
    base2, ext2 = os.path.splitext(base)
    new_loc = base2 + '_lz'+ext2+ext
    index_dict, line = pc_toolbox.create_index_dict(table_loc,'assoc')
    pc_toolbox.give_table_annotation(table_loc,new_loc,index_dict,annot_dict)
def main(argv):
    global table_type, region_loc, cell_type, table_loc, perm, build, population
    build = 'hg19'
    cis = True
    population = 'EUR'
    region_loc = '/home/jkb4y/work/data/Region_Lists/hg19/T1D_regions_hg19_05242012_extra.5MB.txt'
    prelude_base = '/home/jkb4y/h4t1/programs/achilleas_plots/gene_prelude.R'
    cell_type = "CD8"
    postlude_folder= '/home/jkb4y/h4t1/programs/achilleas_plots/postludes'
    tablefold = '/home/jkb4y/ubs/work/data/Achilleas/cis-eQTL/'
    table_loc = os.path.join(tablefold,'{0}_cis_eqtls_permwBP_JB_LZ.txt'.format(cell_type))
    table_type = 'perm'
    index_dict, thing = pc_toolbox.create_index_dict(table_loc, table_type)
    perm = True
    achilleas_cell_results = "/home/jkb4y/ubs/work/results/Achilleas/hg19/{0}".format(cell_type)
    genefolder = os.path.join(achilleas_cell_results,'GeneLists')
    base_outfolder = os.path.join(achilleas_cell_results, 'PerGene')
    if not os.path.exists(base_outfolder):
        os.makedirs(base_outfolder)
    regions = pc_toolbox.create_bp_region_list(region_loc)
    for region in regions:
        ID = region.ID
        band = region.band
        outfolder = os.path.join(base_outfolder, ID)
        if not os.path.exists(outfolder):
            os.makedirs(outfolder)
        os.chdir(outfolder)
        region_genefolder = os.path.join(genefolder, ID)
        genelist = os.path.join(region_genefolder, ID+'_genes.list')
        genes = read_list(genelist)
        for gene in genes:
##                outfolder = os.path.join(base_outfolder, region.ID)
##                if not os.path.exists(outfolder):
##                    os.makedirs(outfolder)
            refsnp_loc = os.path.join(region_genefolder, gene + '_ref.txt')
            refsnp = read_single(refsnp_loc)
            gene_prelude = locate_prelude(outfolder, gene, cell_type, ID)
            cell_postlude = None#locate_postlude(cell_type, postlude_folder)
            write_prelude(prelude_base, gene, gene_prelude)
            graph_title = create_title(cell_type, ID, gene)
            prefix = create_prefix(cell_type, band, gene, perm, cis)
##                os.chdir(outfolder)
            locuszoom(table_loc, region,graph_title, index_dict, outfolder,
                      refsnp, prefix, gene_prelude, cell_postlude)
        os.chdir(base_outfolder)
        try:
            os.rmdir(outfolder)
        except OSError:
            pass
def main(argv):
    global out_base, freq_loc, table_loc, bfile, table_type
    global covar_loc, annot, weight_min, build, region_loc, pop, aa_freq_loc
    cl_arguments(argv)
    zlist = list()
    index_dict, input_title_line = pc_toolbox.create_index_dict(table_loc, table_type)
    region_list = pc_toolbox.create_region_list(region_loc)
    annot_dict = create_annot_dict(build, 'LOG')
    out_file = out_base + '_yank.tbl'
    output_title_line = create_output_title_line(table_type, input_title_line)
    with open(out_file, mode="w") as out_text:
##        title_line = '\t'.join(META_TITLE_LIST)
        out_text.write(output_title_line +'\n')
        for region in region_list:
            print zlist
            sig_line, zlist, multicounter = read_table(table_loc, index_dict, region, weight_min, table_type, annot_dict, zlist)
            info = document_result(sig_line, region, index_dict, table_type,annot_dict, multicounter)
            if table_type == 'assoc':
                if pop == 'AA':
                    for item in AA_ASSOC_ORDER_LIST:
                        out_text.write(str(info[item]) + '\t')
                if pop == 'UK':
                    for item in ASSOC_ORDER_LIST:
                        out_text.write(str(info[item]) + '\t')
                
##            if table_type in ['perm']:
##                out_list = sig_line.strip().split()
##                out_list.append(info['note'])
##                out_list.append(info['band'])
##                out_list.append(info['ID'])
##                out_text.write('\t'.join(out_list))
            if table_type in ['meta','family']:
                for item in META_ORDER_LIST:
                    out_text.write(str(info[item]) + '\t')
            if table_type =='perm':
                for item in PERM_ORDER_LIST:
                    out_text.write(str(info[item]) + '\t')
            out_text.write('\n')
    if table_type in ['meta','family']:
        repair_meta_for_lz(zlist, table_loc, index_dict, weight_min)