//taxid lineage name rank sample sample .....
// the first line should be the root, we need to handle this specially because a previous bug printed out the root taxon differenly
values = oneHierBlock.get(1);
if( result == null){
// the first line should be the root taxon
ConcretRoot root = new ConcretRoot<MCTaxon>(new MCTaxon(Integer.parseInt(values[0]), values[2], values[3]) );
result = new MultiClassifierResult(root);
result.addSampleList(curSampleList);
}
MCTaxon curTaxon = (MCTaxon)(result.getRoot().getRootTaxonHodler().getTaxon());
// add counts
for ( int i = offset; i< values.length; i++){
curTaxon.incCount(curSampleList.get(i-offset), Double.parseDouble(values[i]));
}
for ( int ln = 2; ln < oneHierBlock.size(); ln++){
values = oneHierBlock.get(ln);
int taxid = Integer.parseInt(values[0]);
// find the parent taxon
String[] lineage = values[1].split(";");
TaxonHolder parentTaxon = result.getRoot().getRootTaxonHodler();
for ( int i= 2; i< lineage.length-2; i+=2){ // the first taxon should be the root
TaxonHolder temp = parentTaxon.getImediateChildTaxon(lineage[i]);
if ( temp == null){
throw new IOException("Error: Something is wrong with input file, can not find parent node " + lineage[i] + " in line: "+ values[1] );
}
parentTaxon = temp;
}
//check if the name and rank match the existing one, in case the result from different version
TaxonHolder tempChild = parentTaxon.getImediateChildTaxon(values[2]);
if ( tempChild != null){
curTaxon = (MCTaxon) tempChild.getTaxon();
if ( curTaxon.getTaxid() != taxid ){
throw new IOException("Error: Something is wrong with input file: taxon name " + values[2] + " with taxid " + taxid
+ " does not match previous processed taxon " + curTaxon.getName() + " with taxid " + curTaxon.getTaxid()
+ ". Possibly from different training sets ??");
}
}else {
curTaxon = new MCTaxon(taxid, values[2], values[3], false);
result.getRoot().addChild(curTaxon, parentTaxon.getTaxon().getTaxid());
curTaxon.setLineage(values[1]);
}
// add counts
for ( int i = offset; i< values.length; i++){
curTaxon.incCount(curSampleList.get(i-offset), Double.parseDouble(values[i]));
}
}
}