Esempio n. 1
0
def main():
    args = sys.argv[1:]

    if len(args) < 1:
        logging.warning('Usage: python <filename> <function> <parameters..>')

    elif args[0] == 'init':
        init()

    elif args[0] == 'add':

        data_to_copy_path = args[1]
        add(data_to_copy_path)

    elif args[0] == 'commit':
        message = args[1]
        commit(message)

    elif args[0] == 'status':
        status()

    elif args[0] == 'checkout':
        commit_id = args[1]
        checkout(commit_id)

    elif args[0] == 'graph':
        graph()

    elif args[0] == 'branch':
        branch_name = args[1]
        branch(branch_name)

    elif args[0] == 'merge':
        branch_name = args[1]
        merge()
Esempio n. 2
0
    def rootify(self,center_branch):

	# remember the old branch:
	self.root_branch = center_branch

	# create a new node
	center_name = center_branch.ends[0].name
	center_name += "-" + center_branch.ends[1].name
	center_node = node.node(center_name,self)
	self.root = center_node
	
	# give it children branches
	child1 = branch.branch(center_branch.length/2)
	child1.addNode(center_node)
	child1.addNode(center_branch.ends[0])
	child2 = branch.branch(center_branch.length/2)
	child2.addNode(center_node)
	child2.addNode(center_branch.ends[1])
	center_node.child_branches.append(child1)
	center_node.child_branches.append(child2)

	# erase the original branch from the child nodes branch_list
	for kids in center_branch.ends:
	    kids.branch_list.remove(center_branch)

	# impose a hierarchy from the root
	center_node.imposeHierarchy()
        self.labelSubtrees()
        self.Get_Subnodes()
        self.root.Fill_Node_Dict()
Esempio n. 3
0
    def rootify(self, center_branch):

        # remember the old branch:
        self.root_branch = center_branch

        # create a new node
        center_name = center_branch.ends[0].name
        center_name += "-" + center_branch.ends[1].name
        center_node = node.node(center_name, self)
        self.root = center_node

        # give it children branches
        child1 = branch.branch(center_branch.length / 2)
        child1.addNode(center_node)
        child1.addNode(center_branch.ends[0])
        child2 = branch.branch(center_branch.length / 2)
        child2.addNode(center_node)
        child2.addNode(center_branch.ends[1])
        center_node.child_branches.append(child1)
        center_node.child_branches.append(child2)

        # erase the original branch from the child nodes branch_list
        for kids in center_branch.ends:
            kids.branch_list.remove(center_branch)

        # impose a hierarchy from the root
        center_node.imposeHierarchy()
        self.labelSubtrees()
        self.Get_Subnodes()
        self.root.Fill_Node_Dict()
Esempio n. 4
0
    def Unroot(self):

        center_length = reduce(lambda i,j:i.length+j.length,self.root.child_branches)
	self.root.NodeWipe()

        # new center branch
        center_branch = branch.branch(center_length)
        self.a_branch = center_branch

	# find the two kids 
	kids = []
	for kid_branches in self.root.branch_list:
            for kid_nodes in kid_branches.ends:
               if kid_nodes != self.root:

                   center_branch.addNode(kid_nodes)
                   kid_nodes.myBranch = center_branch
                   kid_nodes.branch_list.remove(kid_branches)
                   kids.append(kid_nodes)

        # do unrooted tree stuff
        if len(kids[0].branch_list) == 3:
            self.a_node = kids[0]
        else:
            self.a_node = kids[1]

        self.a_node.UnrootedLeaving()
        self.branch_list.remove(self.root_branch)
        self.root_branch = center_branch
Esempio n. 5
0
def bot():
    print(self_intro())
    print(get_time())
    name = input("Please Enter your Name :")
    print(welcome(name))
    # print(get_time())
    choice = showmenu()

    while choice != 5:
        if (choice == 1):
            print(location())
        elif choice == 2:
            print(college())
        elif choice == 3:
            print('1.ECE',
                  '2.CSE',
                  '3.EEE',
                  '4.MECH',
                  '5.CIVIL',
                  '6.IT',
                  sep='\n')
            print("Enter your choice")
            c = (int(input()))
            print(branch(c))
        elif choice == 4:
            print("AC or Non AC")

            print(hostel(input()))
        elif choice >= 5:
            print("I can't understand... sorry")
        else:
            return 0
        choice = showmenu()
