Beispiel #1
0
def print_menu(arr):
    global buffered
    """Main menu printer
	   @param arr is the menu array to print.  Fetches input, 
		parses and built-in command keywords, and returns the selected idx.
	"""

    if not buffered is None:
        # buffered input, return
        if len(buffered) > 0:
            return buffered.pop(0)
        else:
            buffered = None

    tmp = Cmd()
    arr = ['\t[%d] %s' % (x + 1, arr[x]) for x in xrange(len(arr))]
    tmp.columnize(arr, 35)
    print '\n0) Back'
    try:
        choice = raw_input('> ')
        choice = check_opts(choice)

        # buffered input
        if choice > 1:
            choice = choice.split(' ')
            buffered = []
            for entry in choice[1:]:
                buffered.append(int(entry))
            choice = int(choice[0])
    except KeyboardInterrupt:
        choice = -1
    except Exception, e:
        debug(e)
        os.system('clear')
        choice = -1
Beispiel #2
0
 def __init__(self, args):
     self.is_act = True
     self.cons = Cmd(args.image)
     self.cons.add_action("exit", self.exit, "Exit from viwer")
     if args.cmd:
         self.execute(args.cmd)
         sys.exit(0)
Beispiel #3
0
 def build_index(self) -> None:
     """Builds the salmon index."""
     logger.debug("Build salmon index.")
     # TODO: Implement check to avoid duplicate runs
     indexing = Cmd(
         f"salmon index -p {self.threads} -t {self.input_file} -i {self.index_name} --keepDuplicates"
     )
     indexing.run()
Beispiel #4
0
 def run(self, reads):
     """ Run the Hisat2 mapping with the given reads. """
     logger.debug("Perform Hisat2 mapping.")
     if len(reads) == 1:  # single end reads
         hisat = Cmd(
             f"hisat2 -q --threads {self.threads} -k 1 -x {self.index_name} -U {reads[0]} --no-unal | \
                     samtools view --threads {self.threads} -hS -F 4 -q 1 -O SAM"
         )
     elif len(reads) == 2:  # paired end reads
         hisat = Cmd(
             f"hisat2 -q --threads {self.threads} -k 1 -x {self.index_name} -1 {reads[0]} -2 {reads[1]} --no-unal | \
                         samtools view --threads {self.threads} -hS -F 4 -q 1 -O SAM"
         )
     hisat.run()
     self.mapping_has_run = True
     return (entry for entry in hisat.stdout.split("\n")[:-1]
             if not entry.startswith("@"))
Beispiel #5
0
    def __init__(self, input_file, output_dir, index_name, threads):
        which = Cmd("which salmon")
        which.run()

        self.input_file = input_file
        self.output_dir = output_dir
        self.index_name = index_name
        self.threads = threads
Beispiel #6
0
    def default(self, line):
        """Called on an input line when the command prefix is not recognized.

        Args:
            line (str): command with args to be executed.
        """
        Cmd(self).default(line)
        self.do_help("help")
Beispiel #7
0
 def build_stage(self, stg):
     for item in stg:
         self.log.log('trace', '   build_stage, item: %s', (item))
         for k in item:
             if k.casefold() == 'cmd':
                 cmd = Cmd(self.log, item[k])
                 self.cmds.append(cmd)
             elif k.casefold() == 'name':
                 self.name = item[k]
     return
Beispiel #8
0
    def __init__(self, input_file, index_name, threads):
        which = Cmd("which hisat2")
        which.run()

        # Check if indexing already run
        self.index_build_has_run = (True if len(
            glob.glob(f"{index_name}.*.ht2")) == 8 else False)

        self.input_file = input_file
        self.index_name = index_name
        self.threads = threads
Beispiel #9
0
    def run(self, reads: list) -> None:
        """Run the salmon mapping with the given reads.

        Args:
            reads: List of reads. Either paired end or single end.

        """
        logger.debug("Perform salmon mapping.")
        if not os.path.exists(f"{self.output_dir}/aux_info/eq_classes.txt"):
            if len(reads) == 1:  # single end reads
                salmon = Cmd(
                    f"salmon quant --libType A --validateMappings --dumpEq -p {self.threads} -i {self.index_name} --unmatedReads {reads[0]} -o {self.output_dir}"
                )
            elif len(reads) == 2:  # paired end reads
                salmon = Cmd(
                    f"salmon quant --libType A --validateMappings --dumpEq -p {self.threads} -i {self.index_name} -1 {reads[0]} -2 {reads[1]} -o {self.output_dir}"
                )
            salmon.run()
        else:
            logger.info("Skipping mapping.")
Beispiel #10
0
 def build_index(self):
     """ Build the Hisat2 index. """
     if not self.index_build_has_run:
         logger.debug("Build Hisat2 index.")
         indexing = Cmd(
             f"hisat2-build -q -p {self.threads} {self.input_file} {self.index_name}"
         )
         indexing.run()
         self.index_build_has_run = True
     else:
         logger.debug("Skipping index building.")
