try {
if (abort == true) { return 0; }
- srand( (unsigned)time( NULL ) ); //needed to assign names to temporary files
-
-
if(search == "kmer") { templateDB = new KmerDB(templateFileName, kmerSize); }
else if(search == "suffix") { templateDB = new SuffixDB(templateFileName); }
else if(search == "blast") { templateDB = new BlastDB(templateFileName, gapOpen, gapExtend, match, misMatch); }
LibShuffCommand::LibShuffCommand(string option){
try {
- srand( (unsigned)time( NULL ) );
globaldata = GlobalData::getInstance();
abort = false;
else {
//valid paramters for this command
- string AlignArray[] = {"fasta", "start", "end", "maxambig", "maxhomop", "minlength", "maxlength", "name", "group"};
+ string AlignArray[] = {"fasta", "start", "end", "maxambig", "maxhomop", "minlength", "maxlength",
+ "name", "group", "alignreport"};
vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
OptionParser parser(option);
if (namefile == "not open") { abort = true; }
else if (namefile == "not found") { namefile = ""; }
-
+ alignreport = validParameter.validFile(parameters, "alignreport", true);
+ if (alignreport == "not open") { abort = true; }
+ else if (alignreport == "not found") { namefile = ""; }
+
//check for optional parameter and set defaults
// ...at some point should added some additional type checking...
string temp;
}
gobble(inFASTA);
}
- if(namefile != ""){
- screenNameGroupFile(badSeqNames);
- }
- else if(groupfile != ""){
- screenGroupFile(badSeqNames);
- }
+ if(namefile != "") { screenNameGroupFile(badSeqNames); }
+ if(groupfile != "") { screenGroupFile(badSeqNames); }
+ if(alignreport != "") { screenAlignReport(badSeqNames); }
return 0;
}
//***************************************************************************************************************
+void ScreenSeqsCommand::screenAlignReport(set<string> badSeqNames){
+
+ ifstream inputAlignReport;
+ openInputFile(alignreport, inputAlignReport);
+ string seqName, group;
+ set<string>::iterator it;
+
+ string goodAlignReportFile = getRootName(alignreport) + "good" + getExtension(alignreport);
+ string badAlignReportFile = getRootName(alignreport) + "bad" + getExtension(alignreport);
+
+ ofstream goodAlignReportOut; openOutputFile(goodAlignReportFile, goodAlignReportOut);
+ ofstream badAlignReportOut; openOutputFile(badAlignReportFile, badAlignReportOut);
+
+ while (!inputAlignReport.eof()) { // need to copy header
+ char c = inputAlignReport.get();
+ goodAlignReportOut << c;
+ badAlignReportOut << c;
+ if (c == 10 || c == 13){ break; }
+ }
+
+ while(!inputAlignReport.eof()){
+ inputAlignReport >> seqName;
+ it = badSeqNames.find(seqName);
+ string line;
+ while (!inputAlignReport.eof()) { // need to copy header
+ char c = inputAlignReport.get();
+ line += c;
+ if (c == 10 || c == 13){ break; }
+ }
+
+ if(it != badSeqNames.end()){
+ badSeqNames.erase(it);
+ badAlignReportOut << seqName << '\t' << line;;
+ }
+ else{
+ goodAlignReportOut << seqName << '\t' << line;
+ }
+ gobble(inputAlignReport);
+ }
+ inputAlignReport.close();
+ goodAlignReportOut.close();
+ badAlignReportOut.close();
+
+}
+
+//***************************************************************************************************************
+
private:
void screenNameGroupFile(set<string>);
void screenGroupFile(set<string>);
-
+ void screenAlignReport(set<string>);
+
bool abort;
- string fastafile, namefile, groupfile;
+ string fastafile, namefile, groupfile, alignreport;
int startPos, endPos, maxAmbig, maxHomoP, minLength, maxLength;
};
temp = validParameter.validFile(parameters, "allfiles", false); if (temp == "not found") { temp = "F"; }
allFiles = isTrue(temp);
-
+
if(allFiles && oligoFile == ""){
cout << "You selected allfiles, but didn't enter an oligos file. Ignoring the allfiles request." << endl;
}
-
+ if((qAverage != 0 && qThreshold != 0) && qFileName == ""){
+ cout << "You didn't provide a quality file name, quality criteria will be ignored." << endl;
+ qAverage=0;
+ qThreshold=0;
+ }
if(!flip && oligoFile=="" && !maxLength && !minLength && (maxAmbig==-1) && !maxHomoP && qFileName == ""){
cout << "You didn't set any options... quiting command." << endl;
abort = true;
}
-
}
}
try{
if (abort == true) { return 0; }
-
- vector<ofstream*> groupFileNames;
- vector<ofstream*> fastaFileNames;
- if(oligoFile != "") { getOligos(fastaFileNames, groupFileNames); }
ifstream inFASTA;
openInputFile(fastaFile, inFASTA);
-
+
ofstream outFASTA;
string trimSeqFile = getRootName(fastaFile) + "trim.fasta";
openOutputFile(trimSeqFile, outFASTA);
ofstream outGroups;
- string groupFile = getRootName(fastaFile) + "groups";
- openOutputFile(groupFile, outGroups);
+ vector<ofstream*> fastaFileNames;
+ if(oligoFile != ""){
+ string groupFile = getRootName(fastaFile) + "groups";
+ openOutputFile(groupFile, outGroups);
+ getOligos(fastaFileNames);
+ }
ofstream scrapFASTA;
string scrapSeqFile = getRootName(fastaFile) + "scrap.fasta";
outGroups << currSeq.getName() << '\t' << groupVector[group] << endl;
if(allFiles){
- *groupFileNames[group] << currSeq.getName() << '\t' << groupVector[group] << endl;
currSeq.printSequence(*fastaFileNames[group]);
}
}
scrapFASTA.close();
outGroups.close();
- for(int i=0;i<groupFileNames.size();i++){
- groupFileNames[i]->close();
- delete groupFileNames[i];
-
+ for(int i=0;i<fastaFileNames.size();i++){
fastaFileNames[i]->close();
delete fastaFileNames[i];
+ }
+
+ for(int i=0;i<fastaFileNames.size();i++){
+ string seqName;
+ openInputFile(getRootName(fastaFile) + groupVector[i] + ".fasta", inFASTA);
+ ofstream outGroups;
+ openOutputFile(getRootName(fastaFile) + groupVector[i] + ".groups", outGroups);
+
+ while(!inFASTA.eof()){
+ if(inFASTA.get() == '>'){
+ inFASTA >> seqName;
+ outGroups << seqName << '\t' << groupVector[i] << endl;
+ }
+ while (!inFASTA.eof()) { char c = inFASTA.get(); if (c == 10 || c == 13){ break; } }
+ }
+ outGroups.close();
+ inFASTA.close();
}
+
return 0;
}
catch(exception& e) {
//***************************************************************************************************************
-void TrimSeqsCommand::getOligos(vector<ofstream*>& outFASTAVec, vector<ofstream*>& outGroupsVec){
+void TrimSeqsCommand::getOligos(vector<ofstream*>& outFASTAVec){
ifstream inOligos;
openInputFile(oligoFile, inOligos);
string type, oligo, group;
int index=0;
-
+
while(!inOligos.eof()){
inOligos >> type;
-
+
if(type[0] == '#'){
while (!inOligos.eof()) { char c = inOligos.get(); if (c == 10 || c == 13){ break; } } // get rest of line if there's any crap there
}
if(allFiles){
outFASTAVec.push_back(new ofstream((getRootName(fastaFile) + group + ".fasta").c_str(), ios::ate));
- outGroupsVec.push_back(new ofstream((getRootName(fastaFile) + group + ".groups").c_str(), ios::ate));
}
}
}
void help();
private:
- void getOligos(vector<ofstream*>&, vector<ofstream*>&);
+ void getOligos(vector<ofstream*>&);
bool stripQualThreshold(Sequence&, ifstream&);
bool cullQualAverage(Sequence&, ifstream&);
bool stripBarcode(Sequence&, int&);