Download presentation
Presentation is loading. Please wait.
Published byScot Nichols Modified over 9 years ago
1
Lane Medical Library & Knowledge Management Center http://lane.stanford.edu Perl Programming for Biologists, Second Edition Part 1: 9/11/2007 Yannick Pouliot, PhD Bioresearch Informationist Lane Medical Library & Knowledge Management Center
2
Lane Medical Library & Knowledge Management Center http://lane.stanford.edu 2 Class Requirements You must have wireless access have the admin password to your machine
3
Lane Medical Library & Knowledge Management Center http://lane.stanford.edu 3 To Do Please download all class materials from http://lane.stanford.edu/howto/index.html?id=_2796 http://lane.stanford.edu/howto/index.html?id=_2796 into C:\course
4
Lane Medical Library & Knowledge Management Center http://lane.stanford.edu 4 Class Focus 1. Creating, writing and reading Excel files 2. Reformatting data files for input to an analysis program 3. Writing and reading from a database such as MS Access or other locally installed relational database, as well as from databases available on the Internet And remember: Ask LOTS OF QUESTIONS
5
Lane Medical Library & Knowledge Management Center http://lane.stanford.edu 5 Cautions All examples pertain to MS Office 2003 Examples still work in MS Office 2007 However, Perl modules used here do not work with MS Office 2007-formatted documents All examples pertain to Perl 5.x, not 6.x V.5 and 6 are NOT compatible V.5 is far more common, so not much of an issue
6
Lane Medical Library & Knowledge Management Center http://lane.stanford.edu 6 So Why Perl? Perl = Practical Extraction and Reporting Language Perl Free Very widely used Especially in biological community Very flexible and portable Not the only language of this type E.g., Python Not the absolute easiest … but pretty easy Not suited for everything E.g., for ultra-fast mathematically-oriented code, C is still best
7
Lane Medical Library & Knowledge Management Center http://lane.stanford.edu 7 Today’s session: - Installing and understanding what is required to run Perl - Understanding the basics of a Perl program
8
Lane Medical Library & Knowledge Management Center http://lane.stanford.edu 8 Part 1: Installation
9
Lane Medical Library & Knowledge Management Center http://lane.stanford.edu 9 Components to Install & Configure 1. Perl itself More accurately, the Perl interpreter We’ll use ActiveState Perl 5.8x (ActivePerl) www.activestate.com/store/freedownload.aspx?prdGuid=81fbce82-6bd5-49bc-a915- 08d58c2648ca 2. Additional Perl modules Module = extra functions not part of the interpreter Described at Comprehensive Perl Archive Network (CPAN)CPAN 3. Open Perl IDE IDE = integrated development environment: Editor to write/edit your program Debugger to find bugs A compiler/interpreter to run your program from within the IDE sourceforge.net/project/showfiles.php?group_id=23334&release_id=91440 sourceforge.net/project/showfiles.php?group_id=23334&release_id=91440 4. Configuring the ODBC manager (next week) Part of Windows Allows different programs to interact with databases on your machine or anywhere on the Web via single “doorway”
10
Lane Medical Library & Knowledge Management Center http://lane.stanford.edu 10 What is an Interpreter? = A program that translates an instruction into the computer’s language and executes it before proceeding to the next instruction = compiled and executed once instruction at a time Perl is usually used in interpreted mode Can also be compiled once (= faster)
11
Lane Medical Library & Knowledge Management Center http://lane.stanford.edu 11 Installing Perl from ActiveState 1. Go to www.activestate.com/store/freedownload.aspx ?prdGuid=81fbce82-6bd5-49bc-a915- 08d58c2648ca www.activestate.com/store/freedownload.aspx ?prdGuid=81fbce82-6bd5-49bc-a915- 08d58c2648ca We’ll be downloading Perl 5.8.x.x: 1. Select Windows MSI package for Windows X86 2. Run the installer 3. Install under c:\Perl
12
Lane Medical Library & Knowledge Management Center http://lane.stanford.edu 12 Installing Additional Perl Modules The fountain of all things Perl: CPAN = Comprehensive Perl Archive Network http://www.cpan.org/ http://www.cpan.org/ What does a module look like?look Why modules? PPM for downloading & installing modules PPM What modules are in MY Perl? What
13
Lane Medical Library & Knowledge Management Center http://lane.stanford.edu 13 Perl Modules We’ll Be Using NameFunction IncludedFile::Copymanipulating files IncludedFile::Findmanipulating files IncludedFile::Pathmanipulating files You do it!File::RenameManipulating files IncludedIO::Fileaccessing the insides of files IncludedSpreadsheet::WriteExcelwriting into an MS Excel spreadsheet IncludedSpreadsheet::ParseExcelparsing an MS Excel spreadsheet IncludedSpreadsheet::BasicReadreading the contents of an MS Excel spreadsheet IncludedWin32::OLEprovides easy access to Windows (e.g., launching Excel) IncludedDBIprovides access to relational databases IncludedDBD::ODBCprovides access to relational databases IncludedURIaccessing URLs IncludedLWP::Simpleinteracting with a Web site via http IncludedArray::Uniquereturns unique elements of an array IncludedList::Uniqreturns unique elements of a list IncludedData :: Dumperdumping data out of a data structure IncludedSwitchswitch function ("multiple if-else-then")
14
Lane Medical Library & Knowledge Management Center http://lane.stanford.edu 14 The PPM Module: Installing Perl Modules the Easy Way Perl modules can downloaded and installed manually from CPAN (hard) They can also be installed via the Perl Package Manager: PPM (easy)
15
Lane Medical Library & Knowledge Management Center http://lane.stanford.edu 15 Installing an environment to run and edit Perl: Integrated Development Environment (IDE)
16
Lane Medical Library & Knowledge Management Center http://lane.stanford.edu 16 Why an IDE? IDE = integrated development environment: Editor to write/edit your program Debugger to find bugs A “runner” (compiler/interpreter) to run your program from within the IDE IDEs provide facilities to facilitate writing & debugging E.g., automatic code highlighting We’ll use Open Perl IDE Free, open source, portable sourceforge.net/project/showfiles.php?group_id=23334&release_id= 91440 sourceforge.net/project/showfiles.php?group_id=23334&release_id= 91440 IDE: Definition, descriptionDefinition, description For our Mac friends: AffrusAffrus
17
Lane Medical Library & Knowledge Management Center http://lane.stanford.edu 17 Installing Open Perl IDE 1. Go to sourceforge.net/project/showfiles.php?group_id= 23334&release_id=91440 sourceforge.net/project/showfiles.php?group_id= 23334&release_id=91440 and download the code 2. Create folder Program Files/OpenPerlIDE 3. Unzip into Program Files/OpenPerlIDE 4. Update Path (under System Properties, Advanced, Environment Variables, System Variables) → this makes it possible to run Open Perl IDE from anywhere on your machine…
18
Lane Medical Library & Knowledge Management Center http://lane.stanford.edu 18 BREAK
19
Lane Medical Library & Knowledge Management Center http://lane.stanford.edu 19 Part 2: What does it all do?
20
Lane Medical Library & Knowledge Management Center http://lane.stanford.edu 20 Example Short Program 1. Start Open Perl IDE 2. Load Simple1.pl 3. Run Simple1.pl
21
Lane Medical Library & Knowledge Management Center http://lane.stanford.edu 21 Learning by Example Simple2.pl
22
Lane Medical Library & Knowledge Management Center http://lane.stanford.edu 22 Exploring Perl’s Major Language Elements Norman Matloff’s introduction to Perl: http://heather.cs.ucdavis.edu/~matloff/Perl/PerlIntro.pdf http://heather.cs.ucdavis.edu/~matloff/Perl/PerlIntro.pdf Perl language referencereference http://en.wikipedia.org/wiki/Perl#Data_types
23
Lane Medical Library & Knowledge Management Center http://lane.stanford.edu 23 Additional Key Books/Resources Learning by example: Perl CookbookPerl Cookbook Perl Programming for Biologists Perl Quick Reference Guide My favorite: Perl Quick ReferencePerl Quick Reference
24
Lane Medical Library & Knowledge Management Center http://lane.stanford.edu 24 Going Further: Programming Tips Plan your program Write down how you intend to process the data in more-or-less plain language Goal: making sure that it really does make sense Hacking doesn’t really pay… Have documentation handy ActivePerl documentation (searchable)documentation Perl language referencereference → eBooks: help served on a silver plattereBooks Lane FAQsFAQ When you’re stuck: Search the Web Google can answer almost any programming question … though quality documentation is still best
25
Lane Medical Library & Knowledge Management Center http://lane.stanford.edu 25 Toying with Excel3.pl, a “real” program
26
Lane Medical Library & Knowledge Management Center http://lane.stanford.edu 26 Excel3.pl: Introducing Object Programming Purpose: From an Excel worksheet that lists public identifiers for DNA sequences associated with genes, the program retrieves: UniGene cluster ID UniGene Gene symbol NCBI Gene ID … and writes the result into another Excel worksheet Mix of procedural and object programmingobject programming Relevant links: http://www.ncbi.nlm.nih.gov/sites/entrez?db=unigene&orig_ db=unigene http://www.ncbi.nlm.nih.gov/sites/entrez?db=unigene&orig_ db=unigene Entrez Utilities Entrez Utilities
27
Lane Medical Library & Knowledge Management Center http://lane.stanford.edu 27 What Excel3.pl Does
28
Lane Medical Library & Knowledge Management Center http://lane.stanford.edu 28 Assignments Look at code for Example3.pl Modify it, break it Write down at least one question so we can talk about it next week
29
Lane Medical Library & Knowledge Management Center http://lane.stanford.edu 29
30
Lane Medical Library & Knowledge Management Center http://lane.stanford.edu 30 eBooks Rule
31
Lane Medical Library & Knowledge Management Center http://lane.stanford.edu 31 What Does A Module Look Like?
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.