The Very Basics

Load the library:

>>> import lingpy
>>> import lingpy as lp

Load all important packages:

>>> from lingpy import *

Alignment Analyses

Carry out a multiple alignment analysis of four sequences. First, define the sequences:

>>> seqs = ['woldemort','waldemar','wladimir','vladymyr']

Create an instance of the Multiple class:

>>> msa = Multiple(seqs)

Align the sequences, using simple progressive alignment with default parameters:

>>> msa.prog_align()

Print out the results to the screen:

>>> print(msa)
w    o    l    -    d    e    m    o    r    t
w    a    l    -    d    e    m    a    r    -
w    -    l    a    d    i    m    i    r    -
v    -    l    a    d    y    m    y    r    -

Use a short-cut to align the four sequences:

>>> mult_align(['woldemort', 'waldemar', 'wladimir', 'vladymyr'], pprint=True)

Reconstruction of Phylogenetic Trees

Import LingPy:

>>> from lingpy import *

Import the squareform-function for convenience:

>>> from lingpy.algorithm import squareform

Set up a couple of languages:

>>> languages = ['Norwegian','Swedish','Icelandic','Dutch','English']

Define a distance matrix:

>>> distances = squareform([0.5,0.67,0.8,0.2,0.4,0.7,0.6,0.8,0.8,0.3])

Carry out a Neighbor-Joining cluster analysis:

>>> tree = neighbor(distances,languages)
>>> print(tree)

Print the tree in ASCII-Art to the screen (using PyCogent’s tree class):

>>> tree = Tree(tree)
>>> print(tree.asciiArt())
                   |         |          /-Swedish
          /edge.2--|          \edge.0--|
         |         |                    \-Icelandic
-root----|         |
         |          \-Dutch