Exemplo n.º 1
0
 def test5_motif_to_img(self):
     """ Motif to img """
     seqlogo = which("seqlogo")
     if seqlogo:    
         m = Motif(self.pfm)
         m.to_img("test/test.png", fmt="png", seqlogo=seqlogo)
         self.assertTrue(os.path.exists("test/test.png"))
         os.unlink("test/test.png")
     else:
         print("seqlogo not found, skipping.")
Exemplo n.º 2
0
 def test5_motif_to_img(self):
     """ Motif to img """
     seqlogo = which("seqlogo")
     if seqlogo:
         m = Motif(self.pfm)
         m.to_img("test/test.png", fmt="png", seqlogo=seqlogo)
         self.assertTrue(os.path.exists("test/test.png"))
         os.unlink("test/test.png")
     else:
         print("seqlogo not found, skipping.")
Exemplo n.º 3
0
    def create_default_config(self):
        logger.info("Creating new config.")

        available_tools = []
        self.config.read(self.default_config)
        for m in MOTIF_CLASSES:
            try:
                exe = self.config.get(m, "bin")
                mdir = self.config.get(m, "dir")
                tool_dir = os.path.join(self.package_dir, mdir)
                cmd = os.path.join(tool_dir, exe)
                if which(cmd):
                    logger.info("Using included version of %s.", m)
                    available_tools.append(m)
                else:
                    cmd = which(exe)
                    if cmd:
                        logger.info("Using system version of %s.", m)
                        self.set_program(m, {
                            "bin": cmd,
                            "dir": os.path.dirname(cmd)
                        })
                        available_tools.append(m)
                    else:
                        logger.warn(
                            "%s not found. To include it you will have to install it.",
                            m,
                        )

            except configparser.NoSectionError:
                logger.warn("{} not in config".format(m))

        params = self.get_default_params()
        params["available_tools"] = ",".join(available_tools)
        self.set_default_params(params)

        if not os.path.exists(CONFIG_DIR):
            os.makedirs(CONFIG_DIR, exist_ok=True)
        with open(self.user_config, "w") as f:
            self.config.write(f)
        logger.info("Configuration file: %s", self.user_config)
Exemplo n.º 4
0
    def create_default_config(self):
        logger.info("Creating new config.")
        
        available_tools = []
        cfg = self.config.read(self.default_config)
        for m in MOTIF_CLASSES:
            try:
                exe = self.config.get(m, "bin")
                mdir = self.config.get(m, "dir")
                tool_dir = os.path.join(self.package_dir, mdir)
                cmd = os.path.join(tool_dir, exe)
                if which(cmd):
                    logger.info("Using included version of %s.", m)
                    available_tools.append(m)
                else:
                    cmd = which(exe)
                    if cmd:
                        logger.info("Using system version of %s.", m)
                        self.set_program(m, 
                                {
                                    "bin":cmd, 
                                    "dir":os.path.dirname(cmd)
                                    }
                                )
                        available_tools.append(m)
                    else:
                        logger.warn("%s not found. To include it you will have to install it.", m)

            except configparser.NoSectionError:
                logger.warn("{} not in config".format(m))
         
        params = self.get_default_params()
        params['available_tools'] = ",".join(available_tools)
        self.set_default_params(params)

        if not os.path.exists(CONFIG_DIR):
            os.makedirs(CONFIG_DIR, exist_ok=True)
        with open(self.user_config, "w") as f:
            self.config.write(f)
        logger.info("Configuration file: %s", self.user_config)
Exemplo n.º 5
0
    def run(self):
        if not os.path.exists(self.build_cfg):
            os.mkdir(self.build_cfg)

        from gimmemotifs.config import MotifConfig
        cfg = MotifConfig(use_config="cfg/gimmemotifs.cfg.base")
        
        dlog.info("locating motif programs")
        available = []
        for program in MOTIF_CLASSES:
            # Get class
            m = eval(program)()
            cmd = m.cmd
            
            ### ugly, fixme :)
            if cmd == "trawler.pl":
                cmd = "trawler/bin/trawler.pl"
            if cmd == "ChIPMunk.sh":
                cmd = "ChIPMunk/ChIPMunk.sh"
            if cmd == "hms":
                cmd = "HMS/hms"

            bin = ""
            if cmd == "/bin/false":
                # motif db
                bin = "/bin/false"    
            elif os.path.exists(os.path.join(self.build_tools_dir, cmd)):
                bin = os.path.join(self.build_tools_dir, cmd)
                dlog.info("using included version of %s: %s" % (program, bin))
            else:
                ### ugly, fixme :)
                if cmd == "trawler/bin/trawler.pl":
                    cmd = "trawler.pl"
                if     cmd == "ChIPMunk/ChIPMunk.sh":
                    cmd = "ChIPMunk.sh"
                if cmd == "HMS/hms":
                    cmd = "hms"

                if program in MOTIF_BINS.keys():
                    dlog.info("could not find compiled version of %s" % program)
                bin = which(cmd)
                if bin:
                    dlog.info("using installed version of %s: %s" % (program, bin))
                else:
                    dlog.info("not found: %s" % program)
            
            ### Some more ugly stuff
            if bin:
                dir = bin.replace(m.cmd,"")
                if program == "Weeder":
                    dir = bin.replace("weederTFBS.out","")
                elif program == "Meme":
                    dir = bin.replace("bin/meme.bin", "").replace("meme.bin", "")
                elif program == "Trawler":
                    dir = bin.replace("bin/trawler.pl", "")
                elif program == "ChIPMunk":
                    dir = bin.replace("ChIPMunk.sh", "")

                available.append(m.name)
                cfg.set_program(m.name, {"bin":bin, "dir":dir})

        # Weblogo
        bin = ""
        seq_included = os.path.join(self.build_tools_dir, "seqlogo")
        if os.path.exists(seq_included):
            bin = seq_included
            dlog.info("using included version of weblogo: %s" % seq_included)
        else:
            bin = which("seqlogo")
            dlog.info("using installed version of seqlogo: %s" % (bin))
        if bin:
            cfg.set_seqlogo(bin)
        else:
            dlog.info("couldn't find seqlogo")
        
        # Set the available tools in the config file
        DEFAULT_PARAMS["available_tools"] = ",".join(available)
        
        for tool in available:
            if tool in LONG_RUNNING:
                dlog.info("PLEASE NOTE: %s can take a very long time to run on large datasets. Therefore it is not added to the default tools. You can always enable it later, see documentation for details" % tool)
                available.remove(tool)

        DEFAULT_PARAMS["tools"] = ",".join(available)
        cfg.set_default_params(DEFAULT_PARAMS)

        # Write (temporary) config file
        config_file = os.path.join(self.build_cfg, "%s" % CONFIG_NAME)
        dlog.info("writing (temporary) configuration file: %s" % config_file)
        f = open(config_file, "wb")
        cfg.write(f)
        f.close()
