示例#1
0
def main(module_path, class_name):
    # Explicitly import module
    # If class defined in __main__ module, pickles won't load
    module = __import__(module_path, globals(), fromlist=True)
    designer = getattr(module, class_name)()

    args = sys.argv[1:]

    config.shell_run(designer, args, sys.executable + ' -m ' + module_path)
示例#2
0
文件: design.py 项目: pfh/demakein
def main(module_path, class_name):
    # Explicitly import module
    # If class defined in __main__ module, pickles won't load
    module = __import__(module_path, globals(), fromlist=True)
    designer = getattr(module, class_name)()    
    
    args = sys.argv[1:]
    
    config.shell_run(designer, args, sys.executable + ' -m ' + module_path)
def run_toolbox(action_classes, script_name='', show_make_flags=True):
    """
    Provide a command line interface for a list of Actions.
    
    Note:    
    strings included in the action_classes list will be printed 
    as help text, for example to display section headings.
    """
    args = configure_making(sys.argv[1:])
    
    commands = { }

    for item in action_classes:
        if isinstance(item, str):
            continue
        name = item.shell_name()
        commands[ name ] = item

    if args == [ '--help-make' ]:
        help = [ '\n' ]
        help.append('\nMake options:\n'+Make().describe('', show_help=True, escape_newlines=False)+'\n')

        config.write_colored_text(sys.stdout, ''.join(help)+'\n\n')
        sys.exit(1)

    if not args or args == ['-h'] or args == ['--help']:
        help = [ '\n' ]
        
        for item in action_classes:
            if isinstance(item, str):
                help.append(config.wrap(item, 70) + '\n\n')
                continue
            name = item.shell_name()
            help.append('    %s\n' % config.colored(1,name+':'))
            help.append(config.color_as_comment(config.wrap(item.help_short, 70, '        ')) + '\n\n')

        if show_make_flags:
            #help.append('\nMake options:\n'+Make().describe('', show_help=True, escape_newlines=False)+'\n')
            help.append('\nFor workflow make options type "%s --help-make".\n' % script_name)

        config.write_colored_text(sys.stdout, ''.join(help))
        sys.exit(1)
        
    try:        
        command, args = args[0], args[1:]
        
        mangled_command = command.lower().rstrip(':')
        if mangled_command not in commands:
            raise grace.Error("Don't know how to "+command)        
    except:
        config.report_exception()
        sys.exit(1)

    config.shell_run(commands[mangled_command](), args, (script_name+' ' if script_name else '') + mangled_command+':')
def run_script(function):
    """ Run a workflow script. Various command line flags are parsed,
        then any remaining command line parameters are passed to the 
        function. 
        
        Intended usage:

    
        from nesoni import *
    
        def my_script():
            ...
        
        if __name__ == '__main__':
            run_script(my_script)
    """
    maker = Make_script(function=function)    
    config.shell_run(maker, sys.argv[1:], sys.executable + ' ' + sys.argv[0])
示例#5
0
文件: legion.py 项目: mscook/nesoni
def run_script(function):
    """ Run a workflow script. Various command line flags are parsed,
        then any remaining command line parameters are passed to the 
        function. 
        
        Intended usage:

    
        from nesoni import *
    
        def my_script():
            ...
        
        if __name__ == '__main__':
            run_script(my_script)
    """
    maker = Make_script(function=function)
    config.shell_run(maker, sys.argv[1:], sys.executable + ' ' + sys.argv[0])
示例#6
0
def run_toolbox(action_classes, script_name=''):
    """
    Provide a command line interface for a list of Actions.
    
    Note:    
    strings included in the action_classes list will be printed 
    as help text, for example to display section headings.
    """
    commands = { }
    help = [ '\n' ]
    for item in action_classes:
        if isinstance(item, str):
            help.append(config.wrap(item, 70) + '\n\n')
            continue
        name = item.shell_name()
        commands[ name ] = item
        help.append('    %s\n' % config.colored(1,name+':'))
        help.append(config.wrap(item.help_short, 70, '        ') + '\n\n')

    args = sys.argv[1:]
    
    if not args:
        config.write_colored_text(sys.stdout, ''.join(help)+'\n\n')
        sys.exit(1)
        
    try:        
        command, args = args[0], args[1:]
        
        mangled_command = command.lower().rstrip(':')
        if mangled_command not in commands:
            raise grace.Error("Don't know how to "+command)        
    except:
        config.report_exception()
        sys.exit(1)

    config.shell_run(commands[mangled_command](), args, (script_name+' ' if script_name else '') + mangled_command+':')
