use of dr.evomodel.substmodel.FrequencyModel in project beast-mcmc by beast-dev.
the class PartitionData method createBranchModel.
public BranchModel createBranchModel() {
BranchModel branchModel = null;
if (this.substitutionModelIndex == 0) {
// HKY
Parameter kappa = new Parameter.Default(1, substitutionParameterValues[0]);
FrequencyModel frequencyModel = this.createFrequencyModel();
HKY hky = new HKY(kappa, frequencyModel);
branchModel = new HomogeneousBranchModel(hky);
} else if (this.substitutionModelIndex == 1) {
// GTR
Parameter ac = new Parameter.Default(1, substitutionParameterValues[1]);
Parameter ag = new Parameter.Default(1, substitutionParameterValues[2]);
Parameter at = new Parameter.Default(1, substitutionParameterValues[3]);
Parameter cg = new Parameter.Default(1, substitutionParameterValues[4]);
Parameter ct = new Parameter.Default(1, substitutionParameterValues[5]);
Parameter gt = new Parameter.Default(1, substitutionParameterValues[6]);
FrequencyModel frequencyModel = this.createFrequencyModel();
GTR gtr = new GTR(ac, ag, at, cg, ct, gt, frequencyModel);
branchModel = new HomogeneousBranchModel(gtr);
} else if (this.substitutionModelIndex == 2) {
// TN93
Parameter kappa1 = new Parameter.Default(1, substitutionParameterValues[7]);
Parameter kappa2 = new Parameter.Default(1, substitutionParameterValues[8]);
FrequencyModel frequencyModel = this.createFrequencyModel();
TN93 tn93 = new TN93(kappa1, kappa2, frequencyModel);
branchModel = new HomogeneousBranchModel(tn93);
} else if (this.substitutionModelIndex == 3) {
// Yang Codon Model
FrequencyModel frequencyModel = this.createFrequencyModel();
Parameter kappa = new Parameter.Default(1, substitutionParameterValues[9]);
Parameter omega = new Parameter.Default(1, substitutionParameterValues[10]);
GY94CodonModel yangCodonModel = new GY94CodonModel(Codons.UNIVERSAL, omega, kappa, frequencyModel);
branchModel = new HomogeneousBranchModel(yangCodonModel);
} else if (this.substitutionModelIndex == 4) {
// MG94CodonModel
FrequencyModel frequencyModel = this.createFrequencyModel();
Parameter alpha = new Parameter.Default(1, substitutionParameterValues[11]);
Parameter beta = new Parameter.Default(1, substitutionParameterValues[12]);
Parameter kappa = new Parameter.Default(1, substitutionParameterValues[13]);
MG94HKYCodonModel mg94 = new MG94HKYCodonModel(Codons.UNIVERSAL, alpha, beta, kappa, frequencyModel);
branchModel = new HomogeneousBranchModel(mg94);
} else if (this.substitutionModelIndex == 5) {
// Blosum62
FrequencyModel frequencyModel = this.createFrequencyModel();
EmpiricalRateMatrix rateMatrix = Blosum62.INSTANCE;
EmpiricalAminoAcidModel empiricalAminoAcidModel = new EmpiricalAminoAcidModel(rateMatrix, frequencyModel);
branchModel = new HomogeneousBranchModel(empiricalAminoAcidModel);
} else if (this.substitutionModelIndex == 6) {
// CPREV
FrequencyModel frequencyModel = this.createFrequencyModel();
EmpiricalRateMatrix rateMatrix = CPREV.INSTANCE;
EmpiricalAminoAcidModel empiricalAminoAcidModel = new EmpiricalAminoAcidModel(rateMatrix, frequencyModel);
branchModel = new HomogeneousBranchModel(empiricalAminoAcidModel);
} else if (this.substitutionModelIndex == 7) {
// Dayhoff
FrequencyModel frequencyModel = this.createFrequencyModel();
EmpiricalRateMatrix rateMatrix = Dayhoff.INSTANCE;
EmpiricalAminoAcidModel empiricalAminoAcidModel = new EmpiricalAminoAcidModel(rateMatrix, frequencyModel);
branchModel = new HomogeneousBranchModel(empiricalAminoAcidModel);
} else if (this.substitutionModelIndex == 8) {
// JTT
FrequencyModel frequencyModel = this.createFrequencyModel();
EmpiricalRateMatrix rateMatrix = JTT.INSTANCE;
EmpiricalAminoAcidModel empiricalAminoAcidModel = new EmpiricalAminoAcidModel(rateMatrix, frequencyModel);
branchModel = new HomogeneousBranchModel(empiricalAminoAcidModel);
} else if (this.substitutionModelIndex == 9) {
// LG
FrequencyModel frequencyModel = this.createFrequencyModel();
EmpiricalRateMatrix rateMatrix = LG.INSTANCE;
EmpiricalAminoAcidModel empiricalAminoAcidModel = new EmpiricalAminoAcidModel(rateMatrix, frequencyModel);
branchModel = new HomogeneousBranchModel(empiricalAminoAcidModel);
} else if (this.substitutionModelIndex == 10) {
// MTREV
FrequencyModel frequencyModel = this.createFrequencyModel();
EmpiricalRateMatrix rateMatrix = MTREV.INSTANCE;
EmpiricalAminoAcidModel empiricalAminoAcidModel = new EmpiricalAminoAcidModel(rateMatrix, frequencyModel);
branchModel = new HomogeneousBranchModel(empiricalAminoAcidModel);
} else if (this.substitutionModelIndex == 11) {
// WAG
FrequencyModel frequencyModel = this.createFrequencyModel();
EmpiricalRateMatrix rateMatrix = WAG.INSTANCE;
EmpiricalAminoAcidModel empiricalAminoAcidModel = new EmpiricalAminoAcidModel(rateMatrix, frequencyModel);
branchModel = new HomogeneousBranchModel(empiricalAminoAcidModel);
} else {
System.out.println("Not yet implemented");
}
return branchModel;
}
use of dr.evomodel.substmodel.FrequencyModel in project beast-mcmc by beast-dev.
the class PartitionData method createFrequencyModel.
public FrequencyModel createFrequencyModel() {
FrequencyModel frequencyModel = null;
if (this.frequencyModelIndex == 0) {
// Nucleotidefrequencies
Parameter freqs = new Parameter.Default(new double[] { frequencyParameterValues[0], frequencyParameterValues[1], frequencyParameterValues[2], frequencyParameterValues[3] });
DataType dataType = this.createDataType();
frequencyModel = new FrequencyModel(dataType, freqs);
} else if (this.frequencyModelIndex == 1) {
Parameter freqs = new Parameter.Default(new double[] { frequencyParameterValues[4], frequencyParameterValues[5], frequencyParameterValues[6], frequencyParameterValues[7], frequencyParameterValues[8], frequencyParameterValues[9], frequencyParameterValues[10], frequencyParameterValues[11], frequencyParameterValues[12], frequencyParameterValues[13], frequencyParameterValues[14], frequencyParameterValues[15], frequencyParameterValues[16], frequencyParameterValues[17], frequencyParameterValues[18], frequencyParameterValues[19], frequencyParameterValues[20], frequencyParameterValues[21], frequencyParameterValues[22], frequencyParameterValues[23], frequencyParameterValues[24], frequencyParameterValues[25], frequencyParameterValues[26], frequencyParameterValues[27], frequencyParameterValues[28], frequencyParameterValues[29], frequencyParameterValues[30], frequencyParameterValues[31], frequencyParameterValues[32], frequencyParameterValues[33], frequencyParameterValues[34], frequencyParameterValues[35], frequencyParameterValues[36], frequencyParameterValues[37], frequencyParameterValues[38], frequencyParameterValues[39], frequencyParameterValues[40], frequencyParameterValues[41], frequencyParameterValues[42], frequencyParameterValues[43], frequencyParameterValues[44], frequencyParameterValues[45], frequencyParameterValues[46], frequencyParameterValues[47], frequencyParameterValues[48], frequencyParameterValues[49], frequencyParameterValues[50], frequencyParameterValues[51], frequencyParameterValues[52], frequencyParameterValues[53], frequencyParameterValues[54], frequencyParameterValues[55], frequencyParameterValues[56], frequencyParameterValues[57], frequencyParameterValues[58], frequencyParameterValues[59], frequencyParameterValues[60], frequencyParameterValues[61], frequencyParameterValues[62], frequencyParameterValues[63], frequencyParameterValues[64] });
DataType dataType = this.createDataType();
frequencyModel = new FrequencyModel(dataType, freqs);
} else if (this.frequencyModelIndex == 2) {
Parameter freqs = new Parameter.Default(new double[] { frequencyParameterValues[65], frequencyParameterValues[66], frequencyParameterValues[67], frequencyParameterValues[68], frequencyParameterValues[69], frequencyParameterValues[70], frequencyParameterValues[71], frequencyParameterValues[72], frequencyParameterValues[73], frequencyParameterValues[74], frequencyParameterValues[75], frequencyParameterValues[76], frequencyParameterValues[77], frequencyParameterValues[78], frequencyParameterValues[79], frequencyParameterValues[80], frequencyParameterValues[81], frequencyParameterValues[82], frequencyParameterValues[83], frequencyParameterValues[84] });
DataType dataType = this.createDataType();
frequencyModel = new FrequencyModel(dataType, freqs);
} else {
System.out.println("Not yet implemented");
}
return frequencyModel;
}
use of dr.evomodel.substmodel.FrequencyModel in project beast-mcmc by beast-dev.
the class EmpiricalCodonModelParser method createNewFreqModel.
// creates new FrequencyModel from XML frequencies
private FrequencyModel createNewFreqModel(DataType codons, EmpiricalRateMatrixReader type) throws XMLParseException {
double[] freqs = type.getFrequencies();
double sum = 0;
for (int j = 0; j < freqs.length; j++) {
sum += freqs[j];
}
if (Math.abs(sum - 1.0) > 1e-8) {
throw new XMLParseException("Frequencies do not sum to 1 (they sum to " + sum + ")");
}
FrequencyModel fm = new FrequencyModel(codons, freqs);
Logger.getLogger("dr.evomodel").info("Using frequencies from data file");
return fm;
}
use of dr.evomodel.substmodel.FrequencyModel in project beast-mcmc by beast-dev.
the class GLMSubstitutionModelParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
DataType dataType = DataTypeUtils.getDataType(xo);
if (dataType == null)
dataType = (DataType) xo.getChild(DataType.class);
int rateCount = (dataType.getStateCount() - 1) * dataType.getStateCount();
// Should be constructed as a log-linear model
GeneralizedLinearModel glm = (GeneralizedLinearModel) xo.getChild(GeneralizedLinearModel.class);
// LogLinearModel glm = (LogLinearModel) xo.getChild(GeneralizedLinearModel.class);
int length = glm.getXBeta().length;
if (length != rateCount) {
throw new XMLParseException("Rates parameter in " + getParserName() + " element should have " + (rateCount) + " dimensions. However GLM dimension is " + length);
}
XMLObject cxo = xo.getChild(ComplexSubstitutionModelParser.ROOT_FREQUENCIES);
FrequencyModel rootFreq = (FrequencyModel) cxo.getChild(FrequencyModel.class);
if (dataType != rootFreq.getDataType()) {
throw new XMLParseException("Data type of " + getParserName() + " element does not match that of its rootFrequencyModel.");
}
return new GLMSubstitutionModel(xo.getId(), dataType, rootFreq, glm);
}
use of dr.evomodel.substmodel.FrequencyModel in project beast-mcmc by beast-dev.
the class GY94CodonModelParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
Codons codons = Codons.UNIVERSAL;
if (xo.hasAttribute(GeneticCode.GENETIC_CODE)) {
String codeStr = xo.getStringAttribute(GeneticCode.GENETIC_CODE);
codons = Codons.findByName(codeStr);
}
Parameter omegaParameter = (Parameter) xo.getElementFirstChild(OMEGA);
int dim = omegaParameter.getDimension();
double value = omegaParameter.getParameterValue(dim - 1);
if (value < 0) {
throw new RuntimeException("Negative Omega parameter value " + value);
}
//END: negative check
Parameter kappaParameter = (Parameter) xo.getElementFirstChild(KAPPA);
dim = kappaParameter.getDimension();
value = kappaParameter.getParameterValue(dim - 1);
if (value < 0) {
throw new RuntimeException("Negative kappa parameter value value " + value);
}
//END: negative check
FrequencyModel freqModel = (FrequencyModel) xo.getChild(FrequencyModel.class);
GY94CodonModel codonModel = new GY94CodonModel(codons, omegaParameter, kappaParameter, freqModel);
return codonModel;
}
Aggregations