Exemple #1
0
def uncaught_excepthook(*args):
    sys.__excepthook__(*args)
    if __debug__:
        from pprint import pprint
        from types import BuiltinFunctionType, ClassType, ModuleType, TypeType
        tb = sys.last_traceback
        while tb.tb_next:
            tb = tb.tb_next
        print('\nDumping locals() ...')
        pprint({
            k: v
            for k, v in tb.tb_frame.f_locals.items()
            if not k.startswith('_') and not isinstance(
                v, (BuiltinFunctionType, ClassType, ModuleType, TypeType))
        })
        if sys.stdin.isatty() and (sys.stdout.isatty() or sys.stderr.isatty()):
            try:
                import ipdb as pdb  # try to import the IPython debugger
            except ImportError:
                import pdb as pdb
            print('\nStarting interactive debug prompt ...')
            pdb.pm()
    else:
        import traceback
        title = _('Unexpected error')
        msg = _(
            'Debian Plymouth Manager has failed with the following unexpected error.\nPlease submit a bug report!'
        )
        msg = "<b>{}</b>\n\n<tt>{}</tt>".format(
            msg, '\n'.join(traceback.format_exception(*args)))
        showMsg(title, msg)
    sys.exit(1)
Exemple #2
0
def uncaught_excepthook(*args):
    sys.__excepthook__(*args)
    if __debug__:
        from pprint import pprint
        from types import BuiltinFunctionType, ClassType, ModuleType, TypeType
        tb = sys.last_traceback
        while tb.tb_next:
            tb = tb.tb_next
        print(('\nDumping locals() ...'))
        pprint({
            k: v
            for k, v in tb.tb_frame.f_locals.items()
            if not k.startswith('_') and not isinstance(
                v, (BuiltinFunctionType, ClassType, ModuleType, TypeType))
        })
        if sys.stdin.isatty() and (sys.stdout.isatty() or sys.stderr.isatty()):
            try:
                import ipdb as pdb  # try to import the IPython debugger
            except ImportError:
                import pdb as pdb
            print(('\nStarting interactive debug prompt ...'))
            pdb.pm()
    else:
        import traceback
        details = '\n'.join(traceback.format_exception(*args)).replace(
            '<', '').replace('>', '')
        title = _('Unexpected error')
        msg = _(
            'SolydXK System Settings has failed with the following unexpected error. Please submit a bug report!'
        )
        ErrorDialog(title, "<b>%s</b>" % msg, "<tt>%s</tt>" % details, None,
                    True, 'solydxk')

    sys.exit(1)
def uncaught_excepthook(*args):
    sys.__excepthook__(*args)
    if __debug__:
        from pprint import pprint
        from types import BuiltinFunctionType, ClassType, ModuleType, TypeType

        tb = sys.last_traceback
        while tb.tb_next:
            tb = tb.tb_next
        print(("\nDumping locals() ..."))
        pprint(
            {
                k: v
                for k, v in tb.tb_frame.f_locals.items()
                if not k.startswith("_") and not isinstance(v, (BuiltinFunctionType, ClassType, ModuleType, TypeType))
            }
        )
        if sys.stdin.isatty() and (sys.stdout.isatty() or sys.stderr.isatty()):
            try:
                import ipdb as pdb  # try to import the IPython debugger
            except ImportError:
                import pdb as pdb
            print(("\nStarting interactive debug prompt ..."))
            pdb.pm()
    else:
        import traceback

        details = "\n".join(traceback.format_exception(*args)).replace("<", "").replace(">", "")
        title = _("Unexpected error")
        msg = _("DDM has failed with the following unexpected error. Please submit a bug report!")
        ErrorDialog(title, "<b>%s</b>" % msg, "<tt>%s</tt>" % details, None, True, "ddm")

    sys.exit(1)
def info(type, value, tb):
    import traceback
    import ipdb

    traceback.print_exception(type, value, tb)
    print
    ipdb.pm()
Exemple #5
0
def tracebacker_base(exc_type, exc_obj, exc_tb, debug=False):
    """Standard traceback handling for easy-to-read error messages."""
    tag = say('[TRACEBACK]', 'gray')
    tracetext = tag + ' ' + re.sub(
        r'\n', '\n%s' % tag, str(''.join(traceback.format_tb(exc_tb)).strip()))
    if not debug:
        print(say(tracetext))
        print(
            say('[ERROR]', 'red_black') + ' ' +
            say('%s' % exc_obj, 'cyan_black'))
    else:
        try:
            import ipdb as pdb_this
        except:
            print(
                'note',
                'entering debug mode but cannot find ipdb so we are using pdb')
            import pdb as pdb_this
        print(say(tracetext))
        print(
            say('[ERROR]', 'red_black') + ' ' +
            say('%s' % exc_obj, 'cyan_black'))
        print(say('[DEBUG] entering the debugger', 'mag_gray'))
        import ipdb
        ipdb.set_trace()
        pdb_this.pm()
Exemple #6
0
 def info(t, value, tb):
     if t == KeyboardInterrupt:
         traceback.print_exception(t, value, tb)
         return
     else:
         traceback.print_exception(t, value, tb)
         ipdb.pm()
Exemple #7
0
 def debug_on_exit():
     if hasattr(sys, "last_traceback"):
         try:
             import ipdb as pdb
         except ImportError:
             import pdb
         pdb.pm()
def uncaught_excepthook(*args):
    sys.__excepthook__(*args)
    if __debug__:
        from pprint import pprint
        from types import BuiltinFunctionType, ClassType, ModuleType, TypeType
        tb = sys.last_traceback
        while tb.tb_next: tb = tb.tb_next
        print('\nDumping locals() ...')
        pprint({k:v for k,v in tb.tb_frame.f_locals.items()
                    if not k.startswith('_') and
                       not isinstance(v, (BuiltinFunctionType,
                                          ClassType, ModuleType, TypeType))})
        if sys.stdin.isatty() and (sys.stdout.isatty() or sys.stderr.isatty()):
            try:
                import ipdb as pdb  # try to import the IPython debugger
            except ImportError:
                import pdb as pdb
            print('\nStarting interactive debug prompt ...')
            pdb.pm()
    else:
        import traceback
        title = _('Unexpected error')
        msg = _('Debian Plymouth Manager has failed with the following unexpected error.\nPlease submit a bug report!')
        msg = "<b>{}</b>\n\n<tt>{}</tt>".format(msg, '\n'.join(traceback.format_exception(*args)))
        showMsg(title, msg)
    sys.exit(1)