示例#7
0
                    if a_start > self.length:
                        if a_start < len(seq):
                            n_clipped += 1
                            total_clipped += a_start
                    
                        print >> out_file, '@'+name
                        print >> out_file, seq[:a_start]
                        print >> out_file, '+'
                        print >> out_file, qual[:a_start]
                    else:
                        n_discarded += 1
                    
                    if n%10000 == 0: 
                        grace.status('Clip-runs ' + self.sample + ' ' + grace.pretty_number(n)) # + ' (' + grace.pretty_number(len(dstates)) + ' dstates)')
        
        grace.status('')
        
        self.log.datum(self.sample,'reads',n)
        if n:
            self.log.datum(self.sample,'mean length before poly-A/adaptor clipping',float(total_before)/n)
        self.log.datum(self.sample,'reads discarded as too short after poly-A/adaptor clipping',n_discarded)
        self.log.datum(self.sample,'reads poly-A/adaptor clipped and kept',n_clipped)
        if n_clipped:
            self.log.datum(self.sample,'mean length clipped',float(total_clipped)/n_clipped)




if __name__ == '__main__':
    config.shell_run(Clip_runs(), sys.argv[1:], sys.executable + ' ' + __file__)
def run_tool(action_class):
    """
    Provide a command line interface for an Action.
    """
    args = configure_making(sys.argv[1:])
    config.shell_run(action_class(), args, sys.argv[0])
示例#9
0
文件: legion.py 项目: mscook/nesoni
def run_toolbox(action_classes, script_name='', show_make_flags=True):
    """
    Provide a command line interface for a list of Actions.
    
    Note:    
    strings included in the action_classes list will be printed 
    as help text, for example to display section headings.
    """
    args = configure_making(sys.argv[1:])

    commands = {}

    for item in action_classes:
        if isinstance(item, str):
            continue
        name = item.shell_name()
        commands[name] = item

    if args == ['--help-make']:
        help = ['\n']
        help.append(
            '\nMake options:\n' +
            Make().describe('', show_help=True, escape_newlines=False) + '\n')

        config.write_colored_text(sys.stdout, ''.join(help) + '\n\n')
        sys.exit(1)

    if not args or args == ['-h'] or args == ['--help']:
        help = ['\n']

        for item in action_classes:
            if isinstance(item, str):
                help.append(config.wrap(item, 70) + '\n\n')
                continue
            name = item.shell_name()
            help.append('    %s\n' % config.colored(1, name + ':'))
            help.append(
                config.color_as_comment(
                    config.wrap(item.help_short, 70, '        ')) + '\n\n')

        if show_make_flags:
            #help.append('\nMake options:\n'+Make().describe('', show_help=True, escape_newlines=False)+'\n')
            help.append(
                '\nFor workflow make options type "%s --help-make".\n' %
                script_name)

        config.write_colored_text(sys.stdout, ''.join(help))
        sys.exit(1)

    try:
        command, args = args[0], args[1:]

        mangled_command = command.lower().rstrip(':')
        if mangled_command not in commands:
            raise grace.Error("Don't know how to " + command)
    except:
        config.report_exception()
        sys.exit(1)

    config.shell_run(commands[mangled_command](), args,
                     (script_name + ' ' if script_name else '') +
                     mangled_command + ':')
示例#10
0
文件: legion.py 项目: mscook/nesoni
def run_tool(action_class):
    """
    Provide a command line interface for an Action.
    """
    args = configure_making(sys.argv[1:])
    config.shell_run(action_class(), args, sys.argv[0])
        fq = io.open_possibly_compressed_file(self.qual_file)

        out_file = self.begin_output()

        while True:
            a1 = fa.readline()
            if not a1: break
            a1 = a1.strip()
            a2 = fa.readline().strip()
            q1 = fq.readline().strip()
            q2 = fq.readline().strip()

            assert a1.startswith('>')
            assert a1 == q1

            print >> out_file, '@' + a1[1:]
            print >> out_file, a2
            print >> out_file, '+'
            print >> out_file, ''.join(
                chr(33 + max(0, int(item))) for item in q2.split())

        self.end_output(out_file)

        fa.close()
        fq.close()


