[Biopython-dev] skipping a bad record in SeqIO.parse

Iddo Friedberg idoerg at gmail.com
Sun Jun 7 02:33:47 UTC 2009


Suppose SeqIO throws an exception due to a bad record. I want to note that
in stderr an move on to the next record. How do i do that?


The following eyesore of a code simply leaves me stuck reading the same bad
record over and over:

   seq_reader = SeqIO.parse(in_handle, format)
    while True:
        try:
            seq_record = seq_reader.next()
        except StopIteration:
            break
        except:
            if debug:
                sys.stderr.write("Sequence not read: %s%s" % (seq_record.id,
os.linesep))
                sys.stderr.flush()
            continue
        if not seq_record:
            break





-- 
Iddo Friedberg, Ph.D.
Atkinson Hall, mail code 0446
University of California, San Diego
9500 Gilman Drive
La Jolla, CA 92093-0446, USA
T: +1 (858) 534-0570
http://iddo-friedberg.org



More information about the Biopython-dev mailing list