How to use the genomepy.plugin.Plugin function in genomepy

To help you get started, we’ve selected a few genomepy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vanheeringen-lab / genomepy / genomepy / plugins / minimap2.py View on Github external
import os
from shutil import rmtree
from genomepy.plugin import Plugin
from genomepy.utils import mkdir_p, cmd_ok, run_index_cmd


class Minimap2Plugin(Plugin):
    def after_genome_download(self, genome, threads=1, force=False):
        if not cmd_ok("minimap2"):
            return

        # Create index dir
        index_dir = genome.props["minimap2"]["index_dir"]
        index_name = genome.props["minimap2"]["index_name"]
        if force:
            # Start from scratch
            rmtree(index_dir, ignore_errors=True)
        mkdir_p(index_dir)

        if not any(fname.endswith(".mmi") for fname in os.listdir(index_dir)):
            # Create index
            cmd = "minimap2 -t {} -d {} {}".format(threads, index_name, genome.filename)
            run_index_cmd("minimap2", cmd)
github vanheeringen-lab / genomepy / genomepy / plugins / gmap.py View on Github external
import os.path
from shutil import move, rmtree
from tempfile import TemporaryDirectory
from genomepy.plugin import Plugin
from genomepy.utils import cmd_ok, run_index_cmd, bgunzip_and_name, bgrezip


class GmapPlugin(Plugin):
    def after_genome_download(self, genome, threads=1, force=False):
        if not cmd_ok("gmap_build"):
            return

        # Create index dir
        index_dir = genome.props["gmap"]["index_dir"]
        if force:
            # Start from scratch
            rmtree(index_dir, ignore_errors=True)

        if not os.path.exists(index_dir):
            # unzip genome if zipped and return up-to-date genome name
            bgzip, fname = bgunzip_and_name(genome)

            # gmap outputs a folder named genome.name
            # its content is moved to index dir, consistent with other plugins
github vanheeringen-lab / genomepy / genomepy / plugins / blacklist.py View on Github external
import os.path
import re
import sys
import zlib

from urllib.request import urlopen

from genomepy.plugin import Plugin


class BlacklistPlugin(Plugin):
    base_url = "http://mitra.stanford.edu/kundaje/akundaje/release/blacklists/"
    http_dict = {
        "ce10": base_url + "ce10-C.elegans/ce10-blacklist.bed.gz",
        "dm3": base_url + "dm3-D.melanogaster/dm3-blacklist.bed.gz",
        "hg38": base_url + "hg38-human/hg38.blacklist.bed.gz",
        "hg19": base_url
        + "hg19-human/wgEncodeHg19ConsensusSignalArtifactRegions.bed.gz",
        "mm9": base_url + "mm9-mouse/mm9-blacklist.bed.gz",
        "mm10": base_url + "mm10-mouse/mm10.blacklist.bed.gz",
        # for testing purposes
        "this was a triumph": "I'm making a note here: 'Huge success'",
    }

    def after_genome_download(self, genome, threads=1, force=False):
        fname = self.get_properties(genome)["blacklist"]
        if os.path.exists(fname) and not force:
github vanheeringen-lab / genomepy / genomepy / plugins / star.py View on Github external
import os
from shutil import rmtree
from genomepy.plugin import Plugin
from genomepy.utils import mkdir_p, cmd_ok, run_index_cmd, bgunzip_and_name, bgrezip


class StarPlugin(Plugin):
    def after_genome_download(self, genome, threads=1, force=False):
        if not cmd_ok("STAR"):
            return

        # Create index dir
        index_dir = genome.props["star"]["index_dir"]
        index_name = genome.props["star"]["index_name"]
        if force:
            # Start from scratch
            rmtree(index_dir, ignore_errors=True)
        mkdir_p(index_dir)

        if not os.path.exists(index_name):
            # unzip genome if zipped and return up-to-date genome name
            bgzip, fname = bgunzip_and_name(genome)
github vanheeringen-lab / genomepy / genomepy / plugins / hisat2.py View on Github external
import os
from shutil import rmtree
from genomepy.plugin import Plugin
from genomepy.utils import mkdir_p, cmd_ok, run_index_cmd, bgunzip_and_name, bgrezip


class Hisat2Plugin(Plugin):
    def after_genome_download(self, genome, threads=1, force=False):
        if not cmd_ok("hisat2-build"):
            return

        # Create index dir
        index_dir = genome.props["hisat2"]["index_dir"]
        index_name = genome.props["hisat2"]["index_name"]
        if force:
            # Start from scratch
            rmtree(index_dir, ignore_errors=True)
        mkdir_p(index_dir)

        if not any(fname.endswith(".ht2") for fname in os.listdir(index_dir)):
            # unzip genome if zipped and return up-to-date genome name
            bgzip, fname = bgunzip_and_name(genome)
github vanheeringen-lab / genomepy / genomepy / plugins / bowtie2.py View on Github external
import os
from shutil import rmtree
from genomepy.plugin import Plugin
from genomepy.utils import mkdir_p, cmd_ok, run_index_cmd


class Bowtie2Plugin(Plugin):
    def after_genome_download(self, genome, threads=1, force=False):
        if not cmd_ok("bowtie2-build"):
            return

        # Create index dir
        index_dir = genome.props["bowtie2"]["index_dir"]
        index_name = genome.props["bowtie2"]["index_name"]
        if force:
            # Start from scratch
            rmtree(index_dir, ignore_errors=True)
        mkdir_p(index_dir)

        if not any(fname.endswith(".bt2") for fname in os.listdir(index_dir)):
            # Create index
            cmd = "bowtie2-build --threads {} {} {}".format(
                threads, genome.filename, index_name
github vanheeringen-lab / genomepy / genomepy / plugin.py View on Github external
def init_plugins():
    """Return dictionary of available plugins

    Returns
    -------
    plugins : dictionary
        key is plugin name, value Plugin object
    """
    find_plugins()
    d = {}
    for c in Plugin.__subclasses__():
        ins = c()

        if ins.name() in config.get("plugin", []):
            ins.activate()

        d[ins.name()] = ins

    return d
github vanheeringen-lab / genomepy / genomepy / plugins / bwa.py View on Github external
import os
from shutil import rmtree
from genomepy.plugin import Plugin
from genomepy.utils import mkdir_p, cmd_ok, run_index_cmd


class BwaPlugin(Plugin):
    def after_genome_download(self, genome, threads=1, force=False):
        if not cmd_ok("bwa"):
            return

        # Create index dir
        index_dir = genome.props["bwa"]["index_dir"]
        index_name = genome.props["bwa"]["index_name"]
        if force:
            # Start from scratch
            rmtree(index_dir, ignore_errors=True)
        mkdir_p(index_dir)

        if not any(fname.endswith(".bwt") for fname in os.listdir(index_dir)):
            # Create index
            if not os.path.exists(index_name):
                os.symlink(genome.filename, index_name)
github vanheeringen-lab / genomepy / genomepy / plugins / sizes.py View on Github external
import os.path
from genomepy.plugin import Plugin


class SizesPlugin(Plugin):
    def after_genome_download(self, genome, force=False):
        props = self.get_properties(genome)
        fname = props["sizes"]

        if not os.path.exists(fname) or force:
            with open(fname, "w") as f:
                for seqname in genome.keys():
                    f.write("{}\t{}\n".format(seqname, len(genome[seqname])))

    def get_properties(self, genome):
        props = {"sizes": genome.filename + ".sizes"}
        return props