Exemple #9
0
def uncaught_excepthook(*args):
    sys.__excepthook__(*args)
    if __debug__:
        from pprint import pprint
        from types import BuiltinFunctionType, ClassType, ModuleType, TypeType
        tb = sys.last_traceback
        while tb.tb_next: tb = tb.tb_next
        print('\nDumping locals() ...')
        pprint({k:v for k,v in tb.tb_frame.f_locals.items()
                    if not k.startswith('_') and
                       not isinstance(v, (BuiltinFunctionType,
                                          ClassType, ModuleType, TypeType))})
        if sys.stdin.isatty() and (sys.stdout.isatty() or sys.stderr.isatty()):
            try:
                import ipdb as pdb  # try to import the IPython debugger
            except ImportError:
                import pdb as pdb
            print '\nStarting interactive debug prompt ...'
            pdb.pm()
    else:
        import traceback
        from dialogs import ErrorDialog
        ErrorDialog(_('Unexpected error'),
                    '<b>%s</b>' % _("The installer failed with the following error."),
                    '<tt>' + '\n'.join(traceback.format_exception(*args)) + '</tt>')
    sys.exit(1)
Exemple #10
0
def uncaught_excepthook(*args):
    sys.__excepthook__(*args)
    if __debug__:
        from pprint import pprint
        from types import BuiltinFunctionType, ClassType, ModuleType, TypeType
        tb = sys.last_traceback
        while tb.tb_next: tb = tb.tb_next
        print(('\nDumping locals() ...'))
        pprint({k:v for k,v in tb.tb_frame.f_locals.items()
                    if not k.startswith('_') and
                       not isinstance(v, (BuiltinFunctionType,
                                          ClassType, ModuleType, TypeType))})
        if sys.stdin.isatty() and (sys.stdout.isatty() or sys.stderr.isatty()):
            can_debug = False
            try:
                import ipdb as pdb  # try to import the IPython debugger
                can_debug = True
            except ImportError:
                try:
                    import pdb as pdb
                    can_debug = True
                except ImportError:
                    pass

            if can_debug:
                print(('\nStarting interactive debug prompt ...'))
                pdb.pm()
    else:
        import traceback
        details = '\n'.join(traceback.format_exception(*args)).replace('<', '').replace('>', '')
        title = 'Unexpected error'
        msg = 'The installer has failed with the following unexpected error. Please submit a bug report!'
        ErrorDialog(title, "<b>%s</b>" % msg, "<tt>%s</tt>" % details, None, True, 'live-installer-3')

    sys.exit(1)
Exemple #11
0
def uncaught_excepthook(*args):
    sys.__excepthook__(*args)
    if __debug__:
        from pprint import pprint
        from types import BuiltinFunctionType, ClassType, ModuleType, TypeType
        tb = sys.last_traceback
        while tb.tb_next: tb = tb.tb_next
        print('\nDumping locals() ...')
        pprint({k:v for k,v in tb.tb_frame.f_locals.items()
                    if not k.startswith('_') and
                       not isinstance(v, (BuiltinFunctionType,
                                          ClassType, ModuleType, TypeType))})
        if sys.stdin.isatty() and (sys.stdout.isatty() or sys.stderr.isatty()):
            try:
                import ipdb as pdb  # try to import the IPython debugger
            except ImportError:
                import pdb as pdb
            print '\nStarting interactive debug prompt ...'
            pdb.pm()
    else:
        import traceback
        from dialogs import ErrorDialog
        ErrorDialog(_('Unexpected error'),
                    _('<b>The installer has failed with the following unexpected error. Please submit a bug report!</b>'),
                    '<tt>' + '\n'.join(traceback.format_exception(*args)) + '</tt>')
    sys.exit(1)
Exemple #12
0
def debug_on_assertion(type, value, tb):
   if hasattr(sys, 'ps1') or not sys.stderr.isatty() or type != AssertionError:
      sys.__excepthook__(type, value, tb)
   else:
      import traceback, ipdb
      traceback.print_exception(type, value, tb)
      print()
      ipdb.pm()
 def debug(type, value, tb):
     import traceback
     try:
         from ipdb import pm
     except ImportError:
         from pdb import pm
     traceback.print_exception(type, value, tb)
     pm()
Exemple #14
0
def _try_with_pm(_func_to_try_with_pm, *ar, **kwa):
    """ Debug-helper to call ipdb.pm in case of an unhandled exception in the
    function"""
    try:
        return _func_to_try_with_pm(*ar, **kwa)
    except Exception:
        _, _, sys.last_traceback = sys.exc_info()
        import traceback; traceback.print_exc()
        import ipdb; ipdb.pm()
Exemple #15
0
def exception_info(ex_type, value, tb):
    import traceback
    traceback.print_exception(ex_type, value, tb)
    try:
        # Might not be installed.
        import ipdb as debug
    except ImportError:
        import pdb as debug
    debug.pm()
Exemple #16
0
def _ipdbg(_a_function_thingie, *ar, **kwa):
    """ Run with ipdb post-mortem on exception """
    import ipdb
    try:
        return _a_function_thingie(*ar, **kwa)
    except Exception as exc:
        _, _, sys.last_traceback = sys.exc_info()
        traceback.print_exc()
        ipdb.pm()
        return None
Exemple #17
0
 def info(type, value, tb):
     traceback.print_exception(type, value, tb)
     print()
     # Insert look-around helpers into the frame
     import inspect, ast
     from .asttools import to_source
     frame = inspect.getinnerframes(tb)[-1][0]
     frame.f_globals.setdefault('ast', ast)
     frame.f_globals.setdefault('to_source', to_source)
     # Run debugger
     ipdb.pm()
