Package edu.msu.cme.rdp.classifier

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


        SeqInfo seqInfo = new SeqInfo(result.getSequence().getSeqName(), result.getSequence().getDesc());
        seqInfo.setReverse(result.isReverse());

        TaxonTree curTree = null;
        while (assignIt.hasNext()) {
            RankAssignment assign = (RankAssignment) assignIt.next();

            if (nodeCount == 0) {
                if (root == null) {     // the parent of the root is null
                    root = new TaxonTree(assign.getTaxid(), assign.getName(), assign.getRank(), null);
                } else {
                    if (root.getTaxid() != assign.getTaxid()) {
                        // this should never occur
                        throw new IllegalStateException("Error: the root " + assign.getTaxid()
                                + " of assignment for " + result.getSequence().getSeqName()
                                + " is different from the other sequences " + root.getTaxid());
                    }
                }
                curTree = root;

            } else {
                curTree = curTree.getChildbyTaxid(assign.getTaxid(), assign.getName(), assign.getRank());
            }
            Score score = new Score(assign.getConfidence(), seqInfo, curTree);
            if (sample.equals(SAMPLE1)) {
                curTree.addS1Score(score);
            } else {
                curTree.addS2Score(score);
            }
View Full Code Here


            throw new IllegalArgumentException("Root of \"" + line + "\" does not match the Root node in the original Classifier training data: " + root.getName() + "\t" + root.getRank());
        }
       
        HierarchyTree currRoot = root;

        assignments.add(new RankAssignment(currRoot, Float.valueOf(tokens[4].trim())));

        for(int index = 5;index < tokens.length;index += 3) {
            String nextName = tokens[index].trim();
            boolean found = false;
            for(HierarchyTree tree : (List<HierarchyTree>)currRoot.getSubclasses()) {
                if(tree.getName().equals(nextName)) {
                    currRoot = tree;
                    assignments.add(new RankAssignment(currRoot, Float.valueOf(tokens[index + 2].trim())));
                    found = true;
                    break;
                }
            }
            if ( !found){
View Full Code Here

        for (RankAssignment assignment : (List<RankAssignment>) result.getAssignments()) {
            rankMap.put(assignment.getRank().toLowerCase(), assignment);
        }
       
        // if the score is missing for the rank, report the conf and name from the lower rank
        RankAssignment prevAssign = null;
        for (int i = ranks.length -1; i>=0; i--) {
            RankAssignment assign = rankMap.get(ranks[i]);
            if (assign != null) {
                assignmentStr.insert(0, "\t" + assign.getName() +"\t" + assign.getRank() + "\t" + assign.getConfidence());
                prevAssign = assign;
            } else {
                assignmentStr.insert(0, "\t" + prevAssign.getName() +"\t" + ranks[i] + "\t" + prevAssign.getConfidence());
            }
           
View Full Code Here

        for (RankAssignment assignment : (List<RankAssignment>) result.getAssignments()) {
            rankMap.put(assignment.getRank().toLowerCase(), assignment);
        }
        // if the score is missing for the rank, report the conf and name from the lower rank if above the conf
        // if the lower rank is below the conf, output unclassified node name and the conf from the one above the conf
        RankAssignment prevAssign = result.getAssignments().get(0);
        assignmentStr.append(result.getSequence().getSeqName());
        for (int i = 0; i <= ranks.length -1; i++) {
            RankAssignment assign = rankMap.get(ranks[i]);
            if (assign != null) {
                if ( assign.getConfidence() <= conf){
                    assignmentStr.append("\t" + "unclassified_" + prevAssign.getName() );                  
                }else {
                    assignmentStr.append("\t" + assign.getName() );
                    prevAssign = assign;
                }
               
            } else {
                if ( prevAssign != null && prevAssign.getConfidence() >= conf){
View Full Code Here

            rankMap.put(assignment.getRank().toLowerCase(), assignment);
        }
        // if the score is missing for the rank, report the conf and name from the lower rank if above the conf
        // if the lower rank is below the conf, output unclassified node name and the conf from the one above the conf
        // remove the quotes in the name
        RankAssignment prevAssign = result.getAssignments().get(0);
        assignmentStr.append(result.getSequence().getSeqName() + "\t");
        for (int i = 0; i <= ranks.length -1; i++) {
            RankAssignment assign = rankMap.get(ranks[i]);
            String rank = RANKS[i].substring(0,1).toLowerCase();
            if (assign != null) {
                if ( assign.getConfidence() <= conf){
                    assignmentStr.append(rank + "__" + "unclassified_" + prevAssign.getName().replaceAll("\"", "") );                  
                }else {
                    assignmentStr.append( rank + "__"+ assign.getName().replaceAll("\"", "") );
                    prevAssign = assign;
                }
               
            } else {
                if ( prevAssign != null && prevAssign.getConfidence() >= conf){
View Full Code Here

        StringBuilder assignmentStr = new StringBuilder();
  boolean set = false;
  List assignments = result.getAssignments();
        for (int i = assignments.size() - 1; i >= 0; i--) {
          int markAssigned = 0;
    RankAssignment assign = (RankAssignment) assignments.get(i);
    if (!set && assign.getConfidence() >= conf) {
      markAssigned = 1;
      set = true;
    }
     assignmentStr.append(result.getSequence().getSeqName()).append("\t").append(result.getTrainsetNo()).append("\t").append(assign.getTaxid()).append("\t").append(assign.getConfidence()).append("\t").append(markAssigned).append("\n");
  }

        return assignmentStr.toString();
    }
View Full Code Here

    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());
        assertEquals(classResult.getConfidence(), 1.0, 0.1);
        classResult = (RankAssignment) it.next();
        assertEquals(classResult.getBestClass().getName() , "Firmicutes");
        it.next();
        classResult = (RankAssignment) it.next();
        assertEquals(classResult.getBestClass().getName() , "Clostridiales");
        it.next();
        classResult = (RankAssignment) it.next();
        assertEquals(classResult.getBestClass().getName() , "Clostridium");
        // end of test second sequence
    }
View Full Code Here

   
    private void displayResult(ClassificationResult result){
        List assignments = result.getAssignments();
        Iterator it = assignments.iterator();
        while (it.hasNext()){
            RankAssignment classResult = (RankAssignment) it.next();
            System.err.print("\n" + classResult.getBestClass().getName() + "  " + classResult.getConfidence());
        }
    }
View Full Code Here

TOP

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

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.