本文整理汇总了C++中CountTable类的典型用法代码示例。如果您正苦于以下问题:C++ CountTable类的具体用法?C++ CountTable怎么用?C++ CountTable使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CountTable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getOutputFileName
//**********************************************************************************************************************
int GetSeqsCommand::readCount(){
try {
string thisOutputDir = outputDir;
if (outputDir == "") { thisOutputDir += m->hasPath(countfile); }
map<string, string> variables;
variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(countfile));
variables["[extension]"] = m->getExtension(countfile);
string outputFileName = getOutputFileName("count", variables);
ofstream out;
m->openOutputFile(outputFileName, out);
ifstream in;
m->openInputFile(countfile, in);
bool wroteSomething = false;
int selectedCount = 0;
string headers = m->getline(in); m->gobble(in);
out << headers << endl;
string test = headers; vector<string> pieces = m->splitWhiteSpace(test);
string name, rest; int thisTotal; rest = "";
while (!in.eof()) {
if (m->control_pressed) { in.close(); out.close(); m->mothurRemove(outputFileName); return 0; }
in >> name; m->gobble(in);
in >> thisTotal; m->gobble(in);
if (pieces.size() > 2) { rest = m->getline(in); m->gobble(in); }
if (m->debug) { m->mothurOut("[DEBUG]: " + name + '\t' + rest + "\n"); }
if (names.count(name) != 0) {
out << name << '\t' << thisTotal << '\t' << rest << endl;
wroteSomething = true;
selectedCount+= thisTotal;
}
}
in.close();
out.close();
//check for groups that have been eliminated
CountTable ct;
if (ct.testGroups(outputFileName)) {
ct.readTable(outputFileName, true, false);
ct.printTable(outputFileName);
}
if (wroteSomething == false) { m->mothurOut("Your file does not contain any sequence from the .accnos file."); m->mothurOutEndLine(); }
outputTypes["count"].push_back(outputFileName); outputNames.push_back(outputFileName);
m->mothurOut("Selected " + toString(selectedCount) + " sequences from your count file."); m->mothurOutEndLine();
return 0;
}
catch(exception& e) {
m->errorOut(e, "GetSeqsCommand", "readCount");
exit(1);
}
}
示例2: seq
SequenceCountParser::SequenceCountParser(string countfile, string fastafile) {
try {
m = MothurOut::getInstance();
//read count file
CountTable countTable;
countTable.readTable(countfile, true, false);
//initialize maps
namesOfGroups = countTable.getNamesOfGroups();
for (int i = 0; i < namesOfGroups.size(); i++) {
vector<Sequence> temp;
map<string, int> tempMap;
seqs[namesOfGroups[i]] = temp;
countTablePerGroup[namesOfGroups[i]] = tempMap;
}
//read fasta file making sure each sequence is in the group file
ifstream in;
m->openInputFile(fastafile, in);
int fastaCount = 0;
while (!in.eof()) {
if (m->control_pressed) { break; }
Sequence seq(in); m->gobble(in);
fastaCount++;
if (m->debug) { if((fastaCount) % 1000 == 0){ m->mothurOut("[DEBUG]: reading seq " + toString(fastaCount) + "\n."); } }
if (seq.getName() != "") {
allSeqsMap[seq.getName()] = seq.getName();
vector<int> groupCounts = countTable.getGroupCounts(seq.getName());
for (int i = 0; i < namesOfGroups.size(); i++) {
if (groupCounts[i] != 0) {
seqs[namesOfGroups[i]].push_back(seq);
countTablePerGroup[namesOfGroups[i]][seq.getName()] = groupCounts[i];
}
}
}
}
in.close();
}
catch(exception& e) {
m->errorOut(e, "SequenceCountParser", "SequenceCountParser");
exit(1);
}
}
示例3: readCount
//**********************************************************************************************************************
int ListSeqsCommand::readCount(){
try {
CountTable ct;
ct.readTable(countfile, false, false);
if (m->control_pressed) { return 0; }
names = ct.getNamesOfSeqs();
return 0;
}
catch(exception& e) {
m->errorOut(e, "ListSeqsCommand", "readCount");
exit(1);
}
}
示例4: getOutputFileName
//**********************************************************************************************************************
int SharedCommand::createSharedFromCount() {
try {
//getting output filename
string filename = countfile;
if (outputDir == "") { outputDir += util.hasPath(filename); }
map<string, string> variables;
variables["[filename]"] = outputDir + util.getRootName(util.getSimpleName(filename));
filename = getOutputFileName("shared",variables);
outputNames.push_back(filename); outputTypes["shared"].push_back(filename);
ofstream out; bool printHeaders = true;
util.openOutputFile(filename, out);
CountTable ct; ct.readTable(countfile, true, false);
map<string, string> seqNameToOtuName;
SharedRAbundVectors* lookup = ct.getShared(Groups, seqNameToOtuName);
lookup->setLabels(*labels.begin());
lookup->print(out, printHeaders);
out.close();
delete lookup;
string mapFilename = getOutputFileName("map",variables);
outputNames.push_back(mapFilename); outputTypes["map"].push_back(mapFilename);
ofstream outMap;
util.openOutputFile(mapFilename, outMap);
for (map<string, string>::iterator it = seqNameToOtuName.begin(); it != seqNameToOtuName.end(); it++) { outMap << it->first << '\t' << it->second << endl; }
outMap.close();
return 0;
}
catch(exception& e) {
m->errorOut(e, "SharedCommand", "createSharedFromCount");
exit(1);
}
}
示例5: createRabund
int GetRAbundCommand::createRabund(CountTable& ct, ListVector*& list, RAbundVector*& rabund){
try {
rabund->setLabel(list->getLabel());
for(int i = 0; i < list->getNumBins(); i++) {
if (m->control_pressed) { return 0; }
vector<string> binNames;
string bin = list->get(i);
m->splitAtComma(bin, binNames);
int total = 0;
for (int j = 0; j < binNames.size(); j++) {
total += ct.getNumSeqs(binNames[j]);
}
rabund->push_back(total);
}
return 0;
}
catch(exception& e) {
m->errorOut(e, "GetRAbundCommand", "createRabund");
exit(1);
}
}
示例6: if
//**********************************************************************************************************************
int RemoveRareCommand::processList(){
try {
//you must provide a label because the names in the listfile need to be consistent
string thisLabel = "";
if (allLines) { m->mothurOut("For the listfile you must select one label, using first label in your listfile."); m->mothurOutEndLine(); }
else if (labels.size() > 1) { m->mothurOut("For the listfile you must select one label, using " + (*labels.begin()) + "."); m->mothurOutEndLine(); thisLabel = *labels.begin(); }
else { thisLabel = *labels.begin(); }
InputData input(listfile, "list");
ListVector* list = input.getListVector();
//get first one or the one we want
if (thisLabel != "") {
//use smart distancing
set<string> userLabels; userLabels.insert(thisLabel);
set<string> processedLabels;
string lastLabel = list->getLabel();
while((list != NULL) && (userLabels.size() != 0)) {
if(userLabels.count(list->getLabel()) == 1){
processedLabels.insert(list->getLabel());
userLabels.erase(list->getLabel());
break;
}
if ((m->anyLabelsToProcess(list->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
processedLabels.insert(list->getLabel());
userLabels.erase(list->getLabel());
delete list;
list = input.getListVector(lastLabel);
break;
}
lastLabel = list->getLabel();
delete list;
list = input.getListVector();
}
if (userLabels.size() != 0) {
m->mothurOut("Your file does not include the label " + thisLabel + ". I will use " + lastLabel + "."); m->mothurOutEndLine();
list = input.getListVector(lastLabel);
}
}
string thisOutputDir = outputDir;
if (outputDir == "") { thisOutputDir += m->hasPath(listfile); }
map<string, string> variables;
variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(listfile));
variables["[extension]"] = m->getExtension(listfile);
variables["[tag]"] = list->getLabel();
string outputFileName = getOutputFileName("list", variables);
variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(groupfile));
variables["[extension]"] = m->getExtension(groupfile);
string outputGroupFileName = getOutputFileName("group", variables);
variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(countfile));
variables["[extension]"] = m->getExtension(countfile);
string outputCountFileName = getOutputFileName("count", variables);
ofstream out, outGroup;
m->openOutputFile(outputFileName, out);
bool wroteSomething = false;
//if groupfile is given then use it
GroupMap* groupMap;
CountTable ct;
if (groupfile != "") {
groupMap = new GroupMap(groupfile); groupMap->readMap();
SharedUtil util;
vector<string> namesGroups = groupMap->getNamesOfGroups();
util.setGroups(Groups, namesGroups);
m->openOutputFile(outputGroupFileName, outGroup);
}else if (countfile != "") {
ct.readTable(countfile, true, false);
if (ct.hasGroupInfo()) {
vector<string> namesGroups = ct.getNamesOfGroups();
SharedUtil util;
util.setGroups(Groups, namesGroups);
}
}
if (list != NULL) {
vector<string> binLabels = list->getLabels();
vector<string> newLabels;
//make a new list vector
ListVector newList;
newList.setLabel(list->getLabel());
//for each bin
for (int i = 0; i < list->getNumBins(); i++) {
if (m->control_pressed) { if (groupfile != "") { delete groupMap; outGroup.close(); m->mothurRemove(outputGroupFileName); } out.close(); m->mothurRemove(outputFileName); return 0; }
//parse out names that are in accnos file
string binnames = list->get(i);
vector<string> names;
string saveBinNames = binnames;
m->splitAtComma(binnames, names);
//.........这里部分代码省略.........
示例7: defined
EstOutput Unweighted::createProcesses(Tree* t, vector< vector<string> > namesOfGroupCombos, CountTable* ct) {
try {
int process = 1;
vector<int> processIDS;
bool recalc = false;
EstOutput results;
#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
//loop through and create all the processes you want
while (process != processors) {
pid_t pid = fork();
if (pid > 0) {
processIDS.push_back(pid); //create map from line number to pid so you can append files in correct order later
process++;
}else if (pid == 0){
EstOutput myresults;
myresults = driver(t, namesOfGroupCombos, lines[process].start, lines[process].num, ct);
if (m->control_pressed) { exit(0); }
//pass numSeqs to parent
ofstream out;
string tempFile = outputDir + m->mothurGetpid(process) + ".unweighted.results.temp";
m->openOutputFile(tempFile, out);
out << myresults.size() << endl;
for (int i = 0; i < myresults.size(); i++) { out << myresults[i] << '\t'; } out << endl;
out.close();
exit(0);
}else {
m->mothurOut("[ERROR]: unable to spawn the number of processes you requested, reducing number to " + toString(process) + "\n"); processors = process;
for (int i = 0; i < processIDS.size(); i++) { kill (processIDS[i], SIGINT); }
//wait to die
for (int i=0;i<processIDS.size();i++) {
int temp = processIDS[i];
wait(&temp);
}
m->control_pressed = false;
for (int i=0;i<processIDS.size();i++) {
m->mothurRemove(outputDir + (toString(processIDS[i]) + ".unweighted.results.temp"));
}
recalc = true;
break;
}
}
if (recalc) {
//test line, also set recalc to true.
//for (int i = 0; i < processIDS.size(); i++) { kill (processIDS[i], SIGINT); } for (int i=0;i<processIDS.size();i++) { int temp = processIDS[i]; wait(&temp); } m->control_pressed = false; for (int i=0;i<processIDS.size();i++) {m->mothurRemove(outputDir + (toString(processIDS[i]) + ".unweighted.results.temp"));}processors=3; m->mothurOut("[ERROR]: unable to spawn the number of processes you requested, reducing number to " + toString(processors) + "\n");
//if the users enters no groups then give them the score of all groups
int numGroups = m->getNumGroups();
//calculate number of comparsions
int numComp = 0;
vector< vector<string> > namesOfGroupCombos;
for (int r=0; r<numGroups; r++) {
for (int l = 0; l < r; l++) {
numComp++;
vector<string> groups; groups.push_back((m->getGroups())[r]); groups.push_back((m->getGroups())[l]);
namesOfGroupCombos.push_back(groups);
}
}
if (numComp != 1) {
vector<string> groups;
if (numGroups == 0) {
//get score for all users groups
for (int i = 0; i < (ct->getNamesOfGroups()).size(); i++) {
if ((ct->getNamesOfGroups())[i] != "xxx") {
groups.push_back((ct->getNamesOfGroups())[i]);
}
}
namesOfGroupCombos.push_back(groups);
}else {
for (int i = 0; i < m->getNumGroups(); i++) {
groups.push_back((m->getGroups())[i]);
}
namesOfGroupCombos.push_back(groups);
}
}
lines.clear();
int remainingPairs = namesOfGroupCombos.size();
int startIndex = 0;
for (int remainingProcessors = processors; remainingProcessors > 0; remainingProcessors--) {
int numPairs = remainingPairs; //case for last processor
if (remainingProcessors != 1) { numPairs = ceil(remainingPairs / remainingProcessors); }
lines.push_back(linePair(startIndex, numPairs)); //startIndex, numPairs
startIndex = startIndex + numPairs;
remainingPairs = remainingPairs - numPairs;
}
results.clear();
processIDS.resize(0);
process = 1;
//.........这里部分代码省略.........
示例8: GroupMap
int RemoveGroupsCommand::execute(){
try {
if (abort == true) { if (calledHelp) { return 0; } return 2; }
//get groups you want to remove
if (accnosfile != "") { m->readAccnos(accnosfile, Groups); m->setGroups(Groups); }
if (groupfile != "") {
groupMap = new GroupMap(groupfile);
groupMap->readMap();
//make sure groups are valid
//takes care of user setting groupNames that are invalid or setting groups=all
vector<string> namesGroups = groupMap->getNamesOfGroups();
vector<string> checkedGroups;
for (int i = 0; i < Groups.size(); i++) {
if (m->inUsersGroups(Groups[i], namesGroups)) { checkedGroups.push_back(Groups[i]); }
else { m->mothurOut("[WARNING]: " + Groups[i] + " is not a valid group in your groupfile, ignoring.\n"); }
}
if (checkedGroups.size() == 0) { m->mothurOut("[ERROR]: no valid groups, aborting.\n"); delete groupMap; return 0; }
else {
Groups = checkedGroups;
m->setGroups(Groups);
}
//fill names with names of sequences that are from the groups we want to remove
fillNames();
delete groupMap;
}else if (countfile != ""){
if ((fastafile != "") || (listfile != "") || (taxfile != "")) {
m->mothurOut("\n[NOTE]: The count file should contain only unique names, so mothur assumes your fasta, list and taxonomy files also contain only uniques.\n\n");
}
CountTable ct;
ct.readTable(countfile, true, false);
if (!ct.hasGroupInfo()) { m->mothurOut("[ERROR]: your count file does not contain group info, aborting.\n"); return 0; }
vector<string> gNamesOfGroups = ct.getNamesOfGroups();
SharedUtil util;
util.setGroups(Groups, gNamesOfGroups);
vector<string> namesOfSeqs = ct.getNamesOfSeqs();
sort(Groups.begin(), Groups.end());
for (int i = 0; i < namesOfSeqs.size(); i++) {
vector<string> thisSeqsGroups = ct.getGroups(namesOfSeqs[i]);
if (m->isSubset(Groups, thisSeqsGroups)) { //you only have seqs from these groups so remove you
names.insert(namesOfSeqs[i]);
}
}
}
if (m->control_pressed) { return 0; }
//read through the correct file and output lines you want to keep
if (namefile != "") { readName(); }
if (fastafile != "") { readFasta(); }
if (groupfile != "") { readGroup(); }
if (countfile != "") { readCount(); }
if (listfile != "") { readList(); }
if (taxfile != "") { readTax(); }
if (sharedfile != "") { readShared(); }
if (designfile != "") { readDesign(); }
if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; }
if (outputNames.size() != 0) {
m->mothurOutEndLine();
m->mothurOut("Output File names: "); m->mothurOutEndLine();
for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
m->mothurOutEndLine();
//set fasta file as new current fastafile
string current = "";
itTypes = outputTypes.find("fasta");
if (itTypes != outputTypes.end()) {
if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setFastaFile(current); }
}
itTypes = outputTypes.find("name");
if (itTypes != outputTypes.end()) {
if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setNameFile(current); }
}
itTypes = outputTypes.find("group");
if (itTypes != outputTypes.end()) {
if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setGroupFile(current); }
}
itTypes = outputTypes.find("list");
if (itTypes != outputTypes.end()) {
if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setListFile(current); }
}
itTypes = outputTypes.find("taxonomy");
if (itTypes != outputTypes.end()) {
if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setTaxonomyFile(current); }
}
//.........这里部分代码省略.........
示例9: getOutputFileName
int SeqSummaryCommand::execute(){
try{
if (abort == true) { if (calledHelp) { return 0; } return 2; }
//set current fasta to fastafile
m->setFastaFile(fastafile);
map<string, string> variables;
variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(fastafile));
string summaryFile = getOutputFileName("summary",variables);
int numSeqs = 0;
vector<int> startPosition;
vector<int> endPosition;
vector<int> seqLength;
vector<int> ambigBases;
vector<int> longHomoPolymer;
if (namefile != "") { nameMap = m->readNames(namefile); }
else if (countfile != "") {
CountTable ct;
ct.readTable(countfile, false, false);
nameMap = ct.getNameMap();
}
if (m->control_pressed) { return 0; }
#ifdef USE_MPI
int pid, numSeqsPerProcessor;
int tag = 2001;
int startTag = 1; int endTag = 2; int lengthTag = 3; int baseTag = 4; int lhomoTag = 5;
int outMode=MPI_MODE_CREATE|MPI_MODE_WRONLY;
vector<unsigned long long> MPIPos;
MPI_Status status;
MPI_Status statusOut;
MPI_File inMPI;
MPI_File outMPI;
MPI_Comm_size(MPI_COMM_WORLD, &processors);
MPI_Comm_rank(MPI_COMM_WORLD, &pid);
char tempFileName[1024];
strcpy(tempFileName, fastafile.c_str());
char sumFileName[1024];
strcpy(sumFileName, summaryFile.c_str());
MPI_File_open(MPI_COMM_WORLD, tempFileName, MPI_MODE_RDONLY, MPI_INFO_NULL, &inMPI); //comm, filename, mode, info, filepointer
MPI_File_open(MPI_COMM_WORLD, sumFileName, outMode, MPI_INFO_NULL, &outMPI);
if (m->control_pressed) { MPI_File_close(&inMPI); MPI_File_close(&outMPI); return 0; }
if (pid == 0) { //you are the root process
//print header
string outputString = "seqname\tstart\tend\tnbases\tambigs\tpolymer\tnumSeqs\n";
int length = outputString.length();
char* buf2 = new char[length];
memcpy(buf2, outputString.c_str(), length);
MPI_File_write_shared(outMPI, buf2, length, MPI_CHAR, &statusOut);
delete buf2;
MPIPos = m->setFilePosFasta(fastafile, numSeqs); //fills MPIPos, returns numSeqs
for(int i = 1; i < processors; i++) {
MPI_Send(&numSeqs, 1, MPI_INT, i, tag, MPI_COMM_WORLD);
MPI_Send(&MPIPos[0], (numSeqs+1), MPI_LONG, i, tag, MPI_COMM_WORLD);
}
//figure out how many sequences you have to do
numSeqsPerProcessor = numSeqs / processors;
int startIndex = pid * numSeqsPerProcessor;
if(pid == (processors - 1)){ numSeqsPerProcessor = numSeqs - pid * numSeqsPerProcessor; }
//do your part
MPICreateSummary(startIndex, numSeqsPerProcessor, startPosition, endPosition, seqLength, ambigBases, longHomoPolymer, inMPI, outMPI, MPIPos);
}else { //i am the child process
MPI_Recv(&numSeqs, 1, MPI_INT, 0, tag, MPI_COMM_WORLD, &status);
MPIPos.resize(numSeqs+1);
MPI_Recv(&MPIPos[0], (numSeqs+1), MPI_LONG, 0, tag, MPI_COMM_WORLD, &status);
//figure out how many sequences you have to align
numSeqsPerProcessor = numSeqs / processors;
int startIndex = pid * numSeqsPerProcessor;
if(pid == (processors - 1)){ numSeqsPerProcessor = numSeqs - pid * numSeqsPerProcessor; }
//do your part
MPICreateSummary(startIndex, numSeqsPerProcessor, startPosition, endPosition, seqLength, ambigBases, longHomoPolymer, inMPI, outMPI, MPIPos);
}
MPI_File_close(&inMPI);
MPI_File_close(&outMPI);
MPI_Barrier(MPI_COMM_WORLD); //make everyone wait - just in case
if (pid == 0) {
//get the info from the child processes
//.........这里部分代码省略.........
示例10: getValues
EstOutput Parsimony::getValues(Tree* t, int p, string o) {
try {
processors = p;
outputDir = o;
CountTable* ct = t->getCountTable();
//if the users enters no groups then give them the score of all groups
vector<string> mGroups = m->getGroups();
int numGroups = mGroups.size();
//calculate number of comparsions
int numComp = 0;
vector< vector<string> > namesOfGroupCombos;
for (int r=0; r<numGroups; r++) {
for (int l = 0; l < r; l++) {
numComp++;
vector<string> groups; groups.push_back(mGroups[r]); groups.push_back(mGroups[l]);
//cout << globaldata->Groups[r] << '\t' << globaldata->Groups[l] << endl;
namesOfGroupCombos.push_back(groups);
}
}
//numComp+1 for AB, AC, BC, ABC
if (numComp != 1) {
vector<string> groups;
if (numGroups == 0) {
//get score for all users groups
vector<string> tGroups = ct->getNamesOfGroups();
for (int i = 0; i < tGroups.size(); i++) {
if (tGroups[i] != "xxx") {
groups.push_back(tGroups[i]);
//cout << tmap->namesOfGroups[i] << endl;
}
}
namesOfGroupCombos.push_back(groups);
}else {
for (int i = 0; i < mGroups.size(); i++) {
groups.push_back(mGroups[i]);
//cout << globaldata->Groups[i] << endl;
}
namesOfGroupCombos.push_back(groups);
}
}
lines.clear();
int remainingPairs = namesOfGroupCombos.size();
int startIndex = 0;
for (int remainingProcessors = processors; remainingProcessors > 0; remainingProcessors--) {
int numPairs = remainingPairs; //case for last processor
if (remainingProcessors != 1) { numPairs = ceil(remainingPairs / remainingProcessors); }
lines.push_back(linePair(startIndex, numPairs)); //startIndex, numPairs
startIndex = startIndex + numPairs;
remainingPairs = remainingPairs - numPairs;
}
data = createProcesses(t, namesOfGroupCombos, ct);
return data;
}
catch(exception& e) {
m->errorOut(e, "Parsimony", "getValues");
exit(1);
}
}
示例11: defined
EstOutput Parsimony::createProcesses(Tree* t, vector< vector<string> > namesOfGroupCombos, CountTable* ct) {
try {
int process = 1;
vector<int> processIDS;
EstOutput results;
#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
//loop through and create all the processes you want
while (process != processors) {
int pid = fork();
if (pid > 0) {
processIDS.push_back(pid); //create map from line number to pid so you can append files in correct order later
process++;
}else if (pid == 0){
EstOutput myresults;
myresults = driver(t, namesOfGroupCombos, lines[process].start, lines[process].num, ct);
if (m->control_pressed) { exit(0); }
//pass numSeqs to parent
ofstream out;
string tempFile = outputDir + toString(getpid()) + ".pars.results.temp";
m->openOutputFile(tempFile, out);
out << myresults.size() << endl;
for (int i = 0; i < myresults.size(); i++) { out << myresults[i] << '\t'; } out << endl;
out.close();
exit(0);
}else {
m->mothurOut("[ERROR]: unable to spawn the necessary processes."); m->mothurOutEndLine();
for (int i = 0; i < processIDS.size(); i++) { kill (processIDS[i], SIGINT); }
exit(0);
}
}
results = driver(t, namesOfGroupCombos, lines[0].start, lines[0].num, ct);
//force parent to wait until all the processes are done
for (int i=0;i<processIDS.size();i++) {
int temp = processIDS[i];
wait(&temp);
}
if (m->control_pressed) { return results; }
//get data created by processes
for (int i=0;i<processIDS.size();i++) {
ifstream in;
string s = outputDir + toString(processIDS[i]) + ".pars.results.temp";
m->openInputFile(s, in);
//get scores
if (!in.eof()) {
int num;
in >> num; m->gobble(in);
if (m->control_pressed) { break; }
double w;
for (int j = 0; j < num; j++) {
in >> w;
results.push_back(w);
}
m->gobble(in);
}
in.close();
m->mothurRemove(s);
}
#else
//fill in functions
vector<parsData*> pDataArray;
DWORD dwThreadIdArray[processors-1];
HANDLE hThreadArray[processors-1];
vector<CountTable*> cts;
vector<Tree*> trees;
//Create processor worker threads.
for( int i=1; i<processors; i++ ){
CountTable* copyCount = new CountTable();
copyCount->copy(ct);
Tree* copyTree = new Tree(copyCount);
copyTree->getCopy(t);
cts.push_back(copyCount);
trees.push_back(copyTree);
parsData* temppars = new parsData(m, lines[i].start, lines[i].num, namesOfGroupCombos, copyTree, copyCount);
pDataArray.push_back(temppars);
processIDS.push_back(i);
hThreadArray[i-1] = CreateThread(NULL, 0, MyParsimonyThreadFunction, pDataArray[i-1], 0, &dwThreadIdArray[i-1]);
}
results = driver(t, namesOfGroupCombos, lines[0].start, lines[0].num, ct);
//Wait until all threads have terminated.
WaitForMultipleObjects(processors-1, hThreadArray, TRUE, INFINITE);
//.........这里部分代码省略.........
示例12: help
//.........这里部分代码省略.........
//if the user changes the output directory command factory will send this info to us in the output parameter
outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; }
//check for required parameters
listfile = validParameter.validFile(parameters, "list", true);
if (listfile == "not found") {
//if there is a current list file, use it
listfile = m->getListFile();
if (listfile != "") { m->mothurOut("Using " + listfile + " as input file for the list parameter."); m->mothurOutEndLine(); }
else { m->mothurOut("You have no current listfile and the list parameter is required."); m->mothurOutEndLine(); abort = true; }
}
else if (listfile == "not open") { abort = true; }
else { m->setListFile(listfile); }
taxfile = validParameter.validFile(parameters, "taxonomy", true);
if (taxfile == "not found") { //if there is a current list file, use it
taxfile = m->getTaxonomyFile();
if (taxfile != "") { m->mothurOut("Using " + taxfile + " as input file for the taxonomy parameter."); m->mothurOutEndLine(); }
else { m->mothurOut("You have no current taxonomy file and the taxonomy parameter is required."); m->mothurOutEndLine(); abort = true; }
}
else if (taxfile == "not open") { abort = true; }
else { m->setTaxonomyFile(taxfile); }
refTaxonomy = validParameter.validFile(parameters, "reftaxonomy", true);
if (refTaxonomy == "not found") { refTaxonomy = ""; m->mothurOut("reftaxonomy is not required, but if given will keep the rankIDs in the summary file static."); m->mothurOutEndLine(); }
else if (refTaxonomy == "not open") { abort = true; }
namefile = validParameter.validFile(parameters, "name", true);
if (namefile == "not open") { namefile = ""; abort = true; }
else if (namefile == "not found") { namefile = ""; }
else { m->setNameFile(namefile); }
groupfile = validParameter.validFile(parameters, "group", true);
if (groupfile == "not open") { abort = true; }
else if (groupfile == "not found") { groupfile = ""; }
else { m->setGroupFile(groupfile); }
countfile = validParameter.validFile(parameters, "count", true);
if (countfile == "not open") { countfile = ""; abort = true; }
else if (countfile == "not found") { countfile = ""; }
else { m->setCountTableFile(countfile); }
if ((namefile != "") && (countfile != "")) {
m->mothurOut("[ERROR]: you may only use one of the following: name or count."); m->mothurOutEndLine(); abort = true;
}
if ((groupfile != "") && (countfile != "")) {
m->mothurOut("[ERROR]: you may only use one of the following: group or count."); m->mothurOutEndLine(); abort=true;
}
//check for optional parameter and set defaults
// ...at some point should added some additional type checking...
label = validParameter.validFile(parameters, "label", false);
if (label == "not found") { label = ""; allLines = 1; }
else {
if(label != "all") { m->splitAtDash(label, labels); allLines = 0; }
else { allLines = 1; }
}
basis = validParameter.validFile(parameters, "basis", false);
if (basis == "not found") { basis = "otu"; }
if ((basis != "otu") && (basis != "sequence")) { m->mothurOut("Invalid option for basis. basis options are otu and sequence, using otu."); m->mothurOutEndLine(); }
string temp = validParameter.validFile(parameters, "cutoff", false); if (temp == "not found") { temp = "51"; }
m->mothurConvert(temp, cutoff);
temp = validParameter.validFile(parameters, "probs", false); if (temp == "not found"){ temp = "true"; }
probs = m->isTrue(temp);
temp = validParameter.validFile(parameters, "persample", false); if (temp == "not found"){ temp = "f"; }
persample = m->isTrue(temp);
if ((groupfile == "") && (countfile == "")) { if (persample) { m->mothurOut("persample is only valid with a group file, or count file with group information. Setting persample=f.\n"); persample = false; }
}
if (countfile != "") {
CountTable cts;
if (!cts.testGroups(countfile)) {
if (persample) { m->mothurOut("persample is only valid with a group file, or count file with group information. Setting persample=f.\n"); persample = false; }
}
}
if ((cutoff < 51) || (cutoff > 100)) { m->mothurOut("cutoff must be above 50, and no greater than 100."); m->mothurOutEndLine(); abort = true; }
if (countfile == "") {
if (namefile == ""){
vector<string> files; files.push_back(taxfile);
parser.getNameFile(files);
}
}
}
}
catch(exception& e) {
m->errorOut(e, "ClassifyOtuCommand", "ClassifyOtuCommand");
exit(1);
}
}
示例13: time
int SeqSummaryCommand::execute(){
try{
if (abort == true) { if (calledHelp) { return 0; } return 2; }
int start = time(NULL);
//set current fasta to fastafile
m->setFastaFile(fastafile);
map<string, string> variables;
variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(fastafile));
string summaryFile = getOutputFileName("summary",variables);
long long numSeqs = 0;
long long size = 0;
long long numUniques = 0;
map<int, long long> startPosition;
map<int, long long> endPosition;
map<int, long long> seqLength;
map<int, long long> ambigBases;
map<int, long long> longHomoPolymer;
if (namefile != "") { nameMap = m->readNames(namefile); numUniques = nameMap.size(); }
else if (countfile != "") {
CountTable ct;
ct.readTable(countfile, false, false);
nameMap = ct.getNameMap();
size = ct.getNumSeqs();
numUniques = ct.getNumUniqueSeqs();
}
if (m->control_pressed) { return 0; }
vector<unsigned long long> positions;
#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
positions = m->divideFile(fastafile, processors);
for (int i = 0; i < (positions.size()-1); i++) { lines.push_back(new linePair(positions[i], positions[(i+1)])); }
#else
positions = m->setFilePosFasta(fastafile, numSeqs);
if (numSeqs < processors) { processors = numSeqs; }
//figure out how many sequences you have to process
int numSeqsPerProcessor = numSeqs / processors;
for (int i = 0; i < processors; i++) {
int startIndex = i * numSeqsPerProcessor;
if(i == (processors - 1)){ numSeqsPerProcessor = numSeqs - i * numSeqsPerProcessor; }
lines.push_back(new linePair(positions[startIndex], numSeqsPerProcessor));
}
#endif
if(processors == 1){
numSeqs = driverCreateSummary(startPosition, endPosition, seqLength, ambigBases, longHomoPolymer, fastafile, summaryFile, lines[0]);
}else{
numSeqs = createProcessesCreateSummary(startPosition, endPosition, seqLength, ambigBases, longHomoPolymer, fastafile, summaryFile);
}
if (m->control_pressed) { return 0; }
//set size
if (countfile != "") {}//already set
else if (namefile == "") { size = numSeqs; }
else { for (map<int, long long>::iterator it = startPosition.begin(); it != startPosition.end(); it++) { size += it->second; } }
if ((namefile != "") || (countfile != "")) {
string type = "count";
if (namefile != "") { type = "name"; }
if (numSeqs != numUniques) { // do fasta and name/count files match
m->mothurOut("[ERROR]: Your " + type + " file contains " + toString(numUniques) + " unique sequences, but your fasta file contains " + toString(numSeqs) + ". File mismatch detected, quitting command.\n"); m->control_pressed = true;
}
}
if (m->control_pressed) { m->mothurRemove(summaryFile); return 0; }
long long ptile0_25 = 1+(long long)(size * 0.025); //number of sequences at 2.5%
long long ptile25 = 1+(long long)(size * 0.250); //number of sequences at 25%
long long ptile50 = 1+(long long)(size * 0.500);
long long ptile75 = 1+(long long)(size * 0.750);
long long ptile97_5 = 1+(long long)(size * 0.975);
long long ptile100 = (long long)(size);
vector<int> starts; starts.resize(7,0); vector<int> ends; ends.resize(7,0); vector<int> ambigs; ambigs.resize(7,0); vector<int> lengths; lengths.resize(7,0); vector<int> homops; homops.resize(7,0);
//find means
long long meanStartPosition, meanEndPosition, meanSeqLength, meanAmbigBases, meanLongHomoPolymer;
meanStartPosition = 0; meanEndPosition = 0; meanSeqLength = 0; meanAmbigBases = 0; meanLongHomoPolymer = 0;
//minimum
if ((startPosition.begin())->first == -1) { starts[0] = 0; }
else {starts[0] = (startPosition.begin())->first; }
long long totalSoFar = 0;
//set all values to min
starts[1] = starts[0]; starts[2] = starts[0]; starts[3] = starts[0]; starts[4] = starts[0]; starts[5] = starts[0];
int lastValue = 0;
for (map<int, long long>::iterator it = startPosition.begin(); it != startPosition.end(); it++) {
int value = it->first; if (value == -1) { value = 0; }
meanStartPosition += (value*it->second);
totalSoFar += it->second;
//.........这里部分代码省略.........
示例14: getOutputFileName
int DeconvoluteCommand::execute() {
try {
if (abort) { if (calledHelp) { return 0; } return 2; }
//prepare filenames and open files
map<string, string> variables;
variables["[filename]"] = outputDir + util.getRootName(util.getSimpleName(fastafile));
string outNameFile = getOutputFileName("name", variables);
string outCountFile = getOutputFileName("count", variables);
variables["[extension]"] = util.getExtension(fastafile);
string outFastaFile = getOutputFileName("fasta", variables);
map<string, string> nameMap;
map<string, string>::iterator itNames;
if (namefile != "") {
util.readNames(namefile, nameMap);
if (namefile == outNameFile){
//prepare filenames and open files
map<string, string> mvariables;
mvariables["[filename]"] = outputDir + util.getRootName(util.getSimpleName(fastafile));
mvariables["[tag]"] = "unique";
outNameFile = getOutputFileName("name", mvariables);
}
}
CountTable ct;
if (countfile != "") {
ct.readTable(countfile, true, false);
if (countfile == outCountFile){
//prepare filenames and open files
map<string, string> mvariables;
mvariables["[filename]"] = outputDir + util.getRootName(util.getSimpleName(fastafile));
mvariables["[tag]"] = "unique";
outCountFile = getOutputFileName("count", mvariables); }
}
if (m->getControl_pressed()) { return 0; }
ifstream in;
util.openInputFile(fastafile, in);
ofstream outFasta;
util.openOutputFile(outFastaFile, outFasta);
map<string, string> sequenceStrings; //sequenceString -> list of names. "atgc...." -> seq1,seq2,seq3.
map<string, string>::iterator itStrings;
set<string> nameInFastaFile; //for sanity checking
set<string>::iterator itname;
vector<string> nameFileOrder;
CountTable newCt;
int count = 0;
while (!in.eof()) {
if (m->getControl_pressed()) { in.close(); outFasta.close(); util.mothurRemove(outFastaFile); return 0; }
Sequence seq(in);
if (seq.getName() != "") {
//sanity checks
itname = nameInFastaFile.find(seq.getName());
if (itname == nameInFastaFile.end()) { nameInFastaFile.insert(seq.getName()); }
else { m->mothurOut("[ERROR]: You already have a sequence named " + seq.getName() + " in your fasta file, sequence names must be unique, please correct."); m->mothurOutEndLine(); }
itStrings = sequenceStrings.find(seq.getAligned());
if (itStrings == sequenceStrings.end()) { //this is a new unique sequence
//output to unique fasta file
seq.printSequence(outFasta);
if (namefile != "") {
itNames = nameMap.find(seq.getName());
if (itNames == nameMap.end()) { //namefile and fastafile do not match
m->mothurOut("[ERROR]: " + seq.getName() + " is in your fasta file, and not in your namefile, please correct."); m->mothurOutEndLine();
}else {
if (format == "name") { sequenceStrings[seq.getAligned()] = itNames->second; nameFileOrder.push_back(seq.getAligned());
}else { newCt.push_back(seq.getName(), util.getNumNames(itNames->second)); sequenceStrings[seq.getAligned()] = seq.getName(); nameFileOrder.push_back(seq.getAligned()); }
}
}else if (countfile != "") {
if (format == "name") {
int numSeqs = ct.getNumSeqs(seq.getName());
string expandedName = seq.getName()+"_0";
for (int i = 1; i < numSeqs; i++) { expandedName += "," + seq.getName() + "_" + toString(i); }
sequenceStrings[seq.getAligned()] = expandedName; nameFileOrder.push_back(seq.getAligned());
}else {
ct.getNumSeqs(seq.getName()); //checks to make sure seq is in table
sequenceStrings[seq.getAligned()] = seq.getName(); nameFileOrder.push_back(seq.getAligned());
}
}else {
if (format == "name") { sequenceStrings[seq.getAligned()] = seq.getName(); nameFileOrder.push_back(seq.getAligned()); }
else { newCt.push_back(seq.getName()); sequenceStrings[seq.getAligned()] = seq.getName(); nameFileOrder.push_back(seq.getAligned()); }
}
}else { //this is a dup
if (namefile != "") {
itNames = nameMap.find(seq.getName());
if (itNames == nameMap.end()) { //namefile and fastafile do not match
m->mothurOut("[ERROR]: " + seq.getName() + " is in your fasta file, and not in your namefile, please correct."); m->mothurOutEndLine();
}else {
//.........这里部分代码省略.........
示例15: getValues
EstOutput Weighted::getValues(Tree* t, string groupA, string groupB) {
try {
data.clear(); //clear out old values
CountTable* ct = t->getCountTable();
if (m->control_pressed) { return data; }
//initialize weighted score
WScore[(groupA+groupB)] = 0.0;
double D = 0.0;
set<int> validBranches;
vector<string> groups; groups.push_back(groupA); groups.push_back(groupB);
//adding the wieghted sums from group i
for (int j = 0; j < t->groupNodeInfo[groups[0]].size(); j++) { //the leaf nodes that have seqs from group i
map<string, int>::iterator it = t->tree[t->groupNodeInfo[groups[0]][j]].pcount.find(groups[0]);
int numSeqsInGroupI = it->second;
double sum = getLengthToRoot(t, t->groupNodeInfo[groups[0]][j], groups[0], groups[1]);
double weightedSum = ((numSeqsInGroupI * sum) / (double)ct->getGroupCount(groups[0]));
D += weightedSum;
}
//adding the wieghted sums from group l
for (int j = 0; j < t->groupNodeInfo[groups[1]].size(); j++) { //the leaf nodes that have seqs from group l
map<string, int>::iterator it = t->tree[t->groupNodeInfo[groups[1]][j]].pcount.find(groups[1]);
int numSeqsInGroupL = it->second;
double sum = getLengthToRoot(t, t->groupNodeInfo[groups[1]][j], groups[0], groups[1]);
double weightedSum = ((numSeqsInGroupL * sum) / (double)ct->getGroupCount(groups[1]));
D += weightedSum;
}
//calculate u for the group comb
for(int i=0;i<t->getNumNodes();i++){
if (m->control_pressed) { return data; }
double u;
//int pcountSize = 0;
//does this node have descendants from groupA
it = t->tree[i].pcount.find(groupA);
//if it does u = # of its descendants with a certain group / total number in tree with a certain group
if (it != t->tree[i].pcount.end()) {
u = (double) t->tree[i].pcount[groupA] / (double) ct->getGroupCount(groupA);
}else { u = 0.00; }
//does this node have descendants from group l
it = t->tree[i].pcount.find(groupB);
//if it does subtract their percentage from u
if (it != t->tree[i].pcount.end()) {
u -= (double) t->tree[i].pcount[groupB] / (double) ct->getGroupCount(groupB);
}
if (includeRoot) {
if (t->tree[i].getBranchLength() != -1) {
u = abs(u * t->tree[i].getBranchLength());
WScore[(groupA+groupB)] += u;
}
}else{
//if this is not the root then add it
if (rootForGrouping[groups].count(i) == 0) {
if (t->tree[i].getBranchLength() != -1) {
u = abs(u * t->tree[i].getBranchLength());
WScore[(groupA+groupB)] += u;
}
}
}
}
/********************************************************/
//calculate weighted score for the group combination
double UN;
UN = (WScore[(groupA+groupB)] / D);
if (isnan(UN) || isinf(UN)) { UN = 0; }
data.push_back(UN);
return data;
}
catch(exception& e) {
m->errorOut(e, "Weighted", "getValues");
exit(1);
}
}