Beispiel #11
0
 def update_database(self, database_dir, busco_group):
     """
     Updates the dammit database.
     """
     logger.info("Update dammit database.")
     self.database_dir = database_dir
     self.busco_group = busco_group
     database = Cmd(
         f"dammit databases --install --n_threads {self.threads} --database-dir {self.database_dir} --busco-group {self.busco_group}"
     )
     database.run()
Beispiel #12
0
def print_menu(arr):
    global buffered
    """Main menu printer
	   @param arr is the menu array to print.  Fetches input, 
		parses and built-in command keywords, and returns the selected idx.
	"""

    if not buffered is None:
        # buffered input, return
        if len(buffered) > 0:
            return buffered.pop(0)
        else:
            buffered = None

    tmp = Cmd()
    arr = ['\t[%d] %s' % (x + 1, arr[x]) for x in xrange(len(arr))]
    tmp.columnize(arr, 35)
    print '\n0) Back'
    try:
        choice = raw_input('> ')
        if 'info' in choice:
            Error('\'info\' not implemented yet.')
            choice = -1
        elif 'set' in choice:
            opts = choice.split(' ')
            if opts[1] is None or opts[2] is None:
                return
            print '[!] Setting \033[33m%s\033[0m -> \033[32m%s\033[0m..' % (
                opts[1], opts[2])
            config.set(opts[1], opts[2])
            choice = -1
        elif 'opts' in choice:
            config.dump()
            choice = -1
        elif 'quit' in choice or 'exit' in choice:
            # hard quit
            os._exit(1)
        elif 'bg' in choice:
            background()
        else:
            # buffered input
            choice = choice.split(' ')
            if len(choice) > 1:
                buffered = []
                for entry in choice[1:]:
                    buffered.append(int(entry))
            choice = int(choice[0])
    except Exception:
        os.system('clear')
        choice = -1
    return choice
Beispiel #13
0
 def run(self, graph_file, output_file):
     """
     MCL: The input is then a file or stream in which each line encodes an
     edge in terms of two labels (the 'A' and the 'B') and a numerical value
      (the 'C'),  all separated by white space.
     A B 20
     A C 10
     The output is then a file where each line is a cluster of tab-separated
     labels.
     """
     logger.debug("MCL clustering...")
     if os.path.exists(output_file):
         os.remove(output_file)
     mcl = Cmd(
         f"mcl {graph_file} -I {self.inflation} --abc -o {output_file} -te {self.threads} -resource 4 -V all"
     )
     mcl.run()
    def create_shell(shell_context):
        help_func = lambda _: print(
            "\n\thelp [command-name]\n\tdisplays help for specific commands or an overview of available commands (if command-name is ommitted)\n"
        )
        setattr(Cmd, 'help_help', help_func)
        setattr(Cmd, 'intro', shell_context['shell_greeting'])
        setattr(Cmd, 'prompt', shell_context['shell_prompt'])

        for importer, pkgname, ispkg in pkgutil.walk_packages(
                shell_context['shell_command_pkg'].__path__,
                shell_context['shell_command_pkg'].__name__ + "."):
            ismodule = not ispkg
            if ismodule: ShellFactory.add_to_shell(pkgname)

        shell = Cmd()
        shell.context = shell_context
        return shell
Beispiel #15
0
    def run_pipe(self, graph_file):
        """
        Runs the MCL command, but uses stdin as input and stdout as output. Is a
         lot faster than writing and reading a lot of files.
         MCL: The input is then a file or stream in which each line encodes an
         edge in terms of two labels (the 'A' and the 'B') and a numerical value
          (the 'C'), all separated by white space.
        A B 20
        A C 10
        The output is then a file where each line is a cluster of tab-separated
        labels.
        """
        logger.debug("MCL clustering...")

        mcl = Cmd(
            f"mcl - -I {self.inflation} --abc -o - -te {self.threads} -resource 4 -V all"
        )
        mcl.run(in_stream=graph_file)
        return mcl.stdout
Beispiel #16
0
    def run(self):
        """
        Executes the dammit annotation for the original and reduced fasta file.
        """
        logger.info("Run dammit annotation.")
        for name, transcriptome in self.transcriptomes.items():

            output_dir = f"{self.output_dir}/{name}"
            annotation_file = (
                f"{output_dir}/{os.path.basename(transcriptome)}.dammit.gff3")
            self.gff_files[name] = annotation_file
            namemap_file = (
                f"{output_dir}/{os.path.basename(transcriptome)}.dammit.namemap.csv"
            )
            self.namemaps[name] = namemap_file
            if not (os.path.exists(annotation_file)
                    and os.path.exists(namemap_file)):
                dammit = Cmd(
                    f"dammit annotate {transcriptome} -o {output_dir} --database-dir {self.database_dir} --busco-group {self.busco_group} --n_threads {self.threads}"
                )
                dammit.run()
