Search in sources :

Example 21 with Sequence

use of dr.evolution.sequence.Sequence in project beast-mcmc by beast-dev.

the class SimpleAlignment method getSitePattern.

/**
     * Gets the pattern of site as an array of state numbers (one per sequence)
     *
     * @return the site pattern at siteIndex
     */
public int[] getSitePattern(int siteIndex) {
    Sequence seq;
    int i, n = getSequenceCount();
    int[] pattern = new int[n];
    for (i = 0; i < n; i++) {
        seq = getSequence(i);
        if (siteIndex >= seq.getLength())
            pattern[i] = dataType.getGapState();
        else
            pattern[i] = seq.getState(siteIndex);
    }
    return pattern;
}
Also used : Sequence(dr.evolution.sequence.Sequence)

Example 22 with Sequence

use of dr.evolution.sequence.Sequence in project beast-mcmc by beast-dev.

the class ExtractPairs method getPairAlignment.

public Alignment getPairAlignment(int x, int y) {
    SimpleAlignment pairAlignment = new SimpleAlignment();
    StringBuffer sequence0 = new StringBuffer();
    StringBuffer sequence1 = new StringBuffer();
    DataType dataType = alignment.getDataType();
    int stateCount = dataType.getStateCount();
    for (int i = 0; i < alignment.getSiteCount(); i++) {
        int s0 = alignment.getState(x, i);
        int s1 = alignment.getState(y, i);
        char c0 = dataType.getChar(s0);
        char c1 = dataType.getChar(s1);
        if (s0 < stateCount || s1 < stateCount) {
            sequence0.append(c0);
            sequence1.append(c1);
        }
    }
    // trim hanging ends on left
    int left = 0;
    while ((dataType.getState(sequence0.charAt(left)) >= stateCount) || (dataType.getState(sequence1.charAt(left)) >= stateCount)) {
        left += 1;
    }
    // trim hanging ends on right
    int right = sequence0.length() - 1;
    while ((dataType.getState(sequence0.charAt(right)) >= stateCount) || (dataType.getState(sequence1.charAt(right)) >= stateCount)) {
        right -= 1;
    }
    if (right < left)
        return null;
    String sequenceString0 = sequence0.substring(left, right + 1);
    String sequenceString1 = sequence1.substring(left, right + 1);
    pairAlignment.addSequence(new Sequence(alignment.getTaxon(x), sequenceString0));
    pairAlignment.addSequence(new Sequence(alignment.getTaxon(y), sequenceString1));
    return pairAlignment;
}
Also used : DataType(dr.evolution.datatype.DataType) Sequence(dr.evolution.sequence.Sequence)

Example 23 with Sequence

use of dr.evolution.sequence.Sequence in project beast-mcmc by beast-dev.

the class GapStrippedAlignment method getSequence.

/**
     * Very inefficient implementation, use sparingly
     * @param sequenceIndex
     * @return
     */
public final Sequence getSequence(int sequenceIndex) {
    DataType dataType = getDataType();
    StringBuffer buffer = new StringBuffer();
    for (int i = 0; i < alignment.getSiteCount(); i++) {
        if (!hasGap[i]) {
            buffer.append(dataType.getChar(alignment.getState(sequenceIndex, i)));
        }
    }
    return new Sequence(buffer.toString());
}
Also used : DataType(dr.evolution.datatype.DataType) Sequence(dr.evolution.sequence.Sequence)

Example 24 with Sequence

use of dr.evolution.sequence.Sequence in project beast-mcmc by beast-dev.

the class SimpleAlignment method setState.

/**
     */
public void setState(int taxonIndex, int siteIndex, int state) {
    Sequence seq = getSequence(taxonIndex);
    if (siteIndex >= seq.getLength()) {
        throw new IllegalArgumentException();
    }
    seq.setState(siteIndex, state);
}
Also used : Sequence(dr.evolution.sequence.Sequence)

Example 25 with Sequence

use of dr.evolution.sequence.Sequence in project beast-mcmc by beast-dev.

the class IstvanOperator method doOperation.

