Beispiel #1
0
def _make_permutations(recipe, output_dir, overwrite):
    """
    Runs Cactus, then outputs preprocessesed results into output_dir
    """
    work_dir = os.path.join(output_dir, CACTUS_WORKDIR)
    files = {}

    if overwrite and os.path.isdir(work_dir):
        shutil.rmtree(work_dir)

    if os.path.isdir(work_dir):
        #using existing results
        logger.warning("Using existing Cactus results from previous run")
        logger.warning("Use --overwrite to force alignment")
        for block_size in recipe["blocks"]:
            block_dir = os.path.join(work_dir, str(block_size))
            coords_file = os.path.join(block_dir, "blocks_coords.txt")
            if not os.path.isfile(coords_file):
                raise BackendException("Exitsing results are incompatible "
                                       "with input recipe")
            files[block_size] = os.path.abspath(coords_file)

    else:
        #running cactus
        for genome, params in recipe["genomes"].items():
            if "fasta" not in params:
                raise BackendException("FASTA file for {0} is not "
                                       "specified".format(genome))

        os.mkdir(work_dir)
        config_path = _make_cactus_config(recipe, work_dir)
        ref_genome = recipe["target"]
        maf_file = _run_cactus(config_path, ref_genome, work_dir)

        logger.info("Converting maf to synteny")
        if not m2s.make_synteny(maf_file, work_dir, recipe["blocks"]):
            raise BackendException("Something went wrong with maf2synteny")

        for block_size in recipe["blocks"]:
            block_dir = os.path.join(work_dir, str(block_size))
            coords_file = os.path.join(block_dir, "blocks_coords.txt")
            files[block_size] = os.path.abspath(coords_file)
            if not os.path.exists(coords_file):
                raise BackendException("Something bad happened!")

    return files
Beispiel #2
0
def _make_permutations(recipe, output_dir, overwrite):
    work_dir = os.path.join(output_dir, CACTUS_WORKDIR)
    files = {}

    if overwrite and os.path.isdir(work_dir):
        shutil.rmtree(work_dir)

    if os.path.isdir(work_dir):
        #using existing results
        logger.warning("Using existing Cactus results from previous run")
        logger.warning("Use --overwrite to force alignment")
        for block_size in recipe["blocks"]:
            block_dir = os.path.join(work_dir, str(block_size))
            perm_file = os.path.join(block_dir, "genomes_permutations.txt")
            if not os.path.isfile(perm_file):
                raise BackendException("Exitsing results are incompatible "
                                       "with input recipe")
            files[block_size] = os.path.abspath(perm_file)

    else:
        #running cactus
        for genome, params in recipe["genomes"].items():
            if "fasta" not in params:
                raise BackendException("FASTA file for {0} is not "
                                       "specified".format(genome))

        os.mkdir(work_dir)
        config_path = _make_cactus_config(recipe, work_dir)
        ref_genome = recipe["target"]
        maf_file = _run_cactus(config_path, ref_genome, work_dir)

        logger.info("Converting maf to synteny")
        if not m2s.make_synteny(maf_file, work_dir, recipe["blocks"]):
            raise BackendException("Something went wrong with maf2synteny")

        for block_size in recipe["blocks"]:
            block_dir = os.path.join(work_dir, str(block_size))
            perm_file = os.path.join(block_dir, "genomes_permutations.txt")
            files[block_size] = os.path.abspath(perm_file)
            if not os.path.exists(perm_file):
                raise BackendException("Something bad happened!")

    return files
Beispiel #3
0
    def run_backend(self, recipe, output_dir, overwrite):
        logger.warning("Maf support is deprecated and will be removed "
                       "in future releases. Use hal istead.")
        workdir = os.path.join(output_dir, MAF_WORKDIR)
        if overwrite and os.path.isdir(workdir):
            shutil.rmtree(workdir)

        if "maf" not in recipe or not os.path.exists(recipe["maf"]):
            raise BackendException("Could not open MAF file "
                                   "or it is not specified")

        files = {}
        if os.path.isdir(workdir):
            #using existing results
            logger.warning("Using synteny blocks from previous run")
            logger.warning("Use --overwrite to force alignment")
            for block_size in self.blocks:
                block_dir = os.path.join(workdir, str(block_size))
                coords_file = os.path.join(block_dir, "blocks_coords.txt")
                if not os.path.isfile(coords_file):
                    raise BackendException("Exitsing results are incompatible "
                                           "with input recipe")
                files[block_size] = os.path.abspath(coords_file)

        else:
            os.mkdir(workdir)
            logger.info("Converting MAF to synteny")
            if not m2s.make_synteny(recipe["maf"], workdir, self.blocks):
                raise BackendException("Something went wrong with maf2synteny")

            for block_size in self.blocks:
                block_dir = os.path.join(workdir, str(block_size))
                coords_file = os.path.join(block_dir, "blocks_coords.txt")
                files[block_size] = os.path.abspath(coords_file)
                if not os.path.exists(coords_file):
                    raise BackendException("Something bad happened!")

        return files
