Ejemplo n.º 1
0
def main():
    options = interface()
    array_alignments = make_align_list(options.input_dir, options.input_file_format)
    
    # DO BOOTSTRAPPING AND WRITE REPLICATES TO OUTFILES
    # options.bootstrap_reps += 1
    boot_alignments = phylo.bootstrap(array_alignments, options.bootstrap_reps)
    bootstrapped_datasets = []
    for rep_count, boot_rep in enumerate(boot_alignments):
        boot_bases = []
        
        # setup outfile names (make into function?)
        if options.output_file_format == 'nexus':
            fname = 'bootrep_%s.nex' % rep_count
        if options.output_file_format == 'phylip':
            fname = 'bootrep_%s.phylip' % rep_count
        final_path = os.path.join(options.output_dir,fname)
        fout = open(final_path,'a')
    
        for count, align in enumerate(boot_rep):
            seqs = copy(align[0])                               # lots of copying to be 'safe'
            ids = copy(align[1])
            bases_by_col = np.column_stack(seqs)                # flip rows and columns
            bs_bases = phylo.bootstrap(bases_by_col, 1)         # bootstrap the bases within the bootstrapped alignments
            bs_bases = np.column_stack(bs_bases[0])             # [0] corrects weirdnesss due to extra set of brackets
            bs_bases = bs_bases.copy()                          # copy modified replicate
            pair = [bs_bases, ids]                              
            biopy_align = [strarray2biopy(pair)]
            AlignIO.write(biopy_align, fout, options.output_file_format)
            fout.write('\n')
        
        fout.close()
Ejemplo n.º 2
0
def main():
    options = interface()

    alignment = open(options.input_file, "r")
    alignment = AlignIO.read(alignment, "nexus")
    numpy_alignment = biopy2strarray(alignment)

    max_reps = options.bootstrap_reps + 1
    rep = 1
    while rep != max_reps:
        fout_name = os.path.join(options.output_dir, "bootrep_%s")
        fout_name = fout_name + "." + options.output_file_format
        fout_name = fout_name % rep
        fout = open(fout_name, "w")
        seqs = copy(numpy_alignment[0])  # lots of copying to be 'safe'
        ids = copy(numpy_alignment[1])
        bases_by_col = np.column_stack(seqs)  # flip rows and columns
        bs_bases = phylo.bootstrap(bases_by_col, 1)  # bootstrap the bases within the bootstrapped alignments
        bs_bases = np.column_stack(bs_bases[0])  # [0] corrects weirdnesss due to extra set of brackets
        bs_bases = bs_bases.copy()  # copy modified replicate
        pair = [bs_bases, ids]
        biopy_align = [strarray2biopy(pair)]
        AlignIO.write(biopy_align, fout, options.output_file_format)
        fout.write("\n")
        fout.close()
        print "Made boostrap replicate %s" % rep
        rep += 1