use of dr.evolution.sequence.UncertainSequence in project beast-mcmc by beast-dev.
the class SimpleAlignment method getUncertainSitePattern.
@Override
public double[][] getUncertainSitePattern(int siteIndex) {
if (areUncertain()) {
double[][] pattern = new double[getSequenceCount()][];
for (int i = 0; i < getSequenceCount(); ++i) {
Sequence seq = getSequence(i);
if (siteIndex > seq.getLength()) {
pattern[i] = new double[dataType.getStateCount()];
Arrays.fill(pattern[i], 1.0);
} else {
if (seq instanceof UncertainSequence) {
pattern[i] = ((UncertainSequence) seq).getUncertainPattern(siteIndex);
} else {
pattern[i] = new double[dataType.getStateCount()];
int[] states = dataType.getStates(seq.getState(siteIndex));
for (int state : states) {
pattern[i][state] = 1.0;
}
}
}
}
return pattern;
} else {
throw new UnsupportedOperationException("getUncertainSitePattern not implemented yet");
}
}
use of dr.evolution.sequence.UncertainSequence in project beast-mcmc by beast-dev.
the class AlignmentParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
final SimpleAlignment alignment = new SimpleAlignment();
final DataType dataType = DataTypeUtils.getDataType(xo);
if (dataType == null) {
throw new XMLParseException("dataType attribute expected for alignment element");
}
alignment.setDataType(dataType);
for (int i = 0; i < xo.getChildCount(); i++) {
final Object child = xo.getChild(i);
if (child instanceof UncertainSequence) {
alignment.addSequence((UncertainSequence) child);
} else if (child instanceof Sequence) {
alignment.addSequence((Sequence) child);
} else if (child instanceof DataType) {
// already dealt with
} else {
throw new XMLParseException("Unknown child element found in alignment");
}
}
final Logger logger = Logger.getLogger("dr.evoxml");
logger.info("\nRead alignment" + (xo.hasAttribute(XMLParser.ID) ? ": " + xo.getId() : "") + "\n Sequences = " + alignment.getSequenceCount() + "\n Sites = " + alignment.getSiteCount() + "\n Datatype = " + alignment.getDataType().getDescription());
return alignment;
}
use of dr.evolution.sequence.UncertainSequence in project beast-mcmc by beast-dev.
the class SequenceParser method parseXMLObject.
/**
* @return a sequence object based on the XML element it was passed.
*/
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
Taxon taxon = (Taxon) xo.getChild(Taxon.class);
DataType dataType = null;
if (xo.hasAttribute(DataType.DATA_TYPE)) {
String dataTypeStr = xo.getStringAttribute(DataType.DATA_TYPE);
if (dataTypeStr.equals(Nucleotides.DESCRIPTION)) {
dataType = Nucleotides.INSTANCE;
} else if (dataTypeStr.equals(AminoAcids.DESCRIPTION)) {
dataType = AminoAcids.INSTANCE;
} else if (dataTypeStr.equals(Codons.DESCRIPTION)) {
dataType = Codons.UNIVERSAL;
} else if (dataTypeStr.equals(TwoStates.DESCRIPTION)) {
dataType = TwoStates.INSTANCE;
}
}
StringBuffer seqBuf = new StringBuffer();
for (int i = 0; i < xo.getChildCount(); i++) {
Object child = xo.getChild(i);
if (child instanceof String) {
StringTokenizer st = new StringTokenizer((String) child);
while (st.hasMoreTokens()) {
seqBuf.append(st.nextToken());
}
}
}
// We really need to filter the input string to check for illegal characters.
// Perhaps sequence.setSequenceString could throw an exception if any characters
// don't fit the dataType.
String sequenceString = seqBuf.toString();
if (sequenceString.length() == 0) {
throw new XMLParseException("Sequence data missing from sequence element!");
}
Sequence sequence;
if (UncertainSequence.containsWeights(sequenceString)) {
sequence = new UncertainSequence();
} else {
sequence = new Sequence();
}
if (dataType != null) {
sequence.setDataType(dataType);
}
sequence.setSequenceString(sequenceString);
sequence.setTaxon(taxon);
return sequence;
}
Aggregations