from Module import AbstractModule

class Module(AbstractModule):
    def __init__(self):
        AbstractModule.__init__(self)

    def run(
        self, network, in_data, out_attributes, user_options, num_cores,
        out_path):
        import os
        from genomicode import config
        from genomicode import filelib
        from genomicode import parallel
        from genomicode import alignlib
        
        bowtie2_build = filelib.which_assert(config.bowtie2_build)
        ref = alignlib.standardize_reference_genome(
            in_data.identifier, out_path, use_symlinks=True)

        # bowtie2-build <ref.fa> <output_stem>
        # Makes files:
        # <output_stem>.[1234].bt2
        # <output_stem>.rev.[12].bt2

        sq = parallel.quote
        cmd = [
            sq(bowtie2_build),
            sq(ref.fasta_file_full),
            ref.name,
            ]
        parallel.sshell(cmd, path=out_path)

        # Check to make sure index was created successfully.
        f = os.path.join(out_path, "%s.1.bt2" % ref.name)
        assert filelib.exists_nz(f)

    def name_outfile(self, antecedents, user_options):
        return "reference.bowtie2"

from Module import AbstractModule

class Module(AbstractModule):
    def __init__(self):
        AbstractModule.__init__(self)

    def run(
        self, network, in_data, out_attributes, user_options, num_cores,
        out_path):
        import os
        from genomicode import config
        from genomicode import filelib
        from genomicode import parallel
        from genomicode import alignlib
        
        bowtie2_build = filelib.which_assert(config.bowtie2_build)
        ref = alignlib.standardize_reference_genome(
            in_data.identifier, out_path, use_symlinks=True)

        # bowtie2-build <ref.fa> <output_stem>
        # Makes files:
        # <output_stem>.[1234].bt2
        # <output_stem>.rev.[12].bt2

        sq = parallel.quote
        cmd = [
            sq(bowtie2_build),
            sq(ref.fasta_file_full),
            ref.name,
            ]
        parallel.sshell(cmd, path=out_path)

        # Check to make sure index was created successfully.
        f = os.path.join(out_path, "%s.1.bt2" % ref.name)
        assert filelib.exists_nz(f)

    def name_outfile(self, antecedents, user_options):
        return "reference.bowtie2"

# bowtie2-build <ref.fa> <output_stem> # Makes files: # <output_stem>.[1234].bt2 # <output_stem>.rev.[12].bt2 # Check to make sure index was created successfully.