Пример #1
0
    def replace_state(self, i, new_state, keep_uuid=1):
        n = self.get_node(i)
        if len(new_state.end_states) != len(n.data.ref_state.end_states):
            raise ValueError(
                "attempted to replace a state with a different number of ends")

        old_state = n.data.ref_state
        if keep_uuid:
            uuid = n.data.ref_state.uuid

        n.data.ref_state = new_state
        n.data.cur_state = new_state.copy()

        if keep_uuid:
            n.data.ref_state.uuid = uuid
            n.data.cur_state.uuid = uuid

        for i in range(len(old_state.end_names)):
            if self.connections.in_connection(n.index, old_state.end_names[i]):
                self.connections.update_connection_name(
                    n.index, old_state.end_names[i], new_state.end_names[i])

        for n in tree.transverse_tree(self.tree, i):
            parent = n.parent
            if parent is None:
                continue
            pei = n.parent_end_index()

            motif.get_aligned_motif_state(
                parent.data.cur_state.end_states[pei], n.data.cur_state,
                n.data.ref_state)
Пример #2
0
    def add_state(self,
                  state=None,
                  parent_index=-1,
                  parent_end_index=-1,
                  parent_end_name=None,
                  m_name=None,
                  m_end_name=None):

        self._validate_arguments_to_add_state(state, m_name)

        parent = self._get_parent_node(parent_index)

        if parent is None:
            n_data = NodeData(state)
            return self.tree.add_data(n_data, len(state.end_states), -1, -1)

        if state is None and m_name is not None:
            state = self._get_state_from_manager(m_name, m_end_name)

        avail_pos = self._get_parent_available_ends(parent, parent_end_index,
                                                    parent_end_name)

        for p in avail_pos:
            n_data = NodeData(state)
            motif.get_aligned_motif_state(parent.data.cur_state.end_states[p],
                                          n_data.cur_state, n_data.ref_state)

            if self.option('sterics') and self._steric_clash(n_data):
                continue

            return self.tree.add_data(n_data, len(state.end_states),
                                      parent.index, p)

        return -1
Пример #3
0
    def add_state(self,
                  ms=None,
                  parent_index=-1,
                  parent_end_index=-1,
                  parent_end_name=None,
                  m_name=None,
                  m_end_name=None,
                  orphan=0):

        self._validate_arguments_to_add_state(ms, m_name)
        parent = self._get_parent_node(parent_index)

        if ms is None and m_name is not None:
            ms = self._get_state_from_manager(m_name, m_end_name)

        if parent is None or orphan:
            n_data = NodeData(ms)

            pos = self.graph.add_data(n_data,
                                      -1,
                                      -1,
                                      -1,
                                      len(ms.end_states),
                                      orphan=1)
            self.aligned[pos] = 0
            self.update_align_list = 1
            return pos

        avail_pos = self._get_parent_available_ends(parent, parent_end_index,
                                                    parent_end_name)

        for p in avail_pos:
            n_data = NodeData(ms)
            motif.get_aligned_motif_state(parent.data.cur_state.end_states[p],
                                          n_data.cur_state, n_data.ref_state)

            if self.option('sterics') and self._steric_clash(n_data):
                continue

            pos = self.graph.add_data(n_data, parent.index, p, 0,
                                      len(ms.end_states))
            self.aligned[pos] = 1
            self.update_align_list = 1
            return pos

        return -1
Пример #4
0
    def _align_states(self, pos=-1):
        non_aligned_nodes = self.get_not_aligned_nodes()
        align_list = self._get_align_list()

        start = 1
        if pos != -1:
            start = 0

        for n in align_list:
            if start == 0:
                if n.index == pos:
                    start = 1
                else:
                    continue

            if n in non_aligned_nodes:
                continue

            parent = n.connections[0].partner(n.index)
            pei = n.connections[0].end_index(parent.index)

            motif.get_aligned_motif_state(
                parent.data.cur_state.end_states[pei], n.data.cur_state,
                n.data.ref_state)
Пример #5
0
    def _search(self):
        count = 0
        accept_score, max_node_level, sterics, max_size, min_size = self._get_local_variables()
        best = 1000000000
        while not self.queue.empty():
            current = self.queue.get()
            score = self.scorer.accept_score(current)
            count += 1
            #print current.score
            if score < best:
                best = score
                #print score
                #print current.score, current.level

            if score < accept_score:
                if not self.selector.is_valid_solution(current):
                    continue
                if current.size < min_size:
                    continue
                #print count
                return MotifStateSearchSolution(current, score)

            if current.level+1 > max_node_level:
                continue

            motif_states, types = self.selector.get_children_ms(current)

            avail_ends = []
            for i, end in enumerate(current.cur_state.end_states):
                if i == 0:
                    continue
                avail_ends.append(end)
            self.test_node.parent = current
            self.test_node.update()
            for end in avail_ends:
                parent_end_index = current.cur_state.end_states.index(end)
                self.test_node.parent_end_index = parent_end_index
                for i, ms in enumerate(motif_states):
                    self.test_node.update_ms(ms)
                    self.test_node.ntype = types[i]
                    motif.get_aligned_motif_state(end,
                                                  self.test_node.cur_state,
                                                  self.test_node.ref_state)

                    score = self.scorer.score(self.test_node)

                    print score, ms.name

                    #score += self.selector.score(self.test_node)*self.test_node.level*10
                    #print score, current.score, len(current.cur_state.beads)
                    if score > current.score:
                        continue

                    if sterics:
                        if self.lookup is not None:
                            if self.lookup.clash(self.test_node.cur_state.beads):
                                continue
                    child = self.test_node.copy()
                    child.score = score
                    child.update()
                    if child.size > max_size:
                        continue
                    child.ntype = types[i]
                    self.queue.put(child, score)

            exit()

        return None