# Path: checkm/hmmer.py
# class HMMERRunner():
#     """Wrapper for running HMMER3."""
#     def __init__(self, mode="dom"):
#         self.logger = logging.getLogger('timestamp')
# 
#         # make sure HMMER is installed
#         self.checkForHMMER()
# 
#         # set the mode
#         if mode == "dom":
#             self.mode = 'domtblout'
#         elif mode == "tbl":
#             self.mode = 'tblout'
#         elif mode == 'align':
#             self.mode = 'align'
#         elif mode == 'fetch':
#             self.mode = 'fetch'
#         else:
#             raise HMMMERModeError("Mode %s not understood" % mode)
# 
#     def search(self, db, query, tableOut, hmmerOut, cmdlineOptions='', bKeepOutput=True):
#         """Run hmmsearch"""
#         # make the output dir and files
#         if self.mode != 'domtblout' and self.mode != 'tblout':
#             raise HMMMERModeError("Mode %s not compatible with search" % self.mode)
# 
#         if not bKeepOutput:
#             hmmerOut = '/dev/null'
# 
#         cmd = ('hmmsearch --%s %s %s %s %s > %s' % (self.mode, tableOut, cmdlineOptions, db, query, hmmerOut))
#         os.system(cmd)
# 
#     def align(self, db, query, outputFile, writeMode='>', outputFormat='PSIBLAST', trim=True):
#         """Run hmmalign"""
#         if self.mode != 'align':
#             raise HMMMERModeError("Mode %s not compatible with align" % self.mode)
# 
#         # build up the option string
#         opts = ''
#         if trim:
#             opts += ' --trim '
# 
#         # run hmmer
#         cmd = 'hmmalign --allcol %s --outformat %s %s %s %s %s' % (opts, outputFormat, db, query, writeMode, outputFile)
#         rtn = os.system(cmd)
#         if rtn == 256:
#             # assume user has a newer version of HMMER (>= 3.1b1) and the allcol parameter is no longer valid
#             cmd = cmd.replace('--allcol', '')
#             os.system(cmd)
# 
#     def fetch(self, db, key, fetchFileName, bKeyFile=False):
#         """Run hmmfetch"""
#         if self.mode != 'fetch':
#             raise HMMMERModeError("Mode %s not compatible with fetch" % self.mode)
# 
#         keyFileOpt = ''
#         if bKeyFile:
#             keyFileOpt = '-f'
# 
#         os.system('hmmfetch ' + keyFileOpt + ' %s %s > %s' % (db, key, fetchFileName))
# 
#     def press(self, hmmModelFile):
#         """Press a HMM file."""
#         os.system('hmmpress %s > /dev/null' % hmmModelFile)
# 
#     def index(self, hmmModelFile):
#         """Index a HMM file."""
#         if self.mode != 'fetch':
#             raise HMMMERModeError("Mode %s not compatible with fetch" % self.mode)
# 
#         os.system('hmmfetch --index %s > /dev/null' % hmmModelFile)
# 
#     def checkForHMMER(self):
#         """Check to see if HMMER is on the system path."""
#         try:
#             subprocess.call(['hmmsearch', '-h'], stdout=open(os.devnull, 'w'), stderr=subprocess.STDOUT)
#         except:
#             self.logger.error("Make sure HMMER executables (e.g., hmmsearch, hmmfetch) are on your system path.")
#             sys.exit(1)


import os
import sys
import argparse
import multiprocessing as mp
import random
from collections import defaultdict
from checkm.lib.img import IMG
from lib.markerSetBuilder import MarkerSetBuilder
from checkm.seqUtils import readFasta
from checkm.hmmer import HMMERRunner
from genometreeworkflow.makeTrees import MakeTrees
from genometreeworkflow.paralogTest import ParalogTest
from genometreeworkflow.consistencyTest import ConsistencyTest
from genometreeworkflow.getPhylogeneticHMMs import GetPhylogeneticHMMs
from genometreeworkflow.inferGenomeTree import InferGenomeTree
#                                                                             #
#    This program is distributed in the hope that it will be useful,          #
#    but WITHOUT ANY WARRANTY; without even the implied warranty of           #
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            #
#    GNU General Public License for more details.                             #
#                                                                             #
#    You should have received a copy of the GNU General Public License        #
#    along with this program. If not, see <http://www.gnu.org/licenses/>.     #
#                                                                             #
###############################################################################

__prog_desc__ = 'complete workflow for inferring a tree for a taxonomic group'

__author__ = 'Donovan Parks'
__copyright__ = 'Copyright 2013'
__credits__ = ['Donovan Parks']
__license__ = 'GPL3'
__version__ = '0.1'
__maintainer__ = 'Donovan Parks'
__email__ = 'donovan.parks@gmail.com'
__status__ = 'Development'






class GenomeTreeWorkflow(object):
    def __init__(self, outputDir):
        self.img = IMG()

