]> git.donarmstrong.com Git - mothur.git/commitdiff
trim.seqs couts
authorwestcott <westcott>
Tue, 6 Jul 2010 13:30:30 +0000 (13:30 +0000)
committerwestcott <westcott>
Tue, 6 Jul 2010 13:30:30 +0000 (13:30 +0000)
mothur.h
mothurout.cpp
trimseqscommand.cpp

index 93f96df30c73fa91b7119b07eadb27a89dc5109d..0a73f1cf65ae4c0f24bb04d556ef4aa124f29326 100644 (file)
--- a/mothur.h
+++ b/mothur.h
@@ -54,6 +54,8 @@
 
 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
        #include <sys/wait.h>
+       #include <sys/time.h>
+       #include <sys/resource.h>
        #include <unistd.h>
        
        #ifdef USE_READLINE
index 8bf216a39ce9b6d8492e1e2ec10dedc70d46843e..95b523e8a4a71056c782ae8319568eead3240fde 100644 (file)
-/*
- *  m->mothurOut.cpp
- *  Mothur
- *
- *  Created by westcott on 2/25/10.
- *  Copyright 2010 Schloss Lab. All rights reserved.
- *
- */
-
-#include "mothurout.h"
-
-/******************************************************/
-MothurOut* MothurOut::getInstance() {
-       if( _uniqueInstance == 0) {
-               _uniqueInstance = new MothurOut();
-       }
-       return _uniqueInstance;
-}
-/*********************************************************************************************/
-void MothurOut::setFileName(string filename)  {
-       try {
-               logFileName = filename;
-               
-               #ifdef USE_MPI
-                       int pid;
-                       MPI_Comm_rank(MPI_COMM_WORLD, &pid); 
-                                       
-                       if (pid == 0) { //only one process should output to screen
-               #endif
-               
-               openOutputFile(filename, out);
-               
-               #ifdef USE_MPI
-                       }
-               #endif
-       }
-       catch(exception& e) {
-               errorOut(e, "MothurOut", "setFileName");
-               exit(1);
-       }
-}
-/*********************************************************************************************/
-void MothurOut::closeLog()  {
-       try {
-               
-               #ifdef USE_MPI
-                       int pid;
-                       MPI_Comm_rank(MPI_COMM_WORLD, &pid); 
-                                       
-                       if (pid == 0) { //only one process should output to screen
-               #endif
-               
-               out.close();
-               
-               #ifdef USE_MPI
-                       }
-               #endif
-       }
-       catch(exception& e) {
-               errorOut(e, "MothurOut", "closeLog");
-               exit(1);
-       }
-}
-
-/*********************************************************************************************/
-MothurOut::~MothurOut() {
-       try {
-               _uniqueInstance = 0;
-               
-       }
-       catch(exception& e) {
-               errorOut(e, "MothurOut", "MothurOut");
-               exit(1);
-       }
-}
-/*********************************************************************************************/
-void MothurOut::mothurOut(string output) {
-       try {
-               
-               #ifdef USE_MPI
-                       int pid;
-                       MPI_Comm_rank(MPI_COMM_WORLD, &pid); 
-                                       
-                       if (pid == 0) { //only one process should output to screen
-               #endif
-               
-               cout << output;
-               out << output;
-               
-               #ifdef USE_MPI
-                       }
-               #endif
-       }
-       catch(exception& e) {
-               errorOut(e, "MothurOut", "MothurOut");
-               exit(1);
-       }
-}
-/*********************************************************************************************/
-void MothurOut::mothurOutEndLine() {
-       try {
-               #ifdef USE_MPI
-                       int pid;
-                       MPI_Comm_rank(MPI_COMM_WORLD, &pid); 
-                                       
-                       if (pid == 0) { //only one process should output to screen
-               #endif
-               
-               cout << endl;
-               out << endl;
-               
-               #ifdef USE_MPI
-                       }
-               #endif
-       }
-       catch(exception& e) {
-               errorOut(e, "MothurOut", "MothurOutEndLine");
-               exit(1);
-       }
-}
-/*********************************************************************************************/
-void MothurOut::mothurOutJustToLog(string output) {
-       try {
-               #ifdef USE_MPI
-                       int pid;
-                       MPI_Comm_rank(MPI_COMM_WORLD, &pid); 
-                                       
-                       if (pid == 0) { //only one process should output to screen
-               #endif
-               
-               out << output;
-               
-               #ifdef USE_MPI
-                       }
-               #endif
-       }
-       catch(exception& e) {
-               errorOut(e, "MothurOut", "MothurOutJustToLog");
-               exit(1);
-       }
-}
-/*********************************************************************************************/
-void MothurOut::errorOut(exception& e, string object, string function) {
-       double vm, rss;
-       mem_usage(vm, rss);
-       
-       mothurOut("Error: ");
-       mothurOut(toString(e.what()));
-       mothurOut(" has occurred in the " + object + " class function " + function + ". Please contact Pat Schloss at mothur.bugs@gmail.com, and be sure to include the mothur.logFile with your inquiry.");
-       mothurOutEndLine();
-}
-/*********************************************************************************************/
-//The following was originally from http://stackoverflow.com/questions/669438/how-to-get-memory-usage-at-run-time-in-c 
-// process_mem_usage(double &, double &) - takes two doubles by reference,
-// attempts to read the system-dependent data for a process' virtual memory
-// size and resident set size, and return the results in KB.
-//
-// On failure, returns 0.0, 0.0
-int MothurOut::mem_usage(double& vm_usage, double& resident_set) {
-  #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
-  
-          vm_usage     = 0.0;
-          resident_set = 0.0;
-
-          // 'file' stat seems to give the most reliable results
-          //
-          ifstream stat_stream("/proc/self/stat",ios_base::in);
-
-          // dummy vars for leading entries in stat that we don't care about
-          //
-          string pid, comm, state, ppid, pgrp, session, tty_nr;
-          string tpgid, flags, minflt, cminflt, majflt, cmajflt;
-          string utime, stime, cutime, cstime, priority, nice;
-          string O, itrealvalue, starttime;
-
-          // the two fields we want
-          //
-          unsigned long vsize;
-          long rss;
-
-          stat_stream >> pid >> comm >> state >> ppid >> pgrp >> session >> tty_nr
-                                  >> tpgid >> flags >> minflt >> cminflt >> majflt >> cmajflt
-                                  >> utime >> stime >> cutime >> cstime >> priority >> nice
-                                  >> O >> itrealvalue >> starttime >> vsize >> rss; // don't care about the rest
-
-          long page_size_kb = sysconf(_SC_PAGE_SIZE) / 1024; // in case x86-64 is configured to use 2MB pages
-          vm_usage     = vsize / 1024.0;
-          resident_set = rss * page_size_kb;
-          
-          mothurOut("Memory Usage: vm = " + toString(vm_usage) + " rss = " + toString(resident_set) + "\n");
-               return 0;
-
-       #else
-/*             //windows memory usage
-               // Get the list of process identifiers.
-               DWORD aProcesses[1024], cbNeeded, cProcesses;
-               
-               if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) ){ return 1; }
-
-               // Calculate how many process identifiers were returned.
-               cProcesses = cbNeeded / sizeof(DWORD);
-
-               // Print the memory usage for each process
-               for (int i = 0; i < cProcesses; i++ ) {
-                       DWORD processID = aProcesses[i];
-                       
-                       PROCESS_MEMORY_COUNTERS pmc;
-
-                       HANDLE hProcess = OpenProcess((PROCESS_QUERY_INFORMATION | PROCESS_VM_READ), FALSE, processID);
-
-                       // Print the process identifier.
-                       printf( "\nProcess ID: %u\n", processID);
-                       
-                       if (NULL != hProcess) {
-
-                               if ( GetProcessMemoryInfo( hProcess, &pmc, sizeof(pmc)) ) {
-                                       printf( "\tPageFaultCount: 0x%08X\n", pmc.PageFaultCount );
-                                       printf( "\tPeakWorkingSetSize: 0x%08X\n", pmc.PeakWorkingSetSize );
-                                       printf( "\tWorkingSetSize: 0x%08X\n", pmc.WorkingSetSize );
-                                       printf( "\tQuotaPeakPagedPoolUsage: 0x%08X\n", pmc.QuotaPeakPagedPoolUsage );
-                                       printf( "\tQuotaPagedPoolUsage: 0x%08X\n", pmc.QuotaPagedPoolUsage );
-                                       printf( "\tQuotaPeakNonPagedPoolUsage: 0x%08X\n", pmc.QuotaPeakNonPagedPoolUsage );
-                                       printf( "\tQuotaNonPagedPoolUsage: 0x%08X\n", pmc.QuotaNonPagedPoolUsage );
-                                       printf( "\tPagefileUsage: 0x%08X\n", pmc.PagefileUsage ); 
-                                       printf( "\tPeakPagefileUsage: 0x%08X\n", pmc.PeakPagefileUsage );
-                               }
-                               CloseHandle(hProcess);
-                       }
-               }
-*/
-                       return 0;
-
-       #endif
-}
-/*********************************************************************************************/
-
-
-
-
-
+/*\r
+ *  m->mothurOut.cpp\r
+ *  Mothur\r
+ *\r
+ *  Created by westcott on 2/25/10.\r
+ *  Copyright 2010 Schloss Lab. All rights reserved.\r
+ *\r
+ */\r
+\r
+#include "mothurout.h"\r
+\r
+/******************************************************/\r
+MothurOut* MothurOut::getInstance() {\r
+       if( _uniqueInstance == 0) {\r
+               _uniqueInstance = new MothurOut();\r
+       }\r
+       return _uniqueInstance;\r
+}\r
+/*********************************************************************************************/\r
+void MothurOut::setFileName(string filename)  {\r
+       try {\r
+               logFileName = filename;\r
+               \r
+               #ifdef USE_MPI\r
+                       int pid;\r
+                       MPI_Comm_rank(MPI_COMM_WORLD, &pid); \r
+                                       \r
+                       if (pid == 0) { //only one process should output to screen\r
+               #endif\r
+               \r
+               openOutputFile(filename, out);\r
+               \r
+               #ifdef USE_MPI\r
+                       }\r
+               #endif\r
+       }\r
+       catch(exception& e) {\r
+               errorOut(e, "MothurOut", "setFileName");\r
+               exit(1);\r
+       }\r
+}\r
+/*********************************************************************************************/\r
+void MothurOut::closeLog()  {\r
+       try {\r
+               \r
+               #ifdef USE_MPI\r
+                       int pid;\r
+                       MPI_Comm_rank(MPI_COMM_WORLD, &pid); \r
+                                       \r
+                       if (pid == 0) { //only one process should output to screen\r
+               #endif\r
+               \r
+               out.close();\r
+               \r
+               #ifdef USE_MPI\r
+                       }\r
+               #endif\r
+       }\r
+       catch(exception& e) {\r
+               errorOut(e, "MothurOut", "closeLog");\r
+               exit(1);\r
+       }\r
+}\r
+\r
+/*********************************************************************************************/\r
+MothurOut::~MothurOut() {\r
+       try {\r
+               _uniqueInstance = 0;\r
+               \r
+       }\r
+       catch(exception& e) {\r
+               errorOut(e, "MothurOut", "MothurOut");\r
+               exit(1);\r
+       }\r
+}\r
+/*********************************************************************************************/\r
+void MothurOut::mothurOut(string output) {\r
+       try {\r
+               \r
+               #ifdef USE_MPI\r
+                       int pid;\r
+                       MPI_Comm_rank(MPI_COMM_WORLD, &pid); \r
+                                       \r
+                       if (pid == 0) { //only one process should output to screen\r
+               #endif\r
+               \r
+               cout << output;\r
+               out << output;\r
+               \r
+               #ifdef USE_MPI\r
+                       }\r
+               #endif\r
+       }\r
+       catch(exception& e) {\r
+               errorOut(e, "MothurOut", "MothurOut");\r
+               exit(1);\r
+       }\r
+}\r
+/*********************************************************************************************/\r
+void MothurOut::mothurOutEndLine() {\r
+       try {\r
+               #ifdef USE_MPI\r
+                       int pid;\r
+                       MPI_Comm_rank(MPI_COMM_WORLD, &pid); \r
+                                       \r
+                       if (pid == 0) { //only one process should output to screen\r
+               #endif\r
+               \r
+               cout << endl;\r
+               out << endl;\r
+               \r
+               #ifdef USE_MPI\r
+                       }\r
+               #endif\r
+       }\r
+       catch(exception& e) {\r
+               errorOut(e, "MothurOut", "MothurOutEndLine");\r
+               exit(1);\r
+       }\r
+}\r
+/*********************************************************************************************/\r
+void MothurOut::mothurOutJustToLog(string output) {\r
+       try {\r
+               #ifdef USE_MPI\r
+                       int pid;\r
+                       MPI_Comm_rank(MPI_COMM_WORLD, &pid); \r
+                                       \r
+                       if (pid == 0) { //only one process should output to screen\r
+               #endif\r
+               \r
+               out << output;\r
+               \r
+               #ifdef USE_MPI\r
+                       }\r
+               #endif\r
+       }\r
+       catch(exception& e) {\r
+               errorOut(e, "MothurOut", "MothurOutJustToLog");\r
+               exit(1);\r
+       }\r
+}\r
+/*********************************************************************************************/\r
+void MothurOut::errorOut(exception& e, string object, string function) {\r
+       double vm, rss;\r
+       mem_usage(vm, rss);\r
+       \r
+       mothurOut("Error: ");\r
+       mothurOut(toString(e.what()));\r
+       mothurOut(" has occurred in the " + object + " class function " + function + ". Please contact Pat Schloss at mothur.bugs@gmail.com, and be sure to include the mothur.logFile with your inquiry.");\r
+       mothurOutEndLine();\r
+}\r
+/*********************************************************************************************/\r
+//The following was originally from http://stackoverflow.com/questions/669438/how-to-get-memory-usage-at-run-time-in-c \r
+// process_mem_usage(double &, double &) - takes two doubles by reference,\r
+// attempts to read the system-dependent data for a process' virtual memory\r
+// size and resident set size, and return the results in KB.\r
+//\r
+// On failure, returns 0.0, 0.0\r
+int MothurOut::mem_usage(double& vm_usage, double& resident_set) {\r
+  #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)\r
+  \r
+          vm_usage     = 0.0;\r
+          resident_set = 0.0;\r
+\r
+          // 'file' stat seems to give the most reliable results\r
+          //\r
+          ifstream stat_stream("/proc/self/stat",ios_base::in);\r
+\r
+          // dummy vars for leading entries in stat that we don't care about\r
+          //\r
+          string pid, comm, state, ppid, pgrp, session, tty_nr;\r
+          string tpgid, flags, minflt, cminflt, majflt, cmajflt;\r
+          string utime, stime, cutime, cstime, priority, nice;\r
+          string O, itrealvalue, starttime;\r
+\r
+          // the two fields we want\r
+          //\r
+          unsigned long vsize;\r
+          long rss;\r
+\r
+          stat_stream >> pid >> comm >> state >> ppid >> pgrp >> session >> tty_nr\r
+                                  >> tpgid >> flags >> minflt >> cminflt >> majflt >> cmajflt\r
+                                  >> utime >> stime >> cutime >> cstime >> priority >> nice\r
+                                  >> O >> itrealvalue >> starttime >> vsize >> rss; // don't care about the rest\r
+\r
+          long page_size_kb = sysconf(_SC_PAGE_SIZE) / 1024; // in case x86-64 is configured to use 2MB pages\r
+          vm_usage     = vsize / 1024.0;\r
+          resident_set = rss * page_size_kb;\r
+          \r
+          mothurOut("Memory Usage: vm = " + toString(vm_usage) + " rss = " + toString(resident_set) + "\n");\r
+               return 0;\r
+\r
+       #else\r
+/*             //windows memory usage\r
+               // Get the list of process identifiers.\r
+               DWORD aProcesses[1024], cbNeeded, cProcesses;\r
+               \r
+               if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) ){ return 1; }\r
+\r
+               // Calculate how many process identifiers were returned.\r
+               cProcesses = cbNeeded / sizeof(DWORD);\r
+\r
+               // Print the memory usage for each process\r
+               for (int i = 0; i < cProcesses; i++ ) {\r
+                       DWORD processID = aProcesses[i];\r
+                       \r
+                       PROCESS_MEMORY_COUNTERS pmc;\r
+\r
+                       HANDLE hProcess = OpenProcess((PROCESS_QUERY_INFORMATION | PROCESS_VM_READ), FALSE, processID);\r
+\r
+                       // Print the process identifier.\r
+                       printf( "\nProcess ID: %u\n", processID);\r
+                       \r
+                       if (NULL != hProcess) {\r
+\r
+                               if ( GetProcessMemoryInfo( hProcess, &pmc, sizeof(pmc)) ) {\r
+                                       printf( "\tPageFaultCount: 0x%08X\n", pmc.PageFaultCount );\r
+                                       printf( "\tPeakWorkingSetSize: 0x%08X\n", pmc.PeakWorkingSetSize );\r
+                                       printf( "\tWorkingSetSize: 0x%08X\n", pmc.WorkingSetSize );\r
+                                       printf( "\tQuotaPeakPagedPoolUsage: 0x%08X\n", pmc.QuotaPeakPagedPoolUsage );\r
+                                       printf( "\tQuotaPagedPoolUsage: 0x%08X\n", pmc.QuotaPagedPoolUsage );\r
+                                       printf( "\tQuotaPeakNonPagedPoolUsage: 0x%08X\n", pmc.QuotaPeakNonPagedPoolUsage );\r
+                                       printf( "\tQuotaNonPagedPoolUsage: 0x%08X\n", pmc.QuotaNonPagedPoolUsage );\r
+                                       printf( "\tPagefileUsage: 0x%08X\n", pmc.PagefileUsage ); \r
+                                       printf( "\tPeakPagefileUsage: 0x%08X\n", pmc.PeakPagefileUsage );\r
+                               }\r
+                               CloseHandle(hProcess);\r
+                       }\r
+               }\r
+*/\r
+                       return 0;\r
+\r
+       #endif\r
+}\r
+/*********************************************************************************************/\r
+\r
+\r
+\r
+\r
+\r
+\r
index 944e2cdc0a110828157301f14f2470a06ac3e052..71cf7143c55392208523c390cfb3924304eeede9 100644 (file)
@@ -377,7 +377,7 @@ int TrimSeqsCommand::driverCreateTrim(string filename, string qFileName, string
                        int success = 1;
                        
                        Sequence currSeq(inFASTA);
-
+       cout << i << '\t' << currSeq.getName() << endl;
                        string origSeq = currSeq.getUnaligned();
                        if (origSeq != "") {
                                int groupBar, groupPrime;
@@ -583,11 +583,14 @@ void TrimSeqsCommand::getOligos(vector<string>& outFASTAVec){ //vector<ofstream*
                
                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
                        }
                        else{
+                               //make type case insensitive
+                               for(int i=0;i<type.length();i++){       type[i] = toupper(type[i]);  }
+                               
                                inOligos >> oligo;
                                
                                for(int i=0;i<oligo.length();i++){
@@ -595,7 +598,7 @@ void TrimSeqsCommand::getOligos(vector<string>& outFASTAVec){ //vector<ofstream*
                                        if(oligo[i] == 'U')     {       oligo[i] = 'T'; }
                                }
                                
-                               if(type == "forward"){
+                               if(type == "FORWARD"){
                                        group = "";
                                        
                                        // get rest of line in case there is a primer name
@@ -619,13 +622,14 @@ void TrimSeqsCommand::getOligos(vector<string>& outFASTAVec){ //vector<ofstream*
                                                        outFASTAVec.push_back((outputDir + getRootName(getSimpleName(fastaFile)) + toString(index) + "." + group + ".fasta"));
                                                }
                                        }
+
                                }
-                               else if(type == "reverse"){
+                               else if(type == "REVERSE"){
                                        Sequence oligoRC("reverse", oligo);
                                        oligoRC.reverseComplement();
                                        revPrimer.push_back(oligoRC.getUnaligned());
                                }
-                               else if(type == "barcode"){
+                               else if(type == "BARCODE"){
                                        inOligos >> group;
                                        
                                        //check for repeat barcodes