Exemple #18
0
 def info(type, value, tb):
     traceback.print_exception(type, value, tb)
     print()
     # Insert look-around helpers into the frame
     import inspect, ast
     from .asttools import to_source
     frame = inspect.getinnerframes(tb)[-1][0]
     frame.f_globals.setdefault('ast', ast)
     frame.f_globals.setdefault('to_source', to_source)
     # Run debugger
     ipdb.pm()
Exemple #19
0
def info(type, value, tb):
    if hasattr(sys, 'ps1') or not sys.stderr.isatty():
        # we are in interactive mode or we don't have a tty-like
        # device, so we call the default hook
        sys.__excepthook__(type, value, tb)
    else:
        import traceback, ipdb
        # we are NOT in interactive mode, print the exception...
        traceback.print_exception(type, value, tb)
        print
        # ...then start the debugger in post-mortem mode.
        ipdb.pm()
Exemple #20
0
 def info(type1, value, tb):
     if hasattr(sys,
                'ps1') or not sys.stderr.isatty() or type1 == SyntaxError:
         # we are in interactive mode or we don't have a tty-like device, or error is
         # a SyntaxError (can not be debugged), so we call the default hook
         sys.__excepthook__(type1, value, tb)
     else:
         import traceback, ipdb
         # we are NOT in interactive mode, print the exception...
         traceback.print_exception(type1, value, tb)
         print()
         # ...then start the debugger in post-mortem mode.
         ipdb.pm()
def main():
    parser = argparse.ArgumentParser(description="Cosmos Quest Client")
    parser = add_logging_options(parser)
    parser = _add_options(parser)
    args = parser.parse_args()
    conf_logging()
    try:
        eras = execute(args)
    except Exception as ex:
        ipdb.pm()
    else:
        if args.save_response:
            log_response(eras)
def info(type, value, tb):
    # if hasattr(sys, 'ps1') or not sys.stderr.isatty()
    # or type != AssertionError:
    # # we are in interactive mode or we don't have a tty-like
    # # device, so we call the default hook
    # sys.__excepthook__(type, value, tb)
    # else:
    import traceback
    import ipdb
    # we are NOT in interactive mode, print the exception...
    traceback.print_exception(type, value, tb)
    print
    # ...then start the debugger in post-mortem mode.
    ipdb.pm()
Exemple #23
0
def run_pdb_hook(*args, **kwargs):
    """Debug mode exception handler. Drops into a debugger shell"""

    import traceback

    # load ipdb if possible, otherwise fall back to pdb
    try:
        import ipdb as pdb
    except ImportError:
        import pdb

    # if it's a KeyboardInterrupt, ignore it and just tell it and quit.
    if isinstance(args[1], KeyboardInterrupt):
        sys.exit("Caught a KeyboardInterrupt, quitting.")

    traceback.print_exception(*args, **kwargs)
    pdb.pm()
Exemple #24
0
def tracebacker_base(exc_type,exc_obj,exc_tb,debug=False):
	"""Standard traceback handling for easy-to-read error messages."""
	tag = say('[TRACEBACK]','gray')
	tracetext = tag+' '+re.sub(r'\n','\n%s'%tag,str(''.join(traceback.format_tb(exc_tb)).strip()))
	if not debug:
		print(say(tracetext))
		print(say('[ERROR]','red_black')+' '+say('%s'%exc_obj,'cyan_black'))
	else: 
		try: import ipdb as pdb_this
		except: 
			print('note','entering debug mode but cannot find ipdb so we are using pdb')
			import pdb as pdb_this
		print(say(tracetext))	
		print(say('[ERROR]','red_black')+' '+say('%s'%exc_obj,'cyan_black'))
		print(say('[DEBUG] entering the debugger','mag_gray'))
		import ipdb;ipdb.set_trace()
		pdb_this.pm()
Exemple #25
0
def run_pdb_hook(*args, **kwargs):
    """Debug mode exception handler. Drops into a debugger shell"""

    import traceback

    # load ipdb if possible, otherwise fall back to pdb
    try:
        import ipdb as pdb
    except ImportError:
        import pdb

    # if it's a KeyboardInterrupt, ignore it and just tell it and quit.
    if isinstance(args[1], KeyboardInterrupt):
        sys.exit("Caught a KeyboardInterrupt, quitting.")

    traceback.print_exception(*args, **kwargs)
    pdb.pm()
def info(type, value, tb):
    if hasattr(sys, 'ps1') or not sys.stderr.isatty():
        # we are in interactive mode or we don't have a tty-like
        # device, so we call the default hook
        sys.__excepthook__(type, value, tb)
    else:
        import traceback
        # we are NOT in interactive mode, print the exception…
        traceback.print_exception(type, value, tb)
        print
        # …then start the debugger in post-mortem mode.
        try:
            import ipdb
            ipdb.pm()
        except:
            import pdb
            # pdb.pm() # deprecated
            pdb.post_mortem(tb)  # more “modern”
Exemple #27
0
def pyFoamExceptionHook(type,value,tb,debugOnSyntaxError=False):
    if hasattr(sys,'ps1'):
        warning("Interactive mode. No debugger")
        sys.__excepthook__(type,value,tb)
    elif not (isatty(sys.stderr) and isatty(sys.stdin) and isatty(sys.stdout)):
        warning("Not on a terminal. No debugger")
        sys.__excepthook__(type,value,tb)
    elif issubclass(type,SyntaxError) and not debugOnSyntaxError:
        warning("Syntax error. No debugger")
        sys.__excepthook__(type,value,tb)
    else:
        import traceback
        try:
             import ipdb as pdb
        except ImportError:
             import pdb
        traceback.print_exception(type,value,tb)
        print_()
        pdb.pm()
Exemple #28
0
def pyFoamExceptionHook(type, value, tb, debugOnSyntaxError=False):
    if hasattr(sys, 'ps1'):
        warning("Interactive mode. No debugger")
        sys.__excepthook__(type, value, tb)
    elif not (isatty(sys.stderr) and isatty(sys.stdin) and isatty(sys.stdout)):
        warning("Not on a terminal. No debugger")
        sys.__excepthook__(type, value, tb)
    elif issubclass(type, SyntaxError) and not debugOnSyntaxError:
        warning("Syntax error. No debugger")
        sys.__excepthook__(type, value, tb)
    else:
        import traceback
        try:
            import ipdb as pdb
        except ImportError:
            import pdb
        traceback.print_exception(type, value, tb)
        print_()
        pdb.pm()
