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