Esempio n. 6
0
    def RemoveLeaf(this_node):

        tree = this_node.tree

        if not this_node.isLeaf():
            print "this node isn't a leaf."
            sys.exit(1)

        parent_node = this_node.GetParent()
        kids = parent_node.GetKids()
        sib = filter(lambda i: i is not this_node,kids)[0]

        # what to do if parent is the root
        if tree.root is parent_node:
            tree.root = sib
            return

        # if not tied to root, slightly more complex ...
        grandparent = parent_node.GetParent()

        # build a new connecting branch
        branch_len = 0
        branch_len += sib.parent_branch[0].length
        branch_len += parent_node.parent_branch[0].length
        new_branch = branch.branch(branch_len)
        new_branch.addNode(sib)
        new_branch.addNode(grandparent)
        
        sib.parent_branch[0] = new_branch
        gp_branch = parent_node.parent_branch[0]
        
        for i in range(len(grandparent.child_branches)):
            if grandparent.child_branches[i] is gp_branch:
                grandparent.child_branches[i] = new_branch
Esempio n. 7
0
    def RemoveLeaf(this_node):

        tree = this_node.tree

        if not this_node.isLeaf():
            print "this node isn't a leaf."
            sys.exit(1)

        parent_node = this_node.GetParent()
        kids = parent_node.GetKids()
        sib = filter(lambda i: i is not this_node, kids)[0]

        # what to do if parent is the root
        if tree.root is parent_node:
            tree.root = sib
            return

        # if not tied to root, slightly more complex ...
        grandparent = parent_node.GetParent()

        # build a new connecting branch
        branch_len = 0
        branch_len += sib.parent_branch[0].length
        branch_len += parent_node.parent_branch[0].length
        new_branch = branch.branch(branch_len)
        new_branch.addNode(sib)
        new_branch.addNode(grandparent)

        sib.parent_branch[0] = new_branch
        gp_branch = parent_node.parent_branch[0]

        for i in range(len(grandparent.child_branches)):
            if grandparent.child_branches[i] is gp_branch:
                grandparent.child_branches[i] = new_branch
Esempio n. 8
0
    def Unroot(self):

        center_length = reduce(lambda i, j: i.length + j.length,
                               self.root.child_branches)
        self.root.NodeWipe()

        # new center branch
        center_branch = branch.branch(center_length)
        self.a_branch = center_branch

        # find the two kids
        kids = []
        for kid_branches in self.root.branch_list:
            for kid_nodes in kid_branches.ends:
                if kid_nodes != self.root:

                    center_branch.addNode(kid_nodes)
                    kid_nodes.myBranch = center_branch
                    kid_nodes.branch_list.remove(kid_branches)
                    kids.append(kid_nodes)

        # do unrooted tree stuff
        if len(kids[0].branch_list) == 3:
            self.a_node = kids[0]
        else:
            self.a_node = kids[1]

        self.a_node.UnrootedLeaving()
        self.branch_list.remove(self.root_branch)
        self.root_branch = center_branch
Esempio n. 9
0
def commands() -> None:
    """Redirects all the commands that require a wit path."""

    wit_path = _search_parent_dir(".wit")
    _set_logger(os.path.join(wit_path, '.wit'))

    if sys.argv[1] == 'add':
        add(sys.argv[2], wit_path)
    elif sys.argv[1] == 'commit':
        print(commit(sys.argv[2], wit_path))
    elif sys.argv[1] == 'status':
        print(status(wit_path))
    elif sys.argv[1] == 'checkout':
        checkout(sys.argv[2], wit_path)
    elif sys.argv[1] == 'graph':
        graph(wit_path)
    elif sys.argv[1] == 'branch':
        branch(sys.argv[2], wit_path)
    elif sys.argv[1] == 'merge':
        merge(sys.argv[2], wit_path)
    else:
        logging.error(
            MethodNotFoundError(f'unrecognized method: "{sys.argv[1]}".'))
