Exemplo n.º 1
0
def switch_alleles_loop(mappable, family, parent, starting_map, NR_matrix_threshold, reps, MST_grouping_threshold = .0000001, map_type = 'mst', MST_exe = MST_exe):    
    for xx in range(reps):
        ini_map, sq_sum_lod, sq_NR_matrix, R, NR, lgs_longer_than_1 = switchAlleles.calculate_switch_stats(mappable, starting_map, 'mst', MST_grouping_threshold)
        where_pairs = numpy.where(sq_NR_matrix > NR_matrix_threshold)
        LGs_to_switch = switchAlleles.find_LGs_to_switch(lgs_longer_than_1, where_pairs)
        loci_to_switch = switchAlleles.find_loci_to_switch(ini_map, LGs_to_switch)
        switched_alleles_file = '/olympus/WORK/WAPLES/Stacks_mapping/Chum_data/mst/switched_alleles_{}_iter{}.txt'.format(family, xx)
        switchAlleles.update_switched_alleles_file(switched_alleles_file, loci_to_switch)
        mappable = switchAlleles.switch_alleles(loci_to_switch, mappable)
        if len(loci_to_switch) == 0:
            print("found zero loci to switch, ending loop")
            break
        print("Starting MSTmap on family: {}, rep: {}".format(family, xx))
        #run MSTmap
        MSTmap_infile = '/olympus/WORK/WAPLES/Stacks_mapping/Chum_data/mst/chum_{}_iter{}_mstmap.txt'.format(family, xx)
        MSTmap_logfile = '/olympus/WORK/WAPLES/Stacks_mapping/Chum_data/mst/chum_{}_iter{}_mstmap.log'.format(family, xx)
        out_linkage_map_file = '/olympus/WORK/WAPLES/Stacks_mapping/Chum_data/mst/chum_{}_iter{}_mstmap.map'.format(family, xx)
        chum_fams.write_mstmap(parent, MSTmap_infile, mappable)
        run_MSTmap(MST_exe = MST_exe, INFILE = MSTmap_infile, OUTFILE = out_linkage_map_file, LOGFILE = MSTmap_logfile)
        print("Finished MSTmap on family: {}, rep: {}".format(family, xx))
        #renew name
        starting_map = out_linkage_map_file
Exemplo n.º 2
0
with open("/olympus/WORK/WAPLES/Stacks_mapping/Chum_data/mst/switched_alleles_09_iter0.txt") as INFILE:
    for line in INFILE:
        to_switch_09.append(line.strip())


mappable_01 = switchAlleles.switch_alleles(to_switch_01, mappable_01)
mappable_08 = switchAlleles.switch_alleles(to_switch_08, mappable_08)
mappable_09 = switchAlleles.switch_alleles(to_switch_09, mappable_09)



################################


# Calculate some summary stats from the existing recent linkage map
ini_map, sq_sum_lod, sq_NR_matrix, R, NR, lgs_longer_than_1 = switchAlleles.calculate_switch_stats(mappable, in_linkage_map_file, 'mst')
# Determine which pairs of LGs are potential switches
# Perhaps come up with a way to estiamte NR_threshold here.
where_pairs = numpy.where(sq_NR_matrix > NR_matrix_threshold)
# Determines which LGs and loci to switch 
LGs_to_switch = switchAlleles.find_LGs_to_switch(lgs_longer_than_1, where_pairs)
loci_to_switch = switchAlleles.find_loci_to_switch(ini_map, LGs_to_switch)
# updates switched alleles file
switched_alleles_file = '/olympus/WORK/WAPLES/Stacks_mapping/Chum_data/mst/switched_alleles_08_iter{}.txt'.format(xx)
switchAlleles.update_switched_alleles_file(switched_alleles_file, loci_to_switch)
# updates mappapble
mappable = switchAlleles.switch_alleles(loci_to_switch, mappable)
#run MSTmap
MSTmap_infile = '/home/ipseg/Data/chum/data/chum_08_iter{}_mstmap.txt'.format(xx)
MSTmap_logfile = '/home/ipseg/Data/chum/data/chum_08_iter{}_mstmap.log'.format(xx)
out_linkage_map_file = '/home/ipseg/Data/chum/data/chum_08_iter{}_mstmap.map'.format(xx)