vector<string> TrimFlowsCommand::getValidParameters(){
try {
- string Array[] = {"flow", "totalflows", "minflows",
+ string Array[] = {"flow", "maxflows", "minflows",
"fasta", "minlength", "maxlength", "maxhomop", "signal", "noise"
"oligos", "pdiffs", "bdiffs", "tdiffs",
"allfiles", "processors",
-
-
-
-// "group",
"outputdir","inputdir"
};
TrimFlowsCommand::TrimFlowsCommand(){
try {
- abort = true;
- //initialize outputTypes
+ abort = true; calledHelp = true;
vector<string> tempOutNames;
outputTypes["flow"] = tempOutNames;
outputTypes["fasta"] = tempOutNames;
TrimFlowsCommand::TrimFlowsCommand(string option) {
try {
- abort = false;
+ abort = false; calledHelp = false;
comboStarts = 0;
//allow user to run help
- if(option == "help") { help(); abort = true; }
+ if(option == "help") { help(); abort = true; calledHelp = true; }
else {
//valid paramters for this command
- string AlignArray[] = {"flow", "totalflows", "minflows",
+ string AlignArray[] = {"flow", "maxflows", "minflows",
"fasta", "minlength", "maxlength", "maxhomop", "signal", "noise",
"oligos", "pdiffs", "bdiffs", "tdiffs",
"allfiles", "processors",
// ...at some point should added some additional type checking...
string temp;
- temp = validParameter.validFile(parameters, "minflows", false); if (temp == "not found") { temp = "360"; }
+ temp = validParameter.validFile(parameters, "minflows", false); if (temp == "not found") { temp = "360"; }
convert(temp, minFlows);
- temp = validParameter.validFile(parameters, "totalflows", false); if (temp == "not found") { temp = "720"; }
- convert(temp, totalFlows);
+ temp = validParameter.validFile(parameters, "maxflows", false); if (temp == "not found") { temp = "720"; }
+ convert(temp, maxFlows);
temp = validParameter.validFile(parameters, "oligos", true);
convert(temp, tdiffs);
if(tdiffs == 0){ tdiffs = bdiffs + pdiffs; }
- temp = validParameter.validFile(parameters, "allfiles", false); if (temp == "not found") { temp = "T"; }
+ temp = validParameter.validFile(parameters, "allfiles", false); if (temp == "not found"){ temp = "T"; }
allFiles = m->isTrue(temp);
- temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found") { temp = "1"; }
+ temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = "1"; }
convert(temp, processors);
if(oligoFileName == ""){ allFiles = 0; }
int TrimFlowsCommand::execute(){
try{
- if (abort == true) { return 0; }
+ if (abort == true) { if (calledHelp) { return 0; } return 2; }
string trimFlowFileName = outputDir + m->getRootName(m->getSimpleName(flowFileName)) + "trim.flow";
outputNames.push_back(trimFlowFileName); outputTypes["flow"].push_back(trimFlowFileName);
if (m->control_pressed) { return 0; }
+ string flowFilesFileName;
+ ofstream output;
+
if(allFiles){
- ofstream output;
- string flowFilesFileName = outputDir + m->getRootName(m->getSimpleName(flowFileName)) + "flow.files";
+ flowFilesFileName = outputDir + m->getRootName(m->getSimpleName(flowFileName)) + "flow.files";
m->openOutputFile(flowFilesFileName, output);
for(int i=0;i<barcodePrimerComboFileNames.size();i++){
}
if(size < 10){
-// m->mothurOut("deleting: " + barcodePrimerComboFileNames[i][j] + '\n');
remove(barcodePrimerComboFileNames[i][j].c_str());
}
else{
-// m->mothurOut("saving: " + barcodePrimerComboFileNames[i][j] + '\n');
output << barcodePrimerComboFileNames[i][j] << endl;
}
}
}
output.close();
}
+ else{
+ flowFilesFileName = outputDir + m->getRootName(m->getSimpleName(flowFileName)) + "flow.files";
+ m->openOutputFile(flowFilesFileName, output);
+
+ output << trimFlowFileName << endl;
+
+ output.close();
+ }
+ outputTypes["flow.files"].push_back(flowFilesFileName);
+ outputNames.push_back(flowFileName);
m->mothurOutEndLine();
m->mothurOut("Output File Names: "); m->mothurOutEndLine();
scrapFlowFile.setf(ios::fixed, ios::floatfield); scrapFlowFile.setf(ios::showpoint);
if(line->start == 4){
- scrapFlowFile << totalFlows << endl;
- trimFlowFile << totalFlows << endl;
- for(int i=0;i<barcodePrimerComboFileNames.size();i++){
- for(int j=0;j<barcodePrimerComboFileNames[0].size();j++){
- // barcodePrimerComboFileNames[i][j] += toString(getpid()) + ".temp";
- ofstream temp;
- m->openOutputFile(barcodePrimerComboFileNames[i][j], temp);
- temp << totalFlows << endl;
- temp.close();
- }
- }
+ scrapFlowFile << maxFlows << endl;
+ trimFlowFile << maxFlows << endl;
+ if(allFiles){
+ for(int i=0;i<barcodePrimerComboFileNames.size();i++){
+ for(int j=0;j<barcodePrimerComboFileNames[0].size();j++){
+ // barcodePrimerComboFileNames[i][j] += toString(getpid()) + ".temp";
+ ofstream temp;
+ m->openOutputFile(barcodePrimerComboFileNames[i][j], temp);
+ temp << maxFlows << endl;
+ temp.close();
+ }
+ }
+ }
}
FlowData flowData(numFlows, signal, noise, maxHomoP);
int count = 0;
bool moreSeqs = 1;
-
+
while(moreSeqs) {
int success = 1;
string trashCode = "";
flowData.getNext(flowFile);
- flowData.capFlows(totalFlows);
+ flowData.capFlows(maxFlows);
Sequence currSeq = flowData.getSequence();
if(!flowData.hasMinFlows(minFlows)){ //screen to see if sequence is of a minimum number of flows
}
}
- int primerIndex, barcodeIndex;
+ int primerIndex = 0;
+ int barcodeIndex = 0;
if(barcodes.size() != 0){
success = stripBarcode(currSeq, barcodeIndex);
success = stripReverse(currSeq);
if(!success) { trashCode += 'r'; }
}
-
-
+
if(trashCode.length() == 0){
+
flowData.printFlows(trimFlowFile);
+
+ if(fasta) { currSeq.printSequence(fastaFile); }
- if(fasta){
- currSeq.printSequence(fastaFile);
- }
-
- if(barcodes.size() != 0 || primers.size() != 0){
-// string fileName = outputDir + m->getRootName(m->getSimpleName(flowFileName)) + barcodePrimerCombos[barcodeIndex][primerIndex] + ".flow";
+ if(allFiles){
ofstream output;
m->openOutputFileAppend(barcodePrimerComboFileNames[barcodeIndex][primerIndex], output);
output.setf(ios::fixed, ios::floatfield); trimFlowFile.setf(ios::showpoint);
flowData.printFlows(output);
output.close();
- }
-
+ }
}
else{
flowData.printFlows(scrapFlowFile, trashCode);
}
oligosFile.close();
- //add in potential combos
+ if(barcodeNameVector.size() == 0 && primerNameVector[0] == ""){ allFiles = 0; }
+
+ //add in potential combos
+ if(barcodeNameVector.size() == 0){
+ barcodes[""] = 0;
+ barcodeNameVector.push_back("");
+ }
+
+ if(primerNameVector.size() == 0){
+ primers[""] = 0;
+ primerNameVector.push_back("");
+ }
+
+
outFlowFileNames.resize(barcodeNameVector.size());
for(int i=0;i<outFlowFileNames.size();i++){
outFlowFileNames[i].assign(primerNameVector.size(), "");
}
if(allFiles){
+
for(map<string, int>::iterator itBar = barcodes.begin();itBar != barcodes.end();itBar++){
for(map<string, int>::iterator itPrimer = primers.begin();itPrimer != primers.end(); itPrimer++){
fileName = outputDir + m->getRootName(m->getSimpleName(flowFileName)) + comboGroupName + ".flow";
}
else{
- comboGroupName = barcodeNameVector[itBar->second] + "." + primerNameVector[itPrimer->second];
+ if(barcodeName == ""){
+ comboGroupName = primerNameVector[itPrimer->second];
+ }
+ else{
+ comboGroupName = barcodeNameVector[itBar->second] + "." + primerNameVector[itPrimer->second];
+ }
fileName = outputDir + m->getRootName(m->getSimpleName(flowFileName)) + comboGroupName + ".flow";
}
oligo = oligo.substr(0,alnLength);
temp = temp.substr(0,alnLength);
- int newStart=0;
int numDiff = countDiffs(oligo, temp);
if(numDiff < minDiff){
}
//if you found the barcode or if you don't want to allow for diffs
- if ((pdiffs == 0) || (success == 0)) { return success; }
+ if ((pdiffs == 0) || (success == 0)) { return success; }
else { //try aligning and see if you can find it
oligo = oligo.substr(0,alnLength);
temp = temp.substr(0,alnLength);
- int newStart=0;
int numDiff = countDiffs(oligo, temp);
if(numDiff < minDiff){
m->openInputFile(flowFileName, in);
in.seekg(spot);
- unsigned long int newSpot = spot;
string dummy = m->getline(in);
-
//there was not another sequence before the end of the file
unsigned long int sanityPos = in.tellg();
}else if (pid == 0){
vector<vector<string> > tempBarcodePrimerComboFileNames = barcodePrimerComboFileNames;
- for(int i=0;i<tempBarcodePrimerComboFileNames.size();i++){
- for(int j=0;j<tempBarcodePrimerComboFileNames[0].size();j++){
- tempBarcodePrimerComboFileNames[i][j] += toString(getpid()) + ".temp";
- ofstream temp;
- m->openOutputFile(tempBarcodePrimerComboFileNames[i][j], temp);
- temp.close();
-
+ if(allFiles){
+ for(int i=0;i<tempBarcodePrimerComboFileNames.size();i++){
+ for(int j=0;j<tempBarcodePrimerComboFileNames[0].size();j++){
+ tempBarcodePrimerComboFileNames[i][j] += toString(getpid()) + ".temp";
+ ofstream temp;
+ m->openOutputFile(tempBarcodePrimerComboFileNames[i][j], temp);
+ temp.close();
+
+ }
}
}
-
driverCreateTrim(flowFileName,
(trimFlowFileName + toString(getpid()) + ".temp"),
(scrapFlowFileName + toString(getpid()) + ".temp"),