250 likes | 455 Views
Introduction to Python II. BCHB524 2009 Lecture 2 . Outline. DNA as a string Extracting codons in DNA Counting in-frame codons in DNA Reverse Complement User Input Using the Python IDE (IDLE) Command-line arguments Using the Command-Line. DNA as a string. DNA as a string.
E N D
Introduction to Python II BCHB5242009Lecture 2 BCHB524 - 2009 - Edwards
Outline • DNA as a string • Extracting codons in DNA • Counting in-frame codons in DNA • Reverse Complement • User Input • Using the Python IDE (IDLE) • Command-line arguments • Using the Command-Line BCHB524 - 2009 - Edwards
DNA as a string BCHB524 - 2009 - Edwards
DNA as a string • What about upper and lower case? • ATG vs atg? • Differences between DNA and RNA sequence? • Substitute U for each T? • How about ambiguous nucleotide symbols? • What should we do with ‘N’ and other ambiguity codes (R, Y, W, S, M, K, H, B, V, D)? • Strings don’t know any biology! BCHB524 - 2009 - Edwards
DNA as a string BCHB524 - 2009 - Edwards
DNA as a string BCHB524 - 2009 - Edwards
DNA as a string BCHB524 - 2009 - Edwards
Creating and Running Python Scripts • Creating new scripts: • File >> New Window • Write script as desired • Save in My Documents >> BCHB524 • In IDLE: • File >> Open (browse to script.py) • Run >> Run Module (or just hit F5) • Results are in command window • From Command-Line: • python script.py • *Double-click on script.py BCHB524 - 2009 - Edwards
Creating reusable programs • Need to get input data and options from the user • …often us, but sometimes others, or us later. • Sometimes, want completely new inputs • …but often, want the same or similar input. • Sometimes, typing the input is OK • …but often, want to use data in a file. • Sometimes, output to the screen is OK • …but often, want the result to go into a file. BCHB524 - 2009 - Edwards
Program I/O Options • Use IDLE • Good for testing, quick easy, inflexible • Input is “hard-coded” into script. • Use IDLE to change input data in script. • Use IDLE, with raw_input • Program input from the keyboard (or copy-and-paste) • Command-line • Quickly repeat or change program inputs • Easily do input/output from keyboard/screen or files • Copy-and-paste in a pinch • Best integration with other tools • Similar facilities available in most other operating systems BCHB524 - 2009 - Edwards
Use IDLE BCHB524 - 2009 - Edwards
Use IDLE and raw_input BCHB524 - 2009 - Edwards
Command-Line BCHB524 - 2009 - Edwards
Command-Line BCHB524 - 2009 - Edwards
Command-Line BCHB524 - 2009 - Edwards
Command-Line BCHB524 - 2009 - Edwards
Command-Line • Up-Arrow and Down-Arrow for command history • Can easily capture output to a file • Can easily specify filenames as input • Get filename completion using TAB BCHB524 - 2009 - Edwards
Capture output using the Command-Line • Capture program output using “>” • Errors are still printed to the console BCHB524 - 2009 - Edwards
Read sequence from file • Filenames as command-line arguments. • MAGIC to read sequence from the file. BCHB524 - 2009 - Edwards
Complete Program BCHB524 - 2009 - Edwards
Complete Program Usage BCHB524 - 2009 - Edwards
Complete Program II BCHB524 - 2009 - Edwards
Complete Program II BCHB524 - 2009 - Edwards
Lab Exercises • Try each of the examples shown in these slides & make sure you understand them! • Use UniSTS (“google UniSTS”) to look up PCR markers for your favorite gene • For each forward and reverse primer, compute the reverse complement sequence BCHB524 - 2009 - Edwards
Lab Exercises • Write a program to test whether a PCR primer is a reverse complement palindrome. • Such a primer might fold and self-hybridize! • Test your program on the following primers: • TTGAGTAGACGCGTCTACTCAA • TTGAGTAGACGTCGTCTACTCAA • ATATATATATATATAT • ATCTATATATATGTAT BCHB524 - 2009 - Edwards