Beispiel #17
0
def print_menu(arr):
    global buffered
    """ Main menu printer
        @param arr is the menu array to print.  Fetches input,
        parses and built-in command keywords, and returns the selected idx.
    """

    if not buffered is None:
        # buffered input, return
        if len(buffered) > 0:
            return buffered.pop(0)
        else:
            buffered = None

    tmp = Cmd()
    arr = [
        '\t%s[%s%d%s] %s%s%s' %
        (color.B_GREEN, color.B_YELLOW, x + 1, color.B_GREEN, color.B_WHITE,
         arr[x], color.END) for x in xrange(len(arr))
    ]
    tmp.columnize(arr, 100)
    print '\n' + color.B_YELLOW + '0' + color.B_GREEN + ')' + color.B_WHITE + ' Back' + color.END
    try:
        choice = raw_input(color.B_WHITE + '> ' + color.END)
        choice = check_opts(choice)

        # buffered input
        if choice > 1:
            choice = choice.split(' ')
            buffered = []
            for entry in choice[1:]:
                buffered.append(int(entry))
            choice = int(choice[0])
    except KeyboardInterrupt:
        choice = -1
    except Exception, e:
        debug(e)
        os.system('clear')
        choice = -1
Beispiel #18
0
    def __init__(self):
        """Whole project is run from this constructor
        """

        # +++++++++++++++ Init +++++++++++++++ #

        self.keep_run = 1  # used in run for daemon loop, reset by SIGTERM
        self.ret_code = 0  # return code to command line (10 = shutdown)

        # +++++++++++++++ Objects +++++++++++++++ #

        # Each inner object will get reference to PyBlaster as self.main.

        # exceptions in child threads are put here
        self.ex_queue = queue.Queue()

        self.log = Log(self)
        self.settings = Settings(self)
        self.settings.parse()

        PB_GPIO.init_gpio(self)
        self.led = LED(self)
        self.buttons = Buttons(self)
        self.lirc = Lirc(self)
        self.dbhandle = DBHandle(self)
        self.cmd = Cmd(self)
        self.mpc = MPC(self)
        self.bt = RFCommServer(self)
        self.alsa = AlsaMixer(self)
        self.i2c = I2C(self)
        self.usb = UsbDrive(self)

        # +++++++++++++++ Init Objects +++++++++++++++ #

        # Make sure to run init functions in proper order!
        # Some might depend upon others ;)

        self.led.init_leds()
        self.dbhandle.dbconnect()
        self.mpc.connect()
        self.bt.start_server_thread()
        self.alsa.init_alsa()
        self.i2c.open_bus()
        self.usb.start_uploader_thread()

        # +++++++++++++++ Daemoninze +++++++++++++++ #

        self.check_pidfile()
        self.daemonize()
        self.create_pidfile()

        # +++++++++++++++ Daemon loop +++++++++++++++ #

        self.led.show_init_done()
        self.buttons.start()
        self.lirc.start()
        self.run()

        # +++++++++++++++ Finalize +++++++++++++++ #

        self.log.write(log.MESSAGE, "Joining threads...")

        # join remaining threads
        self.usb.join()
        self.bt.join()
        self.buttons.join()
        self.lirc.join()
        self.mpc.join()
        self.led.join()

        self.log.write(log.MESSAGE, "leaving...")

        # cleanup
        self.mpc.exit_client()
        self.delete_pidfile()
        PB_GPIO.cleanup(self)
Beispiel #19
0
 def __init__(self):
     Cmd().__init__(self)
     self.saved = 1
Beispiel #20
0
#!/usr/bin/env python3
from cmd import Cmd

cmd = Cmd()
cmd.setpoint(15)
Beispiel #21
0
def columnize(s):
    """ Print the contents of the list `s` in neat-looking columns. """
    if s:
        Cmd().columnize(list(s))
    else:
        print("None")
Beispiel #22
0
from cmd import Cmd

_author_ = 'czang'
_project_ = 'rssSnake'

c = Cmd()
Beispiel #23
0
import sys

import os

from classpath.classpath import Classpath
from cmd import Cmd


def start_jvm(cmd):
    class_data = None
    cp = Classpath(cmd.jre_option, cmd.cp_option)
    print('classpath:%s class:%s args:%s\n' %
          (cp.string(), cmd.class_name, cmd.args))
    class_name = cmd.class_name.replace('.', '/')

    try:
        class_data = cp.read_class(class_name)
    except FileNotFoundError as e:
        print(e.filename)

    print('class data: ' + str(class_data))


if __name__ == '__main__':
    _cmd = Cmd(sys.argv[1:])
    start_jvm(_cmd)
Beispiel #24
0
 def __init__(self, threads, inflation):
     self.threads = threads
     self.inflation = inflation
     mcl = Cmd("which mcl")
     mcl.run()
Beispiel #25
0
#!/usr/bin/python3
from cmd import Cmd

Cmd().cmdloop()