1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
//
// sequencecountparser.cpp
// Mothur
//
// Created by Sarah Westcott on 8/7/12.
// Copyright (c) 2012 Schloss Lab. All rights reserved.
//
#include "sequencecountparser.h"
#include "splitgroupscommand.h"
/************************************************************/
SequenceCountParser::SequenceCountParser(string countfile, string fastafile, vector<string> groupsSelected) {
try {
m = MothurOut::getInstance();
//run splitGroups command to parse files
string inputString = "";
if (groupsSelected.size() == 0) {
CountTable ct; ct.testGroups(countfile, groupsSelected); //fills groupsSelected with groups in count table
}
m->mothurOut("\n/******************************************/\n");
m->mothurOut("Splitting by sample: \n");
time_t start = time(nullptr);
SplitGroupCommand* splitCommand = new SplitGroupCommand(groupsSelected, fastafile, countfile, "");
//type -> files in groups order. fasta -> vector<string>. fastaFileForGroup1 stored in filenames["fasta"][1]
map<string, vector<string> > filenames = splitCommand->getOutputFiles();
delete splitCommand;
m->mothurOut("\nIt took " + toString(time(nullptr) - start) + " seconds to split the dataset by sample.\n");
m->mothurOut("/******************************************/\n");
vector<string> parsedFastaFiles = filenames["fasta"]; //sorted in groups order
vector<string> parsedCountFiles = filenames["count"]; //sorted in groups order
if (parsedCountFiles.size() != groupsSelected.size()) { cout << "should never get here, quitting\n\n"; m->setControl_pressed(true); }
namesOfGroups = groupsSelected;
for (int i = 0; i < groupsSelected.size(); i++) {
vector<string> thisSamplesFiles;
thisSamplesFiles.push_back(parsedFastaFiles[i]);
thisSamplesFiles.push_back(parsedCountFiles[i]);
groupToFiles[groupsSelected[i]] = thisSamplesFiles;
}
//reset current files changed by split.groups
CurrentFile* current; current = CurrentFile::getInstance();
current->setCountFile(countfile);
current->setFastaFile(fastafile);
}
catch(exception& e) {
m->errorOut(e, "SequenceCountParser", "SequenceCountParser");
exit(1);
}
}
/************************************************************/
SequenceCountParser::~SequenceCountParser(){ }
/************************************************************/
int SequenceCountParser::getNumGroups(){ return namesOfGroups.size(); }
/************************************************************/
vector<string> SequenceCountParser::getNamesOfGroups(){ return namesOfGroups; }
/************************************************************/
vector<string> SequenceCountParser::getFiles(string group){
try {
map<string, vector<string> >::iterator it;
it = groupToFiles.find(group);
if (it != groupToFiles.end()) {
return it->second;
}else {
m->mothurOut("[ERROR]: cannot find files for group " + group + ", quitting.\n"); m->setControl_pressed(true);
}
return nullVector;
}
catch(exception& e) {
m->errorOut(e, "SequenceCountParser", "getFiles");
exit(1);
}
}
/************************************************************/
|