Permalink
Browse files

Changes group name error to warning

Adjusts filenames
  • Loading branch information...
1 parent 41d92f2 commit 9959cedcf4ca0efbe148eaf1a7dff0cee6cbf5f0 @mothur-westcott mothur-westcott committed Aug 8, 2016

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -87,7 +87,13 @@ class Command {
if (filename.length() > 0) { //rip off last "."
filename = filename.substr(0, filename.length()-1);
}
- filename += it->second + ".";
+ filename += it->second + ".";
+ }else if ((it->first == "[group]") || (it->first == "[tag]")) {
+ string group = it->second;
+ for (int j = 0; j < group.length(); j++) {
+ if (group[j] == '-') { group[j] = '_'; }
+ }
+ filename += group + ".";
}else { filename += it->second + "."; }
}
}
@@ -1,55 +0,0 @@
-#ifndef GETOTUSCOMMAND_H
-#define GETOTUSCOMMAND_H
-
-/*
- * getotuscommand.h
- * Mothur
- *
- * Created by westcott on 11/10/10.
- * Copyright 2010 Schloss Lab. All rights reserved.
- *
- */
-
-
-
-#include "command.hpp"
-#include "groupmap.h"
-#include "listvector.hpp"
-
-class GetOtusCommand : public Command {
-
-public:
-
- GetOtusCommand(string);
- GetOtusCommand();
- ~GetOtusCommand(){}
-
- vector<string> setParameters();
- string getCommandName() { return "get.otus"; }
- string getCommandCategory() { return "OTU-Based Approaches"; }
-
- string getHelpString();
- string getOutputPattern(string);
- string getCitation() { return "http://www.mothur.org/wiki/Get.otus"; }
- string getDescription() { return "outputs a new list file containing the otus containing sequences from the groups specified"; }
-
-
- int execute();
- void help() { m->mothurOut(getHelpString()); }
-
-
-private:
- string accnosfile, groupfile, listfile, outputDir, groups, label;
- bool abort;
- vector<string> outputNames, Groups;
- GroupMap* groupMap;
-
- int readListGroup();
- int processList(ListVector*&, GroupMap*&, ofstream&, ofstream&, bool&);
-
-};
-
-#endif
-
-
-
@@ -324,14 +324,7 @@ int ParseListCommand::execute(){
/**********************************************************************************************************************/
int ParseListCommand::parse(ListVector* thisList) {
try {
- map<string, string> files;
- map<string, string>::iterator it3;
-
- //set fileroot
- map<string, string> variables;
- variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(listfile));
- variables["[distance]"] = thisList->getLabel();
-
+
//fill filehandles with neccessary ofstreams
vector<string> gGroups;
if (groupfile != "") { gGroups = groupMap->getNamesOfGroups(); }
@@ -342,11 +335,18 @@ int ParseListCommand::parse(ListVector* thisList) {
map<string, string>::iterator itGroup;
map<string, int> groupNumBins;
+ map<string, string> files;
+
+ //set fileroot
+ map<string, string> variables;
+ variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(listfile));
+ variables["[distance]"] = thisList->getLabel();
+
for (int i=0; i<gGroups.size(); i++) {
variables["[group]"] = gGroups[i];
string filename = getOutputFileName("list",variables);
ofstream temp;
- m->openOutputFile(filename, temp);
+ m->openOutputFile(filename, temp); temp.close();
files[gGroups[i]] = filename;
outputNames.push_back(filename); outputTypes["list"].push_back(filename);
groupNumBins[gGroups[i]] = 0;
@@ -404,9 +404,10 @@ int ParseListCommand::parse(ListVector* thisList) {
}
//end list vector
- for (it3 = files.begin(); it3 != files.end(); it3++) {
+ for (map<string, string>::iterator it3 = files.begin(); it3 != files.end(); it3++) {
ofstream out;
- m->openOutputFileAppend(files[it3->second], out);
+ string filename = it3->second;
+ m->openOutputFileAppend(filename, out);
out << groupLabels[it3->first] << endl;
out << thisList->getLabel() << '\t' << groupNumBins[it3->first] << groupVector[it3->first] << endl; // label numBins listvector for that group
out.close();
@@ -1,52 +0,0 @@
-#ifndef REMOVEOTUSCOMMAND_H
-#define REMOVEOTUSCOMMAND_H
-
-/*
- * removeotuscommand.h
- * Mothur
- *
- * Created by westcott on 11/12/10.
- * Copyright 2010 Schloss Lab. All rights reserved.
- *
- */
-
-#include "command.hpp"
-#include "groupmap.h"
-#include "listvector.hpp"
-
-class RemoveOtusCommand : public Command {
-
-public:
-
- RemoveOtusCommand(string);
- RemoveOtusCommand();
- ~RemoveOtusCommand(){}
-
- vector<string> setParameters();
- string getCommandName() { return "remove.otus"; }
- string getCommandCategory() { return "OTU-Based Approaches"; }
-
- string getHelpString();
- string getOutputPattern(string);
- string getCitation() { return "http://www.mothur.org/wiki/Remove.otus"; }
- string getDescription() { return "outputs a new list file containing the otus NOT containing sequences from the groups specified"; }
-
- int execute();
- void help() { m->mothurOut(getHelpString()); }
-
-private:
- string accnosfile, groupfile, listfile, outputDir, groups, label;
- bool abort;
- vector<string> outputNames, Groups;
- GroupMap* groupMap;
-
- int readListGroup();
- int processList(ListVector*&, GroupMap*&, ofstream&, ofstream&, bool&);
-
-};
-
-#endif
-
-
-
-
@@ -1327,15 +1327,19 @@ int SRACommand::mapGroupToFile(map<string, vector<string> >& files, vector<strin
try {
for (int i = 0; i < Groups.size(); i++) {
+ //correct filename issues if group name contains '-' characters
+ string thisGroup = Groups[i];
+ for (int k = 0; k < thisGroup.length(); k++) { if (thisGroup[k] == '-') { thisGroup[k] = '_'; } }
+
for (int j = 0; j < theseFiles.size(); j++) {
string tempName = m->getSimpleName(theseFiles[j]);
//if ((tempName == "GZGO5KL01.F006D146.sff") || (tempName == "G3BMWHG01.F008D021.sff") || (tempName == "GO2JXTW01.M002D125.sff") || (tempName == "GO5715J01.M003D125.sff")) { cout << Groups[i] << '\t' << theseFiles[j] << endl; }
//cout << i << '\t' << j << '\t' << Groups[i] << '\t' << theseFiles[j] << endl;
- int pos = theseFiles[j].find(Groups[i]);
+ int pos = theseFiles[j].find(thisGroup);
if (pos != string::npos) { //you have a potential match, make sure you dont have a case of partial name
- if (theseFiles[j][pos+Groups[i].length()] == '.') { //final.soil.sff vs final.soil2.sff both would match soil.
- map<string, vector<string> >::iterator it = files.find(Groups[i]);
+ if (theseFiles[j][pos+thisGroup.length()] == '.') { //final.soil.sff vs final.soil2.sff both would match soil.
+ map<string, vector<string> >::iterator it = files.find(thisGroup);
if (it == files.end()) {
vector<string> temp; temp.push_back(theseFiles[j]);
files[Groups[i]] = temp;
@@ -1346,6 +1350,7 @@ int SRACommand::mapGroupToFile(map<string, vector<string> >& files, vector<strin
}
}
}
+
return 0;
}
catch(exception& e) {
@@ -50,8 +50,7 @@ class CountTable {
//reads and creates smart enough to eliminate groups with zero counts
int createTable(set<string>&, map<string, string>&, set<string>&); //seqNames, seqName->group, groupNames
int createTable(string, string, bool); //namefile, groupfile, createGroup
-
- int readTable(string, bool, bool); //file, readGroups, mothurRunning
+ int readTable(string, bool, bool); //filename, readGroups, mothurRunning
int printTable(string);
int printHeaders(ofstream&);
View
@@ -2993,7 +2993,7 @@ bool MothurOut::checkGroupName(string name) {
}
if (!goodName) {
- mothurOut("\n[ERROR]: group " + name + " contains illegal characters in the name. Group names cannot include :, -, or / characters. The ':' character is a special character used in trees. Using ':' will result in your tree being unreadable by tree reading software. The '-' character is a special character used by mothur to parse group names. Using the '-' character will prevent you from selecting groups. The '/' character will created unreadable filenames when mothur includes the group in an output filename. Quitting. \n\n"); control_pressed = true;
+ mothurOut("\n[WARNING]: group " + name + " contains illegal characters in the name. Group names should not include :, -, or / characters. The ':' character is a special character used in trees. Using ':' will result in your tree being unreadable by tree reading software. The '-' character is a special character used by mothur to parse group names. Using the '-' character will prevent you from selecting groups. The '/' character will created unreadable filenames when mothur includes the group in an output filename. \n\n");
}
return goodName;

0 comments on commit 9959ced

Please sign in to comment.