@@ -0,0 +1,2339 @@
+import os%0Aimport luigi%0Aimport json%0Aimport subprocess%0A%0Afrom support import merge_fasta as mf%0A%0A# add parent directory to path%0Aif __name__ == '__main__' and __package__ is None:%0A    os.sys.path.append(%0A        os.path.dirname(os.path.dirname(os.path.abspath(__file__))))%0A%0A# ----------------------------------TASKS--------------------------------------%0A%0A%0Aclass MergeGenome(luigi.Task):%0A    %22%22%22%0A    Task to merge genome fasta files%0A    %22%22%22%0A    updir = luigi.parameter()%0A%0A    def run(self):%0A        %22%22%22%0A        Merge all fasta files in updir%0A        %22%22%22%0A        mf.merge_genome_files(self.updir)%0A%0A    def output(self):%0A        %22%22%22%0A        Check genome fasta file has been generated%0A        %22%22%22%0A        upid = os.path.split(self.updir)%5B1%5D%0A        genome_fasta = os.path.join(self.updir, upid+'.fa')%0A%0A        return luigi.LocalTarget(genome_fasta)%0A%0A# -----------------------------------------------------------------------------%0A%0A%0Aclass GenomeMergeEngine(luigi.Task):%0A    %22%22%22%0A    Task to load accessions from file%0A    %22%22%22%0A    project_dir = luigi.Parameter()%0A    lsf = luigi.BoolParameter(default=True,%0A                              description=%22If used then run on lsf, otherwise run locally%22)%0A%0A    def run(self):%0A        %22%22%22%0A        Call load_upid_gca_file to export all upid_gca accession pairs in%0A        json format.%0A        %22%22%22%0A        id_pairs = None%0A        upid_gca_file_loc = os.path.join(self.project_dir, %22upid_gca_dict.json%22)%0A        upid_gca_fp = open(upid_gca_file_loc, 'r')%0A        accessions = json.load(upid_gca_fp)%0A        upid_gca_fp.close()%0A%0A        upids = accessions.keys()%0A%0A        cmd = ''%0A        for upid in upids:%0A%0A            subdir = os.path.join(self.project_dir, upid%5B-3:%5D)%0A            updir = os.path.join(subdir, updir)%0A%0A            if os.path.exists(updir):%0A%0A                if self.lsf is True:%0A                    # TODO launch an lsf job to merge the genome fasta files%0A                    pass%0A%0A                else:%0A                    cmd = %22python %5C%22%7Bthis_file%7D%5C%22 MergeGenome --updir %7Bupid%7D%22.format(%0A                        this_file=os.path.realpath(__file__),%0A                        updir=updir)%0A%0A                    subprocess.call(cmd, shell=True)%0A%0A            cmd = ''%0A%0A# -----------------------------------------------------------------------------%0A%0A%0Aif __name__ == '__main__':%0A%0A    luigi.run()%0A%0A%0A%0A%0A

Add first version of genome merge pipeline