def summary(args):
    """
    %prog summary fastafile

    Report the number of bases and sequences masked.
    """
    p = OptionParser(summary.__doc__)

    opts, args = p.parse_args(args)

    if len(args) != 1:
        sys.exit(not p.print_help())

    fastafile, = args
    f = Fasta(fastafile, index=False)

    halfmaskedseqs = set()
    allmasked = 0
    allbases = 0
    cutoff = 50
    for key, seq in f.iteritems():
        masked = 0
        for base in seq:
            if base not in "AGCT":
                masked += 1
        seqlen = len(seq)
        if masked * 100. / seqlen > cutoff:
            halfmaskedseqs.add(key)
        allmasked += masked
        allbases += seqlen

    seqnum = len(f)
    maskedseqnum = len(halfmaskedseqs)

    print("Total masked bases: {0}".\
            format(percentage(allmasked, allbases)), file=sys.stderr)
    print("Total masked sequences (contain > {0}% masked): {1}".\
            format(cutoff, percentage(maskedseqnum, seqnum)), file=sys.stderr)
def summary ( args ) : p = OptionParser ( summary . __doc__ ) opts , args = p . parse_args ( args ) if len ( args ) != 1 : sys . exit ( not p . print_help ( ) ) fastafile , = args f = Fasta ( fastafile , index = False ) halfmaskedseqs = set ( ) allmasked = 0 allbases = 0 cutoff = 50 for key , seq in f . iteritems ( ) : masked = 0 for base in seq : if base not in "AGCT" : masked += 1 seqlen = len ( seq ) if masked * 100. / seqlen > cutoff : halfmaskedseqs . add ( key ) allmasked += masked allbases += seqlen seqnum = len ( f ) maskedseqnum = len ( halfmaskedseqs ) print ( "Total masked bases: {0}" . format ( percentage ( allmasked , allbases ) ) , file = sys . stderr ) print ( "Total masked sequences (contain > {0}% masked): {1}" . format ( cutoff , percentage ( maskedseqnum , seqnum ) ) , file = sys . stderr )
%prog summary fastafile

    Report the number of bases and sequences masked.