]> git.donarmstrong.com Git - mothur.git/blob - sharedcommand.cpp
broke apart read matrix file
[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 ReadOTUFile(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                 
50                         if(globaldata->allLines == 1 || globaldata->lines.count(i+1) == 1 || globaldata->labels.count(SharedList->getLabel()) == 1){
51                         
52                                 shared->getSharedVectors(i, SharedList); //fills sharedGroups with new info and updates sharedVector
53                                 printSharedData(); //prints info to the .shared file
54                         }
55                         
56                         SharedList = input->getSharedListVector(); //get new list vector to process
57                         i++;
58                 }
59                 return 0;
60         }
61         catch(exception& e) {
62                 cout << "Standard Error: " << e.what() << " has occurred in the SharedCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
63                 exit(1);
64         }
65         catch(...) {
66                 cout << "An unknown error has occurred in the SharedCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
67                 exit(1);
68         }
69
70 }
71 //**********************************************************************************************************************
72 void SharedCommand::printSharedData() {
73         try {
74                 //prints out horizontally
75                 for (it = shared->sharedGroups.begin(); it != shared->sharedGroups.end(); it++) {
76                         out << it->second->getLabel() << "\t" << it->first << "\t"; //prints out label and groupname
77                         it->second->print(out); // prints sharedrabundvector
78                 }
79         }
80         catch(exception& e) {
81                 cout << "Standard Error: " << e.what() << " has occurred in the SharedCommand class Function printSharedData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
82                 exit(1);
83         }
84         catch(...) {
85                 cout << "An unknown error has occurred in the SharedCommand class function printSharedData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
86                 exit(1);
87         }
88         
89 }
90
91 //**********************************************************************************************************************
92
93 SharedCommand::~SharedCommand(){
94         //delete list;
95         delete read;
96 }
97
98 //**********************************************************************************************************************