1 #ifndef CURRENTFILE_H 2 #define CURRENTFILE_H 3 4 /* 5 * currentfile.h 6 * Mothur 7 * 8 * Created by westcott on 3/15/11. 9 * Copyright 2011 Schloss Lab. All rights reserved. 10 * 11 */ 12 13 14 //NOT ThreadSafe - but designed to be read only from threads and read write from main thread. 15 16 #include "mothurout.h" 17 #include "utils.hpp" 18 19 /***********************************************/ 20 21 class CurrentFile { 22 23 public: getInstance()24 static CurrentFile* getInstance() { 25 if(instance == 0) { instance = new CurrentFile(); } 26 return instance; 27 } 28 29 unsigned long long getRAMUsed(); 30 unsigned long long getTotalRAM(); getPhylipFile()31 string getPhylipFile() { lock_guard<std::mutex> guard(currentProtector); return phylipfile; } getColumnFile()32 string getColumnFile() { lock_guard<std::mutex> guard(currentProtector); return columnfile; } getListFile()33 string getListFile() { lock_guard<std::mutex> guard(currentProtector); return listfile; } getRabundFile()34 string getRabundFile() { lock_guard<std::mutex> guard(currentProtector); return rabundfile; } getSabundFile()35 string getSabundFile() { lock_guard<std::mutex> guard(currentProtector); return sabundfile; } getNameFile()36 string getNameFile() { lock_guard<std::mutex> guard(currentProtector); return namefile; } getGroupFile()37 string getGroupFile() { lock_guard<std::mutex> guard(currentProtector); return groupfile; } getOrderFile()38 string getOrderFile() { lock_guard<std::mutex> guard(currentProtector); return orderfile; } getOrderGroupFile()39 string getOrderGroupFile() { lock_guard<std::mutex> guard(currentProtector); return ordergroupfile; } getTreeFile()40 string getTreeFile() { lock_guard<std::mutex> guard(currentProtector); return treefile; } getSharedFile()41 string getSharedFile() { lock_guard<std::mutex> guard(currentProtector); return sharedfile; } getRelAbundFile()42 string getRelAbundFile() { lock_guard<std::mutex> guard(currentProtector); return relabundfile; } getCLRFile()43 string getCLRFile() { lock_guard<std::mutex> guard(currentProtector); return clrfile; } getDesignFile()44 string getDesignFile() { lock_guard<std::mutex> guard(currentProtector); return designfile; } getFastaFile()45 string getFastaFile() { lock_guard<std::mutex> guard(currentProtector); return fastafile; } getSFFFile()46 string getSFFFile() { lock_guard<std::mutex> guard(currentProtector); return sfffile; } getQualFile()47 string getQualFile() { lock_guard<std::mutex> guard(currentProtector); return qualfile; } getOligosFile()48 string getOligosFile() { lock_guard<std::mutex> guard(currentProtector); return oligosfile; } getSampleFile()49 string getSampleFile() { lock_guard<std::mutex> guard(currentProtector); return samplefile; } getAccnosFile()50 string getAccnosFile() { lock_guard<std::mutex> guard(currentProtector); return accnosfile; } getTaxonomyFile()51 string getTaxonomyFile() { lock_guard<std::mutex> guard(currentProtector); return taxonomyfile; } getFlowFile()52 string getFlowFile() { lock_guard<std::mutex> guard(currentProtector); return flowfile; } getContigsReportFile()53 string getContigsReportFile(){ lock_guard<std::mutex> guard(currentProtector); return contigsreportfile; } getBiomFile()54 string getBiomFile() { lock_guard<std::mutex> guard(currentProtector); return biomfile; } getCountFile()55 string getCountFile() { lock_guard<std::mutex> guard(currentProtector); return countfile; } getSummaryFile()56 string getSummaryFile() { lock_guard<std::mutex> guard(currentProtector); return summaryfile; } getFileFile()57 string getFileFile() { lock_guard<std::mutex> guard(currentProtector); return filefile; } getConsTaxonomyFile()58 string getConsTaxonomyFile(){ lock_guard<std::mutex> guard(currentProtector); return constaxonomyfile; } 59 setListFile(string f)60 void setListFile(string f) { lock_guard<std::mutex> guard(currentProtector); listfile = util.getFullPathName(f); } setBiomFile(string f)61 void setBiomFile(string f) { lock_guard<std::mutex> guard(currentProtector); biomfile = util.getFullPathName(f); } setFlowFile(string f)62 void setFlowFile(string f) { lock_guard<std::mutex> guard(currentProtector); flowfile = util.getFullPathName(f); } setContigsReportFile(string f)63 void setContigsReportFile(string f) { lock_guard<std::mutex> guard(currentProtector); contigsreportfile = util.getFullPathName(f); } setSummaryFile(string f)64 void setSummaryFile(string f) { lock_guard<std::mutex> guard(currentProtector); summaryfile = util.getFullPathName(f); } setTreeFile(string f)65 void setTreeFile(string f) { lock_guard<std::mutex> guard(currentProtector); treefile = util.getFullPathName(f); } setGroupFile(string f)66 void setGroupFile(string f) { lock_guard<std::mutex> guard(currentProtector); groupfile = util.getFullPathName(f); setGroupMode("group"); } setCountFile(string f)67 void setCountFile(string f) { lock_guard<std::mutex> guard(currentProtector); countfile = util.getFullPathName(f); setGroupMode("count"); } setPhylipFile(string f)68 void setPhylipFile(string f) { lock_guard<std::mutex> guard(currentProtector); phylipfile = util.getFullPathName(f); } setColumnFile(string f)69 void setColumnFile(string f) { lock_guard<std::mutex> guard(currentProtector); columnfile = util.getFullPathName(f); } setNameFile(string f)70 void setNameFile(string f) { lock_guard<std::mutex> guard(currentProtector); namefile = util.getFullPathName(f); } setRabundFile(string f)71 void setRabundFile(string f) { lock_guard<std::mutex> guard(currentProtector); rabundfile = util.getFullPathName(f); } setSabundFile(string f)72 void setSabundFile(string f) { lock_guard<std::mutex> guard(currentProtector); sabundfile = util.getFullPathName(f); } setSharedFile(string f)73 void setSharedFile(string f) { lock_guard<std::mutex> guard(currentProtector); sharedfile = util.getFullPathName(f); } setRelAbundFile(string f)74 void setRelAbundFile(string f) { lock_guard<std::mutex> guard(currentProtector); relabundfile = util.getFullPathName(f); } setCLRFile(string f)75 void setCLRFile(string f) { lock_guard<std::mutex> guard(currentProtector); clrfile = util.getFullPathName(f); } setOrderFile(string f)76 void setOrderFile(string f) { lock_guard<std::mutex> guard(currentProtector); orderfile = util.getFullPathName(f); } setOrderGroupFile(string f)77 void setOrderGroupFile(string f) { lock_guard<std::mutex> guard(currentProtector); ordergroupfile = util.getFullPathName(f); } setDesignFile(string f)78 void setDesignFile(string f) { lock_guard<std::mutex> guard(currentProtector); designfile = util.getFullPathName(f); } setFastaFile(string f)79 void setFastaFile(string f) { lock_guard<std::mutex> guard(currentProtector); fastafile = util.getFullPathName(f); } setSFFFile(string f)80 void setSFFFile(string f) { lock_guard<std::mutex> guard(currentProtector); sfffile = util.getFullPathName(f); } setQualFile(string f)81 void setQualFile(string f) { lock_guard<std::mutex> guard(currentProtector); qualfile = util.getFullPathName(f); } setOligosFile(string f)82 void setOligosFile(string f) { lock_guard<std::mutex> guard(currentProtector); oligosfile = util.getFullPathName(f); } setAccnosFile(string f)83 void setAccnosFile(string f) { lock_guard<std::mutex> guard(currentProtector); accnosfile = util.getFullPathName(f); } setTaxonomyFile(string f)84 void setTaxonomyFile(string f) { lock_guard<std::mutex> guard(currentProtector); taxonomyfile = util.getFullPathName(f); } setConsTaxonomyFile(string f)85 void setConsTaxonomyFile(string f) { lock_guard<std::mutex> guard(currentProtector); constaxonomyfile = util.getFullPathName(f); } setProgramPath(string f)86 void setProgramPath(string f) { lock_guard<std::mutex> guard(currentProtector); mothurProgramPath = util.getFullPathName(f); } setFileFile(string f)87 void setFileFile(string f) { lock_guard<std::mutex> guard(currentProtector); filefile = util.getFullPathName(f); } setSampleFile(string f)88 void setSampleFile(string f) { lock_guard<std::mutex> guard(currentProtector); samplefile = util.getFullPathName(f); } 89 90 //current files - if you add a new type you must edit optionParser->getParameters, get.current and set.current commands and mothurOut->printCurrentFiles/clearCurrentFiles/getCurrentTypes/hasCurrentFiles. add a get and set function. 91 getProcessors()92 string getProcessors() { lock_guard<std::mutex> guard(currentProtector); return processors; } 93 int setProcessors(string p); getProgramPath()94 string getProgramPath() { lock_guard<std::mutex> guard(currentProtector); return mothurProgramPath; } getDefaultPath()95 string getDefaultPath() { lock_guard<std::mutex> guard(currentProtector); return defaultPath; } 96 void setDefaultPath(string); getTestFilePath()97 string getTestFilePath() { lock_guard<std::mutex> guard(currentProtector); return testFilePath; } 98 void setTestFilePath(string); getBlastPath()99 string getBlastPath() { lock_guard<std::mutex> guard(currentProtector); return blastPath; } 100 void setBlastPath(string); getToolsPath()101 string getToolsPath() { lock_guard<std::mutex> guard(currentProtector); return toolsPath; } 102 void setToolsPath(string); getHomePath()103 string getHomePath() { lock_guard<std::mutex> guard(currentProtector); return homePath; } 104 void setHomePath(string); getPaths()105 vector<string> getPaths() { lock_guard<std::mutex> guard(currentProtector); return paths; } //environment variable 'PATH' values 106 void setPaths(vector<string>); getOutputDir()107 string getOutputDir() { lock_guard<std::mutex> guard(currentProtector); return outputDir; } setOutputDir(string f)108 void setOutputDir(string f) { lock_guard<std::mutex> guard(currentProtector); outputDir = util.getFullPathName(f); } getInputDir()109 string getInputDir() { lock_guard<std::mutex> guard(currentProtector); return inputDir; } setInputDir(string f)110 void setInputDir(string f) { lock_guard<std::mutex> guard(currentProtector); inputDir = util.getFullPathName(f); } 111 void setFileName(string); getReleaseDate()112 string getReleaseDate() { lock_guard<std::mutex> guard(currentProtector); return releaseDate; } setReleaseDate(string r)113 void setReleaseDate(string r) { lock_guard<std::mutex> guard(currentProtector); releaseDate = r; } getVersion()114 string getVersion() { lock_guard<std::mutex> guard(currentProtector); return version; } setVersion(string r)115 void setVersion(string r) { lock_guard<std::mutex> guard(currentProtector); version = r; } getLocations()116 vector<string> getLocations() { lock_guard<std::mutex> guard(currentProtector); vector<string> locations; locations.push_back(inputDir); locations.push_back(outputDir); locations.push_back(defaultPath); locations.push_back(mothurProgramPath); locations.push_back(toolsPath); return locations; } 117 118 getMothurCalling()119 bool getMothurCalling() { lock_guard<std::mutex> guard(currentProtector); return mothurCalling; } setMothurCalling(bool t)120 void setMothurCalling(bool t) { lock_guard<std::mutex> guard(currentProtector); mothurCalling = t; } 121 void printCurrentFiles(string); //string="" for just to logfile. 122 void clearCurrentFiles(); 123 set<string> getCurrentTypes(); 124 bool hasCurrentFiles(); 125 getGroupMode()126 string getGroupMode() { lock_guard<std::mutex> guard(currentProtector); return groupMode; } 127 getTestDirectory()128 string getTestDirectory() { lock_guard<std::mutex> guard(currentProtector); return testDirectory; } setTestDirectory(string t)129 void setTestDirectory(string t) { lock_guard<std::mutex> guard(currentProtector); testDirectory = t; } 130 131 132 private: 133 MothurOut* m; 134 Utils util; 135 136 vector<string> paths; //paths stored in PATH environment variables 137 string logFileName, mothurProgramPath, homePath; 138 string defaultPath, outputDir, blastPath, inputDir; 139 string releaseDate, version; 140 141 string accnosfile, phylipfile, columnfile, listfile, rabundfile, sabundfile, namefile, groupfile, designfile, taxonomyfile, biomfile, filefile, testFilePath, contigsreportfile, clrfile; 142 string orderfile, treefile, sharedfile, ordergroupfile, relabundfile, fastafile, qualfile, sfffile, oligosfile, processors, flowfile, countfile, summaryfile, constaxonomyfile, groupMode, testDirectory, sharedHeaderMode, samplefile, toolsPath; 143 bool mothurCalling; 144 setGroupMode(string t)145 void setGroupMode(string t) { groupMode = t; } 146 147 static CurrentFile* instance; 148 CurrentFile( const CurrentFile& ); // Disable copy constructor 149 void operator=( const CurrentFile& ); // Disable assignment operator 150 151 std::mutex currentProtector; CurrentFile()152 CurrentFile() { 153 m = MothurOut::getInstance(); 154 defaultPath=""; blastPath=""; toolsPath=""; testFilePath = ""; 155 inputDir = ""; outputDir= ""; 156 accnosfile = ""; 157 filefile = ""; 158 phylipfile = ""; 159 columnfile = ""; 160 listfile = ""; 161 rabundfile = ""; 162 sabundfile = ""; 163 namefile = ""; 164 phylipfile = ""; 165 columnfile = ""; 166 listfile = ""; 167 rabundfile = ""; 168 sabundfile = ""; 169 namefile = ""; 170 groupfile = ""; 171 designfile = ""; 172 orderfile = ""; 173 treefile = ""; 174 sharedfile = ""; 175 ordergroupfile = ""; 176 relabundfile = ""; 177 clrfile = ""; 178 fastafile = ""; 179 qualfile = ""; 180 sfffile = ""; 181 oligosfile = ""; 182 groupfile = ""; 183 designfile = ""; 184 orderfile = ""; 185 treefile = ""; 186 sharedfile = ""; 187 ordergroupfile = ""; 188 relabundfile = ""; 189 fastafile = ""; 190 qualfile = ""; 191 sfffile = ""; 192 oligosfile = ""; 193 accnosfile = ""; 194 taxonomyfile = ""; 195 constaxonomyfile = ""; 196 samplefile = ""; 197 unsigned concurentThreadsSupported = std::thread::hardware_concurrency(); 198 if (concurentThreadsSupported < 1) { concurentThreadsSupported = 1; } //in case thread errors 199 processors = toString(concurentThreadsSupported); 200 flowfile = ""; 201 biomfile = ""; 202 countfile = ""; 203 summaryfile = ""; 204 contigsreportfile = ""; 205 groupMode = "group"; 206 sharedHeaderMode = "otu"; 207 mothurCalling = false; 208 } ~CurrentFile()209 ~CurrentFile() { instance = 0; } 210 }; 211 /***********************************************/ 212 213 #endif 214 215