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 cout << "When using the groups parameter you must have at least 1 valid group. I will run the command using the first three groups in your groupfile." << endl;
145 for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {
146 globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
149 }else{//user has enter "all" and wants the default groups
150 globaldata->Groups.clear();
151 for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {
152 globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
154 globaldata->setGroups("");
157 for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {
158 globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
163 //check to make sure their are only 3 groups
164 if (globaldata->Groups.size() > 3) {
165 cout << "You may only use 3 groups at a time with this command. I will choose the first three and disregard the rest." << endl;
166 for (int i = 3; i < globaldata->Groups.size(); i++) {
167 globaldata->Groups.erase(globaldata->Groups.begin()+i);
172 catch(exception& e) {
173 cout << "Standard Error: " << e.what() << " has occurred in the VennCommand class Function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
177 cout << "An unknown error has occurred in the VennCommand class function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
182 /***********************************************************/