% class-4 talking points announcements - be sure to check course home page and refresh midcourse evaluations - there won't be any big changes recursion.py, review recursion from last week's quiz good quiz for diagnostic purposes - lots of different ways to go wrong: - print function *invocation* as well as function body - prints from each pending function call, not just once at the end - prints in reverse invocation order (because print follows function return) add even more prints: before *and* after recursive call, with idents compare to factorial in book 6.9, p. 79 (but he does indents backwards) alternative: run in debugger (I prefer printouts) key idea: all recursive calls in memory at once, all the data is stored but implicit, not explicit recursive algorithms make elegant use of that recursion is most useful for nested data structures see recursive directory lister in book 14.4, 162 strings_files.py strings and files -- it's starting to get interesting, can do real work strings are a new type str, types have values and operations string ops ==, <, >, +, * analogous to numeric types, but also in, find ... strings have structure - made up of characters (characters are not a distinct type, just strings of length 1) strings are indexed (addressable), slice notation strings are iterable - you can use them in 'for' statement: for c in s: ... strings are immutable, can't change them, must create new ones files, yes they're on disk, persistent, known to OS. BUT also... files are a type: file - also have structure and operations files are iterable: for line in f: ... many things are made to work like files: also processes, web pages, (sockets?) fd = open(...), pd = popen(...), but also wd = urlopen(...), In general different types have a lot of similarities, there was an effort to make different types work the same way when possible, or to differ along a few key properties like mutable/immutable. We'll consider this more deeply later in the course. exceptions - typical Python style, "easier to ask forgiveness than permission" try/except is another control structure like for... or if... book 14.5 163, better: except IOError Don't mask other errors! Also: os module Quiz (break) review quiz Presenters: (break) bio_demo.py, regexp and biopython example string library (show the PQR2.6.html), also format strings, regexp, os library regexp - only when string library won't do! example, protein structure: problem: find a pattern in a protein - ceru_human is human ceruloplasmin (see refs in file itself) - PS00079 is a prosite pattern, "Multicopper oxidases signature" data in file format called SwissProt (after database) use BioPython package to help analyze it (must be installed) BioPython has modules to read SwissProt files and many many others open the file, get fd use SwissProt.read to get record with attributes this read is defined in BioPython.SwissProt, not same read as book 14.8, 166 we're interested in r.sequence, a string, that's what we'll search using re in Python: compile, then search returns match object with m.start etc. A (one-off )script: ad-lib programming in interpreter, then save in module. No functions are defined. (break, adjourn)