exit(1);
}
}
+/**********************************************************************************************************************/
+map<string, int> MothurOut::readNames(string namefile) {
+ try {
+
+ map<string, int> nameMap;
+
+ //open input file
+ ifstream in;
+ openInputFile(namefile, in);
+
+ while (!in.eof()) {
+ if (control_pressed) { break; }
+
+ string firstCol, secondCol;
+ in >> firstCol >> secondCol; gobble(in);
+
+ int num = getNumNames(secondCol);
+
+ nameMap[firstCol] = num;
+ }
+ in.close();
+
+ return nameMap;
+
+ }
+ catch(exception& e) {
+ errorOut(e, "MothurOut", "readNames");
+ exit(1);
+ }
+}
/***********************************************************************/
string getline(istringstream&);
void gobble(istream&);
void gobble(istringstream&);
+ map<string, int> readNames(string);
//searchs and checks
bool checkReleaseVersion(ifstream&, string);
else if (groupfile == "not found") { groupfile = ""; }
namefile = validParameter.validFile(parameters, "name", true);
- if (namefile == "not open") { abort = true; }
+ if (namefile == "not open") { namefile = ""; abort = true; }
else if (namefile == "not found") { namefile = ""; }
alignreport = validParameter.validFile(parameters, "alignreport", true);
if (abort == true) { if (calledHelp) { return 0; } return 2; }
- //if the user want to optimize we need to no the 90% mark
+ //if the user want to optimize we need to know the 90% mark
vector<unsigned long int> positions;
- if (optimize.size() != 0) { getSummary(positions); } //get summary is paralellized so we need to divideFile, no need to do this step twice so I moved it here
+ if (optimize.size() != 0) { //get summary is paralellized so we need to divideFile, no need to do this step twice so I moved it here
+ //use the namefile to optimize correctly
+ if (namefile != "") { nameMap = m->readNames(namefile); }
+ getSummary(positions);
+ }
else {
positions = m->divideFile(fastafile, processors);
for (int i = 0; i < (positions.size()-1); i++) {
sort(ambigBases.begin(), ambigBases.end());
sort(longHomoPolymer.begin(), longHomoPolymer.end());
- int criteriaPercentile = int(numSeqs * (criteria / (float) 100));
+ //numSeqs is the number of unique seqs, startPosition.size() is the total number of seqs, we want to optimize using all seqs
+ int criteriaPercentile = int(startPosition.size() * (criteria / (float) 100));
for (int i = 0; i < optimize.size(); i++) {
if (optimize[i] == "start") { startPos = startPosition[criteriaPercentile]; m->mothurOut("Optimizing start to " + toString(startPos) + "."); m->mothurOutEndLine(); }
Sequence current(in); m->gobble(in);
if (current.getName() != "") {
- startPosition.push_back(current.getStartPos());
- endPosition.push_back(current.getEndPos());
- seqLength.push_back(current.getNumBases());
- ambigBases.push_back(current.getAmbigBases());
- longHomoPolymer.push_back(current.getLongHomoPolymer());
+ int num = 1;
+ if (namefile != "") {
+ //make sure this sequence is in the namefile, else error
+ map<string, int>::iterator it = nameMap.find(current.getName());
+
+ if (it == nameMap.end()) { m->mothurOut("[ERROR]: " + current.getName() + " is not in your namefile, please correct."); m->mothurOutEndLine(); m->control_pressed = true; }
+ else { num = it->second; }
+ }
+
+ //for each sequence this sequence represents
+ for (int i = 0; i < num; i++) {
+ startPosition.push_back(current.getStartPos());
+ endPosition.push_back(current.getEndPos());
+ seqLength.push_back(current.getNumBases());
+ ambigBases.push_back(current.getAmbigBases());
+ longHomoPolymer.push_back(current.getLongHomoPolymer());
+ }
+
count++;
}
m->openOutputFile(tempFile, out);
out << num << endl;
+ out << startPosition.size() << endl;
for (int k = 0; k < startPosition.size(); k++) { out << startPosition[k] << '\t'; } out << endl;
for (int k = 0; k < endPosition.size(); k++) { out << endPosition[k] << '\t'; } out << endl;
for (int k = 0; k < seqLength.size(); k++) { out << seqLength[k] << '\t'; } out << endl;
int temp, tempNum;
in >> tempNum; m->gobble(in); num += tempNum;
+ in >> tempNum; m->gobble(in);
for (int k = 0; k < tempNum; k++) { in >> temp; startPosition.push_back(temp); } m->gobble(in);
for (int k = 0; k < tempNum; k++) { in >> temp; endPosition.push_back(temp); } m->gobble(in);
for (int k = 0; k < tempNum; k++) { in >> temp; seqLength.push_back(temp); } m->gobble(in);
vector<string> outputNames;
vector<string> optimize;
map<string, vector<string> > outputTypes;
+ map<string, int> nameMap;
+ int readNames();
int getSummary(vector<unsigned long int>&);
int createProcessesCreateSummary(vector<int>&, vector<int>&, vector<int>&, vector<int>&, vector<int>&, string);
//**********************************************************************************************************************
vector<string> AlignCheckCommand::getValidParameters(){
try {
- string Array[] = {"fasta","map", "outputdir","inputdir"};
+ string Array[] = {"fasta", "name","map", "outputdir","inputdir"};
vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
return myArray;
}
else {
//valid paramters for this command
- string Array[] = {"fasta","map", "outputdir","inputdir"};
+ string Array[] = {"fasta","name","map", "outputdir","inputdir"};
vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
OptionParser parser(option);
//if the user has not given a path then, add inputdir. else leave path alone.
if (path == "") { parameters["map"] = inputDir + it->second; }
}
+
+ it = parameters.find("name");
+ //user has given a template file
+ if(it != parameters.end()){
+ path = m->hasPath(it->second);
+ //if the user has not given a path then, add inputdir. else leave path alone.
+ if (path == "") { parameters["name"] = inputDir + it->second; }
+ }
}
//check for required parameters
if (fastafile == "not open") { abort = true; }
else if (fastafile == "not found") { fastafile = ""; m->mothurOut("You must provide an fasta file."); m->mothurOutEndLine(); abort = true; }
+ namefile = validParameter.validFile(parameters, "name", true);
+ if (namefile == "not open") { namefile = ""; abort = true; }
+ else if (namefile == "not found") { namefile = ""; }
+
//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 = "";
//get secondary structure info.
readMap();
+ if (namefile != "") { nameMap = m->readNames(namefile); }
+
+ if (m->control_pressed) { return 0; }
+
ifstream in;
m->openInputFile(fastafile, in);
string outfile = outputDir + m->getRootName(m->getSimpleName(fastafile)) + "align.check";
m->openOutputFile(outfile, out);
+
out << "name" << '\t' << "pound" << '\t' << "dash" << '\t' << "plus" << '\t' << "equal" << '\t';
- out << "loop" << '\t' << "tilde" << '\t' << "total" << endl;
+ out << "loop" << '\t' << "tilde" << '\t' << "total" << '\t' << "numseqs" << endl;
while(!in.eof()){
if (haderror == 1) { break; }
+ int num = 1;
+ if (namefile != "") {
+ //make sure this sequence is in the namefile, else error
+ map<string, int>::iterator it = nameMap.find(seq.getName());
+
+ if (it == nameMap.end()) { cout << "[ERROR]: " << seq.getName() << " is not in your namefile, please correct." << endl; m->control_pressed = true; }
+ else { num = it->second; }
+ }
+
out << seq.getName() << '\t' << data.pound << '\t' << data.dash << '\t' << data.plus << '\t' << data.equal << '\t';
- out << data.loop << '\t' << data.tilde << '\t' << data.total << endl;
+ out << data.loop << '\t' << data.tilde << '\t' << data.total << '\t' << num << endl;
}
}
exit(1);
}
}
-
-
//**********************************************************************************************************************
private:
vector<int> structMap;
- string mapfile, fastafile, outputDir;
+ string mapfile, fastafile, outputDir, namefile;
bool abort;
int seqLength, haderror;
vector<string> outputNames;
map<string, vector<string> > outputTypes;
+ map<string, int> nameMap;
void readMap();
statData getStats(string sequence);
vector<int> ambigBases;
vector<int> longHomoPolymer;
- if (namefile != "") { readNames(); }
+ if (namefile != "") { nameMap = m->readNames(namefile); }
if (m->control_pressed) { return 0; }
//make sure this sequence is in the namefile, else error
map<string, int>::iterator it = nameMap.find(current.getName());
- if (it == nameMap.end()) { m->mothurOut("[ERROR]: " + current.getName() + " is not in your namefile, please correct."); m->mothurOutEndLine(); m->control_pressed = true; }
+ if (it == nameMap.end()) { cout << "[ERROR]: " << current.getName() << " is not in your namefile, please correct." << endl; m->control_pressed = true; }
else { num = it->second; }
}
}
}
/**********************************************************************************************************************/
-int SeqSummaryCommand::readNames() {
- try {
- //open input file
- ifstream in;
- m->openInputFile(namefile, in);
-
- while (!in.eof()) {
- if (m->control_pressed) { break; }
-
- string firstCol, secondCol;
- in >> firstCol >> secondCol; m->gobble(in);
-
- int num = m->getNumNames(secondCol);
-
- nameMap[firstCol] = num;
- }
- in.close();
-
- return 0;
-
- }
- catch(exception& e) {
- m->errorOut(e, "SeqSummaryCommand", "readNames");
- exit(1);
- }
-}
-
-/**********************************************************************************************************************/
int createProcessesCreateSummary(vector<int>&, vector<int>&, vector<int>&, vector<int>&, vector<int>&, string, string);
int driverCreateSummary(vector<int>&, vector<int>&, vector<int>&, vector<int>&, vector<int>&, string, string, linePair*);
- int readNames();
#ifdef USE_MPI
int MPICreateSummary(int, int, vector<int>&, vector<int>&, vector<int>&, vector<int>&, vector<int>&, MPI_File&, MPI_File&, vector<unsigned long int>&);