Esempio n. 10
0
    def SPR(self, prune_node, graft_node):

        # find nodes
        prune_parent = prune_node.GetParent()
        graft_parent = graft_node.GetParent()

        # don't bother if they are already siblings
        if prune_parent is graft_parent:
            return self

        # get the sibling
        prune_sibling = prune_node.GetSibling()

        # adjust the pruned subtree
        prune_parent_branch = prune_parent.parent_branch
        prune_parent_branch.length += prune_sibling.parent_branch.length
        prune_sibling.parent_branch = prune_parent_branch
        prune_gparent = prune_parent.GetParent()
        # prune_node.parent_branch.length /= 2

        if prune_gparent is None:
            self.root = prune_sibling
        else:
            del prune_gparent.kid_nodes[prune_parent]
            prune_gparent.kid_nodes[prune_sibling] = 1

        # now, handle the grafting
        new_node = node.node('new', self)
        graft_parent_branch = graft_node.parent_branch
        new_branch_length = graft_parent_branch.length / 2
        new_node.parent_branch = branch.branch(new_branch_length)
        graft_node.parent_branch.length = new_branch_length

        del graft_parent.kid_nodes[graft_node]
        graft_parent.kid_nodes[new_node] = 1
        new_node.kid_nodes[graft_node] = 1
        new_node.kid_nodes[prune_node] = 1
        new_tree = multitree()

        tree_str = "(" + str(self) + ");"
        new_tree.Build(tree_str)

        return new_tree
Esempio n. 11
0
    def SPR(self,prune_node,graft_node):

        # find nodes
        prune_parent = prune_node.GetParent()
        graft_parent = graft_node.GetParent()

        # don't bother if they are already siblings
        if prune_parent is graft_parent:
            return self

        # get the sibling
        prune_sibling = prune_node.GetSibling()

        # adjust the pruned subtree
        prune_parent_branch = prune_parent.parent_branch
        prune_parent_branch.length += prune_sibling.parent_branch.length
        prune_sibling.parent_branch = prune_parent_branch
        prune_gparent = prune_parent.GetParent()
        # prune_node.parent_branch.length /= 2

        if prune_gparent is None:
            self.root = prune_sibling
        else:
            del prune_gparent.kid_nodes[prune_parent]
            prune_gparent.kid_nodes[prune_sibling] = 1

        # now, handle the grafting
        new_node = node.node('new',self)
        graft_parent_branch = graft_node.parent_branch
        new_branch_length = graft_parent_branch.length/2
        new_node.parent_branch = branch.branch(new_branch_length)
        graft_node.parent_branch.length = new_branch_length
        
        del graft_parent.kid_nodes[graft_node]
        graft_parent.kid_nodes[new_node] = 1
        new_node.kid_nodes[graft_node] = 1
        new_node.kid_nodes[prune_node] = 1
        new_tree = multitree()

        tree_str = "(" + str(self) + ");"
        new_tree.Build(tree_str)

        return new_tree
Esempio n. 12
0
    if branchProg.status == 2:
        print 'Problem seems infeasible'
        for element in binding:
            bindingCounter[element] += 1
        out.write('Problem seems infeasible\n')
        iscontradiction = True
    elif branchProg.status == 0:
        out.write('The maximum epsilon is ' + str(-branchProg.fun) +
                  '\nThe involved inequality constraints are ' + str(binding) +
                  '\nThe computed solution is ' + str(branchProg.x) + '\n')
        if branchProg.fun >= -1.0e-8:
            iscontradiction = True
            for element in binding:
                bindingCounter[element] += 1
            print 'Solution failed the strictness conditions'
            out.write('Solution failed the strictness conditions\n')
        else:
            iscontradiction = False
    else:
        print 'Unexpected branchProg.status'
        out.write('Unexpected branchProg.status\n')
        quit
    [conf, vxseq, onoffseq] = branch(collisionMatrix, conf, vxseq, onoffseq,
                                     iscontradiction, out)
    if not len(conf):
        break

print '\n-------- %s seconds ---------' % (time.time() - starttime)
out.write('\n-------- %s seconds ---------' % (time.time() - starttime))
out.close()
Esempio n. 13
0
    def addBranch(self, length):

        self.myBranch = branch.branch(length)
        self.myBranch.addNode(self)
