]> git.donarmstrong.com Git - mothur.git/blob - sharedcommand.cpp
fixed bug in sharedcommand and parselistcommand and changed file extension of sorenso...
[mothur.git] / sharedcommand.cpp
1 /*
2  *  sharedcommand.cpp
3  *  Dotur
4  *
5  *  Created by Sarah Westcott on 1/2/09.
6  *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
7  *
8  */
9
10 #include "sharedcommand.h"
11
12 //**********************************************************************************************************************
13
14 SharedCommand::SharedCommand(){
15         try {
16                 globaldata = GlobalData::getInstance();
17                 
18                 //getting output filename
19                 filename = globaldata->inputFileName;
20                 filename = getRootName(filename);
21                 filename = filename + "shared";
22                 openOutputFile(filename, out);
23         }
24         catch(exception& e) {
25                 cout << "Standard Error: " << e.what() << " has occurred in the SharedCommand class Function SharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
26                 exit(1);
27         }
28         catch(...) {
29                 cout << "An unknown error has occurred in the SharedCommand class function SharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
30                 exit(1);
31         }
32
33 }
34 //**********************************************************************************************************************
35
36 int SharedCommand::execute(){
37         try {
38                 globaldata = GlobalData::getInstance();
39                         
40                 //read in listfile
41                 read = new ReadPhilFile(globaldata->inputFileName);     
42                 read->read(&*globaldata); 
43                 input = globaldata->ginput;
44                 SharedList = globaldata->gSharedList;
45                 
46                 shared = new Shared();
47                 int i = 0;
48                 while(SharedList != NULL){
49                         shared->getSharedVectors(i, SharedList); //fills sharedGroups with new info and updates sharedVector
50                         SharedList = input->getSharedListVector(); //get new list vector to process
51                         printSharedData(); //prints info to the .shared file
52                         i++;
53                 }
54                 return 0;
55         }
56         catch(exception& e) {
57                 cout << "Standard Error: " << e.what() << " has occurred in the SharedCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
58                 exit(1);
59         }
60         catch(...) {
61                 cout << "An unknown error has occurred in the SharedCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
62                 exit(1);
63         }
64
65 }
66 //**********************************************************************************************************************
67 void SharedCommand::printSharedData() {
68         try {
69                 //prints out horizontally
70                 for (it = shared->sharedGroups.begin(); it != shared->sharedGroups.end(); it++) {
71                         out << it->second->getLabel() << "\t" << it->first << "\t"; //prints out label and groupname
72                         it->second->print(out); // prints sharedrabundvector
73                 }
74         }
75         catch(exception& e) {
76                 cout << "Standard Error: " << e.what() << " has occurred in the SharedCommand class Function printSharedData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
77                 exit(1);
78         }
79         catch(...) {
80                 cout << "An unknown error has occurred in the SharedCommand class function printSharedData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
81                 exit(1);
82         }
83         
84 }
85
86 //**********************************************************************************************************************
87
88 SharedCommand::~SharedCommand(){
89         //delete list;
90         delete read;
91 }
92
93 //**********************************************************************************************************************