public double doOperation() {
    Tree tree = likelihood.getTreeModel();
    alignment = likelihood.getAlignment();
    //System.out.println("Incoming alignment");
    //System.out.println(alignment);
    //System.out.println();
    SubstitutionModel substModel = likelihood.getSiteModel().getSubstitutionModel();
    // initialize the iParent and iTau arrays based on the given tree.
    initTree(tree, likelihood.getSiteModel().getMu());
    int[] treeIndex = new int[tree.getTaxonCount()];
    for (int i = 0; i < treeIndex.length; i++) {
        treeIndex[i] = tree.getTaxonIndex(alignment.getTaxonId(i));
    }
    // initialize the iAlignment array from the given alignment.
    initAlignment(alignment, treeIndex);
    // initialize the iProbs array from the substitution model -- must be called after populating tree!
    initSubstitutionModel(substModel);
    DataType dataType = substModel.getDataType();
    proposal.setGapSymbol(dataType.getGapState());
    int[][] returnedAlignment = new int[iAlignment.length][];
    //System.out.println("Initialization done, starting proposal proper...");
    double logq = proposal.propose(iAlignment, iProbs, iBaseFreqs, iParent, iTau, returnedAlignment, tuning, exponent, gapPenalty);
    //System.out.println("Proposal finished, logq=" + logq);
    //create new alignment object
    SimpleAlignment newAlignment = new SimpleAlignment();
    for (int i = 0; i < alignment.getTaxonCount(); i++) {
        StringBuffer seqBuffer = new StringBuffer();
        for (int j = 0; j < returnedAlignment[i].length; j++) {
            seqBuffer.append(dataType.getChar(returnedAlignment[treeIndex[i]][j]));
        }
        // add sequences in order of tree
        String seqString = seqBuffer.toString();
        Sequence sequence = new Sequence(alignment.getTaxon(i), seqString);
        newAlignment.addSequence(sequence);
        String oldunaligned = alignment.getUnalignedSequenceString(i);
        String unaligned = newAlignment.getUnalignedSequenceString(i);
        if (!unaligned.equals(oldunaligned)) {
            System.err.println("Sequence changed from:");
            System.err.println("old:'" + oldunaligned + "'");
            System.err.println("new:'" + unaligned + "'");
            throw new RuntimeException();
        }
    }
    //System.out.println("Outgoing alignment");
    //System.out.println(newAlignment);
    //System.out.println();
    likelihood.setAlignment(newAlignment);
    return logq;
}
Also used : SimpleAlignment(dr.evolution.alignment.SimpleAlignment) Tree(dr.evolution.tree.Tree) DataType(dr.evolution.datatype.DataType) Sequence(dr.evolution.sequence.Sequence) SubstitutionModel(dr.oldevomodel.substmodel.SubstitutionModel)

Aggregations

Sequence (dr.evolution.sequence.Sequence)31 SimpleAlignment (dr.evolution.alignment.SimpleAlignment)15 Taxon (dr.evolution.util.Taxon)12 DataType (dr.evolution.datatype.DataType)6 BranchRateModel (dr.evomodel.branchratemodel.BranchRateModel)6 GammaSiteRateModel (dr.evomodel.siteratemodel.GammaSiteRateModel)5 TreeModel (dr.evomodel.tree.TreeModel)5 Parameter (dr.inference.model.Parameter)5 Tree (dr.evolution.tree.Tree)4 Date (dr.evolution.util.Date)4 HomogeneousBranchModel (dr.evomodel.branchmodel.HomogeneousBranchModel)4 DefaultBranchRateModel (dr.evomodel.branchratemodel.DefaultBranchRateModel)4 FrequencyModel (dr.evomodel.substmodel.FrequencyModel)4 Partition (dr.app.beagle.tools.Partition)3 NewickImporter (dr.evolution.io.NewickImporter)3 HKY (dr.evomodel.substmodel.nucleotide.HKY)3 ArrayList (java.util.ArrayList)3 BeagleSequenceSimulator (dr.app.beagle.tools.BeagleSequenceSimulator)2 ImportException (dr.evolution.io.Importer.ImportException)2 Taxa (dr.evolution.util.Taxa)2