Exemple #29
0
def uncaught_excepthook(*args):
    sys.__excepthook__(*args)
    if __debug__:
        from pprint import pprint
        from types import BuiltinFunctionType, ClassType, ModuleType, TypeType
        tb = sys.last_traceback
        while tb.tb_next: tb = tb.tb_next
        print('\nDumping locals() ...')
        pprint({k:v for k,v in tb.tb_frame.f_locals.items()
                    if not k.startswith('_') and
                       not isinstance(v, (BuiltinFunctionType,
                                          ClassType, ModuleType, TypeType))})
        if sys.stdin.isatty() and (sys.stdout.isatty() or sys.stderr.isatty()):
            try:
                import ipdb as pdb  # try to import the IPython debugger
            except ImportError:
                import pdb as pdb
            print '\nStarting interactive debug prompt ...'
            pdb.pm()
    sys.exit(1)
def pyFoamExceptionHook(type,value,tb,debugOnSyntaxError=False):
    if hasattr(sys,'ps1'):
        warning("Interactive mode. No debugger")
        sys.__excepthook__(type,value,tb)
    elif not (isatty(sys.stderr) and isatty(sys.stdin) and isatty(sys.stdout)) and not (path.basename(sys.executable) in ["pvpython"]):
        warning("Not on a terminal. No debugger")
        sys.__excepthook__(type,value,tb)
    elif issubclass(type,SyntaxError) and not debugOnSyntaxError:
        warning("Syntax error. No debugger")
        sys.__excepthook__(type,value,tb)
    else:
        import traceback
        try:
             import ipdb as pdb
        except ImportError:
             import pdb
        except AttributeError:
             # ipdb doesn't work in pvpython
             import pdb
        traceback.print_exception(type,value,tb)
        print_()
        pdb.pm()
def pyFoamExceptionHook(type, value, tb, debugOnSyntaxError=False):
    if hasattr(sys, 'ps1'):
        warning("Interactive mode. No debugger")
        sys.__excepthook__(type, value, tb)
    elif not (isatty(sys.stderr) and isatty(sys.stdin) and isatty(sys.stdout)
              ) and not (path.basename(sys.executable) in ["pvpython"]):
        warning("Not on a terminal. No debugger")
        sys.__excepthook__(type, value, tb)
    elif issubclass(type, SyntaxError) and not debugOnSyntaxError:
        warning("Syntax error. No debugger")
        sys.__excepthook__(type, value, tb)
    else:
        import traceback
        try:
            import ipdb as pdb
        except ImportError:
            import pdb
        except AttributeError:
            # ipdb doesn't work in pvpython
            import pdb
        traceback.print_exception(type, value, tb)
        print_()
        pdb.pm()
Exemple #32
0
        w.walk_and_compare()
        f.write(w.json_results())
        if f != sys.stdout:
            f.close()
    except StandardError as e:
        if not options.debug:
            print >>sys.stderr, u"Unhandled exception: %s" % e
        else:
            tb = sys.exc_info()[2]

            try:
                import ipdb as pdb
            except ImportError:
                import pdb

            sys.last_traceback = tb
            pdb.pm()
            raise

    if options.profile:
        profiler.disable()
        profiler.dump_stats("webcompare.cprofile")

        profiler.print_stats(sort="cumulative")

        print
        print "Dumped full cProfile data to webcompare.cprofile: try loading",
        print " it with `python -mpstats webcompare.cprofile`"
        print
