Package edu.msu.cme.rdp.classifier

Examples of edu.msu.cme.rdp.classifier.Classifier


        FileInputStream inStream1 = new FileInputStream(s1);
        FileInputStream inStream2 = new FileInputStream(s2);
        BufferedWriter wt = new BufferedWriter(new FileWriter(detailFile));


        Classifier aClassifier = factory.createClassifier();
        TaxonTree root = null;
        SequenceReader parser = null;
        Sequence pSeq = null;
        int count = 0;

        try {
            parser = new SequenceReader(inStream1);
            while((pSeq = parser.readNextSequence()) != null) {
                try {
                    ClassificationResult result = aClassifier.classify(pSeq);
                    root = reconstructTree(result, root, SAMPLE1);
                    wt.write(ClassificationResultFormatter.getOutput(result, format));

                } catch (ShortSequenceException e) {
                    System.out.println(e.getMessage());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            parser = new SequenceReader(inStream2);
            while((pSeq = parser.readNextSequence()) != null) {
                try {
                    ClassificationResult result = aClassifier.classify(pSeq);
                    root = reconstructTree(result, root, SAMPLE2);
                    wt.write(ClassificationResultFormatter.getOutput(result, format));

                } catch (ShortSequenceException e) {
                    System.out.println(e.getMessage());
View Full Code Here


       
        HierarchyTree rootTree = train.getRootTree();
        assertEquals(rootTree.getName(), "Bacteria");
        assertNotNull( rootTree.getSubclasses());
       
        Classifier aClassifier = train.createClassifier();
       
        //test addConfidence()
       
        HashMap<HierarchyTree, RankAssignment> determinedMap = new HashMap <HierarchyTree, RankAssignment>();
    HierarchyTree determinedGenusNode = train.getGenusNodebyIndex(4);
    HierarchyTree Enterobacteriales = determinedGenusNode.getParent().getParent();
    HierarchyTree Gammaproteobacteria = Enterobacteriales.getParent();
   
    HierarchyTree aNode = determinedGenusNode;
    while (aNode != null){     
      determinedMap.put(aNode, new RankAssignment(aNode, 0));
      aNode = aNode.getParent();
    }
   
    HierarchyTree bestNode = train.getGenusNodebyIndex(1)// Vibrio
    aClassifier.addConfidence(bestNode, determinedMap);
    assertEquals( determinedMap.get(determinedGenusNode).getConfidence(), 0.0f, 0.0001)//Enterobacter
    assertEquals( determinedMap.get(Enterobacteriales).getConfidence(), 0.0f, 0.0001)//Enterobacteriales
    assertEquals( determinedMap.get(Gammaproteobacteria).getConfidence(), 1.0f, 0.0001)//Gammaproteobacteria
       
    bestNode = train.getGenusNodebyIndex(4);   //Enterobacter
    aClassifier.addConfidence(bestNode, determinedMap);
    assertEquals( determinedMap.get(determinedGenusNode).getConfidence(), 1.0f, 0.0001)//Enterobacter
    assertEquals( determinedMap.get(Enterobacteriales).getConfidence(), 1.0f, 0.0001)//Enterobacteriales
    assertEquals( determinedMap.get(Gammaproteobacteria).getConfidence(), 2.0f, 0.0001)//Gammaproteobacteria
   
    aClassifier.addConfidence(train.getGenusNodebyIndex(4), determinedMap)//Enterobacter
    aClassifier.addConfidence(train.getGenusNodebyIndex(0), determinedMap)//Clostridium
    assertEquals( determinedMap.get(determinedGenusNode).getConfidence(), 2.0f, 0.0001)//Enterobacter
    assertEquals( determinedMap.get(Enterobacteriales).getConfidence(), 2.0f, 0.0001)//Enterobacteriales
    assertEquals( determinedMap.get(Gammaproteobacteria).getConfidence(), 3.0f, 0.0001)//Gammaproteobacteria
    assertEquals( determinedMap.get(rootTree).getConfidence(), 4.0f, 0.0001)//Bacteria
        // end test addConfidence()
       
       
        // end of
        dstream = System.class.getResourceAsStream("/test/classifier/testQuerySeq.fasta");
        in =  new InputStreamReader( dstream );
        BufferedReader infile = new BufferedReader(in);
        // test the first sequence
        String sequence = "";
        infile.readLine();
        sequence = infile.readLine();
        sequence = sequence.toUpperCase();
        ClassifierSequence pSeq = new ClassifierSequence("name", "title", sequence);
        ClassificationResult result = aClassifier.classify(pSeq);
       
        Iterator it = result.getAssignments().iterator();
        RankAssignment classResult = (RankAssignment) it.next();
        assertEquals(classResult.getBestClass().getName() , rootTree.getName());
        assertEquals(classResult.getConfidence(), 1.0, 0.1);
        classResult = (RankAssignment) it.next();
        assertEquals(classResult.getBestClass().getName() , "Proteobacteria");
        it.next();
        classResult = (RankAssignment) it.next();
        assertEquals(classResult.getBestClass().getName() , "Rhizobiales");
        it.next();
        classResult = (RankAssignment) it.next();
        assertEquals(classResult.getBestClass().getName() , "Rhizobium");
       
        //displayResult(result);
        // end of test first sequence
       
        // test the second sequence
        infile.readLine();
        sequence = infile.readLine();
        sequence = sequence.toUpperCase();
        pSeq = new ClassifierSequence("name", "title", sequence);
        result = aClassifier.classify(pSeq);
       
       
        it = result.getAssignments().iterator();
        classResult = (RankAssignment) it.next();
        assertEquals(classResult.getBestClass().getName() , rootTree.getName());
View Full Code Here

TOP

Related Classes of edu.msu.cme.rdp.classifier.Classifier

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.