# Path: graftm/graftm_package.py
# class GraftMPackage:
#     '''Package to represent a GraftM package. To start using a package, run
# 
#     pkg = GraftMPackage.acquire('/path/to/a.gpkg')
# 
#     and then retrieve values with e.g.
# 
#     pkg.alignment_hmm_path()
#       #=> '/path/to/a.gpkg/the.hmm'
#     '''
# 
#     _CONTENTS_FILE_NAME = 'CONTENTS.json'
# 
#     # The key names are unlikely to change across package format versions,
#     # so store them here in the superclass
#     DIAMOND_DATABASE_KEY = 'diamond_database'
#     VERSION_KEY = 'graftm_package_version'
#     ALIGNMENT_HMM_KEY = 'align_hmm'
#     SEARCH_HMM_KEY = "search_hmms"
#     REFERENCE_PACKAGE_KEY = "refpkg"
#     HMM_TRUSTED_CUTOFF_KEY = "trusted_cutoff"
#     RANGE_KEY = "range"
#     UNALIGNED_SEQUENCE_DATABASE_KEY = "unaligned_sequence_database"
#     _CONTENTS_FILE_NAME = 'CONTENTS.json'
# 
#     _CURRENT_VERSION = 3
# 
#     _REQUIRED_KEYS = {'2': [
#                              VERSION_KEY,
#                              ALIGNMENT_HMM_KEY,
#                              SEARCH_HMM_KEY,
#                              REFERENCE_PACKAGE_KEY,
#                              HMM_TRUSTED_CUTOFF_KEY,
#                              RANGE_KEY
#                              ],
#                       '3': [
#                              VERSION_KEY,
#                              ALIGNMENT_HMM_KEY,
#                              SEARCH_HMM_KEY,
#                              REFERENCE_PACKAGE_KEY,
#                              HMM_TRUSTED_CUTOFF_KEY,
#                              RANGE_KEY,
#                              UNALIGNED_SEQUENCE_DATABASE_KEY
#                              ]
#                       }
# 
# 
#     @staticmethod
#     def acquire(graftm_package_path):
#         '''Acquire a new graftm Package
# 
#         Parameters
#         ----------
#         graftm_output_path: str
#             path to base directory of graftm
#         '''
# 
#         with open(os.path.join(
#                 graftm_package_path,
#                 GraftMPackage._CONTENTS_FILE_NAME
#                 )) as f:
#             contents_hash = json.load(f)
# 
#         v=contents_hash[GraftMPackage.VERSION_KEY]
#         logging.debug("Loading version %i GraftM package: %s" % (v, graftm_package_path))
#         if v == 2:
#             pkg = GraftMPackageVersion2()
#         elif v == 3:
#             pkg = GraftMPackageVersion3()
#         else:
#             raise InsufficientGraftMPackageException("Bad version: %s" % v)
# 
#         pkg._contents_hash = contents_hash
#         pkg._base_directory = graftm_package_path
#         # check we are at current version otherwise choke
#         pkg.check_universal_keys(v)
#         pkg.check_required_keys(GraftMPackage._REQUIRED_KEYS[str(v)])
#         return pkg
# 
#     def check_universal_keys(self, version):
#         h = self._contents_hash
#         try:
#             v = h[GraftMPackage.VERSION_KEY]
#         except KeyError:
#             raise InsufficientGraftMPackageException("No version information in graftm package")
#         if v != version:
#             raise InsufficientGraftMPackageException("Bad version: %s" % v)
# 
#     def check_required_keys(self, required_keys):
#         '''raise InsufficientGraftMPackageException if this package does not
#         conform to the standard of the given package'''
#         h = self._contents_hash
#         for key in required_keys:
#             if key not in h:
#                 raise InsufficientGraftMPackageException("Package missing key %s" % key)
# 
#     def __getitem__(self, key):
#         '''Return the value of the given key from the contents file'''
#         return self.contents_hash[key]
# 
#     def contents_file_path(self):
#         return os.path.join(self._base_directory, GraftMPackage._CONTENTS_FILE_NAME)


