Search in sources :

Example 16 with DataType

use of dr.evolution.datatype.DataType in project beast-mcmc by beast-dev.

the class HomologyRecursion method init.

public void init(Tree tree, Alignment alignment, SubstitutionModel substModel, double mutationRate, double lengthDistr, double deathRate) {
    // initialize the iParent and iTau arrays based on the given tree.
    initTree(tree, mutationRate);
    int[] treeIndex = new int[tree.getTaxonCount()];
    for (int i = 0; i < treeIndex.length; i++) {
        treeIndex[i] = tree.getTaxonIndex(alignment.getTaxonId(i));
    // System.out.println("alignment[" + i + "] = tree[" + treeIndex[i] + "]");
    }
    // initialize the iAlignment array from the given alignment.
    initAlignment(alignment, treeIndex);
    // initialize the iSequences array from the given alignment.
    initSequences(alignment, treeIndex);
    // initialize the iTrans array from the substitution model -- must be called after populating tree!
    initSubstitutionModel(substModel);
    // iLambda, iMu
    iLambda = deathRate * lengthDistr;
    iMu = deathRate;
    // iNumNucs - alphabet size
    DataType dataType = substModel.getDataType();
    iNumNucs = dataType.getStateCount();
    // Initialise TKF91 coefficients in iB, iH, iN, iE, and iInitial
    initTKF91();
    // Check
    checkConsistency();
    // Initialise native method
    iNativeMethod = new NativeTreeLikelihood();
    iNativeMethod.init(iNumNucs, cMaxUnalignDimension, iParent, iEquil, iTrans, iSequences, iN, iH, iE, iB);
}
Also used : DataType(dr.evolution.datatype.DataType)

Example 17 with DataType

use of dr.evolution.datatype.DataType in project beast-mcmc by beast-dev.

the class HomologyRecursion method initSubstitutionModel.

/**
 * initialize the iTrans array from the substitution model -- must be called after populating tree!
 */
private void initSubstitutionModel(SubstitutionModel model) {
    DataType dataType = model.getDataType();
    int stateCount = dataType.getStateCount();
    iTrans = new double[iTau.length][stateCount][stateCount];
    double[] transProb = new double[stateCount * stateCount];
    int count;
    for (int i = 0; i < iTau.length; i++) {
        model.getTransitionProbabilities(iTau[i], transProb);
        count = 0;
        for (int j = 0; j < stateCount; j++) {
            for (int k = 0; k < stateCount; k++) {
                iTrans[i][j][k] = transProb[count];
                count += 1;
            }
        }
    }
    // initialize equlibrium distribution
    iEquil = new double[stateCount];
    for (int k = 0; k < stateCount; k++) {
        iEquil[k] = model.getFrequencyModel().getFrequency(k);
    }
}
Also used : DataType(dr.evolution.datatype.DataType)

Example 18 with DataType

use of dr.evolution.datatype.DataType in project beast-mcmc by beast-dev.

the class HomologyRecursion method initSequences.

/**
 * Initializes the iSequence array from the given alignment.
 */
private void initSequences(Alignment alignment, int[] treeIndex) {
    int numSeqs = alignment.getSequenceCount();
    DataType dataType = alignment.getDataType();
    int numStates = dataType.getStateCount();
    iSequences = new int[numSeqs][];
    for (int i = 0; i < numSeqs; i++) {
        int seqLength = 0;
        for (int j = 0; j < alignment.getSiteCount(); j++) {
            int state = alignment.getState(i, j);
            if (state >= 0 && state < numStates) {
                seqLength += 1;
            }
        }
        iSequences[treeIndex[i]] = new int[seqLength];
        int count = 0;
        for (int j = 0; j < alignment.getSiteCount(); j++) {
            int state = alignment.getState(i, j);
            if (state >= 0 && state < numStates) {
                iSequences[treeIndex[i]][count] = state;
                count += 1;
            }
        }
    }
}
Also used : DataType(dr.evolution.datatype.DataType)

Example 19 with DataType

use of dr.evolution.datatype.DataType in project beast-mcmc by beast-dev.