if __name__ == '__main__':
    config.shell_run(Fasta_qual_merge(), sys.argv[1:],
                     sys.executable + ' ' + __file__)
        fa = io.open_possibly_compressed_file(self.fasta_file)
        fq = io.open_possibly_compressed_file(self.qual_file)

        out_file = self.begin_output()

        while True:
            a1 = fa.readline()
            if not a1:
                break
            a1 = a1.strip()
            a2 = fa.readline().strip()
            q1 = fq.readline().strip()
            q2 = fq.readline().strip()

            assert a1.startswith(">")
            assert a1 == q1

            print >> out_file, "@" + a1[1:]
            print >> out_file, a2
            print >> out_file, "+"
            print >> out_file, "".join(chr(33 + max(0, int(item))) for item in q2.split())

        self.end_output(out_file)

        fa.close()
        fq.close()


if __name__ == "__main__":
    config.shell_run(Fasta_qual_merge(), sys.argv[1:], sys.executable + " " + __file__)
示例#13
0
                #if reverse:
                #    tail_refpos = al.pos-extension
                #else:
                #    tail_refpos = al.pos+al.length+extension-1
                #al.extra.append('AA:i:%d'%tail_refpos)
                al.extra.append('AA:i:1')

            cigar += 'M' * extension
            read_bases += 'N' * extension  #Since mispriming is so common (and loading the original sequence here would be a pain)
            read_qual += chr(33 + 20) * extension  #Arbitrarily give quality 20
            al.length += extension
            if reverse:
                al.pos -= extension
                al.seq = rev_comp(read_bases)
                al.qual = read_qual[::-1]
                al.cigar = cigar_encode(cigar[::-1])
            else:
                al.seq = read_bases
                al.qual = read_qual
                al.cigar = cigar_encode(cigar)

            print >> out_file, al

        self.end_output(out_file)
        self.end_input(in_file)


if __name__ == '__main__':
    config.shell_run(Extend_sam(), sys.argv[1:],
                     sys.executable + ' ' + __file__)
示例#14
0
                    
                        print >> out_file, '@'+name
                        print >> out_file, seq[:a_start]
                        print >> out_file, '+'
                        print >> out_file, qual[:a_start]
                    else:
                        n_discarded += 1
                    
                    if n%10000 == 0: 
                        grace.status('Clip-runs ' + self.sample + ' ' + grace.pretty_number(n)) # + ' (' + grace.pretty_number(len(dstates)) + ' dstates)')
                    
                    # Option to do a quick subsample
                    if self.only and self.only <= n:
                        break
        
        grace.status('')
        
        self.log.datum(self.sample,'reads',n)
        if n:
            self.log.datum(self.sample,'mean length before poly-A/adaptor clipping',float(total_before)/n)
        self.log.datum(self.sample,'reads discarded as too short after poly-A/adaptor clipping',n_discarded)
        self.log.datum(self.sample,'reads poly-A/adaptor clipped and kept',n_clipped)
        if n_clipped:
            self.log.datum(self.sample,'mean length clipped',float(total_clipped)/n_clipped)




if __name__ == '__main__':
    config.shell_run(Clip_runs(), sys.argv[1:], sys.executable + ' ' + __file__)
                #if reverse:
                #    tail_refpos = al.pos-extension
                #else:
                #    tail_refpos = al.pos+al.length+extension-1 
                #al.extra.append('AA:i:%d'%tail_refpos)
                al.extra.append('AA:i:1')
            
            cigar += 'M' * extension
            read_bases += 'N' * extension #Since mispriming is so common (and loading the original sequence here would be a pain)
            read_qual += chr(33+20) * extension #Arbitrarily give quality 20
            al.length += extension
            if reverse:
                al.pos -= extension
                al.seq = rev_comp(read_bases)
                al.qual = read_qual[::-1]
                al.cigar = cigar_encode(cigar[::-1])
            else: 
                al.seq = read_bases
                al.qual = read_qual
                al.cigar = cigar_encode(cigar)
                
            print >> out_file, al
    
        self.end_output(out_file)
        self.end_input(in_file)
                       
if __name__ == '__main__':
    config.shell_run(Extend_sam(), sys.argv[1:], sys.executable + ' ' + __file__)


示例#16
0
def run_tool(action_class):
    """
    Provide a command line interface for an Action.
    """
    config.shell_run(action_class(), sys.argv[1:], sys.argv[0])