]> git.donarmstrong.com Git - mothur.git/blob - distancedb.cpp
added logfile feature
[mothur.git] / distancedb.cpp
1 /*
2  *  distancedb.cpp
3  *  
4  *
5  *  Created by Pat Schloss on 12/29/08.
6  *  Copyright 2008 Patrick D. Schloss. All rights reserved.
7  *
8  */
9
10
11 #include "database.hpp"
12 #include "sequence.hpp"
13 #include "distancedb.hpp"
14
15
16 /**************************************************************************************************/
17
18 DistanceDB::DistanceDB(string fastaFileName, string distanceFileName) : Database(fastaFileName) {
19         
20         ifstream inputData;
21         openInputFile(distanceFileName, inputData);
22         int numCandSeqs=count(istreambuf_iterator<char>(inputData),istreambuf_iterator<char>(), '\n');  //      count the number of
23         inputData.seekg(0);                                                                                                                                             //      sequences
24
25         hit closestMatch;
26         string candidateSeqName;
27         string junk;
28         
29         mostSimSequenceVector.resize(numCandSeqs);
30         
31         for(int i=0;i<numCandSeqs;i++){
32                 inputData >> candidateSeqName >> closestMatch.seqName >> closestMatch.indexNumber >> closestMatch.simScore;
33 //              getline(inputData, junk);       
34                 mostSimSequenceVector[i] = closestMatch;
35         }
36         mothurOut(toString(numCandSeqs)); mothurOutEndLine();
37         searchIndex = 0;
38         inputData.close();
39 }
40
41 /**************************************************************************************************/
42
43 Sequence DistanceDB::findClosestSequence(Sequence* candidateSeq){
44         
45         hit simAccession = mostSimSequenceVector[searchIndex];
46 //      string candidateSeqName, closestMatchSeqName, junk;
47 //      int closestMatchIndexNumber;
48 //      float closestMatchSimScore;
49 //      
50 //      inputData >> candidateSeqName >> closestMatchSeqName >> closestMatchIndexNumber >> closestMatchSimScore;
51 //      getline(inputData, junk);       
52
53 //      searchScore = 100. * closestMatchSimScore;
54
55         searchScore = 100. * simAccession.simScore;
56         searchIndex++;
57 //      return templateSequences[closestMatchIndexNumber];
58         return templateSequences[simAccession.indexNumber];
59         
60 }
61
62 /**************************************************************************************************/