# Path: checkm/hmmer.py
# class HMMERRunner():
#     """Wrapper for running HMMER3."""
#     def __init__(self, mode="dom"):
#         self.logger = logging.getLogger('timestamp')
# 
#         # make sure HMMER is installed
#         self.checkForHMMER()
# 
#         # set the mode
#         if mode == "dom":
#             self.mode = 'domtblout'
#         elif mode == "tbl":
#             self.mode = 'tblout'
#         elif mode == 'align':
#             self.mode = 'align'
#         elif mode == 'fetch':
#             self.mode = 'fetch'
#         else:
#             raise HMMMERModeError("Mode %s not understood" % mode)
# 
#     def search(self, db, query, tableOut, hmmerOut, cmdlineOptions='', bKeepOutput=True):
#         """Run hmmsearch"""
#         # make the output dir and files
#         if self.mode != 'domtblout' and self.mode != 'tblout':
#             raise HMMMERModeError("Mode %s not compatible with search" % self.mode)
# 
#         if not bKeepOutput:
#             hmmerOut = '/dev/null'
# 
#         cmd = ('hmmsearch --%s %s %s %s %s > %s' % (self.mode, tableOut, cmdlineOptions, db, query, hmmerOut))
#         os.system(cmd)
# 
#     def align(self, db, query, outputFile, writeMode='>', outputFormat='PSIBLAST', trim=True):
#         """Run hmmalign"""
#         if self.mode != 'align':
#             raise HMMMERModeError("Mode %s not compatible with align" % self.mode)
# 
#         # build up the option string
#         opts = ''
#         if trim:
#             opts += ' --trim '
# 
#         # run hmmer
#         cmd = 'hmmalign --allcol %s --outformat %s %s %s %s %s' % (opts, outputFormat, db, query, writeMode, outputFile)
#         rtn = os.system(cmd)
#         if rtn == 256:
#             # assume user has a newer version of HMMER (>= 3.1b1) and the allcol parameter is no longer valid
#             cmd = cmd.replace('--allcol', '')
#             os.system(cmd)
# 
#     def fetch(self, db, key, fetchFileName, bKeyFile=False):
#         """Run hmmfetch"""
#         if self.mode != 'fetch':
#             raise HMMMERModeError("Mode %s not compatible with fetch" % self.mode)
# 
#         keyFileOpt = ''
#         if bKeyFile:
#             keyFileOpt = '-f'
# 
#         os.system('hmmfetch ' + keyFileOpt + ' %s %s > %s' % (db, key, fetchFileName))
# 
#     def press(self, hmmModelFile):
#         """Press a HMM file."""
#         os.system('hmmpress %s > /dev/null' % hmmModelFile)
# 
#     def index(self, hmmModelFile):
#         """Index a HMM file."""
#         if self.mode != 'fetch':
#             raise HMMMERModeError("Mode %s not compatible with fetch" % self.mode)
# 
#         os.system('hmmfetch --index %s > /dev/null' % hmmModelFile)
# 
#     def checkForHMMER(self):
#         """Check to see if HMMER is on the system path."""
#         try:
#             subprocess.call(['hmmsearch', '-h'], stdout=open(os.devnull, 'w'), stderr=subprocess.STDOUT)
#         except:
#             self.logger.error("Make sure HMMER executables (e.g., hmmsearch, hmmfetch) are on your system path.")
#             sys.exit(1)


# Path: scripts/taxonomicTreeWorkflow.py
import os
import sys
import argparse
import multiprocessing as mp
import random
from collections import defaultdict
from checkm.lib.img import IMG
from lib.markerSetBuilder import MarkerSetBuilder
from checkm.seqUtils import readFasta
from checkm.hmmer import HMMERRunner
from genometreeworkflow.makeTrees import MakeTrees
from genometreeworkflow.paralogTest import ParalogTest
from genometreeworkflow.consistencyTest import ConsistencyTest
from genometreeworkflow.getPhylogeneticHMMs import GetPhylogeneticHMMs
from genometreeworkflow.inferGenomeTree import InferGenomeTree

#                                                                             #
#    This program is distributed in the hope that it will be useful,          #
#    but WITHOUT ANY WARRANTY; without even the implied warranty of           #
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            #
#    GNU General Public License for more details.                             #
#                                                                             #
#    You should have received a copy of the GNU General Public License        #
#    along with this program. If not, see <http://www.gnu.org/licenses/>.     #
#                                                                             #
###############################################################################

__prog_desc__ = 'complete workflow for inferring a tree for a taxonomic group'

__author__ = 'Donovan Parks'
__copyright__ = 'Copyright 2013'
__credits__ = ['Donovan Parks']
__license__ = 'GPL3'
__version__ = '0.1'
__maintainer__ = 'Donovan Parks'
__email__ = 'donovan.parks@gmail.com'
__status__ = 'Development'






class GenomeTreeWorkflow(object):
    def __init__(self, outputDir):
        self.img = IMG()

        self.markerSetBuilder = MarkerSetBuilder()