5 * Created by Sarah Westcott on 3/30/09.
6 * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
10 #include "venncommand.h"
12 //**********************************************************************************************************************
14 VennCommand::VennCommand(){
16 globaldata = GlobalData::getInstance();
18 format = globaldata->getFormat();
22 cout << "Standard Error: " << e.what() << " has occurred in the VennCommand class Function VennCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
26 cout << "An unknown error has occurred in the VennCommand class function VennCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
30 //**********************************************************************************************************************
32 VennCommand::~VennCommand(){
38 //**********************************************************************************************************************
40 int VennCommand::execute(){
44 if (format == "sharedfile") {
46 read = new ReadPhilFile(globaldata->inputFileName);
47 read->read(&*globaldata);
49 input = globaldata->ginput;
50 order = input->getSharedOrderVector();
51 }else if (format == "shared") {
52 //you are using a list and a groupfile
53 read = new ReadPhilFile(globaldata->inputFileName);
54 read->read(&*globaldata);
56 input = globaldata->ginput;
57 SharedList = globaldata->gSharedList;
58 order = SharedList->getSharedOrderVector();
59 }else if (format == "list") {
60 //you are using just a list file and have only one group
61 read = new ReadPhilFile(globaldata->inputFileName);
62 read->read(&*globaldata);
64 ordersingle = globaldata->gorder;
65 input = globaldata->ginput;
69 if (format != "list") {
75 if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){
77 cout << order->getLabel() << '\t' << count << endl;
82 //get next line to process
83 if (format == "sharedfile") {
84 order = input->getSharedOrderVector();
86 //you are using a list and a groupfile
87 SharedList = input->getSharedListVector(); //get new list vector to process
88 if (SharedList != NULL) {
89 order = SharedList->getSharedOrderVector(); //gets new order vector with group info.
97 //reset groups parameter
98 globaldata->Groups.clear(); globaldata->setGroups("");
101 while(ordersingle != NULL){
103 if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(ordersingle->getLabel()) == 1){
105 cout << ordersingle->getLabel() << '\t' << count << endl;
106 venn->getPic(ordersingle);
110 ordersingle = (input->getOrderVector());
117 catch(exception& e) {
118 cout << "Standard Error: " << e.what() << " has occurred in the VennCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
122 cout << "An unknown error has occurred in the VennCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
127 //**********************************************************************************************************************
128 void VennCommand::setGroups() {
130 //if the user has not entered specific groups to analyze then do them all
131 if (globaldata->Groups.size() != 0) {
132 if (globaldata->Groups[0] != "all") {
133 //check that groups are valid
134 for (int i = 0; i < globaldata->Groups.size(); i++) {
135 if (globaldata->gGroupmap->isValidGroup(globaldata->Groups[i]) != true) {
136 cout << globaldata->Groups[i] << " is not a valid group, and will be disregarded." << endl;
137 // erase the invalid group from globaldata->Groups
138 globaldata->Groups.erase(globaldata->Groups.begin()+i);
142 //if the user only entered invalid groups
143 if (globaldata->Groups.size() == 0) {
144 if (globaldata->gGroupmap->namesOfGroups.size() > 4) {
145 cout << "When using the groups parameter you must have at least 1 valid group. I will run the command using the first four groups in your groupfile." << endl;
146 for (int i = 0; i < 4; i++) {
147 globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
150 cout << "When using the groups parameter you must have at least 1 valid group. I will run the command using all the groups in your groupfile." << endl;
151 for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {
152 globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
157 }else{//user has enter "all" and wants the default groups
158 globaldata->Groups.clear();
159 for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {
160 globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
162 globaldata->setGroups("");
165 for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {
166 globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
171 //check to make sure their are only 3 groups
172 if (globaldata->Groups.size() > 4) {
173 cout << "You may only use up to 4 groups at a time with this command. I will choose the first four and disregard the rest." << endl;
174 for (int i = 4; i < globaldata->Groups.size(); i++) {
175 globaldata->Groups.erase(globaldata->Groups.begin()+i);
180 catch(exception& e) {
181 cout << "Standard Error: " << e.what() << " has occurred in the VennCommand class Function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
185 cout << "An unknown error has occurred in the VennCommand class function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
190 /***********************************************************/