Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to LISP Programming of Pathway Tools Queries and Updates.

Similar presentations

Presentation on theme: "Introduction to LISP Programming of Pathway Tools Queries and Updates."— Presentation transcript:

1 Introduction to LISP Programming of Pathway Tools Queries and Updates

2 SRI International Bioinformatics Myths and Facts About Lisp Myth: Lisp runs interpreted only Fact: All major Lisp implementations have compilers Myth: Lisp uses huge amounts of memory Fact: Baseline Lisp installation requires 8-10MB Myth: Lisp is complicated Fact: Lisp is much simpler and more elegant than Perl

3 SRI International Bioinformatics LISP and GFP References Lisp on the web: ANSI Common LISP l Paul Graham Common LISP, the Language -- The standard reference l Guy L. Steele On Common LISP l Paul Graham The Art of the Metaobject Protocol l Kiczales, Rivieres, Bobrow Information on writing Pathway Tools queries: l l l

4 SRI International Bioinformatics Accessing Lisp through the Pathway Tools Starting Pathway Tools for Lisp work: l pathway-tools –lisp l (select-organism :org-id XXX) Lisp expressions can be typed at any time to the Pathway Tools listener l Command: (get-slot-value trp common-name) -> L- tryptophan Invoking the Navigator from Lisp: l (eco)

5 SRI International Bioinformatics LISP Syntax Prefix notation Simple and clean syntax l Expressions are delimited by parentheses The same syntax is used for programs and for data l ( ) l (a b c d e f) l (+ 1 2) l (subseq abcdefg 0 2)

6 SRI International Bioinformatics LISP Expressions and Evaluation ( ) l + is a function l ( ) is a function call with 3 arguments Arguments are evaluated: l Numbers evaluate to themselves l If any of the args are themselves expressions, they are evaled in the same way l (+ 1 (+ 3 4)) The values of the args are passed to the function Because of prefix notation, variable number of args l (+) ---> 0 l (+ 1) ---> 1 l ( ) ----> 24 (+ (* 3 4) 6) --> 18 Turning off evaluation with Quote l (+ 1 3) ----> (+ 1 3)

7 SRI International Bioinformatics LISP Listener Also called top level and read-eval-print loop Expressions typed in listener are evaluated interactively Uses a three-step process l Read u Reader converts elements outside and || to uppercase l Evaluate l Print Useful forms in listener: l Previous Results: *, **, *** l DO NOT use in programs (+ 1 2) -> 3 (+ 3 *) -> 6 ** -> 3

8 SRI International Bioinformatics LISP Data Types Usual types in other languages: l Numbers -- 2, 312, 1.45, -222e2 l Strings -- sky, this is a lisp intro l Characters - #\D, #\space l Hashtables l True/False T / NIL Fundamental LISP data types l Symbols - BLUE, :CONT l Lists - (1 2 3) (a b c) (a 2 X)

9 SRI International Bioinformatics Lisp Variables Global variable values can be set and used during a session Declarations not needed (setq x 5) -> 5 x -> 5 (+ 3 x) -> 8 (setq y atgc) -> atgc

10 SRI International Bioinformatics Examples (select-organism :org-id ecoli) -> ECOLI (setq genes (get-class-all-instances |Genes|)) -> (……………) (setq monomers (get-class-all-instances |Polypeptides|)) -> (…………….) (setq genes2 genes) -> (…………….)

11 SRI International Bioinformatics LISP Lists Fundamental to LISP ::: LISt Processing Zero or more elements enclosed by parentheses Typing a list to the listener: l (this is a list) => (THIS IS A LIST) Creating a list with functions : l (list so is this) => (SO IS THIS) Examples: l ( ), ((2 4 6) 10 (0 8)), (1 this T NIL that) l The empty list: nil ()

12 SRI International Bioinformatics List Examples (length genes) -> 4316 (first genes) -> XXX (subseq genes 0 50) -> (……………) (nth 3 genes) -> XXX

13 SRI International Bioinformatics Functions for Operating on Lists Length l (length x) l Returns the number of elements in the list X First l (first x) l Returns the first element in the list X Subseq l (subseq x j k) l Returns a newly created list containing a subsequence of list X, starting at element number J and ending before element number K Nth l (nth j x) l Returns the Jth element of list X (element 0 is the first element)

14 SRI International Bioinformatics Equality in LISP Internally LISP refers to objects via pointers Fundamental equality operation is EQ l True if the two arguments point to the same object l Very efficient Other comparison operators: l = for numbers: (= x 4) l EQUAL for list structures or exact string matching: (equal x abc) l STRING-EQUAL for case-insensitive string matching: (string-equal x AbC) l EQL for characters: (eql x #\A) l EQ for list structures or symbols (compares pointers): (eq x ABC) l FEQUAL for frames: (fequal x trp) Simple rule: Use EQUAL for everything except frames

15 SRI International Bioinformatics LISP Symbols Think of them as words in a dictionary, not strings l Lisp looks to see if symbol already exists l If so, it returns a pointer to that symbol, otherwise it creates a new one Similar to strings, but different Symbols live in packages, strings do not

16 SRI International Bioinformatics Symbols vs Strings (setq x trp) -> TRP (eq x trp) -> T (setq y trp) -> trp (eq y trp) -> NIL (equal y trp) -> T

17 SRI International Bioinformatics Example Session (setq x (trp arg)) => (TRP ARG) (replace-answer-list x) => (TRP ARG) (eco)

18 SRI International Bioinformatics Defining Functions Put function definitions in a file Reload the file when definitions change (defun ( ) … code for function …) Creates a new operation called Examples: l (defun square (x) (* x x)) l (defun message () (print Hello)) l (defun test-fn () )

19 SRI International Bioinformatics Arglist Keywords Are markers in arglist Not themselves argument names, but flag that following arguments are different somehow Most common are: l &optional l &rest l &key Examples: l (defun plus5 (x &optional (y 5)) (+ x y) ) l (plus5 3) ==> 8 (plus5 4 4) ==> 8 l (defun embed (x &key (y >>)) (concatenate string y x z) ) l (embed foo :z ]]]) ==> <<

20 SRI International Bioinformatics Problems all-substrates enzymes-of-reaction genes-of-reaction genes-of-pathway monomers-of-protein genes-of-enzyme

21 SRI International Bioinformatics Example Session (setq x trp) => trp (get-slot-value x common-name) => L-tryptophan (setq aas (get-class-all-instances |Amino-Acids|)) => (……..) (loop for x in aas count x) => 20

22 SRI International Bioinformatics Example Session (loop for x in genes for name = (get-slot-value x common-name) when (and name (search trp name)) collect x)) -> (…) (setq rxns (get-class-all-instances |Reactions|)) -> (…) (loop for x in rxns when (member-slot-value-p x substrates trp) collect x) -> (…) (replace-answer-list *)

Download ppt "Introduction to LISP Programming of Pathway Tools Queries and Updates."

Similar presentations

Ads by Google