From 80c3fe03a8fd1635d3ad7918ff00beb973449f50 Mon Sep 17 00:00:00 2001 From: westcott Date: Mon, 19 Jul 2010 14:39:18 +0000 Subject: [PATCH] added compile time default path --- aligncommand.cpp | 17 +- chimerabellerophoncommand.cpp | 14 +- chimeraccodecommand.cpp | 14 +- chimeracheckcommand.cpp | 28 ++- chimerapintailcommand.cpp | 14 +- chimeraslayercommand.cpp | 14 +- classifyseqscommand.cpp | 53 ++++- degapseqscommand.cpp | 14 +- filterseqscommand.cpp | 17 +- makefile | 162 +++++++------- makegroupcommand.cpp | 18 +- mothur.cpp | 408 +++++++++++++++++----------------- mothurout.cpp | 20 ++ mothurout.h | 6 +- sffinfocommand.cpp | 28 ++- validparameter.cpp | 20 +- validparameter.h | 2 +- 17 files changed, 529 insertions(+), 320 deletions(-) diff --git a/aligncommand.cpp b/aligncommand.cpp index 8d1b40f..ee27776 100644 --- a/aligncommand.cpp +++ b/aligncommand.cpp @@ -107,9 +107,18 @@ AlignCommand::AlignCommand(string option) { if (pid == 0) { #endif - ableToOpen = openInputFile(candidateFileNames[i], in); - in.close(); - + ableToOpen = openInputFile(candidateFileNames[i], in, "noerror"); + + //if you can't open it, try default location + if (ableToOpen == 1) { + if (m->getDefaultPath() != "") { //default path is set + string tryPath = m->getDefaultPath() + getSimpleName(candidateFileNames[i]); + m->mothurOut("Unable to open " + candidateFileNames[i] + ". Trying default " + tryPath); m->mothurOutEndLine(); + ableToOpen = openInputFile(tryPath, in, "noerror"); + candidateFileNames[i] = tryPath; + } + } + in.close(); #ifdef USE_MPI for (int j = 1; j < processors; j++) { MPI_Send(&ableToOpen, 1, MPI_INT, j, 2001, MPI_COMM_WORLD); @@ -122,7 +131,7 @@ AlignCommand::AlignCommand(string option) { #endif if (ableToOpen == 1) { - m->mothurOut(candidateFileNames[i] + " will be disregarded."); m->mothurOutEndLine(); + m->mothurOut("Unable to open " + candidateFileNames[i] + ". It will be disregarded."); m->mothurOutEndLine(); //erase from file list candidateFileNames.erase(candidateFileNames.begin()+i); i--; diff --git a/chimerabellerophoncommand.cpp b/chimerabellerophoncommand.cpp index 2a38438..fd768a7 100644 --- a/chimerabellerophoncommand.cpp +++ b/chimerabellerophoncommand.cpp @@ -63,7 +63,17 @@ ChimeraBellerophonCommand::ChimeraBellerophonCommand(string option) { if (pid == 0) { #endif - ableToOpen = openInputFile(fastaFileNames[i], in); + ableToOpen = openInputFile(fastaFileNames[i], in, "noerror"); + + //if you can't open it, try default location + if (ableToOpen == 1) { + if (m->getDefaultPath() != "") { //default path is set + string tryPath = m->getDefaultPath() + getSimpleName(fastaFileNames[i]); + m->mothurOut("Unable to open " + fastaFileNames[i] + ". Trying default " + tryPath); m->mothurOutEndLine(); + ableToOpen = openInputFile(tryPath, in, "noerror"); + fastaFileNames[i] = tryPath; + } + } in.close(); #ifdef USE_MPI @@ -78,7 +88,7 @@ ChimeraBellerophonCommand::ChimeraBellerophonCommand(string option) { #endif if (ableToOpen == 1) { - m->mothurOut(fastaFileNames[i] + " will be disregarded."); m->mothurOutEndLine(); + m->mothurOut("Unable to open " + fastaFileNames[i] + ". It will be disregarded."); m->mothurOutEndLine(); //erase from file list fastaFileNames.erase(fastaFileNames.begin()+i); i--; diff --git a/chimeraccodecommand.cpp b/chimeraccodecommand.cpp index 578c7d6..69c3401 100644 --- a/chimeraccodecommand.cpp +++ b/chimeraccodecommand.cpp @@ -74,7 +74,17 @@ ChimeraCcodeCommand::ChimeraCcodeCommand(string option) { if (pid == 0) { #endif - ableToOpen = openInputFile(fastaFileNames[i], in); + ableToOpen = openInputFile(fastaFileNames[i], in, "noerror"); + + //if you can't open it, try default location + if (ableToOpen == 1) { + if (m->getDefaultPath() != "") { //default path is set + string tryPath = m->getDefaultPath() + getSimpleName(fastaFileNames[i]); + m->mothurOut("Unable to open " + fastaFileNames[i] + ". Trying default " + tryPath); m->mothurOutEndLine(); + ableToOpen = openInputFile(tryPath, in, "noerror"); + fastaFileNames[i] = tryPath; + } + } in.close(); #ifdef USE_MPI @@ -89,7 +99,7 @@ ChimeraCcodeCommand::ChimeraCcodeCommand(string option) { #endif if (ableToOpen == 1) { - m->mothurOut(fastaFileNames[i] + " will be disregarded."); m->mothurOutEndLine(); + m->mothurOut("Unable to open " + fastaFileNames[i] + ". It will be disregarded."); m->mothurOutEndLine(); //erase from file list fastaFileNames.erase(fastaFileNames.begin()+i); i--; diff --git a/chimeracheckcommand.cpp b/chimeracheckcommand.cpp index 098896e..f002a02 100644 --- a/chimeracheckcommand.cpp +++ b/chimeracheckcommand.cpp @@ -73,7 +73,17 @@ ChimeraCheckCommand::ChimeraCheckCommand(string option) { if (pid == 0) { #endif - ableToOpen = openInputFile(fastaFileNames[i], in); + ableToOpen = openInputFile(fastaFileNames[i], in, "noerror"); + + //if you can't open it, try default location + if (ableToOpen == 1) { + if (m->getDefaultPath() != "") { //default path is set + string tryPath = m->getDefaultPath() + getSimpleName(fastaFileNames[i]); + m->mothurOut("Unable to open " + fastaFileNames[i] + ". Trying default " + tryPath); m->mothurOutEndLine(); + ableToOpen = openInputFile(tryPath, in, "noerror"); + fastaFileNames[i] = tryPath; + } + } in.close(); #ifdef USE_MPI @@ -88,7 +98,7 @@ ChimeraCheckCommand::ChimeraCheckCommand(string option) { #endif if (ableToOpen == 1) { - m->mothurOut(fastaFileNames[i] + " will be disregarded."); m->mothurOutEndLine(); + m->mothurOut("Unable to open " + fastaFileNames[i] +". It will be disregarded."); m->mothurOutEndLine(); //erase from file list fastaFileNames.erase(fastaFileNames.begin()+i); i--; @@ -130,7 +140,17 @@ ChimeraCheckCommand::ChimeraCheckCommand(string option) { if (pid == 0) { #endif - ableToOpen = openInputFile(nameFileNames[i], in); + ableToOpen = openInputFile(nameFileNames[i], in, "noerror"); + + //if you can't open it, try default location + if (ableToOpen == 1) { + if (m->getDefaultPath() != "") { //default path is set + string tryPath = m->getDefaultPath() + getSimpleName(nameFileNames[i]); + m->mothurOut("Unable to open " + nameFileNames[i] + ". Trying default " + tryPath); m->mothurOutEndLine(); + ableToOpen = openInputFile(tryPath, in, "noerror"); + nameFileNames[i] = tryPath; + } + } in.close(); #ifdef USE_MPI @@ -145,7 +165,7 @@ ChimeraCheckCommand::ChimeraCheckCommand(string option) { #endif if (ableToOpen == 1) { - m->mothurOut(nameFileNames[i] + " will be disregarded."); m->mothurOutEndLine(); + m->mothurOut("Unable to open " + nameFileNames[i] + ". It will be disregarded."); m->mothurOutEndLine(); //erase from file list nameFileNames.erase(nameFileNames.begin()+i); i--; diff --git a/chimerapintailcommand.cpp b/chimerapintailcommand.cpp index 8dffd3a..fa7fd17 100644 --- a/chimerapintailcommand.cpp +++ b/chimerapintailcommand.cpp @@ -91,7 +91,17 @@ ChimeraPintailCommand::ChimeraPintailCommand(string option) { if (pid == 0) { #endif - ableToOpen = openInputFile(fastaFileNames[i], in); + ableToOpen = openInputFile(fastaFileNames[i], in, "noerror"); + + //if you can't open it, try default location + if (ableToOpen == 1) { + if (m->getDefaultPath() != "") { //default path is set + string tryPath = m->getDefaultPath() + getSimpleName(fastaFileNames[i]); + m->mothurOut("Unable to open " + fastaFileNames[i] + ". Trying default " + tryPath); m->mothurOutEndLine(); + ableToOpen = openInputFile(tryPath, in, "noerror"); + fastaFileNames[i] = tryPath; + } + } in.close(); #ifdef USE_MPI @@ -106,7 +116,7 @@ ChimeraPintailCommand::ChimeraPintailCommand(string option) { #endif if (ableToOpen == 1) { - m->mothurOut(fastaFileNames[i] + " will be disregarded."); m->mothurOutEndLine(); + m->mothurOut("Unable to open " + fastaFileNames[i] + ". It will be disregarded."); m->mothurOutEndLine(); //erase from file list fastaFileNames.erase(fastaFileNames.begin()+i); i--; diff --git a/chimeraslayercommand.cpp b/chimeraslayercommand.cpp index 74fd3aa..89d89e3 100644 --- a/chimeraslayercommand.cpp +++ b/chimeraslayercommand.cpp @@ -77,7 +77,17 @@ ChimeraSlayerCommand::ChimeraSlayerCommand(string option) { if (pid == 0) { #endif - ableToOpen = openInputFile(fastaFileNames[i], in); + ableToOpen = openInputFile(fastaFileNames[i], in, "noerror"); + + //if you can't open it, try default location + if (ableToOpen == 1) { + if (m->getDefaultPath() != "") { //default path is set + string tryPath = m->getDefaultPath() + getSimpleName(fastaFileNames[i]); + m->mothurOut("Unable to open " + fastaFileNames[i] + ". Trying default " + tryPath); m->mothurOutEndLine(); + ableToOpen = openInputFile(tryPath, in, "noerror"); + fastaFileNames[i] = tryPath; + } + } in.close(); #ifdef USE_MPI @@ -92,7 +102,7 @@ ChimeraSlayerCommand::ChimeraSlayerCommand(string option) { #endif if (ableToOpen == 1) { - m->mothurOut(fastaFileNames[i] + " will be disregarded."); m->mothurOutEndLine(); + m->mothurOut("Unable to open " + fastaFileNames[i] + ". It will be disregarded."); m->mothurOutEndLine(); //erase from file list fastaFileNames.erase(fastaFileNames.begin()+i); i--; diff --git a/classifyseqscommand.cpp b/classifyseqscommand.cpp index 2a210b0..a20a383 100644 --- a/classifyseqscommand.cpp +++ b/classifyseqscommand.cpp @@ -107,7 +107,17 @@ ClassifySeqsCommand::ClassifySeqsCommand(string option) { #endif ifstream in; - ableToOpen = openInputFile(fastaFileNames[i], in); + ableToOpen = openInputFile(fastaFileNames[i], in, "noerror"); + + //if you can't open it, try default location + if (ableToOpen == 1) { + if (m->getDefaultPath() != "") { //default path is set + string tryPath = m->getDefaultPath() + getSimpleName(fastaFileNames[i]); + m->mothurOut("Unable to open " + fastaFileNames[i] + ". Trying default " + tryPath); m->mothurOutEndLine(); + ableToOpen = openInputFile(tryPath, in, "noerror"); + fastaFileNames[i] = tryPath; + } + } in.close(); #ifdef USE_MPI @@ -122,7 +132,7 @@ ClassifySeqsCommand::ClassifySeqsCommand(string option) { #endif if (ableToOpen == 1) { - m->mothurOut(fastaFileNames[i] + " will be disregarded."); m->mothurOutEndLine(); + m->mothurOut("Unable to open " + fastaFileNames[i] + ". It will be disregarded."); m->mothurOutEndLine(); //erase from file list fastaFileNames.erase(fastaFileNames.begin()+i); i--; @@ -168,7 +178,17 @@ ClassifySeqsCommand::ClassifySeqsCommand(string option) { #endif ifstream in; - ableToOpen = openInputFile(namefileNames[i], in); + ableToOpen = openInputFile(namefileNames[i], in, "noerror"); + + //if you can't open it, try default location + if (ableToOpen == 1) { + if (m->getDefaultPath() != "") { //default path is set + string tryPath = m->getDefaultPath() + getSimpleName(namefileNames[i]); + m->mothurOut("Unable to open " + namefileNames[i] + ". Trying default " + tryPath); m->mothurOutEndLine(); + ableToOpen = openInputFile(tryPath, in, "noerror"); + namefileNames[i] = tryPath; + } + } in.close(); #ifdef USE_MPI @@ -181,8 +201,14 @@ ClassifySeqsCommand::ClassifySeqsCommand(string option) { } #endif - if (ableToOpen == 1) { m->mothurOut("Unable to match name file with fasta file."); m->mothurOutEndLine(); abort = true; } + if (ableToOpen == 1) { + m->mothurOut("Unable to open " + namefileNames[i] + ". It will be disregarded."); m->mothurOutEndLine(); abort = true; + //erase from file list + namefileNames.erase(namefileNames.begin()+i); + i--; + } + } } @@ -213,7 +239,17 @@ ClassifySeqsCommand::ClassifySeqsCommand(string option) { #endif ifstream in; - ableToOpen = openInputFile(groupfileNames[i], in); + ableToOpen = openInputFile(groupfileNames[i], in, "noerror"); + + //if you can't open it, try default location + if (ableToOpen == 1) { + if (m->getDefaultPath() != "") { //default path is set + string tryPath = m->getDefaultPath() + getSimpleName(groupfileNames[i]); + m->mothurOut("Unable to open " + groupfileNames[i] + ". Trying default " + tryPath); m->mothurOutEndLine(); + ableToOpen = openInputFile(tryPath, in, "noerror"); + groupfileNames[i] = tryPath; + } + } in.close(); #ifdef USE_MPI @@ -226,8 +262,13 @@ ClassifySeqsCommand::ClassifySeqsCommand(string option) { } #endif - if (ableToOpen == 1) { m->mothurOut("Unable to match group file with fasta file, not using " + groupfileNames[i] + "."); m->mothurOutEndLine(); groupfileNames[i] = ""; } + if (ableToOpen == 1) { + m->mothurOut("Unable to open " + groupfileNames[i] + ". It will be disregarded."); m->mothurOutEndLine(); groupfileNames[i] = ""; + //erase from file list + groupfileNames.erase(groupfileNames.begin()+i); + i--; + } } } diff --git a/degapseqscommand.cpp b/degapseqscommand.cpp index c6c4b55..8f8a5c3 100644 --- a/degapseqscommand.cpp +++ b/degapseqscommand.cpp @@ -54,11 +54,21 @@ DegapSeqsCommand::DegapSeqsCommand(string option) { } ifstream in; - int ableToOpen = openInputFile(fastaFileNames[i], in); + int ableToOpen = openInputFile(fastaFileNames[i], in, "noerror"); + + //if you can't open it, try default location + if (ableToOpen == 1) { + if (m->getDefaultPath() != "") { //default path is set + string tryPath = m->getDefaultPath() + getSimpleName(fastaFileNames[i]); + m->mothurOut("Unable to open " + fastaFileNames[i] + ". Trying default " + tryPath); m->mothurOutEndLine(); + ableToOpen = openInputFile(tryPath, in, "noerror"); + fastaFileNames[i] = tryPath; + } + } in.close(); if (ableToOpen == 1) { - m->mothurOut(fastaFileNames[i] + " will be disregarded."); m->mothurOutEndLine(); + m->mothurOut("Unable to open " + fastaFileNames[i] + ". It will be disregarded."); m->mothurOutEndLine(); //erase from file list fastaFileNames.erase(fastaFileNames.begin()+i); i--; diff --git a/filterseqscommand.cpp b/filterseqscommand.cpp index fada19a..3784c3d 100644 --- a/filterseqscommand.cpp +++ b/filterseqscommand.cpp @@ -72,11 +72,22 @@ FilterSeqsCommand::FilterSeqsCommand(string option) { if (path == "") { fastafileNames[i] = inputDir + fastafileNames[i]; } } - int ableToOpen; ifstream in; - ableToOpen = openInputFile(fastafileNames[i], in); + int ableToOpen = openInputFile(fastafileNames[i], in, "noerror"); + + //if you can't open it, try default location + if (ableToOpen == 1) { + if (m->getDefaultPath() != "") { //default path is set + string tryPath = m->getDefaultPath() + getSimpleName(fastafileNames[i]); + m->mothurOut("Unable to open " + fastafileNames[i] + ". Trying default " + tryPath); m->mothurOutEndLine(); + ableToOpen = openInputFile(tryPath, in, "noerror"); + fastafileNames[i] = tryPath; + } + } + in.close(); + if (ableToOpen == 1) { - m->mothurOut(fastafileNames[i] + " will be disregarded."); m->mothurOutEndLine(); + m->mothurOut("Unable to open " + fastafileNames[i] + ". It will be disregarded."); m->mothurOutEndLine(); //erase from file list fastafileNames.erase(fastafileNames.begin()+i); i--; diff --git a/makefile b/makefile index 8ea410e..3f0893c 100644 --- a/makefile +++ b/makefile @@ -1,78 +1,84 @@ -################################################### -# -# Makefile for mothur -# Created: June 29, 2010 -# -################################################### - -# -# Macros -# - -# Optimize to level 3: - -CXXFLAGS += -O3 - -CYGWIN_BUILD ?= no -ifeq ($(strip $(CYGWIN_BUILD)),yes) - CXXFLAGS += -mno-cygwin - LDFLAGS += -mno-cygwin -endif - -64BIT_VERSION ?= yes - -ifeq ($(strip $(64BIT_VERSION)),yes) - TARGET_ARCH += -arch x86_64 - CXXFLAGS += -DBIT_VERSION - - #if you are using centos uncomment the following lines - #CC = g++44 - #CXXFLAGS += -mtune=native -march=native -m64 -endif - -# if you do not want to use the readline library, set this to no. -# make sure you have the library installed - -USEREADLINE ?= yes - -ifeq ($(strip $(USEREADLINE)),yes) - CXXFLAGS += -DUSE_READLINE - LDFLAGS += \ - -lreadline\ - -lncurses -endif - -USEMPI ?= no - -ifeq ($(strip $(USEMPI)),yes) - CXX = mpic++ - CXXFLAGS += -DUSE_MPI -endif - -# -# INCLUDE directories for mothur -# - - CXXFLAGS += -I. - -# -# Get the list of all .cpp files, rename to .o files -# - -OBJECTS=$(patsubst %.cpp,%.o,$(wildcard *.cpp)) - -mothur : $(OBJECTS) - $(CXX) $(LDFLAGS) $(TARGET_ARCH) -o $@ $(OBJECTS) - -install : mothur - cp mothur ../Release/mothur - -%.o : %.cpp %.h - $(COMPILE.cpp) $(OUTPUT_OPTION) $< -%.o : %.cpp %.hpp - $(COMPILE.cpp) $(OUTPUT_OPTION) $< - - -clean : - @rm -f $(OBJECTS) - +################################################### +# +# Makefile for mothur +# Created: June 29, 2010 +# +################################################### + +# +# Macros +# + +# Optimize to level 3: + +CXXFLAGS += -O3 + +MOTHUR_FILES = "\"Enter_your_default_path_here\"" +ifeq ($(strip $(MOTHUR_FILES)),"\"Enter_your_default_path_here\"") +else + CXXFLAGS += -DMOTHUR_FILES=${MOTHUR_FILES} +endif + +CYGWIN_BUILD ?= no +ifeq ($(strip $(CYGWIN_BUILD)),yes) + CXXFLAGS += -mno-cygwin + LDFLAGS += -mno-cygwin +endif + +64BIT_VERSION ?= yes + +ifeq ($(strip $(64BIT_VERSION)),yes) + TARGET_ARCH += -arch x86_64 + CXXFLAGS += -DBIT_VERSION + + #if you are using centos uncomment the following lines + #CC = g++44 + #CXXFLAGS += -mtune=native -march=native -m64 +endif + +# if you do not want to use the readline library, set this to no. +# make sure you have the library installed + +USEREADLINE ?= yes + +ifeq ($(strip $(USEREADLINE)),yes) + CXXFLAGS += -DUSE_READLINE + LDFLAGS += \ + -lreadline\ + -lncurses +endif + +USEMPI ?= no + +ifeq ($(strip $(USEMPI)),yes) + CXX = mpic++ + CXXFLAGS += -DUSE_MPI +endif + +# +# INCLUDE directories for mothur +# + + CXXFLAGS += -I. + +# +# Get the list of all .cpp files, rename to .o files +# + +OBJECTS=$(patsubst %.cpp,%.o,$(wildcard *.cpp)) + +mothur : $(OBJECTS) + $(CXX) $(LDFLAGS) $(TARGET_ARCH) -o $@ $(OBJECTS) + +install : mothur + cp mothur ../Release/mothur + +%.o : %.cpp %.h + $(COMPILE.cpp) $(OUTPUT_OPTION) $< +%.o : %.cpp %.hpp + $(COMPILE.cpp) $(OUTPUT_OPTION) $< + + +clean : + @rm -f $(OBJECTS) + diff --git a/makegroupcommand.cpp b/makegroupcommand.cpp index 57028c9..455826a 100644 --- a/makegroupcommand.cpp +++ b/makegroupcommand.cpp @@ -60,18 +60,26 @@ MakeGroupCommand::MakeGroupCommand(string option) { if (path == "") { fastaFileNames[i] = inputDir + fastaFileNames[i]; } } - int ableToOpen; ifstream in; - - ableToOpen = openInputFile(fastaFileNames[i], in); + int ableToOpen = openInputFile(fastaFileNames[i], in, "noerror"); + + //if you can't open it, try default location + if (ableToOpen == 1) { + if (m->getDefaultPath() != "") { //default path is set + string tryPath = m->getDefaultPath() + getSimpleName(fastaFileNames[i]); + m->mothurOut("Unable to open " + fastaFileNames[i] + ". Trying default " + tryPath); m->mothurOutEndLine(); + ableToOpen = openInputFile(tryPath, in, "noerror"); + fastaFileNames[i] = tryPath; + } + } in.close(); - + if (ableToOpen == 1) { + m->mothurOut("Unable to open " + fastaFileNames[i] + ". It will be disregarded."); m->mothurOutEndLine(); //erase from file list fastaFileNames.erase(fastaFileNames.begin()+i); i--; }else{ filename += getRootName(getSimpleName(fastaFileNames[i])); } - } filename += "groups"; diff --git a/mothur.cpp b/mothur.cpp index 1e5b41b..cb8d1e8 100644 --- a/mothur.cpp +++ b/mothur.cpp @@ -1,201 +1,207 @@ -/* - * interface.cpp - * - * - * Created by Pat Schloss on 8/14/08. - * Copyright 2008 Patrick D. Schloss. All rights reserved. - * - */ - -#include "mothur.h" -#include "engine.hpp" -#include "globaldata.hpp" -#include "mothurout.h" - - -/**************************************************************************************************/ - -GlobalData* GlobalData::_uniqueInstance = 0; -CommandFactory* CommandFactory::_uniqueInstance = 0; -MothurOut* MothurOut::_uniqueInstance = 0; - -/***********************************************************************/ -volatile int ctrlc_pressed = 0; -void ctrlc_handler ( int sig ) { - MothurOut* m = MothurOut::getInstance(); - ctrlc_pressed = 1; - m->control_pressed = ctrlc_pressed; - - if (m->executing) { //if mid command quit execution, else quit mothur - m->mothurOutEndLine(); m->mothurOut("quitting command..."); m->mothurOutEndLine(); - }else{ - m->mothurOut("quitting mothur"); m->mothurOutEndLine(); - exit(1); - } -} -/***********************************************************************/ -int main(int argc, char *argv[]){ - MothurOut* m = MothurOut::getInstance(); - try { - - signal(SIGINT, ctrlc_handler ); - - time_t ltime = time(NULL); /* calendar time */ - string logFileName = "mothur." + toString(ltime) + ".logfile"; - - #ifdef USE_MPI - MPI_Init(&argc, &argv); - #endif - - m->setFileName(logFileName); - - - //version - #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) - system("clear"); - #if defined (__APPLE__) || (__MACH__) - m->mothurOutJustToLog("Mac version"); - m->mothurOutEndLine(); m->mothurOutEndLine(); - #else - m->mothurOutJustToLog("Linux version"); - m->mothurOutEndLine(); m->mothurOutEndLine(); - #endif - - #else - system("CLS"); - m->mothurOutJustToLog("Windows version"); - m->mothurOutEndLine(); m->mothurOutEndLine(); - #endif - - #ifdef USE_READLINE - m->mothurOutJustToLog("Using ReadLine"); - m->mothurOutEndLine(); m->mothurOutEndLine(); - #endif - - #ifdef BIT_VERSION - m->mothurOutJustToLog("Running 64Bit Version"); - m->mothurOutEndLine(); m->mothurOutEndLine(); - #else - m->mothurOutJustToLog("Running 32Bit Version"); - m->mothurOutEndLine(); m->mothurOutEndLine(); - #endif - - //header - m->mothurOut("mothur v.1.11.0"); - m->mothurOutEndLine(); - m->mothurOut("Last updated: 6/18/2010"); - m->mothurOutEndLine(); - m->mothurOutEndLine(); - m->mothurOut("by"); - m->mothurOutEndLine(); - m->mothurOut("Patrick D. Schloss"); - m->mothurOutEndLine(); - m->mothurOutEndLine(); - m->mothurOut("Department of Microbiology & Immunology"); - m->mothurOutEndLine(); - m->mothurOut("University of Michigan"); - m->mothurOutEndLine(); - m->mothurOut("pschloss@umich.edu"); - m->mothurOutEndLine(); - m->mothurOut("http://www.mothur.org"); - m->mothurOutEndLine(); - m->mothurOutEndLine(); - m->mothurOut("When using, please cite:"); - m->mothurOutEndLine(); - m->mothurOut("Schloss, P.D., et al., Introducing mothur: Open-source, platform-independent, community-supported software for describing and comparing microbial communities. Appl Environ Microbiol, 2009. 75(23):7537-41."); - m->mothurOutEndLine(); - m->mothurOutEndLine(); - m->mothurOut("Distributed under the GNU General Public License"); - m->mothurOutEndLine(); - m->mothurOutEndLine(); - m->mothurOut("Type 'help()' for information on the commands that are available"); - m->mothurOutEndLine(); - m->mothurOutEndLine(); - m->mothurOut("Type 'quit()' to exit program"); - m->mothurOutEndLine(); - - #ifdef USE_MPI - m->mothurOutJustToLog("Using MPI\tversion "); - int version, subversion; - MPI_Get_version(&version, &subversion); - m->mothurOutJustToLog(toString(version) + "." + toString(subversion) + "\n"); - #endif - - //srand(54321); - srand( (unsigned)time( NULL ) ); - - Engine* mothur; - bool bail = 0; - string input; - - if(argc>1){ - input = argv[1]; - - if (input[0] == '#') { - m->mothurOutJustToLog("Script Mode"); - m->mothurOutEndLine(); m->mothurOutEndLine(); - - mothur = new ScriptEngine(argv[0], argv[1]); - }else{ - m->mothurOutJustToLog("Batch Mode"); - m->mothurOutEndLine(); m->mothurOutEndLine(); - - mothur = new BatchEngine(argv[0], argv[1]); - } - } - else{ - m->mothurOutJustToLog("Interactive Mode"); - m->mothurOutEndLine(); m->mothurOutEndLine(); - - mothur = new InteractEngine(argv[0]); - } - - while(bail == 0) { bail = mothur->getInput(); } - - //closes logfile so we can rename - m->closeLog(); - - string outputDir = mothur->getOutputDir(); - string tempLog = mothur->getLogFileName(); - bool append = mothur->getAppend(); - - string newlogFileName; - if (tempLog != "") { - newlogFileName = outputDir + tempLog; - - if (!append) { - //need this because m->mothurOut makes the logfile, but doesn't know where to put it - rename(logFileName.c_str(), newlogFileName.c_str()); //logfile with timestamp - - }else { - ofstream outNewLog; - openOutputFileAppend(newlogFileName, outNewLog); - outNewLog << endl << endl << "*********************************************************************************" << endl << endl; - outNewLog.close(); - - appendFiles(logFileName, newlogFileName); - remove(logFileName.c_str()); - } - }else{ - newlogFileName = outputDir + logFileName; - //need this because m->mothurOut makes the logfile, but doesn't know where to put it - rename(logFileName.c_str(), newlogFileName.c_str()); //logfile with timestamp - } - - - delete mothur; - - #ifdef USE_MPI - MPI_Finalize(); - #endif - - return 0; - } - catch(exception& e) { - m->errorOut(e, "mothur", "main"); - exit(1); - } -} - -/**************************************************************************************************/ - +/* + * interface.cpp + * + * + * Created by Pat Schloss on 8/14/08. + * Copyright 2008 Patrick D. Schloss. All rights reserved. + * + */ + +#include "mothur.h" +#include "engine.hpp" +#include "globaldata.hpp" +#include "mothurout.h" + +/**************************************************************************************************/ + +GlobalData* GlobalData::_uniqueInstance = 0; +CommandFactory* CommandFactory::_uniqueInstance = 0; +MothurOut* MothurOut::_uniqueInstance = 0; + +/***********************************************************************/ +volatile int ctrlc_pressed = 0; +void ctrlc_handler ( int sig ) { + MothurOut* m = MothurOut::getInstance(); + ctrlc_pressed = 1; + m->control_pressed = ctrlc_pressed; + + if (m->executing) { //if mid command quit execution, else quit mothur + m->mothurOutEndLine(); m->mothurOut("quitting command..."); m->mothurOutEndLine(); + }else{ + m->mothurOut("quitting mothur"); m->mothurOutEndLine(); + exit(1); + } +} +/***********************************************************************/ +int main(int argc, char *argv[]){ + MothurOut* m = MothurOut::getInstance(); + try { + + signal(SIGINT, ctrlc_handler ); + + time_t ltime = time(NULL); /* calendar time */ + string logFileName = "mothur." + toString(ltime) + ".logfile"; + + #ifdef USE_MPI + MPI_Init(&argc, &argv); + #endif + + m->setFileName(logFileName); + + + //version + #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) + system("clear"); + #if defined (__APPLE__) || (__MACH__) + m->mothurOutJustToLog("Mac version"); + m->mothurOutEndLine(); m->mothurOutEndLine(); + #else + m->mothurOutJustToLog("Linux version"); + m->mothurOutEndLine(); m->mothurOutEndLine(); + #endif + + #else + system("CLS"); + m->mothurOutJustToLog("Windows version"); + m->mothurOutEndLine(); m->mothurOutEndLine(); + #endif + + #ifdef USE_READLINE + m->mothurOutJustToLog("Using ReadLine"); + m->mothurOutEndLine(); m->mothurOutEndLine(); + #endif + + #ifdef MOTHUR_FILES + string temp = MOTHUR_FILES; + m->setDefaultPath(temp); + m->mothurOutJustToLog("Using default file location " + temp); + m->mothurOutEndLine(); m->mothurOutEndLine(); + #endif + + #ifdef BIT_VERSION + m->mothurOutJustToLog("Running 64Bit Version"); + m->mothurOutEndLine(); m->mothurOutEndLine(); + #else + m->mothurOutJustToLog("Running 32Bit Version"); + m->mothurOutEndLine(); m->mothurOutEndLine(); + #endif + + //header + m->mothurOut("mothur v.1.11.0"); + m->mothurOutEndLine(); + m->mothurOut("Last updated: 6/18/2010"); + m->mothurOutEndLine(); + m->mothurOutEndLine(); + m->mothurOut("by"); + m->mothurOutEndLine(); + m->mothurOut("Patrick D. Schloss"); + m->mothurOutEndLine(); + m->mothurOutEndLine(); + m->mothurOut("Department of Microbiology & Immunology"); + m->mothurOutEndLine(); + m->mothurOut("University of Michigan"); + m->mothurOutEndLine(); + m->mothurOut("pschloss@umich.edu"); + m->mothurOutEndLine(); + m->mothurOut("http://www.mothur.org"); + m->mothurOutEndLine(); + m->mothurOutEndLine(); + m->mothurOut("When using, please cite:"); + m->mothurOutEndLine(); + m->mothurOut("Schloss, P.D., et al., Introducing mothur: Open-source, platform-independent, community-supported software for describing and comparing microbial communities. Appl Environ Microbiol, 2009. 75(23):7537-41."); + m->mothurOutEndLine(); + m->mothurOutEndLine(); + m->mothurOut("Distributed under the GNU General Public License"); + m->mothurOutEndLine(); + m->mothurOutEndLine(); + m->mothurOut("Type 'help()' for information on the commands that are available"); + m->mothurOutEndLine(); + m->mothurOutEndLine(); + m->mothurOut("Type 'quit()' to exit program"); + m->mothurOutEndLine(); + + #ifdef USE_MPI + m->mothurOutJustToLog("Using MPI\tversion "); + int version, subversion; + MPI_Get_version(&version, &subversion); + m->mothurOutJustToLog(toString(version) + "." + toString(subversion) + "\n"); + #endif + + //srand(54321); + srand( (unsigned)time( NULL ) ); + + Engine* mothur; + bool bail = 0; + string input; + + if(argc>1){ + input = argv[1]; + + if (input[0] == '#') { + m->mothurOutJustToLog("Script Mode"); + m->mothurOutEndLine(); m->mothurOutEndLine(); + + mothur = new ScriptEngine(argv[0], argv[1]); + }else{ + m->mothurOutJustToLog("Batch Mode"); + m->mothurOutEndLine(); m->mothurOutEndLine(); + + mothur = new BatchEngine(argv[0], argv[1]); + } + } + else{ + m->mothurOutJustToLog("Interactive Mode"); + m->mothurOutEndLine(); m->mothurOutEndLine(); + + mothur = new InteractEngine(argv[0]); + } + + while(bail == 0) { bail = mothur->getInput(); } + + //closes logfile so we can rename + m->closeLog(); + + string outputDir = mothur->getOutputDir(); + string tempLog = mothur->getLogFileName(); + bool append = mothur->getAppend(); + + string newlogFileName; + if (tempLog != "") { + newlogFileName = outputDir + tempLog; + + if (!append) { + //need this because m->mothurOut makes the logfile, but doesn't know where to put it + rename(logFileName.c_str(), newlogFileName.c_str()); //logfile with timestamp + + }else { + ofstream outNewLog; + openOutputFileAppend(newlogFileName, outNewLog); + outNewLog << endl << endl << "*********************************************************************************" << endl << endl; + outNewLog.close(); + + appendFiles(logFileName, newlogFileName); + remove(logFileName.c_str()); + } + }else{ + newlogFileName = outputDir + logFileName; + //need this because m->mothurOut makes the logfile, but doesn't know where to put it + rename(logFileName.c_str(), newlogFileName.c_str()); //logfile with timestamp + } + + + delete mothur; + + #ifdef USE_MPI + MPI_Finalize(); + #endif + + return 0; + } + catch(exception& e) { + m->errorOut(e, "mothur", "main"); + exit(1); + } +} + +/**************************************************************************************************/ + diff --git a/mothurout.cpp b/mothurout.cpp index 5e0f3d8..d3f8e7a 100644 --- a/mothurout.cpp +++ b/mothurout.cpp @@ -40,6 +40,26 @@ void MothurOut::setFileName(string filename) { } } /*********************************************************************************************/ +void MothurOut::setDefaultPath(string pathname) { + try { + + //add / to name if needed + string lastChar = pathname.substr(pathname.length()-1); + #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) + if (lastChar != "/") { pathname += "/"; } + #else + if (lastChar != "\\") { pathname += "\\"; } + #endif + + defaultPath = pathname; + + } + catch(exception& e) { + errorOut(e, "MothurOut", "setDefaultPath"); + exit(1); + } +} +/*********************************************************************************************/ void MothurOut::closeLog() { try { diff --git a/mothurout.h b/mothurout.h index bf356ae..1b89caf 100644 --- a/mothurout.h +++ b/mothurout.h @@ -25,18 +25,22 @@ class MothurOut { void mothurOutJustToLog(string); void errorOut(exception&, string, string); void closeLog(); + string getDefaultPath() { return defaultPath; } + void setDefaultPath(string); int control_pressed; bool executing; + private: static MothurOut* _uniqueInstance; MothurOut( const MothurOut& ); // Disable copy constructor void operator=( const MothurOut& ); // Disable assignment operator - MothurOut() { control_pressed = false; }; + MothurOut() { control_pressed = false; defaultPath=""; }; ~MothurOut(); string logFileName; + string defaultPath; ofstream out; int mem_usage(double&, double&); diff --git a/sffinfocommand.cpp b/sffinfocommand.cpp index 885aadc..37ab0ba 100644 --- a/sffinfocommand.cpp +++ b/sffinfocommand.cpp @@ -54,11 +54,21 @@ SffInfoCommand::SffInfoCommand(string option) { } ifstream in; - int ableToOpen = openInputFile(filenames[i], in); + int ableToOpen = openInputFile(filenames[i], in, "noerror"); + + //if you can't open it, try default location + if (ableToOpen == 1) { + if (m->getDefaultPath() != "") { //default path is set + string tryPath = m->getDefaultPath() + getSimpleName(filenames[i]); + m->mothurOut("Unable to open " + filenames[i] + ". Trying default " + tryPath); m->mothurOutEndLine(); + ableToOpen = openInputFile(tryPath, in, "noerror"); + filenames[i] = tryPath; + } + } in.close(); if (ableToOpen == 1) { - m->mothurOut(filenames[i] + " will be disregarded."); m->mothurOutEndLine(); + m->mothurOut("Unable to open " + filenames[i] + ". It will be disregarded."); m->mothurOutEndLine(); //erase from file list filenames.erase(filenames.begin()+i); i--; @@ -84,11 +94,21 @@ SffInfoCommand::SffInfoCommand(string option) { } ifstream in; - int ableToOpen = openInputFile(accnosFileNames[i], in); + int ableToOpen = openInputFile(accnosFileNames[i], in, "noerror"); + + //if you can't open it, try default location + if (ableToOpen == 1) { + if (m->getDefaultPath() != "") { //default path is set + string tryPath = m->getDefaultPath() + getSimpleName(accnosFileNames[i]); + m->mothurOut("Unable to open " + accnosFileNames[i] + ". Trying default " + tryPath); m->mothurOutEndLine(); + ableToOpen = openInputFile(tryPath, in, "noerror"); + accnosFileNames[i] = tryPath; + } + } in.close(); if (ableToOpen == 1) { - m->mothurOut(accnosFileNames[i] + " will be disregarded."); m->mothurOutEndLine(); + m->mothurOut("Unable to open " + accnosFileNames[i] + ". It will be disregarded."); m->mothurOutEndLine(); //erase from file list accnosFileNames.erase(accnosFileNames.begin()+i); i--; diff --git a/validparameter.cpp b/validparameter.cpp index 163423b..e82a9e8 100644 --- a/validparameter.cpp +++ b/validparameter.cpp @@ -197,7 +197,7 @@ bool ValidParameters::isValidParameter(string parameter, vector cParams, /******************************************************/ -string ValidParameters::validFile(map container, string parameter, bool isFile) { +string ValidParameters::validFile(map& container, string parameter, bool isFile) { try { int ableToOpen; ifstream in; @@ -217,7 +217,18 @@ string ValidParameters::validFile(map container, string paramete if (pid == 0) { #endif - ableToOpen = openInputFile(it->second, in); + ableToOpen = openInputFile(it->second, in, "noerror"); + + //if you can't open it, try default location + if (ableToOpen == 1) { + if (m->getDefaultPath() != "") { //default path is set + string tryPath = m->getDefaultPath() + getSimpleName(it->second); + m->mothurOut("Unable to open " + it->second + ". Trying default " + tryPath); m->mothurOutEndLine(); + ableToOpen = openInputFile(tryPath, in, "noerror"); + container[parameter] = tryPath; + } + } + in.close(); #ifdef USE_MPI @@ -231,7 +242,10 @@ string ValidParameters::validFile(map container, string paramete MPI_Barrier(MPI_COMM_WORLD); //make everyone wait - just in case #endif - if (ableToOpen == 1) { return "not open"; } + if (ableToOpen == 1) { + m->mothurOut("Unable to open " + container[parameter]); m->mothurOutEndLine(); + return "not open"; + } } }else { return "not found"; } diff --git a/validparameter.h b/validparameter.h index 9aeafa2..782931f 100644 --- a/validparameter.h +++ b/validparameter.h @@ -27,7 +27,7 @@ class ValidParameters { bool isValidParameter(string, vector, string); vector addParameters(string[], int); void initParameterRanges(); - string validFile(map, string, bool); //container, parameter, isFile + string validFile(map&, string, bool); //container, parameter, isFile private: map::iterator it; -- 2.39.2