Return the effective number of paths in the tree.
187846
def get_num_paths(self):
        
        # NB: the algorithm assume a symmetric logic tree for the GSIMs;
        # in the future we may relax such assumption
        num_branches = self.get_num_branches()
        if not sum(num_branches.values()):
            return 0
        num = 1
        for val in num_branches.values():
            if val:  # the branch is effective
                num *= val
        return num
588523
def root_and_path(self):
        """"""
        rt = []
        curAttr = self
        while isinstance(curAttr.parent, AdHocTree):
            rt.append(curAttr.name)
            curAttr = curAttr.parent
        rt.reverse()
        return (curAttr.parent, rt)
1363705
def find_loops(self, _path=None):
        """"""

        if _path is None:
            _path = []

        if self in _path:
            return _path + [self]
        elif self._children == []:
            return None
        else:
            for child in self._children:
                return child.find_loops(_path + [self])
192976
def eliminate_sequential_children(paths):
  ""
  return [p for i,p in enumerate(paths) if not ((i>0 and paths[i-1]==p[:-1]) or (i>1 and paths[i-2]==p[:-1]))]
265026
def _enumerate_paths(self, prefix_path):
        
        for branch in self.branches:
            path = [prefix_path, branch]
            if branch.child_branchset is not None:
                for subpath in branch.child_branchset._enumerate_paths(path):
                    yield subpath
            else:
                yield path
469894
def _get_node_path(self, node):
        """"""
        path = []
        while node.up:
            path.append(node.name)
            node = node.up
        return list(reversed(path))
755330
def get_paths(patterns, start_dirs=None, max_depth=1):
    """"""
    # Shortcut: if there is only one pattern, make sure we process just that.
    if len(patterns) == 1 and not start_dirs:
        pattern = patterns[0]
        directory = os.path.dirname(pattern)
        if directory:
            patterns = [os.path.basename(pattern)]
            start_dirs = directory
            max_depth = 1

    if not start_dirs or start_dirs == '.':
        start_dirs = os.getcwd()
    for start_dir in start_dirs.split(','):
        for root, dirs, files in os.walk(start_dir):  # pylint: disable=W0612
            if max_depth is not None:
                relpath = os.path.relpath(root, start=start_dir)
                depth = len(relpath.split(os.sep))
                if depth > max_depth:
                    continue
            names = []
            for pattern in patterns:
                names += fnmatch.filter(files, pattern)
            for name in names:
                path = os.path.join(root, name)
                yield path
550802
def find_all(root, path):
  """"""
  path = parse_path(path)

  if len(path) == 1:
    yield from get_children(root, path[0])
  else:
    for child in get_children(root, path[0]):
      yield from find_all(child, path[1:])
713219
def n_parent_paths(self, n):
        
        rv = os.path.relpath(os.path.join(self.path, '..'), os.path.join(self.path, *['..'] * (n+1)))
        return rv.replace('\\', '/')
