Back to index

python-biopython  1.60
Classes | Functions
Bio.Phylo.PAML._paml Namespace Reference

Classes

class  PamlError
class  Paml

Functions

def _relpath

Class Documentation

class Bio::Phylo::PAML::_paml::PamlError
paml has failed. Run with verbose = True to view the error
message

Definition at line 40 of file _paml.py.


Function Documentation

def Bio.Phylo.PAML._paml._relpath (   path,
  start = None 
) [private]
Return a relative version of a path.

Implementation by James Gardner in his BareNecessities
package, under MIT licence.

With a fix for Windows where posixpath.sep (and functions like
join) use the Unix slash not the Windows slash.

Definition at line 13 of file _paml.py.

00013 
00014     def _relpath(path, start=None):
00015         """Return a relative version of a path.
00016 
00017         Implementation by James Gardner in his BareNecessities
00018         package, under MIT licence.
00019 
00020         With a fix for Windows where posixpath.sep (and functions like
00021         join) use the Unix slash not the Windows slash.
00022         """
00023         import posixpath
00024         if start is None:
00025             start = posixpath.curdir
00026         else:
00027             start = start.replace(os.path.sep, posixpath.sep)
00028         if not path:
00029             raise ValueError("no path specified")
00030         else:
00031             path = path.replace(os.path.sep, posixpath.sep)
00032         start_list = posixpath.abspath(start).split(posixpath.sep)
00033         path_list = posixpath.abspath(path).split(posixpath.sep)
00034         # Work out how much of the filepath is shared by start and path.
00035         i = len(posixpath.commonprefix([start_list, path_list]))
00036         rel_list = [posixpath.pardir] * (len(start_list)-i) + path_list[i:]
00037         if not rel_list:
00038             return posixpath.curdir.replace(posixpath.sep, os.path.sep)
00039         return posixpath.join(*rel_list).replace(posixpath.sep, os.path.sep)