Скачать презентацию Introduction to LISP Programming of Pathway Tools Queries Скачать презентацию Introduction to LISP Programming of Pathway Tools Queries

fca1bd3627e66b6d14ea19e95698733b.ppt

  • Количество слайдов: 18

Introduction to LISP Programming of Pathway Tools Queries and Updates Introduction to LISP Programming of Pathway Tools Queries and Updates

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

LISP and GFP References l l l SRI International Bioinformatics Lisp on the web: LISP and GFP References l l l SRI International Bioinformatics Lisp on the web: ALU. org 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 http: //bioinformatics. ai. sri. com/ptools-resources. html l http: //www. ai. sri. com/pkarp/loop. html l http: //bioinformatics. ai. sri. com/ptools/debugger. html

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

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

SRI International Bioinformatics LISP Expressions and Evaluation l l (+ 3 4 5) l SRI International Bioinformatics LISP Expressions and Evaluation l l (+ 3 4 5) l ‘+’ is a function l (+ 3 4 5) 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 (+ 2 3 1 3 4 5 6) ----> 24 l (+ (* 3 4) 6) --> 18 l Turning off evaluation with Quote l ’(+ 1 3) ----> (+ 1 3)

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

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

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

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

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

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

Functions for Operating on Lists SRI International Bioinformatics l Length l (length x) l Functions for Operating on Lists SRI International Bioinformatics l Length l (length x) l Returns the number of elements in the list X l First l (first x) l Returns the first element in the list X l 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 l Nth l (nth j x)

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

Arglist Keywords l l SRI International Bioinformatics Are markers in arglist Not themselves argument Arglist Keywords l l SRI International Bioinformatics 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 plus 5 (x &optional (y 5)) (+ x y) ) l (plus 5 3) ==> 8 (plus 5 4 4) ==> 8 l (defun embed (x &key (y “<<<“) (z “>>>”)) (concatenate ‘string y x z) ) (embed “foo” : z “]]]”) ==> “<<

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

Example Session SRI International Bioinformatics (setq x ‘trp) => trp (get-slot-value x ‘common-name) => Example Session SRI International Bioinformatics (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

Example Session SRI International Bioinformatics (loop for x in genes for name = (get-slot-value Example Session SRI International Bioinformatics (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 *)