532802
def _get_result_paths(self,data):
        

        #clustalw .aln is used when no or unkown output type specified
        _treeinfo_formats = {'nj':'.nj',
                            'dist':'.dst',
                            'nexus':'.tre'}

        result = {}
        par = self.Parameters
        abs = self._absolute

        if par['-align'].isOn():
            prefix = par['-infile'].Value.rsplit('.', 1)[0]
            #prefix = par['-infile'].Value.split('.')[0]
            aln_filename = self._aln_filename(prefix)
            if par['-newtree'].isOn():
                dnd_filename = abs(par['-newtree'].Value)
            elif par['-usetree'].isOn():
                dnd_filename = abs(par['-usetree'].Value)
            else:
                dnd_filename = abs(prefix + '.dnd')
            result['Align'] = ResultPath(Path=aln_filename,IsWritten=True)
            result['Dendro'] = ResultPath(Path=dnd_filename,IsWritten=True)
        elif par['-profile'].isOn():
            prefix1 = par['-profile1'].Value.rsplit('.', 1)[0]
            prefix2 = par['-profile2'].Value.rsplit('.', 1)[0]
            #prefix1 = par['-profile1'].Value.split('.')[0]
            #prefix2 = par['-profile2'].Value.split('.')[0]
            aln_filename = ''; aln_written = True
            dnd1_filename = ''; tree1_written = True
            dnd2_filename = ''; tree2_written = True
            aln_filename = self._aln_filename(prefix1)
            #usetree1
            if par['-usetree1'].isOn():
                tree1_written = False
            #usetree2
            if par['-usetree2'].isOn():
                tree2_written = False
            if par['-newtree1'].isOn():
                dnd1_filename = abs(par['-newtree1'].Value)
                aln_written=False
            else:
                dnd1_filename = abs(prefix1 + '.dnd')
            if par['-newtree2'].isOn():
                dnd2_filename = abs(par['-newtree2'].Value)
                aln_written=False
            else:
                dnd2_filename = abs(prefix2 + '.dnd')
            result['Align'] = ResultPath(Path=aln_filename,
                IsWritten=aln_written)
            result['Dendro1'] = ResultPath(Path=dnd1_filename,
                IsWritten=tree1_written)
            result['Dendro2'] = ResultPath(Path=dnd2_filename,
                IsWritten=tree2_written)
        elif par['-sequences'].isOn():
            prefix1 = par['-profile1'].Value.rsplit('.', 1)[0]
            prefix2 = par['-profile2'].Value.rsplit('.', 1)[0]
            #prefix1 = par['-profile1'].Value.split('.')[0] #alignment
            #prefix2 = par['-profile2'].Value.split('.')[0] #sequences
            aln_filename = ''; aln_written = True
            dnd_filename = ''; dnd_written = True

            aln_filename = self._aln_filename(prefix2)
            if par['-usetree'].isOn():
                dnd_written = False
            elif par['-newtree'].isOn():
                aln_written = False
                dnd_filename = abs(par['-newtree'].Value)
            else:
                dnd_filename = prefix2 + '.dnd'
            result['Align'] = ResultPath(Path=aln_filename,\
                IsWritten=aln_written)
            result['Dendro'] = ResultPath(Path=dnd_filename,\
                IsWritten=dnd_written)
        elif par['-tree'].isOn():
            prefix = par['-infile'].Value.rsplit('.', 1)[0]
            #prefix = par['-infile'].Value.split('.')[0]
            tree_filename = ''; tree_written = True
            treeinfo_filename = ''; treeinfo_written = False
            tree_filename = prefix + '.ph'
            if par['-outputtree'].isOn() and\
                par['-outputtree'].Value != 'phylip':
                treeinfo_filename = prefix +\
                    _treeinfo_formats[par['-outputtree'].Value]
                treeinfo_written = True
            result['Tree'] = ResultPath(Path=tree_filename,\
                IsWritten=tree_written)
            result['TreeInfo'] = ResultPath(Path=treeinfo_filename,\
                IsWritten=treeinfo_written)

        elif par['-bootstrap'].isOn():
            prefix = par['-infile'].Value.rsplit('.', 1)[0]
            #prefix = par['-infile'].Value.split('.')[0]
            boottree_filename = prefix + '.phb'
            result['Tree'] = ResultPath(Path=boottree_filename,IsWritten=True)

        return result
451374
def find_paths_breadth_first(from_target, to_target, log):
  """"""
  log.debug('Looking for all paths from {} to {}'.format(from_target.address.reference(),
                                                         to_target.address.reference()))

  if from_target == to_target:
    yield [from_target]
    return

  visited_edges = set()
  to_walk_paths = deque([[from_target]])
  while len(to_walk_paths) > 0:
    cur_path = to_walk_paths.popleft()
    target = cur_path[-1]

    if len(cur_path) > 1:
      prev_target = cur_path[-2]
    else:
      prev_target = None
    current_edge = (prev_target, target)

    if current_edge not in visited_edges:
      for dep in target.dependencies:
        dep_path = cur_path + [dep]
        if dep == to_target:
          yield dep_path
        else:
          to_walk_paths.append(dep_path)
      visited_edges.add(current_edge)
1272997
def child_count(self, path):
        
        stat = self.stat(path)
        if not stat:
            return 0

        count = stat.numChildren
        for _, _, stat in self.tree(path, 0, include_stat=True):
            if stat:
                count += stat.numChildren
        return count
755772
def determine_path():
    """"""
    root = __file__
    if os.path.islink(root):
        root = os.path.realpath(root)
    return os.path.dirname(os.path.abspath(root))
658397
def path(self):
        """"""
        yield self
        if not self.parent: return
        for node in self.parent.path: yield node
66992
def traverse(self):
        '''
        
        '''
        yield self, 0
        if self.name in self.expanded:
            for path in self.getpaths():
                for child, depth in path.traverse():
                    yield child, depth + 1
997113
def path_to_list(pathstr):
    """"""
    return [elem for elem in pathstr.split(os.path.pathsep) if elem]
1023470
def _get_result_paths(self,data):
        
        result = {}
        result['Tree'] = ResultPath(Path=splitext(self._input_filename)[0] + \
                                                  '.tree')
        return result