Esempio n. 14
0
    def RecursiveBuild(self, newick):
        ''' recursively populate tree '''

        # handle the case when you reach a trifurcating node (so
        # unrooted), by looking for when you've got a stretch of 2
        # colons unseparated by a parenthesis
        colon_count = newick.count(':')
        colon_match2 = re.findall(':[^\)]*:[^\)]*:', newick)

        if colon_count == 0:
            # tree is empty.  abdicate.
            print "no nodes in tree"
            return

# if you reach a root or tree only has 1 node
        elif colon_count == 1:
            root_dist = float(newick.split(':')[1].split(')')[0])
            root_branch = branch.branch(root_dist)

            # handle case of 1 node tree
            if len(self.build_queue) < 1:
                # 1 node tree
                open_paren_i = newick.find('(')
                close_paren_i = newick.find(')')
                node_s = newick[open_paren_i + 1:close_paren_i]
                #node_s = newick[1:-2]
                root_node = self.BuildNode(node_s)
            else:
                # multinode tree
                root_node = self.build_queue[0]
                for kid_branches in root_node.branch_list:
                    root_node.child_branches.append(kid_branches)

            root_node.parent_branch = root_branch
            self.node_dict[root_node.species] = root_node

            # do rooted stuff
            self.unrooted = False
            self.root = root_node
            self.root.imposeHierarchy()
            self.labelSubtrees()
            self.Get_Subnodes()

        # handle case of a tree with only 2 nodes:
        elif colon_count == 2:

            # find an innermost set of parentheses:
            regex = re.search('\([^\(\)]*\)', newick).span()
            clade = newick[regex[0] + 1:regex[1] - 1]

            # split up the clade
            children = re.split(',', clade)
            son = children[0]
            daughter = children[1]

            # build node1
            node1 = self.BuildNode(son)
            node2 = self.BuildNode(daughter)

            # unite the two nodes
            center_node = node1.unite(node2)

            # create a fake node:
            dummy_node = self.BuildNode("dummy_node:0.1")
            dummy_node.branch_list = []
            dummy_node.addBranch(0.01)
            dummy_node.myBranch.addNode(center_node)
            self.a_branch = dummy_node.myBranch
            self.a_node = dummy_node
            center_node.UnrootedLeaving()

# handle the trifurcating node of an unrooted tree
        elif colon_count == 3 and len(colon_match2) > 0:

            # note that this updated block can handle trees with leaf
            # count >= 3

            # pull out the first node
            regex = re.search('\([^,]*,', newick).span()
            first_leaf = newick[regex[0] + 1:regex[1] - 1]
            newick = re.sub(first_leaf + ',', '', newick)
            first_node = self.BuildNode(first_leaf)

            # first_node.branch_list = []
            # don't need to worry about clearing, since we'll be
            # adding branches anyway later down in this block.
            self.build_queue.append(first_node)

            # join the last 2 nodes:
            regex = re.search('\(.*,[^\)]*\);', newick).span()
            clade = newick[regex[0] + 1:regex[1] - 2]

            # split up the clade
            children = re.split(',', clade)
            son = children[0]
            daughter = children[1]

            # build two nodes and join
            node1 = self.BuildNode(son)
            node2 = self.BuildNode(daughter)
            center_node = node1.unite(node2)

            # finally, join this new node with the remaining node:
            last_node = self.build_queue[0]
            regex = re.search(':[^,]*,', newick).span()
            last_node.myBranch.addNode(center_node)

            self.a_branch = last_node.myBranch
            self.a_node = last_node

            # do some unrooted stuff, making sure you don't begin on a
            # leaf.
            if len(self.a_branch.ends[0].branch_list) == 3:
                self.a_branch.ends[0].UnrootedLeaving()
            else:
                self.a_branch.ends[1].UnrootedLeaving()

        else:

            # find an innermost set of parentheses:
            regex = re.search('\([^\(\)]*\):', newick).span()
            clade = newick[regex[0] + 1:regex[1] - 2]
            # split up the clade
            children = re.split(',', clade)
            son = children[0]
            daughter = children[1]

            # build nodes and unite
            node1 = self.BuildNode(son)
            node2 = self.BuildNode(daughter)
            center_node = node1.unite(node2)

            # replace the matched string with the new node:
            new_newick = newick[0:regex[0]]
            new_newick += center_node.name
            new_newick += newick[regex[1] - 1:]

            # add the new node to the queue of extant nodes
            self.build_queue.append(center_node)

            # recurse
            self.RecursiveBuild(new_newick)
 def test_branch_true(self):
     branch(True)
     self.assertTrue(True) # do a real test here
 def test_branch_false(self):
     branch(False)
     self.assertTrue(True) # do a real test here