Beispiel #4
0
    def run_backend(self, recipe, output_dir, overwrite):
        logger.warning("Maf support is deprecated and will be removed "
                       "in future releases. Use hal istead.")
        workdir = os.path.join(output_dir, MAF_WORKDIR)
        if overwrite and os.path.isdir(workdir):
            shutil.rmtree(workdir)

        if "maf" not in recipe or not os.path.exists(recipe["maf"]):
            raise BackendException("Could not open MAF file "
                                   "or it is not specified")

        files = {}
        if os.path.isdir(workdir):
            #using existing results
            logger.warning("Using synteny blocks from previous run")
            logger.warning("Use --overwrite to force alignment")
            for block_size in self.blocks:
                block_dir = os.path.join(workdir, str(block_size))
                coords_file = os.path.join(block_dir, "blocks_coords.txt")
                if not os.path.isfile(coords_file):
                    raise BackendException("Exitsing results are incompatible "
                                           "with input recipe")
                files[block_size] = os.path.abspath(coords_file)

        else:
            os.mkdir(workdir)
            logger.info("Converting MAF to synteny")
            if not m2s.make_synteny(recipe["maf"], workdir, self.blocks):
                raise BackendException("Something went wrong with maf2synteny")

            for block_size in self.blocks:
                block_dir = os.path.join(workdir, str(block_size))
                coords_file = os.path.join(block_dir, "blocks_coords.txt")
                files[block_size] = os.path.abspath(coords_file)
                if not os.path.exists(coords_file):
                    raise BackendException("Something bad happened!")

        return files
Beispiel #5
0
    def run_backend(self, recipe, output_dir, overwrite):
        workdir = os.path.join(output_dir, MAF_WORKDIR)
        if overwrite and os.path.isdir(workdir):
            shutil.rmtree(workdir)

        if "maf" not in recipe or not os.path.exists(recipe["maf"]):
            raise BackendException("Could not open MAF file "
                                   "or it is not specified")

        files = {}
        if os.path.isdir(workdir):
            #using existing results
            logger.warning("Using synteny blocks from previous run")
            logger.warning("Use --overwrite to force alignment")
            for block_size in recipe["blocks"]:
                block_dir = os.path.join(workdir, str(block_size))
                perm_file = os.path.join(block_dir, "genomes_permutations.txt")
                if not os.path.isfile(perm_file):
                    raise BackendException("Exitsing results are incompatible "
                                           "with input recipe")
                files[block_size] = os.path.abspath(perm_file)

        else:
            os.mkdir(workdir)
            logger.info("Converting MAF to synteny")
            if not m2s.make_synteny(recipe["maf"], workdir, recipe["blocks"]):
                raise BackendException("Something went wrong with maf2synteny")

            for block_size in recipe["blocks"]:
                block_dir = os.path.join(workdir, str(block_size))
                perm_file = os.path.join(block_dir, "genomes_permutations.txt")
                files[block_size] = os.path.abspath(perm_file)
                if not os.path.exists(perm_file):
                    raise BackendException("Something bad happened!")

        return files
Beispiel #6
0
    def run_backend(self, recipe, output_dir, overwrite):
        workdir = os.path.join(output_dir, MAF_WORKDIR)
        if overwrite and os.path.isdir(workdir):
            shutil.rmtree(workdir)

        if "maf" not in recipe or not os.path.exists(recipe["maf"]):
            raise BackendException("Could not open MAF file "
                                   "or it is not specified")

        files = {}
        if os.path.isdir(workdir):
            #using existing results
            logger.warning("Using synteny blocks from previous run")
            logger.warning("Use --overwrite to force alignment")
            for block_size in recipe["blocks"]:
                block_dir = os.path.join(workdir, str(block_size))
                perm_file = os.path.join(block_dir, "genomes_permutations.txt")
                if not os.path.isfile(perm_file):
                    raise BackendException("Exitsing results are incompatible "
                                           "with input recipe")
                files[block_size] = os.path.abspath(perm_file)

        else:
            os.mkdir(workdir)
            logger.info("Converting MAF to synteny")
            if not m2s.make_synteny(recipe["maf"], workdir, recipe["blocks"]):
                raise BackendException("Something went wrong with maf2synteny")

            for block_size in recipe["blocks"]:
                block_dir = os.path.join(workdir, str(block_size))
                perm_file = os.path.join(block_dir, "genomes_permutations.txt")
                files[block_size] = os.path.abspath(perm_file)
                if not os.path.exists(perm_file):
                    raise BackendException("Something bad happened!")

        return files
