]> git.donarmstrong.com Git - mothur.git/blob - distancedb.cpp
started work on classify.seqs command. changed the database class so that it does...
[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                 mostSimSequenceVector[i] = closestMatch;
34         }
35         mothurOut(toString(numCandSeqs)); mothurOutEndLine();
36         searchIndex = 0;
37         inputData.close();
38 }
39
40 /**************************************************************************************************/
41
42 Sequence DistanceDB::findClosestSequence(Sequence* candidateSeq){
43         
44         hit simAccession = mostSimSequenceVector[searchIndex];
45 //      string candidateSeqName, closestMatchSeqName, junk;
46 //      int closestMatchIndexNumber;
47 //      float closestMatchSimScore;
48 //      
49 //      inputData >> candidateSeqName >> closestMatchSeqName >> closestMatchIndexNumber >> closestMatchSimScore;
50 //      getline(inputData, junk);       
51
52 //      searchScore = 100. * closestMatchSimScore;
53
54         searchScore = 100. * simAccession.simScore;
55         searchIndex++;
56 //      return templateSequences[closestMatchIndexNumber];
57         if (templateValid) {  return templateSequences[simAccession.indexNumber];       }
58         else {  return emptySequence;   }
59         
60 }
61
62 /**************************************************************************************************/