# Copyright 2013-2019 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)

from spack import *
import os
import glob


class GenemarkEt(Package):
    """Gene Prediction in Bacteria, archaea, Metagenomes and
       Metatranscriptomes.
       When downloaded this file is named the same for all versions.
       Spack will search your current directory for the download file.
       Alternatively, add this file to a mirror so that Spack can find it.
       For instructions on how to set up a mirror, see
       http://spack.readthedocs.io/en/latest/mirrors.html"""

    homepage = "http://topaz.gatech.edu/GeneMark"

    version('4.38', sha256='cee3bd73d331be44159eac15469560d0b07ffa2c98ac764c37219e1f3b7d3146')
    version('4.33', '4ab7d7d3277a685dfb49e11bc5b493c3')

    depends_on('perl', type=('build', 'run'))

    def url_for_version(self, version):
        return "file://{0}/gm_et_linux_64.tar.gz".format(os.getcwd())

    def install(self, spec, prefix):
        mkdirp(prefix.bin)
        mkdirp(prefix.bin.heu_dir)
        with working_dir('gmes_petap'):
            install_tree('lib', prefix.lib)
            files = glob.iglob('*')
            for file in files:
                if os.path.isfile(file):
                    install(file, prefix.bin)
            install_tree('heu_dir', prefix.bin.heu_dir)

    def setup_environment(self, spack_env, run_env):
        run_env.prepend_path('PERL5LIB', prefix.lib)

@@ -733,16 +733,111 @@
 eMark%22%0A%0A
+    version('4.46', sha256='856b0b6c7cbd12835e140ff04ecd9124376348efd65f76bfd8b8e08c1834eac0')%0A
     vers
@@ -1025,16 +1025,251 @@
  'run'))
+%0A    depends_on('perl-yaml', type=('build', 'run'))%0A    depends_on('perl-hash-merge', type=('build', 'run'))%0A    depends_on('perl-logger-simple', type=('build', 'run'))%0A    depends_on('perl-parallel-forkmanager', type=('build', 'run'))
 %0A%0A    de
@@ -1484,25 +1484,69 @@
     
-with working
+if self.version %3C= Version('4.38'):%0A            source
 _dir
-(
+ = 
 'gme
@@ -1553,16 +1553,114 @@
 s_petap'
+%0A        else:%0A            source_dir = self.stage.source_path%0A        with working_dir(source_dir
 ):%0A     
@@ -1909,16 +1909,358 @@
 u_dir)%0A%0A
+    @run_after('install')%0A    def filter_sbang(self):%0A        with working_dir(self.prefix.bin):%0A            pattern = '%5E#!.*/usr/bin/perl'%0A            repl = '#!%7B0%7D'.format(self.spec%5B'perl'%5D.command.path)%0A            files = glob.iglob(%22*.pl%22)%0A            for file in files:%0A                filter_file(pattern, repl, *files, backup=False)%0A%0A
     def 

Update genemark-et package