the class BinarySubstitutionModelParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    Parameter ratesParameter;
    XMLObject cxo = xo.getChild(GeneralSubstitutionModelParser.FREQUENCIES);
    FrequencyModel freqModel = (FrequencyModel) cxo.getChild(FrequencyModel.class);
    DataType dataType = freqModel.getDataType();
    if (dataType != TwoStates.INSTANCE)
        throw new XMLParseException("Frequency model must have binary (two state) data type.");
    int relativeTo = 0;
    ratesParameter = new Parameter.Default(0);
    return new GeneralSubstitutionModel(dataType, freqModel, ratesParameter, relativeTo);
}
Also used : FrequencyModel(dr.oldevomodel.substmodel.FrequencyModel) Parameter(dr.inference.model.Parameter) DataType(dr.evolution.datatype.DataType) GeneralSubstitutionModel(dr.oldevomodel.substmodel.GeneralSubstitutionModel)

Example 20 with DataType

use of dr.evolution.datatype.DataType in project beast-mcmc by beast-dev.

the class DataPanel method linkSubstitutionModels.

public void linkSubstitutionModels() {
    int[] selRows = dataTable.getSelectedRows();
    List<AbstractPartitionData> selectedPartitionData = new ArrayList<AbstractPartitionData>();
    DataType dateType = null;
    for (int row : selRows) {
        AbstractPartitionData partition = options.dataPartitions.get(row);
        if (dateType == null) {
            dateType = partition.getDataType();
        } else {
            if (partition.getDataType() != dateType) {
                JOptionPane.showMessageDialog(this, "Can only link the models for data partitions \n" + "of the same data type (e.g., nucleotides)", "Unable to link models", JOptionPane.ERROR_MESSAGE);
                return;
            }
        }
        if (!selectedPartitionData.contains(partition))
            selectedPartitionData.add(partition);
    }
    Object[] modelArray = options.getPartitionSubstitutionModels(selectedPartitionData).toArray();
    if (selectModelDialog == null) {
        selectModelDialog = new SelectModelDialog(frame);
    }
    int result = selectModelDialog.showDialog(modelArray);
    if (result != JOptionPane.CANCEL_OPTION) {
        PartitionSubstitutionModel model = selectModelDialog.getModel();
        if (selectModelDialog.getMakeCopy()) {
            model.setName(selectModelDialog.getName());
        }
        for (AbstractPartitionData partition : selectedPartitionData) {
            partition.setPartitionSubstitutionModel(model);
        }
    }
    if (options.getPartitionSubstitutionModels(Microsatellite.INSTANCE).size() <= 1) {
        options.shareMicroSat = true;
    }
    modelsChanged();
    fireDataChanged();
    repaint();
}
Also used : ArrayList(java.util.ArrayList) DataType(dr.evolution.datatype.DataType)

Aggregations

DataType (dr.evolution.datatype.DataType)66 Parameter (dr.inference.model.Parameter)26 FrequencyModel (dr.evomodel.substmodel.FrequencyModel)11 FrequencyModel (dr.oldevomodel.substmodel.FrequencyModel)11 ArrayList (java.util.ArrayList)8 Sequence (dr.evolution.sequence.Sequence)7 PartitionSubstitutionModel (dr.app.beauti.options.PartitionSubstitutionModel)4 PatternList (dr.evolution.alignment.PatternList)4 GeneralDataType (dr.evolution.datatype.GeneralDataType)4 Taxon (dr.evolution.util.Taxon)4 TaxonList (dr.evolution.util.TaxonList)4 GeneralSubstitutionModel (dr.evomodel.substmodel.GeneralSubstitutionModel)4 SVSComplexSubstitutionModel (dr.oldevomodel.substmodel.SVSComplexSubstitutionModel)4 Attribute (dr.util.Attribute)4 Codons (dr.evolution.datatype.Codons)3 HiddenDataType (dr.evolution.datatype.HiddenDataType)3 NodeRef (dr.evolution.tree.NodeRef)3 Tree (dr.evolution.tree.Tree)3 BranchRateModel (dr.evomodel.branchratemodel.BranchRateModel)3 SubstitutionModel (dr.evomodel.substmodel.SubstitutionModel)3