use of dr.evolution.datatype.Microsatellite in project beast-mcmc by beast-dev.
the class MsatBMAParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
//get microsatellite data type
Microsatellite dataType = (Microsatellite) xo.getChild(Microsatellite.class);
//whether mutational bias is in logit space
boolean logit = xo.getAttribute(LOGIT, true);
XMLObject modelsXO = xo.getChild(MODELS);
int modelCount = modelsXO.getChildCount();
HashMap<Integer, Integer> modelBitIndMap = new HashMap<Integer, Integer>(modelCount);
for (int i = 0; i < modelCount; i++) {
XMLObject modelXO = (XMLObject) modelsXO.getChild(i);
String bitVec = modelXO.getStringAttribute(BINARY);
int bitVecVal = Integer.parseInt(bitVec, 2);
int modelCode = modelXO.getIntegerAttribute(CODE);
modelBitIndMap.put(bitVecVal, modelCode);
}
Parameter[][] paramModelMap = new Parameter[6][modelCount];
XMLObject propRatesXO = xo.getChild(RATE_PROPS);
ArrayList<Parameter> rateProps = processParameters(propRatesXO, paramModelMap, MsatBMA.PROP_INDEX);
XMLObject quadRatesXO = xo.getChild(RATE_QUADS);
ArrayList<Parameter> rateQuads = processParameters(quadRatesXO, paramModelMap, MsatBMA.QUAD_INDEX);
XMLObject biasConstsXO = xo.getChild(BIAS_CONSTS);
ArrayList<Parameter> biasConsts = processParameters(biasConstsXO, paramModelMap, MsatBMA.BIAS_CONST_INDEX);
XMLObject biasLinsXO = xo.getChild(BIAS_LINS);
ArrayList<Parameter> biasLins = processParameters(biasLinsXO, paramModelMap, MsatBMA.BIAS_LIN_INDEX);
XMLObject geosXO = xo.getChild(GEOS);
ArrayList<Parameter> geos = processParameters(geosXO, paramModelMap, MsatBMA.GEO_INDEX);
XMLObject phaseProbXO = xo.getChild(PHASE_PROBS);
ArrayList<Parameter> phaseProbs = processParameters(phaseProbXO, paramModelMap, MsatBMA.PHASE_PROB_INDEX);
Parameter modelChoose = (Parameter) xo.getElementFirstChild(MODEL_CHOOSE);
Parameter modelIndicator = (Parameter) xo.getElementFirstChild(MODEL_INDICATOR);
printParameters(paramModelMap);
return new MsatBMA(dataType, logit, rateProps, rateQuads, biasConsts, biasLins, geos, phaseProbs, paramModelMap, modelChoose, modelIndicator, modelBitIndMap);
}
use of dr.evolution.datatype.Microsatellite in project beast-mcmc by beast-dev.
the class NewMicrosatelliteModelParser method parseXMLObject.
//AbstractXMLObjectParser implementation
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
//get msat data type
System.out.println("Using watkins' model");
Microsatellite msat = (Microsatellite) xo.getChild(Microsatellite.class);
//get FrequencyModel
FrequencyModel freqModel = null;
if (xo.hasChildNamed(FrequencyModelParser.FREQUENCIES)) {
freqModel = (FrequencyModel) xo.getElementFirstChild(FrequencyModelParser.FREQUENCIES);
}
return new NewMicrosatelliteModel(msat, freqModel);
}
use of dr.evolution.datatype.Microsatellite in project beast-mcmc by beast-dev.
the class BeautiOptions method unshareMicroSat.
public void unshareMicroSat() {
Microsatellite microsatellite = null;
for (PartitionSubstitutionModel model : getPartitionSubstitutionModels(Microsatellite.INSTANCE)) {
if (microsatellite == null) {
microsatellite = model.getMicrosatellite();
} else {
microsatellite = new Microsatellite(model.getName() + ".microsat", microsatellite.getMin(), microsatellite.getMax(), 1);
model.setMicrosatellite(microsatellite);
}
}
}
use of dr.evolution.datatype.Microsatellite in project beast-mcmc by beast-dev.
the class TwoPhaseModelParser method parseXMLObject.
//AbstractXMLObjectParser implementation
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
OnePhaseModel subModel = (OnePhaseModel) xo.getElementFirstChild(SUBMODEL);
Microsatellite dataType = (Microsatellite) xo.getChild(Microsatellite.class);
Parameter.Default geoParam = (Parameter.Default) xo.getElementFirstChild(GEO_PARAM);
Parameter paramP = (Parameter) xo.getElementFirstChild(ONEPHASEPR_PARAM);
Parameter limitE = null;
if (xo.hasChildNamed(TRANS_PARAM)) {
limitE = (Parameter) xo.getElementFirstChild(TRANS_PARAM);
}
boolean estimateSubmodelParams = xo.getAttribute(ESTIMATE_SUBMODEL_PARAMS, false);
FrequencyModel freqModel = null;
if (xo.hasChildNamed(FrequencyModelParser.FREQUENCIES)) {
freqModel = (FrequencyModel) xo.getElementFirstChild(FrequencyModelParser.FREQUENCIES);
}
return new TwoPhaseModel(dataType, freqModel, subModel, paramP, geoParam, limitE, estimateSubmodelParams);
}
use of dr.evolution.datatype.Microsatellite in project beast-mcmc by beast-dev.
the class MicroSatImporter method importPatterns.
public List<Patterns> importPatterns() throws IOException, Importer.ImportException {
List<Patterns> microsatPatList = new ArrayList<Patterns>();
// 1st List<String> is taxon names
List<List<String>> data = new ArrayList<List<String>>();
// microsatName[0] is keyword, microsatName[1] is name
String[] microsatName = new String[2];
microsatName[1] = "unnamed.microsat";
String line = reader.readLine();
while (line.startsWith("#")) {
// comments
if (line.toUpperCase().contains("NAME")) {
microsatName = line.trim().split("[" + delimiter + " ]+");
if (microsatName[1] == null || microsatName[1].length() < 1)
throw new Importer.ImportException("Improper microsatellite name : " + microsatName[1]);
}
line = reader.readLine();
}
// read locus (microsat pattern) names in the 1st row after comments, where 1st element is id
// trim trailing whitespace ?
String[] names = line.trim().split("[" + delimiter + " ]+");
// for validation
int colLen = names.length;
if (colLen < 2)
throw new Importer.ImportException("Import file must have more than 1 columns : " + colLen);
for (int i = 0; i < colLen; i++) {
// init data
List<String> l = new ArrayList<String>();
data.add(l);
}
int min = Integer.MAX_VALUE;
int max = Integer.MIN_VALUE;
line = reader.readLine();
while (line != null) {
// read data
String[] dataLine = line.trim().split("[" + delimiter + " ]+");
if (dataLine.length != colLen)
throw new Importer.ImportException("The number of name columns are different with values columns," + "\nplease use only letters or numbers in the name.");
for (int i = 0; i < dataLine.length; i++) {
data.get(i).add(dataLine[i]);
if (i > 0) {
int v = parseInt(dataLine[i]);
if (v != Microsatellite.UNKNOWN_STATE_LENGTH) {
if (min > v)
min = v;
if (max < v)
max = v;
}
}
}
line = reader.readLine();
}
if (max < min)
throw new Importer.ImportException("Importing invalid data: max < min !");
// if (min - 2 < 0) throw new Importer.ImportException("Importing invaild data: min-2 < 0 where min = " + min);
// The min also = 1 and max should be the longest repeat length + 2.
microsatellite = new Microsatellite(microsatName[1], 1, max + 2, 1);
Taxa taxaHaploid = new Taxa();
for (String name : data.get(0)) {
Taxon t = new Taxon(name);
taxaHaploid.addTaxon(t);
}
// unionSetTaxonList.addTaxa(taxaHaploid);
Patterns microsatPat;
for (int i = 1; i < data.size(); i++) {
// create pattern
// List<Integer> pattern = new ArrayList<Integer>();
List<Integer> pattern;
Taxa taxa = new Taxa();
if ((i + 1 < data.size()) && names[i].equalsIgnoreCase(names[i + 1])) {
// diploid: Locus2 Locus2
Taxa taxaDiploid = new Taxa();
for (String name : data.get(0)) {
Taxon t = new Taxon(names[i] + "_1_" + name);
taxaDiploid.addTaxon(t);
}
for (String name : data.get(0)) {
Taxon t = new Taxon(names[i] + "_2_" + name);
taxaDiploid.addTaxon(t);
}
if (unionSetTaxonList.containsAny(taxaDiploid))
throw new Importer.ImportException("Importing invalid data: duplicate taxon name in this locus : " + names[i]);
unionSetTaxonList.addTaxa(taxaDiploid);
hasDifferentTaxon = true;
pattern = new ArrayList<Integer>();
String value;
int size = data.get(i).size();
for (int v = 0; v < size; v++) {
value = data.get(i).get(v);
// if (!isUnknownChar(value)) {
Taxon t = taxaDiploid.getTaxon(v);
if (!taxa.contains(t)) {
taxa.addTaxon(t);
//microsatellite.getState(value);
pattern.add(parseInt(value));
if (!unionSetTaxonList.contains(t)) {
unionSetTaxonList.addTaxon(t);
if (i > 1)
hasDifferentTaxon = true;
}
}
// }
}
for (int v = 0; v < data.get(i + 1).size(); v++) {
value = data.get(i + 1).get(v);
// if (!isUnknownChar(value)) {
Taxon t = taxaDiploid.getTaxon(v + size);
if (!taxa.contains(t)) {
taxa.addTaxon(t);
//microsatellite.getState(value);
pattern.add(parseInt(value));
if (!unionSetTaxonList.contains(t)) {
unionSetTaxonList.addTaxon(t);
if (i > 1)
hasDifferentTaxon = true;
}
}
// }
}
i++;
} else {
// haploid Locus1
pattern = new ArrayList<Integer>();
for (int v = 0; v < data.get(i).size(); v++) {
String value = data.get(i).get(v);
// if (!isUnknownChar(value)) {
Taxon t = taxaHaploid.getTaxon(v);
if (!taxa.contains(t)) {
taxa.addTaxon(t);
//microsatellite.getState(value);
pattern.add(parseInt(value));
if (!unionSetTaxonList.contains(t)) {
unionSetTaxonList.addTaxon(t);
if (i > 1)
hasDifferentTaxon = true;
}
}
// }
}
}
int[] p = new int[pattern.size()];
for (int v = 0; v < pattern.size(); v++) {
p[v] = pattern.get(v);
}
microsatPat = new Patterns(microsatellite, taxa);
microsatPat.addPattern(p);
microsatPat.setId(names[i]);
microsatPatList.add(microsatPat);
}
return microsatPatList;
}
Aggregations