File: TreeFileParserTest.java

package info (click to toggle)
rdp-classifier 2.10.2-4
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 5,280 kB
  • sloc: java: 9,679; xml: 1,522; sh: 56; makefile: 20
file content (83 lines) | stat: -rw-r--r-- 2,563 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
 * TreeFileParserTest.java
 * 
 * Copyright 2006 Michigan State University Board of Trustees
 *
 * Created on September 11, 2003, 12:07 PM
 */

package edu.msu.cme.rdp.classifier.rrnaclassifier;

import edu.msu.cme.rdp.classifier.HierarchyTree;
import edu.msu.cme.rdp.classifier.utils.HierarchyVersion;
import edu.msu.cme.rdp.classifier.io.TreeFileParser;
import java.io.*;
import junit.framework.*;
import java.util.Iterator;

/**
 * A test class for TreeFileParser.
 * @author wangqion
 */
public class TreeFileParserTest extends TestCase {
  
  public TreeFileParserTest(java.lang.String testName) {
    super(testName);
  }
  
  public static void main(java.lang.String[] args) {
    junit.textui.TestRunner.run(suite());
  }
  
  public static Test suite() {
    TestSuite suite = new TestSuite(TreeFileParserTest.class);
    
    return suite;
  }
  
  /** Test of parseTreeFile method, of class classification.TrainingFileParser. */
  public void testParseTreeFile() throws Exception{
    System.out.println("testParseTreeFile");
    TreeFileParser parser = new TreeFileParser();
    InputStream dstream = TreeFileParserTest.class.getResourceAsStream("/test/classifier/testTreeFile.xml");
    HierarchyVersion hVersion = null;
    
    Reader in =  new InputStreamReader( dstream );
    HierarchyTree root = parser.createTree(in, null);
    assertEquals(root.getName(), "BACTERIA");
    assertEquals(root.getLeaveCount(), 4123);
    assertEquals(root.getSizeofSubclasses(), 3);
    //displayTrainingTree(root);
    
    Iterator i = root.getSubclasses().iterator();
    
    while (i.hasNext()){
      HierarchyTree child = (HierarchyTree)i.next();
      if (child.getTaxid() == 1247){  //PLANCTOMYCETES
         assertEquals(child.getName(), "PLANCTOMYCETES");
         assertEquals(child.getRank(), "PHYLUM");
         assertEquals(child.getLeaveCount(), 11);
         assertEquals(child.getSizeofSubclasses(), 1);
      }
    }
  }
  
  private void displayTrainingTree(HierarchyTree root) throws IOException{
    
    System.err.print(" name=" + root.getName() + " leaveCount=" +
    root.getLeaveCount() + " genusIndex=" + root.getGenusIndex() + " taxid=" + root.getTaxid() );
    if (root.getParent() != null){
      System.err.print(" parentTaxid=" + root.getParent().getTaxid() + " rank="+ root.getRank() +"\n");
    }else {
      System.err.print( " rank="+ root.getRank() +"\n");
    }
    
    Iterator i = root.getSubclasses().iterator();
    
    while (i.hasNext()){
      displayTrainingTree( (HierarchyTree)i.next() );
    }
  }
  
  
}