Exemple #33
0
def parse_vcf(vcf, CHROM, sample_id, database, min_dp_to_include, output_base):
    logger = logging.getLogger(__name__)
    logger.info("starting CHROM {}\n".format(CHROM))
    start_time = time()
    # store the set of indel_ids for calls, because in rare circumstances there
    # are multiple entries for the same indel
    # (because of repetitive genome/indel matching)
    indel_ids = set()

    # note: make sure we pass in the right connection (waldb)
    # db = get_connection(database)
    db = get_local_connection(database)
    try:
        cur = db.cursor()
        max_variant_id = get_max_variant_id(cur, CHROM)
        novel_variant_id = max_variant_id

        (effect_rankings, high_impact_effect_ids, moderate_impact_effect_ids,
         low_impact_effect_ids,
         modifier_impact_effect_ids) = (get_effect_rankings(cur))
        # print (effect_rankings)
        # print (high_impact_effect_ids)
        # print (modifier_impact_effect_ids)
        # sys.exit(0)

        polyphen_matrixes_by_stable_id = {"humvar": {}, "humdiv": {}}
        polyphen_stable_ids_to_ignore = {"humvar": set(), "humdiv": set()}

        pid_variant_ids = {}
        hp_variant_ids = {}

        #         novel_variants = output_base + ".novel_variants.txt"
        #         novel_indels = output_base + ".novel_indels.txt"
        #         novel_transcripts = output_base + ".novel_transcripts.txt"
        #         calls = output_base + ".calls.txt"
        #         variant_id_vcf = output_base + ".variant_id.vcf"
        #         matched_indels = output_base + ".matched_indels.txt"

        novel_variants = CHROM + '.' + output_base + ".novel_variants.txt"
        novel_indels = CHROM + '.' + output_base + ".novel_indels.txt"
        novel_transcripts = CHROM + '.' + output_base + ".novel_transcripts.txt"
        calls = CHROM + '.' + output_base + ".calls.txt"
        variant_id_vcf = CHROM + '.' + output_base + ".variant_id.vcf"
        matched_indels = CHROM + '.' + output_base + ".matched_indels.txt"

        custom_transcript_ids, novel_transcripts_id = get_custom_transcript_ids(
            cur, CHROM)

        # print (custom_transcript_ids)
        # print (novel_transcripts_id)
        # sys.exit(0)

        vcf_tabix = tabix.open(vcf)

        with open(novel_variants, "w") as novel_fh, \
                open(novel_indels, "w") as novel_indels_fh, \
                open(novel_transcripts, "w") as novel_transcripts_fh, \
                open(calls, "w") as calls_fh, \
                open(variant_id_vcf, "w") as vcf_out, \
                open(matched_indels, "w") as matched_indels_fh:
            try:
                vcf_iter = vcf_tabix.querys(CHROM)
            except tabix.TabixError:
                logger.warning(
                    "sample_id {sample_id} has no calls in chromosome {CHROM}".
                    format(sample_id=sample_id, CHROM=CHROM))
                return
            for x, line_fields in enumerate(vcf_iter):
                fields = VCF_fields_dict(line_fields)
                if fields["CHROM"] != CHROM:
                    raise ValueError(
                        "error: encountered chromosome {chromosome} when "
                        "{CHROM} was expected".format(
                            CHROM=CHROM, chromosome=fields["CHROM"]))
                POS = int(fields["POS"])
                INFO = create_INFO_dict(fields["INFO"])
                if fields["FILTER"] == "PASS":
                    INFO["FILTER"] = "PASS"

                elif fields["FILTER"] == "SNP_filter":
                    INFO["FILTER"] = "FAIL"
                elif fields["FILTER"] == "INDEL_filter":
                    INFO["FILTER"] = "FAIL"
                elif fields["FILTER"] == "VQSRTrancheSNP90.00to99.00":
                    INFO["FILTER"] = "LIKELY"
                elif fields["FILTER"] == "VQSRTrancheSNP99.00to99.90":
                    INFO["FILTER"] = "INTERMEDIATE"
                elif fields["FILTER"] == "VQSRTrancheSNP99.90to100.00":
                    INFO["FILTER"] = "FAIL"
                elif fields["FILTER"] == "VQSRTrancheINDEL90.00to99.00":
                    INFO["FILTER"] = "LIKELY"
                elif fields["FILTER"] == "VQSRTrancheINDEL99.00to99.90":
                    INFO["FILTER"] = "INTERMEDIATE"
                elif fields["FILTER"] == "VQSRTrancheINDEL99.90to100.00":
                    INFO["FILTER"] = "FAIL"
                else:
                    raise ValueError(
                        "\n\ninvalid FILTER= '{}' @ line= '{}'\n".format(
                            fields["FILTER"], x))

                call_stats = create_call_dict(fields["FORMAT"], fields["call"])
                try:
                    call = {
                        "sample_id": sample_id,
                        "GQ": call_stats["GQ"],
                        "DP": call_stats["DP"],
                        "QUAL": int(round(float(fields["QUAL"])))
                    }

                except KeyError:
                    # import pprint
                    # logger.error(pprint.pformat(fields))
                    print(KeyError)
                    raise

                # we will not load calls less than 3 DP
                if int(call["DP"]) < min_dp_to_include:
                    # just output the record unchanged
                    vcf_out.write("\t".join(line_fields) + "\n")
                    continue
                high_quality_call = call_is_high_quality(
                    int(round(float(fields["QUAL"]))),
                    int(round(float(INFO["MQ"]))) if "MQ" in INFO else 0,
                    INFO["FILTER"],
                    DP=int(call_stats["DP"]))
                ALT_alleles = fields["ALT"].split(",")
                nalleles = len(ALT_alleles)
                if nalleles > 2:
                    raise ValueError("{CHROM}-{POS} has {nalleles} alternate "
                                     "alleles".format(
                                         CHROM=CHROM,
                                         POS=POS,
                                         nalleles=len(ALT_alleles)))
                # we truncate these to 255 characters, so if they differ after
                # that we'll get different variants that have the same
                # "alternate" - our solution is to just retain the first entry
                # in such a rare instance
                elif nalleles == 2:
                    multiallelic = True
                    if ALT_alleles[0][:255] == ALT_alleles[1][:255]:
                        # logger.debug(
                        #     "{CHROM}-{POS} has two alternate alleles with > 255 "
                        #     "length that are identical to that point".format(
                        #         CHROM=CHROM, POS=POS))
                        print(
                            "{CHROM}-{POS} has two alternate alleles with > 255 "
                            "length that are identical to that point".format(
                                CHROM=CHROM, POS=POS))
                        del ALT_alleles[1]
                        nalleles = 1
                        # need to change the GT to 1/1 instead of 1/2
                        call_stats["GT"] = call_stats["GT"].replace("2", "1")
                        # also need to change AD from x,y,z to x,y+z
                        ads = call_stats["AD"].split(",")
                        ads[1] = str(int(ads[1]) + int(ads[2]))
                        del ads[2]
                        call_stats["AD"] = ",".join(ads)
                else:
                    multiallelic = False

                variant_ids = []
                for ALT_allele in ALT_alleles:

                    (variant_id, highest_impact, block_id, novel_variant_id,
                     novel_transcripts_id) = get_variant_id(
                         novel_fh, novel_indels_fh, novel_transcripts_fh,
                         matched_indels_fh, cur, sample_id, CHROM, POS,
                         fields["REF"], ALT_allele, fields["rs_number"],
                         INFO["ANN"], novel_variant_id, novel_transcripts_id,
                         effect_rankings, high_impact_effect_ids,
                         moderate_impact_effect_ids, low_impact_effect_ids,
                         modifier_impact_effect_ids,
                         polyphen_matrixes_by_stable_id,
                         polyphen_stable_ids_to_ignore, high_quality_call,
                         custom_transcript_ids, logger)

                    indel = len(fields["REF"]) != len(ALT_allele)
                    variant_ids.append(
                        (variant_id, block_id, highest_impact, indel))

                if "PID" in call_stats:
                    if len(ALT_alleles) > 1:
                        # this is currently unsupported; throw an error until we
                        # get such an example and can determine how to handle it
                        raise ValueError(
                            "there are {} alternate alleles at line "
                            "#{} in the VCF with the PID annotation".format(
                                len(ALT_alleles), x))
                    else:
                        pid_pos, pid_ref, pid_alt = call_stats["PID"].split(
                            "_")
                        if (pid_pos == fields["POS"]
                                and pid_ref == fields["REF"]
                                and pid_alt == fields["ALT"]):
                            # new phasing block, store this variant_id
                            pid_variant_ids[(pid_pos, pid_ref,
                                             pid_alt)] = (str(
                                                 variant_ids[0][0]))
                            call["PID_variant_id"] = "\\N"
                            call["PGT"] = "\\N"
                        elif (pid_pos, pid_ref, pid_alt) in pid_variant_ids:
                            call["PID_variant_id"] = pid_variant_ids[(pid_pos,
                                                                      pid_ref,
                                                                      pid_alt)]
                            pgt = call_stats["PGT"]
                            if pgt in ("0|1", "1|1"):
                                call["PGT"] = "1"
                            elif pgt == "1|0":
                                call["PGT"] = "0"
                            else:
                                raise ValueError(
                                    "Unexpected PGT at line count {}: {}".
                                    format(x, pgt))
                        else:
                            # GATK issue in which PGT refers to a tossed-out
                            # candidate variant, which we will just treat as
                            # unphased
                            call["PID_variant_id"] = "\\N"
                            call["PGT"] = "\\N"
                else:
                    # variant is unphased (from HaplotypeCaller)
                    call["PID_variant_id"] = "\\N"
                    call["PGT"] = "\\N"

