ofstream out;
m->openOutputFile(outputFileName, out);
out.setf(ios::fixed, ios::floatfield); out.setf(ios::showpoint);
- out << "Node\tOTU#\tIndVal" << endl;
-
+
string treeOutputDir = outputDir;
if (outputDir == "") { treeOutputDir += m->hasPath(treefile); }
string outputTreeFileName = treeOutputDir + m->getRootName(m->getSimpleName(treefile)) + "indicator.tre";
if (sharedfile != "") {
vector< vector<SharedRAbundVector*> > groupings;
- /*groupings.resize(1);
- groupings[0].push_back(lookup[0]);
- groupings[0].push_back(lookup[1]);
- groupings[0].push_back(lookup[2]);
- groupings[0].push_back(lookup[3]);
- groupings[0].push_back(lookup[4]);*/
-
//get nodes that will be a valid grouping
//you are valid if you are not one of my descendants
//AND your distToLeaf is <= mine
if (m->control_pressed) { out.close(); return 0; }
+
/******************************************************/
//output indicator values to table form + label tree //
/*****************************************************/
+ out << (i+1) << '\t';
for (int j = 0; j < indicatorValues.size(); j++) {
if (m->control_pressed) { out.close(); return 0; }
- out << (i+1) << '\t' << (j+1) << '\t' << indicatorValues[j] << endl;
+ out << indicatorValues[j] << '\t';
}
+ out << endl;
T->tree[i].setLabel((i+1));
try {
map<int, float> dists;
+ bool hasBranchLengths = false;
+ for (int i = 0; i < T->getNumNodes(); i++) {
+ if (T->tree[i].getBranchLength() > 0.0) { hasBranchLengths = true; break; }
+ }
+
for (int i = 0; i < T->getNumNodes(); i++) {
int lc = T->tree[i].getLChild();
int rc = T->tree[i].getRChild();
//if you have no branch length, set it then calc
- if (T->tree[i].getBranchLength() <= 0.0) {
-
+ if (!hasBranchLengths) {
if (lc == -1) { // you are a leaf
//if you are a leaf set you priliminary length to 1.0, this may adjust later
T->tree[i].setBranchLength(1.0);
float rdist = dists[rc];
float greater = ldist;
- if (rdist > greater) { greater = rdist; dists[i] = ldist; }
- else { dists[i] = rdist; }
+ if (rdist > greater) { greater = rdist; dists[i] = ldist + 1.0; }
+ else { dists[i] = rdist + 1.0; }
//branch length = difference + 1
T->tree[lc].setBranchLength((abs(ldist-greater) + 1.0));
if (header.name.length() > header.nameLength) { header.name = header.name.substr(0, header.nameLength); }
delete[] tempBuffer;
+ //extract info from name
+ decodeName(header.timestamp, header.region, header.xy, header.name);
+
/* Pad to 8 chars */
unsigned long int spotInFile = in.tellg();
unsigned long int spot = (spotInFile + 7)& ~7;
}
}
//**********************************************************************************************************************
+int SffInfoCommand::decodeName(string& timestamp, string& region, string& xy, string name) {
+ try {
+
+ string time = name.substr(0, 6);
+ unsigned int timeNum = m->fromBase36(time);
+
+ int q1 = timeNum / 60;
+ int sec = timeNum - 60 * q1;
+ int q2 = q1 / 60;
+ int minute = q1 - 60 * q2;
+ int q3 = q2 / 24;
+ int hr = q2 - 24 * q3;
+ int q4 = q3 / 32;
+ int day = q3 - 32 * q4;
+ int q5 = q4 / 13;
+ int mon = q4 - 13 * q5;
+ int year = 2000 + q5;
+
+ timestamp = toString(year) + "_" + toString(mon) + "_" + toString(day) + "_" + toString(hr) + "_" + toString(minute) + "_" + toString(sec);
+
+ region = name.substr(7, 2);
+
+ string xyNum = name.substr(9);
+ unsigned int myXy = m->fromBase36(xyNum);
+ int x = myXy >> 12;
+ int y = myXy & 4095;
+
+ xy = toString(x) + "_" + toString(y);
+
+ return 0;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "SffInfoCommand", "decodeName");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
int SffInfoCommand::printCommonHeader(ofstream& out, CommonHeader& header) {
try {
try {
out << ">" << header.name << endl;
- out << "Run Prefix: " << endl;
- out << "Region #: " << endl;
- out << "XY Location: " << endl << endl;
+ out << "Run Prefix: " << header.timestamp << endl;
+ out << "Region #: " << header.region << endl;
+ out << "XY Location: " << header.xy << endl << endl;
out << "Run Name: " << endl;
out << "Analysis Name: " << endl;
}
}
- out << ">" << header.name << endl;
+ out << ">" << header.name << " xy=" << header.xy << endl;
out << seq << endl;
return 0;
out << "0\t0\t0\t0";
}
else if((header.clipQualRight != 0) && ((header.clipQualRight-header.clipQualLeft) >= 0)){
- out << ">" << header.name << " length=" << (header.clipQualRight-header.clipQualLeft) << endl;
+ out << ">" << header.name << " xy=" << header.xy << " length=" << (header.clipQualRight-header.clipQualLeft) << endl;
for (int i = (header.clipQualLeft-1); i < (header.clipQualRight-1); i++) { out << read.qualScores[i] << '\t'; }
}
else{
- out << ">" << header.name << " length=" << (header.clipQualRight-header.clipQualLeft) << endl;
+ out << ">" << header.name << " xy=" << header.xy << " length=" << (header.clipQualRight-header.clipQualLeft) << endl;
for (int i = (header.clipQualLeft-1); i < read.qualScores.size(); i++) { out << read.qualScores[i] << '\t'; }
}
}else{
- out << ">" << header.name << " length=" << read.qualScores.size() << endl;
+ out << ">" << header.name << " xy=" << header.xy << " length=" << read.qualScores.size() << endl;
for (int i = 0; i < read.qualScores.size(); i++) { out << read.qualScores[i] << '\t'; }
}
int SffInfoCommand::printFlowSeqData(ofstream& out, seqRead& read, Header& header) {
try {
- out << ">" << header.name << endl;
+ out << ">" << header.name << " xy=" << header.xy << endl;
for (int i = 0; i < read.flowgram.size(); i++) { out << setprecision(2) << (read.flowgram[i]/(float)100) << '\t'; }
out << endl;
outputNames.push_back(groupFile); outputTypes["group"].push_back(groupFile);
getOligos(fastaFileNames, qualFileNames);
}
-
+ cout << fastaFileNames.size() << '\t' << qualFileNames.size() << endl;
vector<unsigned long int> fastaFilePos;
vector<unsigned long int> qFilePos;
#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
if(processors == 1){
-
driverCreateTrim(fastaFile, qFileName, trimSeqFile, scrapSeqFile, trimQualFile, scrapQualFile, groupFile, fastaFileNames, qualFileNames, lines[0], qLines[0]);
-
- for (int j = 0; j < fastaFileNames.size(); j++) {
- rename((fastaFileNames[j] + toString(getpid()) + ".temp").c_str(), fastaFileNames[j].c_str());
- }
- if(qFileName != ""){
- for (int j = 0; j < qualFileNames.size(); j++) {
- rename((qualFileNames[j] + toString(getpid()) + ".temp").c_str(), qualFileNames[j].c_str());
- }
- }
-
}else{
createProcessesCreateTrim(fastaFile, qFileName, trimSeqFile, scrapSeqFile, trimQualFile, scrapQualFile, groupFile, fastaFileNames, qualFileNames);
-
- rename((trimSeqFile + toString(processIDS[0]) + ".temp").c_str(), trimSeqFile.c_str());
- rename((scrapSeqFile + toString(processIDS[0]) + ".temp").c_str(), scrapSeqFile.c_str());
- rename((groupFile + toString(processIDS[0]) + ".temp").c_str(), groupFile.c_str());
-
- if(qFileName != ""){
- rename((trimQualFile + toString(processIDS[0]) + ".temp").c_str(), trimQualFile.c_str());
- rename((scrapQualFile + toString(processIDS[0]) + ".temp").c_str(), scrapQualFile.c_str());
- }
-
-
- for (int j = 0; j < fastaFileNames.size(); j++) {
- rename((fastaFileNames[j] + toString(processIDS[0]) + ".temp").c_str(), fastaFileNames[j].c_str());
- }
- if(qFileName != ""){
- for (int j = 0; j < qualFileNames.size(); j++) {
- rename((qualFileNames[j] + toString(getpid()) + ".temp").c_str(), qualFileNames[j].c_str());
- }
- }
-
- //append files
- for(int i=1;i<processors;i++){
- m->appendFiles((trimSeqFile + toString(processIDS[i]) + ".temp"), trimSeqFile);
- remove((trimSeqFile + toString(processIDS[i]) + ".temp").c_str());
- m->appendFiles((scrapSeqFile + toString(processIDS[i]) + ".temp"), scrapSeqFile);
- remove((scrapSeqFile + toString(processIDS[i]) + ".temp").c_str());
-
- m->appendFiles((trimQualFile + toString(processIDS[i]) + ".temp"), trimQualFile);
- remove((trimQualFile + toString(processIDS[i]) + ".temp").c_str());
- m->appendFiles((scrapQualFile + toString(processIDS[i]) + ".temp"), scrapQualFile);
- remove((scrapQualFile + toString(processIDS[i]) + ".temp").c_str());
-
- m->appendFiles((groupFile + toString(processIDS[i]) + ".temp"), groupFile);
- remove((groupFile + toString(processIDS[i]) + ".temp").c_str());
- for (int j = 0; j < fastaFileNames.size(); j++) {
- m->appendFiles((fastaFileNames[j] + toString(processIDS[i]) + ".temp"), fastaFileNames[j]);
- remove((fastaFileNames[j] + toString(processIDS[i]) + ".temp").c_str());
- }
-
- if(qFileName != ""){
- for (int j = 0; j < qualFileNames.size(); j++) {
- m->appendFiles((qualFileNames[j] + toString(processIDS[i]) + ".temp"), qualFileNames[j]);
- remove((qualFileNames[j] + toString(processIDS[i]) + ".temp").c_str());
- }
- }
-
-
- }
- }
-
- if (m->control_pressed) { return 0; }
+ }
#else
driverCreateTrim(fastaFile, qFileName, trimSeqFile, scrapSeqFile, trimQualFile, scrapQualFile, groupFile, fastaFileNames, qualFileNames, lines[0], qLines[0]);
-
- for (int j = 0; j < fastaFileNames.size(); j++) {
- rename((fastaFileNames[j] + toString(j) + ".temp").c_str(), fastaFileNames[j].c_str());
- }
- if(qFileName != ""){
- for (int j = 0; j < qualFileNames.size(); j++) {
- rename((qualFileNames[j] + toString(j) + ".temp").c_str(), qualFileNames[j].c_str());
- }
- }
-
- if (m->control_pressed) { return 0; }
#endif
-
-
+
+ if (m->control_pressed) { return 0; }
+ cout << "done with driver " << endl;
for(int i=0;i<fastaFileNames.size();i++){
- if (m->isBlank(fastaFileNames[i])) { remove(fastaFileNames[i].c_str()); }
- else if (filesToRemove.count(fastaFileNames[i]) > 0) { remove(fastaFileNames[i].c_str()); }
+ cout << fastaFileNames[i] << endl;
+
+ if (m->isBlank(fastaFileNames[i])) { cout << fastaFileNames[i] << " was blank" << endl; remove(fastaFileNames[i].c_str()); }
+ else if (filesToRemove.count(fastaFileNames[i]) > 0) { cout << fastaFileNames[i] << " was on the remove list" << endl; remove(fastaFileNames[i].c_str()); }
else {
ifstream inFASTA;
string seqName;
if(itCombo->second == i){ thisGroup = itCombo->first; combos.erase(itCombo); break; }
}
}else{ thisGroup = groupVector[i]; }
-
+ cout << thisGroup << '\t' << i << '\t' << comboStarts << endl;
while(!inFASTA.eof()){
if(inFASTA.get() == '>'){
inFASTA >> seqName;
inFASTA.close();
}
}
-
+ cout << "done with fastaFileNames " << endl;
if(qFileName != ""){
for(int i=0;i<qualFileNames.size();i++){
- if (m->isBlank(qualFileNames[i])) { remove(qualFileNames[i].c_str()); }
- else if (filesToRemove.count(qualFileNames[i]) > 0) { remove(qualFileNames[i].c_str()); }
+ cout << qualFileNames[i] << endl;
+ if (m->isBlank(qualFileNames[i])) { cout << qualFileNames[i] << " was blank" << endl; remove(qualFileNames[i].c_str()); }
+ else if (filesToRemove.count(qualFileNames[i]) > 0) { cout << qualFileNames[i] << " was on the remove list" << endl; remove(qualFileNames[i].c_str()); }
else {
ifstream inQual;
string seqName;
}
}
}
-
+ cout << "done with qualFileNames " << endl;
if (m->control_pressed) {
for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
if (oligoFile != "") {
m->openOutputFile(groupFile, outGroups);
- for (int i = 0; i < fastaNames.size(); i++) {
-
- #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
- fastaNames[i] = (fastaNames[i] + toString(getpid()) + ".temp");
- //fastaFileNames.push_back(new ofstream((fastaNames[i] + toString(getpid()) + ".temp").c_str(), ios::ate));
- //clear old file if it exists
- ofstream temp;
- m->openOutputFile(fastaNames[i], temp);
- temp.close();
- if(qFileName != ""){
- qualNames[i] = (qualNames[i] + toString(getpid()) + ".temp");
- //qualFileNames.push_back(new ofstream((qualNames[i] + toString(getpid()) + ".temp").c_str(), ios::ate));
- //clear old file if it exists
- ofstream temp2;
- m->openOutputFile(qualNames[i], temp2);
- temp2.close();
- }
- #else
- //fastaFileNames.push_back(new ofstream((fastaNames[i] + toString(i) + ".temp").c_str(), ios::ate));
- fastaNames[i] = (fastaNames[i] + toString(i) + ".temp");
- ofstream temp;
- m->openOutputFile(fastaNames[i], temp);
- temp.close();
- if(qFileName != ""){
- //qualFileNames.push_back(new ofstream((qualNames[i] + toString(i) + ".temp").c_str(), ios::ate));
- qualNames[i] = (qualNames[i] + toString(i) + ".temp");
- ofstream temp2;
- m->openOutputFile(qualNames[i], temp2);
- temp2.close();
- }
- #endif
- }
}
ifstream inFASTA;
if (m->control_pressed) {
inFASTA.close(); outFASTA.close(); scrapFASTA.close();
if (oligoFile != "") { outGroups.close(); }
-
- //for(int i=0;i<fastaFileNames.size();i++){ fastaFileNames[i]->close(); delete fastaFileNames[i]; }
if(qFileName != ""){
qFile.close();
- //for(int i=0;i<qualFileNames.size();i++){ qualFileNames[i]->close(); delete qualFileNames[i]; }
}
for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
if (oligoFile != "") { outGroups.close(); }
if(qFileName != "") { qFile.close(); scrapQual.close(); outQual.close(); }
- //for(int i=0;i<fastaFileNames.size();i++){
- // fastaFileNames[i]->close();
- // delete fastaFileNames[i];
- //}
-
- //if(qFileName != ""){
- //for(int i=0;i<qualFileNames.size();i++){
- //qualFileNames[i]->close();
- //delete qualFileNames[i];
- //}
- //}
-
return count;
}
catch(exception& e) {
int TrimSeqsCommand::createProcessesCreateTrim(string filename, string qFileName, string trimFile, string scrapFile, string trimQFile, string scrapQFile, string groupFile, vector<string> fastaNames, vector<string> qualNames) {
try {
#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
- int process = 0;
+ int process = 1;
int exitCommand = 1;
processIDS.clear();
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){
+ for (int i = 0; i < fastaNames.size(); i++) {
+ fastaNames[i] = (fastaNames[i] + toString(getpid()) + ".temp");
+ //clear old file if it exists
+ ofstream temp;
+ m->openOutputFile(fastaNames[i], temp);
+ temp.close();
+ if(qFileName != ""){
+ qualNames[i] = (qualNames[i] + toString(getpid()) + ".temp");
+ //clear old file if it exists
+ ofstream temp2;
+ m->openOutputFile(qualNames[i], temp2);
+ temp2.close();
+ }
+ }
+
driverCreateTrim(filename, qFileName, (trimFile + toString(getpid()) + ".temp"), (scrapFile + toString(getpid()) + ".temp"), (trimQFile + toString(getpid()) + ".temp"), (scrapQFile + toString(getpid()) + ".temp"), (groupFile + toString(getpid()) + ".temp"), fastaNames, qualNames, lines[process], qLines[process]);
exit(0);
}else {
}
}
+ //parent do my part
+ for (int i = 0; i < fastaNames.size(); i++) {
+ //clear old file if it exists
+ ofstream temp;
+ m->openOutputFile(fastaNames[i], temp);
+ temp.close();
+ if(qFileName != ""){
+ //clear old file if it exists
+ ofstream temp2;
+ m->openOutputFile(qualNames[i], temp2);
+ temp2.close();
+ }
+ }
+
+ driverCreateTrim(filename, qFileName, trimFile, scrapFile, trimQFile, scrapQFile, groupFile, fastaNames, qualNames, lines[0], qLines[0]);
+
+
//force parent to wait until all the processes are done
- for (int i=0;i<processors;i++) {
+ for (int i=0;i<processIDS.size();i++) {
int temp = processIDS[i];
wait(&temp);
}
+ //append files
+ for(int i=0;i<processIDS.size();i++){
+ m->mothurOut("Appending files from process " + processIDS[i]); m->mothurOutEndLine();
+
+ m->appendFiles((trimFile + toString(processIDS[i]) + ".temp"), trimFile);
+ remove((trimFile + toString(processIDS[i]) + ".temp").c_str());
+ m->appendFiles((scrapFile + toString(processIDS[i]) + ".temp"), scrapFile);
+ remove((scrapFile + toString(processIDS[i]) + ".temp").c_str());
+
+ m->mothurOut("Done with fasta files"); m->mothurOutEndLine();
+
+ if(qFileName != ""){
+ m->appendFiles((trimQFile + toString(processIDS[i]) + ".temp"), trimQFile);
+ remove((trimQFile + toString(processIDS[i]) + ".temp").c_str());
+ m->appendFiles((scrapQFile + toString(processIDS[i]) + ".temp"), scrapQFile);
+ remove((scrapQFile + toString(processIDS[i]) + ".temp").c_str());
+
+ m->mothurOut("Done with quality files"); m->mothurOutEndLine();
+ }
+
+ m->appendFiles((groupFile + toString(processIDS[i]) + ".temp"), groupFile);
+ remove((groupFile + toString(processIDS[i]) + ".temp").c_str());
+
+ m->mothurOut("Done with group file"); m->mothurOutEndLine();
+
+ for (int j = 0; j < fastaNames.size(); j++) {
+ m->appendFiles((fastaNames[j] + toString(processIDS[i]) + ".temp"), fastaNames[j]);
+ remove((fastaNames[j] + toString(processIDS[i]) + ".temp").c_str());
+ }
+
+ if(qFileName != ""){
+ for (int j = 0; j < qualNames.size(); j++) {
+ m->appendFiles((qualNames[j] + toString(processIDS[i]) + ".temp"), qualNames[j]);
+ remove((qualNames[j] + toString(processIDS[i]) + ".temp").c_str());
+ }
+ }
+
+ if (allFiles) { m->mothurOut("Done with allfile"); m->mothurOutEndLine(); }
+ }
+
return exitCommand;
#endif
}