]> git.donarmstrong.com Git - mothur.git/blob - readdistcommand.cpp
8de0c34ee039e3c79d539fb7ed531fb2351f3400
[mothur.git] / readdistcommand.cpp
1 /*
2  *  readdistcommand.cpp
3  *  Mothur
4  *
5  *  Created by Sarah Westcott on 1/20/09.
6  *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
7  *
8  */
9
10 #include "readdistcommand.h"
11 #include "readphylip.h"
12 #include "readcolumn.h"
13 #include "readmatrix.hpp"
14
15 ReadDistCommand::ReadDistCommand(){
16         try {
17                 globaldata = GlobalData::getInstance();
18                 
19                 filename = globaldata->inputFileName;
20                 format = globaldata->getFormat();       
21                 
22                 if (format == "column") { read = new ReadColumnMatrix(filename); }      
23                 else if (format == "phylip") { read = new ReadPhylipMatrix(filename); }
24                 else if (format == "matrix") { 
25                                 groupMap = new GroupMap(globaldata->getGroupFile());
26                                 groupMap->readMap();
27                                 //if (globaldata->gGroupmap != NULL) { delete globaldata->gGroupmap;  }
28                                 globaldata->gGroupmap = groupMap;
29                 }
30                 
31                 if (format != "matrix" ) {
32                         if(globaldata->getPrecision() != ""){
33                                 convert(globaldata->getPrecision(), precision); 
34                         }
35                 
36                         if(globaldata->getCutOff() != ""){
37                                 convert(globaldata->getCutOff(), cutoff);       
38                                 cutoff += (5 / (precision * 10.0));
39                         }
40                         read->setCutoff(cutoff);
41         
42                         if(globaldata->getNameFile() != ""){    
43                                 nameMap = new NameAssignment(globaldata->getNameFile());
44                                 nameMap->readMap(1,2);
45                         }
46                         else{
47                                 nameMap = NULL;
48                         }
49                 }
50                         
51         }
52         catch(exception& e) {
53                 cout << "Standard Error: " << e.what() << " has occurred in the ReadDistCommand class Function ReadDistCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
54                 exit(1);
55         }
56         catch(...) {
57                 cout << "An unknown error has occurred in the ReadDistCommand class function ReadDistCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
58                 exit(1);
59         }
60 }
61
62 //**********************************************************************************************************************
63 ReadDistCommand::~ReadDistCommand(){
64         delete read;
65         delete nameMap;
66 }
67
68 //**********************************************************************************************************************
69 int ReadDistCommand::execute(){
70         try {
71                 
72                 if (format == "matrix") {
73                         ifstream in;
74                         openInputFile(filename, in);
75                         matrix = new FullMatrix(in); //reads the matrix file
76                         //memory leak prevention
77                         //if (globaldata->gMatrix != NULL) { delete globaldata->gMatrix;  }
78                         globaldata->gMatrix = matrix; //save matrix for coverage commands
79                 }else {
80                         read->read(nameMap);
81                         //to prevent memory leak
82                         if (globaldata->gListVector != NULL) { delete globaldata->gListVector;  }
83                         globaldata->gListVector = read->getListVector();
84                         if (globaldata->gSparseMatrix != NULL) { delete globaldata->gSparseMatrix;  }
85                         globaldata->gSparseMatrix = read->getMatrix();
86                 }
87                 return 0;
88         }
89         catch(exception& e) {
90                 cout << "Standard Error: " << e.what() << " has occurred in the ReadDistCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
91                 exit(1);
92         }
93         catch(...) {
94                 cout << "An unknown error has occurred in the ReadDistCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
95                 exit(1);
96         }
97 }