}
}
//**********************************************************************************************************************
+string TreeGroupCommand::getOutputFileNameTag(string type, string inputName=""){
+ try {
+ string outputFileName = "";
+ map<string, vector<string> >::iterator it;
+
+ //is this a type this command creates
+ it = outputTypes.find(type);
+ if (it == outputTypes.end()) { m->mothurOut("[ERROR]: this command doesn't create a " + type + " output file.\n"); }
+ else {
+ if (type == "tree") { outputFileName = "tre"; }
+ else { m->mothurOut("[ERROR]: No definition for type " + type + " output file tag.\n"); m->control_pressed = true; }
+ }
+ return outputFileName;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "TreeGroupCommand", "getOutputFileNameTag");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
TreeGroupCommand::TreeGroupCommand(){
try {
abort = true; calledHelp = true;
TreeGroupCommand::~TreeGroupCommand(){
if (abort == false) {
if (format == "sharedfile") { delete input; }
- else { delete readMatrix; delete matrix; delete list; }
- delete tmap;
+ else { delete list; }
+ delete ct;
}
}
m->runParse = false;
//create treemap class from groupmap for tree class to use
- tmap = new TreeMap();
- tmap->makeSim(m->getAllGroups());
+ ct = new CountTable();
+ set<string> nameMap;
+ map<string, string> groupMap;
+ set<string> gps;
+ for (int i = 0; i < m->getAllGroups().size(); i++) {
+ nameMap.insert(m->getAllGroups()[i]);
+ gps.insert(m->getAllGroups()[i]);
+ groupMap[m->getAllGroups()[i]] = m->getAllGroups()[i];
+ }
+ ct->createTable(nameMap, groupMap, gps);
//clear globaldatas old tree names if any
m->Treenames.clear();
}else{
//read in dist file
filename = inputfile;
-
+
+ ReadMatrix* readMatrix;
if (format == "column") { readMatrix = new ReadColumnMatrix(filename); }
else if (format == "phylip") { readMatrix = new ReadPhylipMatrix(filename); }
nameMap = new NameAssignment(namefile);
nameMap->readMap();
}
- else{
- nameMap = NULL;
- }
+ else{ nameMap = NULL; }
readMatrix->read(nameMap);
list = readMatrix->getListVector();
- matrix = readMatrix->getMatrix();
+ SparseDistanceMatrix* dMatrix = readMatrix->getDMatrix();
//make treemap
- tmap = new TreeMap();
-
- if (m->control_pressed) { return 0; }
-
- tmap->makeSim(list);
+ ct = new CountTable();
+ set<string> nameMap;
+ map<string, string> groupMap;
+ set<string> gps;
+ for (int i = 0; i < list->getNumBins(); i++) {
+ string bin = list->get(i);
+ nameMap.insert(bin);
+ gps.insert(bin);
+ groupMap[bin] = bin;
+ }
+ ct->createTable(nameMap, groupMap, gps);
- vector<string> namesGroups = tmap->getNamesOfGroups();
+ vector<string> namesGroups = ct->getNamesOfGroups();
m->setGroups(namesGroups);
//clear globaldatas old tree names if any
if (m->control_pressed) { return 0; }
- vector< vector<double> > matrix = makeSimsDist();
+ vector< vector<double> > matrix = makeSimsDist(dMatrix);
+ delete readMatrix;
+ delete dMatrix;
if (m->control_pressed) { return 0; }
//create a new filename
- string outputFile = outputDir + m->getRootName(m->getSimpleName(inputfile)) + "tre";
+ string outputFile = outputDir + m->getRootName(m->getSimpleName(inputfile)) + getOutputFileNameTag("tree");
outputNames.push_back(outputFile); outputTypes["tree"].push_back(outputFile);
Tree* newTree = createTree(matrix);
Tree* TreeGroupCommand::createTree(vector< vector<double> >& simMatrix){
try {
//create tree
- t = new Tree(tmap, simMatrix);
+ t = new Tree(ct, simMatrix);
if (m->control_pressed) { delete t; t = NULL; return t; }
//assemble tree
- map<string, string> empty;
- t->assembleTree(empty);
+ t->assembleTree();
return t;
}
}
}
/***********************************************************/
-vector< vector<double> > TreeGroupCommand::makeSimsDist() {
+vector< vector<double> > TreeGroupCommand::makeSimsDist(SparseDistanceMatrix* matrix) {
try {
numGroups = list->size();
//go through sparse matrix and fill sims
//go through each cell in the sparsematrix
- for(MatData currentCell = matrix->begin(); currentCell != matrix->end(); currentCell++){
- //similairity = -(distance-1)
- simMatrix[currentCell->row][currentCell->column] = -(currentCell->dist -1.0);
- simMatrix[currentCell->column][currentCell->row] = -(currentCell->dist -1.0);
-
- if (m->control_pressed) { return simMatrix; }
+ for (int i = 0; i < matrix->seqVec.size(); i++) {
+ for (int j = 0; j < matrix->seqVec[i].size(); j++) {
+
+ //already checked everyone else in row
+ if (i < matrix->seqVec[i][j].index) {
+ simMatrix[i][matrix->seqVec[i][j].index] = -(matrix->seqVec[i][j].dist -1.0);
+ simMatrix[matrix->seqVec[i][j].index][i] = -(matrix->seqVec[i][j].dist -1.0);
+ if (m->control_pressed) { return simMatrix; }
+ }
+ }
}
return simMatrix;
int TreeGroupCommand::makeSimsShared() {
try {
- numGroups = lookup.size();
- lines.resize(processors);
- for (int i = 0; i < processors; i++) {
- lines[i].start = int (sqrt(float(i)/float(processors)) * numGroups);
- lines[i].end = int (sqrt(float(i+1)/float(processors)) * numGroups);
- }
-
if (subsample) {
if (subsampleSize == -1) { //user has not set size, set size = smallest samples size
subsampleSize = lookup[0]->getNumSeqs();
lookup = temp;
m->setGroups(Groups);
}
+
+ if (lookup.size() < 2) { m->mothurOut("You have not provided enough valid groups. I cannot run the command."); m->mothurOutEndLine(); m->control_pressed = true; return 0; }
}
+ numGroups = lookup.size();
+ lines.resize(processors);
+ for (int i = 0; i < processors; i++) {
+ lines[i].start = int (sqrt(float(i)/float(processors)) * numGroups);
+ lines[i].end = int (sqrt(float(i+1)/float(processors)) * numGroups);
+ }
+
set<string> processedLabels;
set<string> userLabels = labels;
}
//create a new filename
- string outputFile = outputDir + m->getRootName(m->getSimpleName(inputfile)) + treeCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + ".ave.tre";
+ string outputFile = outputDir + m->getRootName(m->getSimpleName(inputfile)) + treeCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + ".ave." + getOutputFileNameTag("tree");
outputNames.push_back(outputFile); outputTypes["tree"].push_back(outputFile);
//creates tree from similarity matrix and write out file
if (m->control_pressed) { break; }
//create a new filename
- string outputFile = outputDir + m->getRootName(m->getSimpleName(inputfile)) + treeCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + ".all.tre";
+ string outputFile = outputDir + m->getRootName(m->getSimpleName(inputfile)) + treeCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + ".all." + getOutputFileNameTag("tree");
outputNames.push_back(outputFile); outputTypes["tree"].push_back(outputFile);
ofstream outAll;
Tree* conTree = consensus.getTree(trees);
//create a new filename
- string conFile = outputDir + m->getRootName(m->getSimpleName(inputfile)) + treeCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + ".cons.tre";
+ string conFile = outputDir + m->getRootName(m->getSimpleName(inputfile)) + treeCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + ".cons." + getOutputFileNameTag("tree");
outputNames.push_back(conFile); outputTypes["tree"].push_back(conFile);
ofstream outTree;
m->openOutputFile(conFile, outTree);
}
//create a new filename
- string outputFile = outputDir + m->getRootName(m->getSimpleName(inputfile)) + treeCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + ".tre";
+ string outputFile = outputDir + m->getRootName(m->getSimpleName(inputfile)) + treeCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + "." + getOutputFileNameTag("tree");
outputNames.push_back(outputFile); outputTypes["tree"].push_back(outputFile);
//creates tree from similarity matrix and write out file