\

### Navigation

- index
- next |
- previous |
- PyCogent 1.5.3 documentation »
- Cogent Usage Examples »

# Estimate parameter values using a sampling from a dataset

Section author: Gavin Huttley

This script uses the `sample` method of the alignment class to provide an estimate for a two stage optimisation. This allows rapid optimisation of long alignments and complex models with a good chance of arriving at the global maximum for the model and data. Local optimisation of the full alignment may end up in local maximum and for this reason results from this strategy my be inaccurate.

From cogent import all the components we need.

    >>> from cogent import LoadSeqs, LoadTree
    >>> from cogent.evolve import  substitution_model

Load your alignment, note that if your file ends with a suffix that is the same as it’s format (assuming it’s a supported format) then you can just give the filename. Otherwise you can specify the format using the format argument.

    >>> aln = LoadSeqs(filename = "data/long_testseqs.fasta")

Get your tree

    >>> t = LoadTree(filename = "data/test.tree")

Get the substitution model (defaults to Felsensteins 1981 model)

    >>> sm = substitution_model.Nucleotide()

Make a likelihood function from a sample of the alignment the `sample` method selects the chosen number of bases at random.

    >>> lf = sm.makeLikelihoodFunction(t)
    >>> lf.setMotifProbsFromData(aln)
    >>> lf.setAlignment(aln.sample(20))

Optimise with the local optimiser

    >>> lf.optimise(local=True)

Next use the whole alignment

    >>> lf.setAlignment(aln)

and the faster Powell optimiser that will only find the best result near the provided starting point

    >>> lf.optimise(local=True)

    >>> print lf
    Likelihood Function Table
    =============================
         edge    parent    length
    -----------------------------
        Human    edge.0    0.0309
    HowlerMon    edge.0    0.0412
       edge.0    edge.1    0.0359
        Mouse    edge.1    0.2666
       edge.1      root    0.0226
    NineBande      root    0.0895
     DogFaced      root    0.1095
    -----------------------------
    ===============
    motif    mprobs
    ---------------
        T    0.2317
        C    0.1878
        A    0.3681
        G    0.2125
    ---------------

### Navigation

- index
- next |
- previous |
- PyCogent 1.5.3 documentation »
- Cogent Usage Examples »