#                 print (call)
#                 sys.exit(0)

                if "HP" in call_stats:
                    if len(ALT_alleles) > 1:
                        # this is currently unsupported; throw an error until we
                        # get such an example and can determine how to handle it
                        raise ValueError(
                            "there are {} alternate alleles at line "
                            "#{} in the VCF with the HP annotation".format(
                                len(ALT_alleles), x))
                    else:
                        phase_one, phase_two = call_stats["HP"].split(",")
                        hp_pos, allele_one = phase_one.split("-")
                        _, allele_two = phase_two.split("-")
                        if hp_pos == fields["POS"]:
                            # new phasing block, store this variant_id
                            hp_variant_ids[hp_pos] = str(variant_ids[0][0])
                            call["HP_variant_id"] = "\\N"
                            call["HP_GT"] = "\\N"
                            call["PQ"] = "\\N"
                        elif hp_pos in hp_variant_ids:
                            call["HP_variant_id"] = hp_variant_ids[hp_pos]
                            if allele_one == "1" and allele_two == "2":
                                call["HP_GT"] = "1"
                            elif allele_one == "2" and allele_two == "1":
                                call["HP_GT"] = "0"
                            else:
                                raise ValueError(
                                    "unexpected phase (HP) at line count {}: {}"
                                    .format(x, call_stats["HP"]))
                            if "PQ" in call_stats:
                                call["PQ"] = str(
                                    int(round(float(call_stats["PQ"]))))
                            else:
                                call["PQ"] = "\\N"
                        else:
                            logger.debug(
                                "Unexpected phasing with respect to a "
                                "variant that is not present at line {}".
                                format(x))
                            call["HP_variant_id"] = "\\N"
                            call["HP_GT"] = "\\N"
                            call["PQ"] = "\\N"
                else:
                    # variant is unphased (from ReadBackedPhasing)
                    call["HP_variant_id"] = "\\N"
                    call["HP_GT"] = "\\N"
                    call["PQ"] = "\\N"
#                 print (call)
#                 sys.exit()

                for variant_stat in ("MQ", "QD"):
                    # we store these two values as ints instead of float
                    if variant_stat in INFO:
                        INFO[variant_stat] = int(
                            round(float(INFO[variant_stat])))
                for variant_stat in ("FS", "MQ", "QD", "ReadPosRankSum",
                                     "MQRankSum", "VQSLOD", "SOR"):
                    if variant_stat not in INFO:
                        # NULL value for loading
                        INFO[variant_stat] = "\\N"
                    elif INFO[variant_stat] == "Infinity":
                        # GATK can, at least for VQSLOD, claim a value of "Infinity"
                        INFO[variant_stat] = str(MAX_FLOAT_DB)
                    elif INFO[variant_stat] == "-Infinity":
                        INFO[variant_stat] = str(MIN_FLOAT_DB)