Esempio n. 17
0
 # all_instructs is just list of strings of the file per line, mainly just for Randy/Branching, feel free to modify it how you see fit
 instructs, all_instructs = file_read(input_file)
 '''
 print(instructs, all_instructs)
 for i in instructs:
     print(i)
 '''
 done = False
 total_cycles = 1
 toprint=0
 if f == "F":
     print("START OF SIMULATION (forwarding)")
 else:
     print("START OF SIMULATION (no forwarding)")
 while ((not done) and (total_cycles <= 16)):
     instructs = branch(instructs, all_instructs, total_cycles, t, s)
     #for j in instructs:
     #    print(j.instruct,j.taken,j.counter,j.taken_counter)
     if f == "F":
         instructs = forward(instructs, total_cycles)
     else:
         instructs = no_forward(instructs, total_cycles)
     s, t = update_regs(instructs, s, t)
     print_cpu(instructs, s, t, total_cycles)
     done = True
     for i in instructs:
         if i.counter != 6:
             done = False
     if(done==False and instructs[len(instructs)-1].counter==5):
         done=True
     total_cycles += 1
Esempio n. 18
0
    def rootify(self,center_branch):

	# remember the old branch:
	self.root_branch = center_branch

	# create a new node
	center_name = center_branch.ends[0].name
	center_name += "-" + center_branch.ends[1].name
	center_node = node.node(center_name,self)
	self.root = center_node
	
        # in order to "mid-point root" need to find maximum distance
        # from leaf in each subtree to the root
        node_1 = center_branch.ends[0]
        node_2 = center_branch.ends[1]
        leaves_1 = node_1.name_dict[node_2]
        leaves_2 = node_2.name_dict[node_1]
        max_dist_1 = 0.0
        max_dist_2 = 0.0
        node_list = self.leaf_node_list
        for leaf_s in leaves_1:
            leaf = [leaf_node for leaf_node in node_list if leaf_node.name is leaf_s][0]
            leaf_dist = leaf.DistTo(node_1)[1]
            if leaf_dist > max_dist_1:
                max_dist_1 = leaf_dist
        for leaf_s in leaves_2:
            leaf = [leaf_node for leaf_node in node_list if leaf_node.name is leaf_s][0]
            leaf_dist = leaf.DistTo(node_2)[1]
            if leaf_dist > max_dist_2:
                max_dist_2 = leaf_dist

        # figure out how long to make the branches
        cent_dist = center_branch.length
        cent_dist_2 = float(max_dist_1 - max_dist_2 + cent_dist)/2
        cent_dist_1 = cent_dist - cent_dist_2
        
        # account for center branch not being long enough
        min_dist = 0.00001
        if cent_dist_1 < min_dist:
            cent_dist_1 = min_dist
            cent_dist_2 = cent_dist - min_dist
        if cent_dist_2 < min_dist:
            cent_dist_2 = min_dist
            cent_dist_1 = cent_dist - min_dist
            
	# give it children branches
	child1 = branch.branch(cent_dist_1)
	child1.addNode(center_node)
	child1.addNode(node_1)
	child2 = branch.branch(cent_dist_2)
	child2.addNode(center_node)
	child2.addNode(node_2)
	center_node.child_branches.append(child1)
	center_node.child_branches.append(child2)

	# erase the original branch from the child nodes branch_list
	for kids in center_branch.ends:
	    kids.branch_list.remove(center_branch)

	# impose a hierarchy from the root
	center_node.imposeHierarchy()
        self.labelSubtrees()
        self.Get_Subnodes()
        self.root.Fill_Node_Dict()