import os
import shutil
import logging
import inspect
from graftm.graftm_package import GraftMPackage
        Parameters
        ----------
        hmm : str
            path to hmm profile

        Returns
        -------
        Length to search to when linking hits on a single contig
        '''
        length=int([x for x in open(hmm) if x.startswith("LENG")][0].split()[1])
        max_length=round(length*1.5, 0)

        return max_length

    def set_attributes(self, args):


        # Read graftM package and assign HMM and refpkg file
        if args.no_merge_reads:
            setattr(args, 'merge_reads', False)
        else:
            if args.reverse or args.interleaved:
                setattr(args, 'merge_reads', True)
            else:
                setattr(args, 'merge_reads', False)
                
        if args.graftm_package:
            if not os.path.isdir(args.graftm_package):
                raise Exception("%s does not exist. Are you sure you provided the correct path?" % args.graftm_package)
            else:

# Path: graftm/graftm_package.py
# class GraftMPackage:
#     '''Package to represent a GraftM package. To start using a package, run
# 
#     pkg = GraftMPackage.acquire('/path/to/a.gpkg')
# 
#     and then retrieve values with e.g.
# 
#     pkg.alignment_hmm_path()
#       #=> '/path/to/a.gpkg/the.hmm'
#     '''
# 
#     _CONTENTS_FILE_NAME = 'CONTENTS.json'
# 
#     # The key names are unlikely to change across package format versions,
#     # so store them here in the superclass
#     DIAMOND_DATABASE_KEY = 'diamond_database'
#     VERSION_KEY = 'graftm_package_version'
#     ALIGNMENT_HMM_KEY = 'align_hmm'
#     SEARCH_HMM_KEY = "search_hmms"
#     REFERENCE_PACKAGE_KEY = "refpkg"
#     HMM_TRUSTED_CUTOFF_KEY = "trusted_cutoff"
#     RANGE_KEY = "range"
#     UNALIGNED_SEQUENCE_DATABASE_KEY = "unaligned_sequence_database"
#     _CONTENTS_FILE_NAME = 'CONTENTS.json'
# 
#     _CURRENT_VERSION = 3
# 
#     _REQUIRED_KEYS = {'2': [
#                              VERSION_KEY,
#                              ALIGNMENT_HMM_KEY,
#                              SEARCH_HMM_KEY,
#                              REFERENCE_PACKAGE_KEY,
#                              HMM_TRUSTED_CUTOFF_KEY,
#                              RANGE_KEY
#                              ],
#                       '3': [
#                              VERSION_KEY,
#                              ALIGNMENT_HMM_KEY,
#                              SEARCH_HMM_KEY,
#                              REFERENCE_PACKAGE_KEY,
#                              HMM_TRUSTED_CUTOFF_KEY,
#                              RANGE_KEY,
#                              UNALIGNED_SEQUENCE_DATABASE_KEY
#                              ]
#                       }
# 
# 
#     @staticmethod
#     def acquire(graftm_package_path):
#         '''Acquire a new graftm Package
# 
#         Parameters
#         ----------
#         graftm_output_path: str
#             path to base directory of graftm
#         '''
# 
#         with open(os.path.join(
#                 graftm_package_path,
#                 GraftMPackage._CONTENTS_FILE_NAME
#                 )) as f:
#             contents_hash = json.load(f)
# 
#         v=contents_hash[GraftMPackage.VERSION_KEY]
#         logging.debug("Loading version %i GraftM package: %s" % (v, graftm_package_path))
#         if v == 2:
#             pkg = GraftMPackageVersion2()
#         elif v == 3:
#             pkg = GraftMPackageVersion3()
#         else:
#             raise InsufficientGraftMPackageException("Bad version: %s" % v)
# 
#         pkg._contents_hash = contents_hash
#         pkg._base_directory = graftm_package_path
#         # check we are at current version otherwise choke
#         pkg.check_universal_keys(v)
#         pkg.check_required_keys(GraftMPackage._REQUIRED_KEYS[str(v)])
#         return pkg
# 
#     def check_universal_keys(self, version):
#         h = self._contents_hash
#         try:
#             v = h[GraftMPackage.VERSION_KEY]
#         except KeyError:
#             raise InsufficientGraftMPackageException("No version information in graftm package")
#         if v != version:
#             raise InsufficientGraftMPackageException("Bad version: %s" % v)
# 
#     def check_required_keys(self, required_keys):
#         '''raise InsufficientGraftMPackageException if this package does not
#         conform to the standard of the given package'''
#         h = self._contents_hash
#         for key in required_keys:
#             if key not in h:
#                 raise InsufficientGraftMPackageException("Package missing key %s" % key)
# 
#     def __getitem__(self, key):
#         '''Return the value of the given key from the contents file'''
#         return self.contents_hash[key]
# 
#     def contents_file_path(self):
#         return os.path.join(self._base_directory, GraftMPackage._CONTENTS_FILE_NAME)


# Path: graftm/housekeeping.py
import os
import shutil
import logging
import inspect
from graftm.graftm_package import GraftMPackage

        Parameters
        ----------
        hmm : str
            path to hmm profile

        Returns
        -------
        Length to search to when linking hits on a single contig
        '''
        length=int([x for x in open(hmm) if x.startswith("LENG")][0].split()[1])
        max_length=round(length*1.5, 0)

        return max_length

    def set_attributes(self, args):


        # Read graftM package and assign HMM and refpkg file
        if args.no_merge_reads:
            setattr(args, 'merge_reads', False)
        else:
            if args.reverse or args.interleaved:
                setattr(args, 'merge_reads', True)
            else:
                setattr(args, 'merge_reads', False)
                
        if args.graftm_package:
            if not os.path.isdir(args.graftm_package):
                raise Exception("%s does not exist. Are you sure you provided the correct path?" % args.graftm_package)
            else:

                gpkg = GraftMPackage.acquire(args.graftm_package)