Exemplo n.º 1
0
 def write(self):
     if hasattr(self, 'result'):
         errors.directorymake(self.outdir)
         for rec in self.result:
             filename = fileIO.join_path(self.outdir, rec.name) + '.phy'
             rec.write_phylip(filename, interleaved=True)
         for i in range(self.num_classes):
             tree = self.class_trees[i+1]
             name = 'tree{0:0>{1}}.nwk'.format(i+1, len(str(self.num_classes)))
             filename = fileIO.join_path(self.outdir, name)
             tree.write_to_file(filename)
         filename = fileIO.join_path(self.outdir, 'true_partition.txt')
         with open(filename, 'w') as partition_file:
             partition_file.write(repr(self.true_partition))
Exemplo n.º 2
0
 def write(self):
     if hasattr(self, 'result'):
         errors.directorymake(self.outdir)
         for rec in self.result:
             filename = fileIO.join_path(self.outdir, rec.name) + '.phy'
             rec.write_phylip(filename, interleaved=True)
         for i in range(self.num_classes):
             tree = self.class_trees[i + 1]
             name = 'tree{0:0>{1}}.nwk'.format(i + 1,
                                               len(str(self.num_classes)))
             filename = fileIO.join_path(self.outdir, name)
             tree.write_to_file(filename)
         filename = fileIO.join_path(self.outdir, 'true_partition.txt')
         with open(filename, 'w') as partition_file:
             partition_file.write(repr(self.true_partition))
Exemplo n.º 3
0
 def make_alf_dirs(self):
     alf_dirs = {}
     for k in range(self.num_classes):
         dirname = fileIO.join_path(self.tmpdir,
                                    'class{0:0>1}'.format(k + 1))
         alf_dirs[k + 1] = errors.directorymake(dirname)
     self.alf_dirs = alf_dirs
Exemplo n.º 4
0
 def make_alf_dirs(self):
     alf_dirs = {}
     for k in range(self.num_classes):
         dirname = fileIO.join_path(self.tmpdir, 'class{0:0>1}'.format(
             k+1))
         alf_dirs[k+1] = errors.directorymake(dirname)
     self.alf_dirs = alf_dirs
Exemplo n.º 5
0
 def __init__(
     self,
     class_list,
     permutations_list,
     nspecies,
     tmpdir,
     datatype='protein',
     master_tree_generator_method='yule',
     master_tree=None,
     class_tree_permuter='nni',
     gene_length_kappa=1.7719,
     gene_length_theta=279.9,
     gene_length_min=10,
     outdir='./'
     ):
     # default
     errors.optioncheck(master_tree_generator_method, ['yule', 'coal',
                        'rtree', 'custom'])
     errors.optioncheck(class_tree_permuter, ['nni', 'spr', 'lgt', 'genetree'
                        ])
     if master_tree is None and master_tree_generator_method == 'custom':
         raise Exception('No custom tree was specified')
     self.num_classes = len(class_list)
     self.num_genes = sum(class_list)
     self.class_list = class_list
     if master_tree is None:
         tree = self.generate_master_tree(master_tree_generator_method,
                 nspecies)
         self.master_tree = tree
         self.num_species = nspecies
     else:
         self.master_tree = master_tree
         if len(master_tree) != nspecies:
             msg = [
                 'Warning: supplied tree has {0} taxa.'.format(
                     len(master_tree)),
                 'Required number is {0}.\n'.format(nspecies),
                 'Resetting number of species to match the supplied tree.'
             ]
             print ''.join(msg)
             self.num_species = nspecies
     self.set_gene_lengths(gene_length_kappa, gene_length_theta,
                           gene_length_min)
     self.permuter = class_tree_permuter
     self.permutations_list = permutations_list
     self.datatype = datatype
     self.tmpdir = errors.directorymake(tmpdir)
     self.outdir = outdir
     self.generate_class_trees() # sets self.class_trees dict
     self.make_alf_dirs() # sets self.alf_dirs dict
     self.write_alf_params() 
     self.get_true_partition()