Exemplo n.º 6
0
    def run(self):
        if not os.path.exists(self.build_cfg):
            os.mkdir(self.build_cfg)

        from gimmemotifs.config import MotifConfig
        cfg = MotifConfig(use_config="cfg/gimmemotifs.cfg.base")

        dlog.info("locating motif programs")
        available = []
        for program in MOTIF_CLASSES:
            # Get class
            m = eval(program)()
            cmd = m.cmd

            ### ugly, fixme :)
            if cmd == "ChIPMunk.sh":
                cmd = "ChIPMunk/ChIPMunk.sh"
            if cmd == "hms":
                cmd = "HMS/hms"

            bin = ""
            if cmd == "/bin/false":
                # motif db
                bin = "/bin/false"
            elif os.path.exists(os.path.join(self.build_tools_dir, cmd)):
                bin = os.path.join(self.build_tools_dir, cmd)
                dlog.info("using included version of %s: %s" % (program, bin))
            else:
                ### ugly, fixme :)
                if cmd == "ChIPMunk/ChIPMunk.sh":
                    cmd = "ChIPMunk.sh"
                if cmd == "HMS/hms":
                    cmd = "hms"

                if program in MOTIF_BINS.keys():
                    dlog.info("could not find compiled version of %s" %
                              program)
                bin = which(cmd)
                if bin:
                    dlog.info("using installed version of %s: %s" %
                              (program, bin))
                else:
                    dlog.info("not found: %s" % program)

            ### Some more ugly stuff
            if bin:
                dir = bin.replace(m.cmd, "")
                if program == "Weeder":
                    dir = bin.replace("weederTFBS.out", "")
                elif program == "Meme":
                    dir = bin.replace("bin/meme.bin",
                                      "").replace("meme.bin", "")
                elif program == "ChIPMunk":
                    dir = bin.replace("ChIPMunk.sh", "")

                available.append(m.name)
                cfg.set_program(m.name, {
                    "bin": os.path.abspath(bin),
                    "dir": os.path.abspath(dir),
                })

        # Weblogo
        bin = ""
        seq_included = os.path.abspath(
            os.path.join(self.build_tools_dir, "seqlogo"))
        if os.path.exists(seq_included):
            bin = seq_included
            dlog.info("using included version of weblogo: %s" % seq_included)
        else:
            bin = which("seqlogo")
            dlog.info("using installed version of seqlogo: %s" %
                      (os.path.abspath(bin)))
        if bin:
            cfg.set_seqlogo(os.path.abspath(bin))
        else:
            dlog.info("couldn't find seqlogo")

        # Set the available tools in the config file
        DEFAULT_PARAMS["available_tools"] = ",".join(available)

        for tool in available:
            if tool in LONG_RUNNING:
                dlog.info(
                    "PLEASE NOTE: %s can take a very long time to run on large datasets. Therefore it is not added to the default tools. You can always enable it later, see documentation for details"
                    % tool)
                available.remove(tool)

        DEFAULT_PARAMS["tools"] = ",".join(available)
        cfg.set_default_params(DEFAULT_PARAMS)

        # Write (temporary) config file
        config_file = os.path.join(self.build_cfg, "%s" % CONFIG_NAME)
        dlog.info("writing (temporary) configuration file: %s" % config_file)
        f = open(config_file, "w")
        cfg.write(f)
        f.close()

        # TODO: fix this hack
        my_cfg = open(config_file).read()
        with open(config_file, "w") as f:
            cwd = os.getcwd()
            f.write(my_cfg.replace("/usr/share/gimmemotifs/", cwd + "/"))