Esempio n. 19
0
    def rootify(self, center_branch):

        # remember the old branch:
        self.root_branch = center_branch

        # create a new node
        center_name = center_branch.ends[0].name
        center_name += "-" + center_branch.ends[1].name
        center_node = node.node(center_name, self)
        self.root = center_node

        # in order to "mid-point root" need to find maximum distance
        # from leaf in each subtree to the root
        node_1 = center_branch.ends[0]
        node_2 = center_branch.ends[1]
        leaves_1 = node_1.name_dict[node_2]
        leaves_2 = node_2.name_dict[node_1]
        max_dist_1 = 0.0
        max_dist_2 = 0.0
        node_list = self.leaf_node_list
        for leaf_s in leaves_1:
            leaf = [
                leaf_node for leaf_node in node_list
                if leaf_node.name is leaf_s
            ][0]
            leaf_dist = leaf.DistTo(node_1)[1]
            if leaf_dist > max_dist_1:
                max_dist_1 = leaf_dist
        for leaf_s in leaves_2:
            leaf = [
                leaf_node for leaf_node in node_list
                if leaf_node.name is leaf_s
            ][0]
            leaf_dist = leaf.DistTo(node_2)[1]
            if leaf_dist > max_dist_2:
                max_dist_2 = leaf_dist

    # figure out how long to make the branches
        cent_dist = center_branch.length
        cent_dist_2 = float(max_dist_1 - max_dist_2 + cent_dist) / 2
        cent_dist_1 = cent_dist - cent_dist_2

        # account for center branch not being long enough
        min_dist = 0.00001
        if cent_dist_1 < min_dist:
            cent_dist_1 = min_dist
            cent_dist_2 = cent_dist - min_dist
        if cent_dist_2 < min_dist:
            cent_dist_2 = min_dist
            cent_dist_1 = cent_dist - min_dist

        # give it children branches
        child1 = branch.branch(cent_dist_1)
        child1.addNode(center_node)
        child1.addNode(node_1)
        child2 = branch.branch(cent_dist_2)
        child2.addNode(center_node)
        child2.addNode(node_2)
        center_node.child_branches.append(child1)
        center_node.child_branches.append(child2)

        # erase the original branch from the child nodes branch_list
        for kids in center_branch.ends:
            kids.branch_list.remove(center_branch)

        # impose a hierarchy from the root
        center_node.imposeHierarchy()
        self.labelSubtrees()
        self.Get_Subnodes()
        self.root.Fill_Node_Dict()