#                 print (INFO)
#                 sys.exit(0)

                if nalleles == 1:
                    (call["variant_id"], call["block_id"],
                     call["highest_impact"], indel) = variant_ids[0]
                    if "PL" in call_stats:
                        if multiallelic:
                            call["PL_AA"], _, _, _, call["PL_AB"], call[
                                "PL_BB"] = (call_stats["PL"].split(","))
                        else:
                            call["PL_AA"], call["PL_AB"], call["PL_BB"] = (
                                call_stats["PL"].split(","))
                    else:
                        # seems as MNPs we don't have these at this point
                        call["PL_AA"], call["PL_AB"], call["PL_BB"] = ("\\N",
                                                                       "\\N",
                                                                       "\\N")
                    output_call = True
                    if indel:
                        if call["variant_id"] in indel_ids:
                            # skip outputting this call, because this is a
                            # matched indel which we already output
                            output_call = False
                        else:
                            indel_ids.add(call["variant_id"])
                if nalleles == 1 and output_call:
                    GTs = call_stats["GT"].split("/")
                    if len(GTs) == 2:
                        for x, GT in enumerate(GTs):
                            if GT in VALID_GTS:
                                GTs[x] = int(GT)
                            else:
                                raise ValueError(
                                    "error: invalid GT {GT} @ {CHROM}-{POS}-{REF}"
                                    "-{ALT}".format(GT=call_stats["GT"],
                                                    **fields))
                    else:
                        raise ValueError(
                            "error: invalid GT {GT} @ {CHROM}-{POS}-{REF}"
                            "-{ALT}".format(GT=call_stats["GT"], **fields))
                    call["GT"] = sum(GTs)
                    try:
                        call["AD_REF"], call["AD_ALT"] = call_stats[
                            "AD"].split(",")
                        gg = VARIANT_CALL_FORMAT.format(
                            **merge_dicts(call, INFO)) + "\n"
                    except:
                        if __name__ == "__main__":
                            import ipdb
                            ipdb.set_trace()
                            ipdb.pm()
                        else:
                            from pprint import pprint
                            pprint(line_fields)
                            pprint(call)
                            pprint(call_stats)
                            pprint(INFO)
                            raise
                    calls_fh.write(gg)
                elif nalleles != 1:
                    if call_stats["GT"] == "1/2":
                        call["GT"] = 1
                    else:
                        raise ValueError(
                            "error: invalid GT {GT} @ {CHROM}-{POS}-{REF}"
                            "-{ALT}".format(GT=call_stats["GT"], **fields))
                    ADs = call_stats["AD"].split(",")
                    call["AD_REF"] = ADs[0]
                    pl_scores = call_stats["PL"].split(",")
                    call["PL_AA"] = pl_scores[0]  # PL(AA)
                    call["PL_AB"] = pl_scores[4]  # this is PL(BC)
                    for x, (variant_id, block_id, highest_impact,
                            indel) in enumerate(variant_ids):
                        if indel:
                            if variant_id in indel_ids:
                                continue
                            else:
                                indel_ids.add(variant_id)
                        call["PL_BB"] = pl_scores[2 + 3 * x]
                        # if first alternate allele, use PL(BB); if second alternate allele, use PL(CC)
                        calls_fh.write(
                            VARIANT_CALL_FORMAT.format(**merge_dicts(
                                call, {
                                    "AD_ALT": ADs[1 + x],
                                    "variant_id": variant_id,
                                    "block_id": block_id,
                                    "highest_impact": highest_impact
                                }, INFO)) + "\n")
                # annotate each variant with its variant_id for storage purposes
                line_fields[VCF_COLUMNS_DICT["INFO"]] = (
                    "VariantID=" +
                    ",".join(str(variant_id[0])
                             for variant_id in variant_ids) + ";" +
                    fields["INFO"])
                vcf_out.write("\t".join(line_fields) + "\n")
        # confirm the highest variant_id is still the same; otherwise something
        # else (e.g. another job added a variant and we can run into collisions)
        # we won't get new results unless we commit/reconnect
        db.commit()
        current_max_variant_id = get_max_variant_id(cur, CHROM)
        if max_variant_id != current_max_variant_id:
            raise ValueError(
                "The max variant_id while starting, {max_variant_id}, does not "
                "match the current max variant_id, {current_max_variant_id}".
                format(max_variant_id=max_variant_id,
                       current_max_variant_id=current_max_variant_id))
    finally:
        logger.info("elapsed time on chromosome {}: {} seconds\n".format(
            CHROM,
            time() - start_time))
        if db.open:
            db.close()
Exemple #34
0
 def _excepthook(exc_type, value, tb):
     traceback.print_exception(exc_type, value, tb)
     print()
     ipdb.pm()
Exemple #35
0
    frame_n = int(float(frame_str.split('_')[0]))

    if frame_n > last_t:
        img_cloned = get_specific_frame(frame_n, cap).copy()
        last_t = frame_n

    if key == 'enemys':
        # update in
        try:
            updater.update_with_measures(data['coords'], data['imgs'],
                                         time_now, frame_str)
            measures = updater.get_last_instances()
        except Exception as e:
            raise e
            import ipdb
            ipdb.pm()

        # draw msg bbs TODO USE THINGY ???
        img_cloned_measure = get_specific_frame(frame_n, cap).copy()
        for t in data['coords']:
            x2 = cv2.rectangle(img_cloned_measure, t[0], t[1], (0, 0, 255), 2)
        cv2.imshow('t2', img_cloned_measure)

        # draw msg bbs
        for k, mt in measures.items():
            points = mt.coord
            cv2.rectangle(img_cloned, points[0], points[1],
                          tuple(all_colors[key]), 2)
            cv2.putText(img_cloned, str(k), points[0],
                        cv2.FONT_HERSHEY_SIMPLEX, 0.6, (200, 0, 0), 2,
                        cv2.LINE_AA)
Exemple #36
0
 def info(type, value, tb):
     traceback.print_exception(type, value, tb)
     print
     ipdb.pm()
Exemple #37
0
import inspect,ipdb; ipdb.launch_ipdb_on_exception(); # is not visible to py9
### pkg_reload broken %reload, reload() (.pyc,loads old ver from some cache)
# %tb:
# pdb
# TODO # FIXME # HINT

#--- ipdb h; init in .pdbrc,pdb~ipdb;
# kb(),insp_stack2(),whos2(); from numpy.lib.utils import source; source(fn1) 'fnm+src,good enough';
# help,h; alias,unalias;
# run,restart; where,w,bt; up,u; down,d; next,n; step,s; jump,j;continue,cont,c; return,r; until,unt; commands[cmd to continue]; debug[dbg2];
# whatis;args,a; pinfo,pdef,pdoc; list,l; pp,p # pp get_ipython().magic('who_ls'); src_code,print
# break,b,tbreak,enable,disable,condition,ignore,clear,cl; quit,q,exit; EOF; #bpts
# if stuck on input - do empty line; stuck on output - "q"
# b=123; whos2() 'mixed statemt fail in ipdb'; a?? fails in ipdb,eval(), use numpy.lib.utils.source(fn), insp_stack2,whos2(),
# frm_stack~stack_trace~stack_snapshot, for interactive and post-mortem debugging (pm uses traceback)
%pdb on; %debug~ipdb.pm() # open dbg at latest exception (it clobbers/kills prev ones), init in `InteractiveShell.pdb`;
## ipdb test
clear(); from vm9 import *;
import ipdb; ipdb.launch_ipdb_on_exception(); # ipdb.set_trace()
ipdb.run('wh()'); ipdb.pm() # dbg/traceback printout; ipdb.post_mortem, vars in "old fn frames" are preserved until gc
def set_trace(): from IPython.core.debugger import Pdb; Pdb(color_scheme='Linux').set_trace(sys._getframe().f_back) # set bpt
def debug(f,*args,**kargs): from IPython.core.debugger import Pdb; pdb=Pdb(color_scheme='Linux'); return pdb.runcall(f,*args,**kargs) # dbg_run_fn
def fn1(): a1=1.1; b1='b1_'; print 'in fn1'; fn2(); return
def fn2(): a2=2.2; b2='b2_'; print 'in fn2'; fn3(); return
# def fn3(): a3=4.4; b3='b3_wert'; print 'in fn3,running dbg/ipdb'; ipdb.set_trace(); return
def fn3():
  try: 1/0
  except: pass
  a3=3.3; b3='b3_'; print 'in fn3,running dbg/ipdb'; kb(); 1; # ipdb.set_trace();
