File: sensspeccalc.cpp

package info (click to toggle)
mothur 1.48.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 13,684 kB
  • sloc: cpp: 161,854; makefile: 122; sh: 31
file content (75 lines) | stat: -rwxr-xr-x 2,786 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
//
//  sensspeccalc.cpp
//  Mothur
//
//  Created by Sarah Westcott on 1/22/18.
//  Copyright © 2018 Schloss Lab. All rights reserved.
//

#include "sensspeccalc.hpp"


//***************************************************************************************************************
//removes anyone with no valid dists and changes name to matrix short names
SensSpecCalc::SensSpecCalc(OptiData& matrix, ListVector* list){
    try {
        m = MothurOut::getInstance();
        map<string, long long> nameIndex = matrix.getNameIndexMap();
        
        if (list != nullptr) {
            //for each bin
            for (int i = 0; i < list->getNumBins(); i++) {
                
                string binnames = list->get(i);
                vector<string> bnames;
                util.splitAtComma(binnames, bnames);
                
                vector<int> newNames;
                for (int j = 0; j < bnames.size(); j++) {
                    string name = bnames[j];
                    map<string, long long>::iterator itSeq1 = nameIndex.find(name);
                    long long seq1Index = -1;
                    if (itSeq1 != nameIndex.end()) { seq1Index = itSeq1->second; } //you have distances in the matrix
                    
                    newNames.push_back(seq1Index); 
                }
                
                //if there are names in this bin add to new list
                if (newNames.size() != 0) { otus.push_back(newNames); }
            }
        }
    }
    catch(exception& e) {
        m->errorOut(e, "SensSpecCalc", "SensSpecCalc");
        exit(1);
    }
}
//***************************************************************************************************************
void SensSpecCalc::getResults(OptiData& matrix, double& tp, double& tn, double& fp, double& fn){
    try {
        tp = 0; tn = 0; fp = 0; fn = 0;
        
        for(int otu=0;otu<otus.size();otu++){
            if (m->getControl_pressed()) { break; }
            
            for(int i=0;i<otus[otu].size();i++){
                for(int j=0;j<i;j++){
                    if (matrix.isClose(otus[otu][i], otus[otu][j])) { tp++; }
                    else { fp++; }
                }
            }
        }
        double numSeqs = matrix.getNumSeqs() + matrix.getNumSingletons();
        double numDists = matrix.OptiData::getNumDists(); //square matrix OptiData:: uses the parent class function so that we can pass a optiref matrix
        
        fn = (numDists/2) - tp;
        tn = numSeqs * (numSeqs-1)/2  - (fp + fn + tp);
    }
    catch(exception& e) {
        m->errorOut(e, "SensSpecCalc", "getResults");
        exit(1);
    }
}

//***************************************************************************************************************