Esempio n. 20
0
    def RecursiveBuild(self,newick):
        ''' recursively populate tree '''

	# handle the case when you reach a trifurcating node (so
	# unrooted), by looking for when you've got a stretch of 2
	# colons unseparated by a parenthesis
        colon_count = newick.count(':')
	colon_match2 = re.findall(':[^\)]*:[^\)]*:',newick)


        if colon_count == 0:
            # tree is empty.  abdicate.
            print "no nodes in tree"
            return

	# if you reach a root or tree only has 1 node            
        elif colon_count == 1:
            root_dist = float(newick.split(':')[1].split(')')[0])
            root_branch = branch.branch(root_dist)

            # handle case of 1 node tree
            if len (self.build_queue) < 1:
                # 1 node tree
                open_paren_i = newick.find('(')
                close_paren_i = newick.find(')')
                node_s = newick[open_paren_i+1:close_paren_i]
                #node_s = newick[1:-2]
                root_node = self.BuildNode(node_s)
            else:
                # multinode tree
                root_node = self.build_queue[0]
                for kid_branches in root_node.branch_list:
                    root_node.child_branches.append(kid_branches)

            root_node.parent_branch = root_branch
	    self.node_dict[root_node.species] = root_node

            # do rooted stuff
            self.unrooted = False
	    self.root = root_node
	    self.root.imposeHierarchy()
            self.labelSubtrees()
            self.Get_Subnodes()

        # handle case of a tree with only 2 nodes:
        elif colon_count == 2:

	    # find an innermost set of parentheses:
            regex = re.search('\([^\(\)]*\)',newick).span()
	    clade = newick[regex[0]+1:regex[1]-1]

	    # split up the clade
	    children = re.split(',',clade)
	    son = children[0]
	    daughter = children[1]

            # build node1
            node1 = self.BuildNode(son)
            node2 = self.BuildNode(daughter)

	    # unite the two nodes
	    center_node = node1.unite(node2)
            
            # create a fake node:
            dummy_node = self.BuildNode("dummy_node:0.1")
            dummy_node.branch_list = []
            dummy_node.addBranch(0.01)
            dummy_node.myBranch.addNode(center_node)
            self.a_branch = dummy_node.myBranch
            self.a_node = dummy_node
            center_node.UnrootedLeaving()

	# handle the trifurcating node of an unrooted tree
	elif colon_count == 3 and len(colon_match2) > 0:

            # note that this updated block can handle trees with leaf
            # count >= 3

            # pull out the first node
            regex = re.search('\([^,]*,',newick).span()
            first_leaf = newick[regex[0]+1:regex[1]-1]
            newick = re.sub(first_leaf + ',','',newick)
            first_node = self.BuildNode(first_leaf)

            # first_node.branch_list = []
            # don't need to worry about clearing, since we'll be
            # adding branches anyway later down in this block.
            self.build_queue.append(first_node)

	    # join the last 2 nodes:
            regex = re.search('\(.*,[^\)]*\);',newick).span()
            clade = newick[regex[0]+1:regex[1]-2]

            # split up the clade
            children = re.split(',',clade)
            son = children[0]
            daughter = children[1]

            # build two nodes and join
            node1 = self.BuildNode(son)
            node2 = self.BuildNode(daughter)
            center_node = node1.unite(node2)

            # finally, join this new node with the remaining node:
            last_node = self.build_queue[0]
            regex = re.search(':[^,]*,',newick).span()
            last_node.myBranch.addNode(center_node)

            self.a_branch = last_node.myBranch
            self.a_node = last_node

            # do some unrooted stuff, making sure you don't begin on a
            # leaf. 
            if len(self.a_branch.ends[0].branch_list) == 3:
                self.a_branch.ends[0].UnrootedLeaving()
            else:
                self.a_branch.ends[1].UnrootedLeaving()

	else:

	    # find an innermost set of parentheses:
	    regex = re.search('\([^\(\)]*\):',newick).span()
	    clade = newick[regex[0]+1:regex[1]-2]
	    # split up the clade
	    children = re.split(',',clade)
	    son = children[0]
	    daughter = children[1]

            # build nodes and unite
            node1 = self.BuildNode(son)
            node2 = self.BuildNode(daughter)
	    center_node = node1.unite(node2)

	    # replace the matched string with the new node:
	    new_newick = newick[0:regex[0]]
	    new_newick += center_node.name
	    new_newick += newick[regex[1]-1:]

	    # add the new node to the queue of extant nodes
	    self.build_queue.append(center_node)

	    # recurse
	    self.RecursiveBuild(new_newick)
Esempio n. 21
0
    def addBranch(self,length):

	self.myBranch = branch.branch(length)
	self.myBranch.addNode(self)
Esempio n. 22
0
@author: Yani
"""
import numpy as np
from branch import branch

collisionMatrix = np.load('collisionmatrix4paths.npy')

testansseq = np.array([
    0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 1., 0., 1., 0., 1.,
    0., 0., 0., 0., 0., 1., 0., 1., 0., 1., 0., 1., 0., 1., 0., 1., 0., 1., 0.,
    1., 0., 1., 0., 1., 0., 1., 0., 1., 0., 0., 1., 0., 1., 0., 1., 0., 1., 0.,
    1., 0., 1., 0., 1., 0., 1., 0., 1., 0., 1., 0., 1., 0., 1., 0., 0., 1., 1.,
    0., 1., 0., 1., 0., 1., 0., 0., 1., 1., 0., 0., 1., 1., 0., 1., 0., 1., 0.,
    1., 0., 0., 0., 1.
])
testansseq = testansseq.astype(bool)

#generate random answers to iscontradiction to see behaviour

nsteps = 100

conf = np.zeros((256), dtype=int)
iscontr = False
vxseq = np.array([], dtype=int)
onoffseq = np.array([], dtype=int)

for step in range(nsteps):
    [conf, vxseq, onoffseq] = branch(collisionMatrix, conf, vxseq, onoffseq,
                                     testansseq[step])
    if not len(conf):
        break