Exemplo n.º 1
0
def locate_tool(tool, verbose=True): 
    tool = re.sub(r'[^a-zA-Z]','',tool) 
    m = eval(tool)() 
    tool_bin = which(m.cmd) 
    if tool_bin:
        if verbose:
            print "Found {} in {}".format(m.name, tool_bin) 
        return tool_bin 
    else: 
        print "Couldn't find {}".format(m.name)
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", format="png", seqlogo=seqlogo)
         self.assert_(os.path.exists("test/test.png"))
         os.unlink("test/test.png")
     else:
         print "seqlogo not found, skipping."
Exemplo n.º 3
0
def locate_tool(tool, verbose=True):
    tool = re.sub(r'[^a-zA-Z]', '', tool)
    m = eval(tool)()
    tool_bin = which(m.cmd)
    if tool_bin:
        if verbose:
            print "Found {} in {}".format(m.name, tool_bin)
        return tool_bin
    else:
        print "Couldn't find {}".format(m.name)
Exemplo n.º 4
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", format="png", seqlogo=seqlogo)
			self.assert_(os.path.exists("test/test.png"))
			os.unlink("test/test.png")
		else:
			print "seqlogo not found, skipping."
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"

            bin = ""
            if 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 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", "")

                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 == "trawler.pl":
				cmd = "trawler/bin/trawler.pl"

			bin = ""
			if 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 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", "")

				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.º 7
0
	def write_config(self):
		from gimmemotifs.config import MotifConfig
		cfg = MotifConfig(use_config="cfg/gimmemotifs.cfg.example")

		data_dir = os.path.abspath(self.install_data)
		cfg.set_template_dir(os.path.join(data_dir, 'gimmemotifs/templates'))
		cfg.set_gene_dir(os.path.join(data_dir, 'gimmemotifs/genes'))
		cfg.set_score_dir(os.path.join(data_dir, 'gimmemotifs/score_dists'))
		cfg.set_index_dir(os.path.join(data_dir, 'gimmemotifs/genome_index'))
		cfg.set_motif_dir(os.path.join(data_dir, 'gimmemotifs/motif_databases'))
		cfg.set_bg_dir(os.path.join(data_dir, 'gimmemotifs/bg'))
		
		print 
		print "Trying to locate motif programs"
		
		MOTIF_CLASSES = ["MDmodule", "Meme", "Weeder", "Gadem", "MotifSampler", "Trawler", "Improbizer", "MoAn", "BioProspector"]
		available = []
		for program in MOTIF_CLASSES:
			m = eval(program)()
			cmd = m.cmd
			bin = which(cmd)
			if bin:
				print "Found %s in %s" % (m.name, bin)
				available.append(m.name)
				dir = None
				if program == "Weeder":
					dir = bin.replace("weederTFBS.out","")
				elif program == "Meme":
					dir = bin.replace("bin/meme", "")
				elif program == "Trawler":
					dir = bin.replace("bin/trawler.pl", "")
		
				cfg.set_program(m.name, {"bin":bin, "dir":dir})
			else:
				print "Couldn't find %s" % m.name
		
		print
		print "Trying to locate seqlogo"
		bin = which("seqlogo")
		if bin:
			print "Found seqlogo in %s" % (bin)
			cfg.set_seqlogo(bin)
		else:
			print "Couldn't find seqlogo"
		print
		
		DEFAULT_PARAMS["available_tools"] = ",".join(available)
		DEFAULT_PARAMS["tools"] = ",".join(available)
		cfg.set_default_params(DEFAULT_PARAMS)
		
		# Use a user-specific configfile if any other installation scheme is used
		if os.path.abspath(self.install_data) == "/usr/share":
			config_file = "/usr/share/gimmemotifs/%s" % CONFIG_NAME
		else:
			config_file = os.path.expanduser("~/.%s" % CONFIG_NAME)
		
		if os.path.exists(config_file):
			new_config = config_file + ".tmp"
			print "INFO: Configfile %s already exists!\n      Will create %s, which contains the new config.\n      If you want to use the newly generated config you can move %s to %s, otherwise you can delete %s.\n" % (config_file, new_config, new_config, config_file, new_config)

			f =  open(new_config, "wb")
			cfg.write(f)
		else: 
			print "Writing configuration file %s" % config_file
			f =  open(config_file, "wb")
			cfg.write(f)
		
		print "Edit %s to further configure GimmeMotifs." % config_file