String qName, // qualified name
Attributes attrs) throws SAXException {
try {
// the older training file does not contain the copy number info.
if (attrs == null || (attrs.getLength() != 6 && attrs.getLength() != 7)) {
throw new TrainingDataException("Error: the attribute for element: "
+ qName + " is missing or do not have exactly number of attributes");
}
int taxid = Integer.parseInt(attrs.getValue(1));
int parentTaxid = Integer.parseInt(attrs.getValue(3));
int leaveCount = Integer.parseInt(attrs.getValue(4));
int genusIndex = Integer.parseInt(attrs.getValue(5));
double copyNumber = 0.0f;
if ( attrs.getLength() > 6){
copyNumber = Double.parseDouble(attrs.getValue(6));
}
HierarchyTree aTree = new HierarchyTree(attrs.getValue(0), taxid, attrs.getValue(2), leaveCount, genusIndex, copyNumber);
// The first TreeNode is the root
if (root == null) {
aTree.addParent(null);
root = aTree;
} else {
HierarchyTree parent = null;
while (!treeNodeStack.empty()) {
HierarchyTree topNode = (HierarchyTree) treeNodeStack.peek();
if (topNode.getTaxid() == parentTaxid) {
parent = topNode;
break;
}
treeNodeStack.pop();
}
if (parent == null) {
throw new TrainingDataException("Error: The parent for treenode name=: "
+ attrs.getValue(0) + " rank=" + attrs.getValue(2) + " parentTaxid=" + parentTaxid
+ " can not be found in the input file");
}
//System.err.println("parent: " + parent.getName() + " root=" + root.getName());
aTree.addParent(parent);