ipdb.run('fn1()')
assert x<0,'x too small' # break if error (chk dupl_in_list,broken "invariants"~smth_constant_in_class,like inv_map(map) etc)
Exemple #38
0
#!/usr/bin/env python
#imports go here
import ipdb

#
# Free Coding session for 2014-10-08
# Written by Matt Warren
#

def foo(msg):
    """prints something then raises an exception"""
    # ipdb.set_trace()
    print msg
    try:
        raise Exception("WAT?!")
    except Exception, e:
        ipdb.set_trace()

if __name__=='__main__':
    ipdb.pm()
    foo("Hello World")
Exemple #39
0
def debug_hook(type, value, tb):
    """Launch the ipdb debugger on errors."""
    traceback.print_exception(type, value, tb)
    print
    ipdb.pm()
Exemple #40
0
def _stacktrace_and_pm(type, value, tb):
    import traceback
    traceback.print_exception(type, value, tb)
    mypdb.pm()
 def breaker(type, value, tb):
     import traceback
     import ipdb
     traceback.print_exception(type, value, tb)
     print()
     ipdb.pm()
Exemple #42
0
def info(type, value, tb):
    import traceback
    import ipdb
    traceback.print_exception(type, value, tb)
    print
    ipdb.pm()
Exemple #43
0
o=sys.exc_info()[2]; o=sys.last_traceback; insp_stack2(o)
%tb 'prints tb, mode set up in %xmode'; traceback.print_exc(file=open('fnm.txt','w')); threading.settrace(fn) 'tb_multithr'
from IPython.core.debugger import Tracer; Tracer()()
#--- ipdb h; init in .pdbrc,pdb~ipdb;
# kb(),insp_stack2(),whos2(); from numpy.lib.utils import source; source(fn1) 'fnm+src,good enough';
# help,h; alias,unalias;
# run,restart; where,w,bt; up,u; down,d; next,n; step,s; jump,j;continue,cont,c; return,r; until,unt; commands[cmd to continue]; debug[dbg2];
# whatis;args,a; pinfo,pdef,pdoc; list,l; pp,p # pp get_ipython().magic('who_ls'); src_code,print
# break,b,tbreak,enable,disable,condition,ignore,clear,cl; quit,q,exit; EOF; #bpts
# if stuck on input - do empty line; stuck on output - "q"
# b=123; whos2() 'mixed statemt fail in ipdb'; a?? fails in ipdb,eval(), use numpy.lib.utils.source(fn), insp_stack2,whos2(),
# frm_stack~stack_trace~stack_snapshot, for interactive and post-mortem debugging (pm uses traceback)
%pdb on; %debug~ipdb.pm() # open dbg at latest exception (it clobbers/kills prev ones), init in `InteractiveShell.pdb`;
#--- ipdb test
get_ipython().magic('%reset -f'); from vm0 import *; import ipdb; ipdb.launch_ipdb_on_exception(); # ipdb.set_trace()
ipdb.run('wh()'); ipdb.pm() # dbg/traceback printout; ipdb.post_mortem, vars in "old fn frames" are preserved until gc
def set_trace(): from IPython.core.debugger import Pdb; Pdb(color_scheme='Linux').set_trace(sys._getframe().f_back) # set bpt
def debug(f,*args,**kargs): from IPython.core.debugger import Pdb; pdb=Pdb(color_scheme='Linux'); return pdb.runcall(f,*args,**kargs) # dbg_run_fn
def fn1(): a1=1.1; b1='b1_'; print 'in fn1'; fn2(); return
def fn2(): a2=2.2; b2='b2_'; print 'in fn2'; fn3(); return
# def fn3(): a3=4.4; b3='b3_wert'; print 'in fn3,running dbg/ipdb'; ipdb.set_trace(); return
def fn3():
  try: 1/0
  except: pass
  a3=3.3; b3='b3_'; print 'in fn3,running dbg/ipdb'; kb(); 1; # ipdb.set_trace();
ipdb.run('fn1()')
assert x<0,'x too small' # break if error (chk dupl_in_list,broken "invariants"~smth_constant_in_class,like inv_map(map) etc)
## pydevd: remote_dbg uses dbg_server and py_main_thread; launch dbg_svr, then run pydevd.settrace() in main; set bpt - green_pin,ipdb generates warn;
# start dbg server, F9 (open dbg win,run fnm_in_dbg,stop at bpt), select frm_stack_level in GUI, on bp in Debug window shows "Debug"/extended_frame/fn_stack,"variables" and "expressions (broken a bit)"
# navigate frm_stack in "Debug" window, run cmd in PyDev debug_console; use dir(),whos2() etc (%whos, a?? and oth magics do not work); running in dbg is quite slower;
### want ipdb.post_mortem(sys.last_traceback()) (problem with traceback),remote_dbg; is fn_stack with vars avail in pm?
Exemple #44
0
def interactive_debug(type, value, tb):
    import ipdb, traceback
    traceback.print_exception(type, value, tb)
    ipdb.pm()
Exemple #45
0
def info(type, value, tb):
    traceback.print_exception(type, value, tb)
    print
    ipdb.pm()
Exemple #46
0
 def _excepthook(exc_type, value, tb):
     traceback.print_exception(exc_type, value, tb)
     print()
     pdb.pm()
Exemple #47
0
def interactive_debug(type, value, tb):
    import ipdb, traceback
    traceback.print_exception(type, value, tb)
    ipdb.pm()
def info(type, value, tb):
    ipdb.pm()
Exemple #49
0
 def error_catcher(*exc_info):
     logexcept(exc_info, raise_except=False)
     pdb.pm()