Beispiel #7
0
    def run_backend(self, recipe, output_dir, overwrite):
        workdir = os.path.join(output_dir, HAL_WORKDIR)
        if overwrite and os.path.isdir(workdir):
            shutil.rmtree(workdir)

        if "hal" not in recipe or not os.path.exists(recipe["hal"]):
            raise BackendException("Could not open HAL file "
                                   "or it is not specified")

        files = {}
        #using existing results
        if os.path.isdir(workdir):
            logger.warning("Using synteny blocks from previous run")
            logger.warning("Use --overwrite to force alignment")

            all_good = True
            for block_size in self.blocks:
                block_dir = os.path.join(workdir, str(block_size))
                coords_file = os.path.join(block_dir, "blocks_coords.txt")
                if not os.path.isfile(coords_file):
                    all_good = False
                    break
                files[block_size] = os.path.abspath(coords_file)

            target_fasta = os.path.join(workdir, TARGET_FASTA)
            if not os.path.isfile(target_fasta):
                all_good = False
            else:
                self.target_fasta = target_fasta

            if not all_good:
                raise BackendException("Exitsing results are incompatible "
                                           "with current run")

        else:
            os.mkdir(workdir)

            logger.info("Extracting FASTA from HAL")
            target_fasta = os.path.join(workdir, TARGET_FASTA)
            cmdline = [HAL2FASTA, recipe["hal"], recipe["target"],
                       "--inMemory"]
            subprocess.check_call(cmdline, stdout=open(target_fasta, "w"))
            self.target_fasta = target_fasta

            logger.info("Converting HAL to MAF")
            out_maf = os.path.join(workdir, "alignment.maf")
            ref_genome = recipe["target"]   #Tricky notation, huh?
            export_genomes = ",".join(recipe["genomes"])

            cmdline = [HAL2MAF, recipe["hal"], out_maf, "--noAncestors",
                        "--numProc", str(self.threads),  "--refGenome",
                        ref_genome, "--targetGenomes", export_genomes]
            logger.debug(" ".join(cmdline))
            subprocess.check_call(cmdline, stdout=open(os.devnull, "w"))

            logger.info("Extracting synteny blocks from MAF")
            if not m2s.make_synteny(out_maf, workdir, self.blocks):
                raise BackendException("Something went wrong with maf2synteny")

            for block_size in self.blocks:
                block_dir = os.path.join(workdir, str(block_size))
                coords_file = os.path.join(block_dir, "blocks_coords.txt")
                files[block_size] = os.path.abspath(coords_file)
                if not os.path.exists(coords_file):
                    raise BackendException("Something bad happened!")

        return files
Beispiel #8
0
    def run_backend(self, recipe, output_dir, overwrite):
        workdir = os.path.join(output_dir, HAL_WORKDIR)
        if overwrite and os.path.isdir(workdir):
            shutil.rmtree(workdir)

        if "hal" not in recipe or not os.path.exists(recipe["hal"]):
            raise BackendException("Could not open HAL file "
                                   "or it is not specified")

        files = {}
        #using existing results
        if os.path.isdir(workdir):
            logger.warning("Using synteny blocks from previous run")
            logger.warning("Use --overwrite to force alignment")

            all_good = True
            for block_size in self.blocks:
                block_dir = os.path.join(workdir, str(block_size))
                coords_file = os.path.join(block_dir, "blocks_coords.txt")
                if not os.path.isfile(coords_file):
                    all_good = False
                    break
                files[block_size] = os.path.abspath(coords_file)

            target_fasta = os.path.join(workdir, TARGET_FASTA)
            if not os.path.isfile(target_fasta):
                all_good = False
            else:
                self.target_fasta = target_fasta

            if not all_good:
                raise BackendException("Exitsing results are incompatible "
                                           "with current run")

        else:
            os.mkdir(workdir)

            logger.info("Extracting FASTA from HAL")
            target_fasta = os.path.join(workdir, TARGET_FASTA)
            cmdline = [HAL2FASTA, recipe["hal"], recipe["target"],
                       "--inMemory"]
            subprocess.check_call(cmdline, stdout=open(target_fasta, "w"))
            self.target_fasta = target_fasta

            logger.info("Converting HAL to MAF")
            out_maf = os.path.join(workdir, "alignment.maf")
            ref_genome = recipe["target"]   #Tricky notation, huh?
            export_genomes = ",".join(recipe["genomes"])

            cmdline = [HAL2MAF, recipe["hal"], out_maf, "--noAncestors",
                        "--numProc", str(self.threads),  "--refGenome",
                        ref_genome, "--targetGenomes", export_genomes]
            logger.debug(" ".join(cmdline))
            subprocess.check_call(cmdline, stdout=open(os.devnull, "w"))

            logger.info("Extracting synteny blocks from MAF")
            if not m2s.make_synteny(out_maf, workdir, self.blocks):
                raise BackendException("Something went wrong with maf2synteny")

            for block_size in self.blocks:
                block_dir = os.path.join(workdir, str(block_size))
                coords_file = os.path.join(block_dir, "blocks_coords.txt")
                files[block_size] = os.path.abspath(coords_file)
                if not os.path.exists(coords_file):
                    raise BackendException("Something bad happened!")

        return files