Introduction%20to%20LISP%20Programming%20of%20Pathway%20Tools%20Queries%20and%20Updates - PowerPoint PPT Presentation

About This Presentation
Title:

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

Description:

http://bioinformatics.ai.sri.com/ptools/ptools-resources.html. http://www.ai.sri.com/pkarp/loop.html. http://bioinformatics.ai.sri.com/ptools/debugger.html ... – PowerPoint PPT presentation

Number of Views:88
Avg rating:3.0/5.0
Slides: 19
Provided by: pangeasy
Category:

less

Transcript and Presenter's Notes

Title: Introduction%20to%20LISP%20Programming%20of%20Pathway%20Tools%20Queries%20and%20Updates


1
Introduction to LISP Programming of Pathway
Tools Queries and Updates
2
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
LISP and GFP References
  • Lisp on the web ALU.org
  • ANSI Common LISP
  • Paul Graham
  • Common LISP, the Language -- The standard
    reference
  • Guy L. Steele
  • On Common LISP
  • Paul Graham
  • The Art of the Metaobject Protocol
  • Kiczales, Rivieres, Bobrow
  • Information on writing Pathway Tools queries
  • http//bioinformatics.ai.sri.com/ptools/ptools-res
    ources.html
  • http//www.ai.sri.com/pkarp/loop.html
  • http//bioinformatics.ai.sri.com/ptools/debugger.h
    tml

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

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

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

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

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

9
Lisp Variables
  • Global variable values can be set and used during
    a session
  • Declarations not needed
  • (setq x 5)
  • -gt 5
  • x
  • -gt 5
  • ( 3 x)
  • -gt 8
  • (setq y atgc)
  • -gt atgc

10
Examples
  • (select-organism org-id ecoli)
  • -gt ECOLI
  • (setq genes (get-class-all-instances Genes))
  • -gt ()
  • (setq monomers (get-class-all-instances
    Polypeptides))
  • -gt (.)
  • (setq genes2 genes)
  • -gt (.)

11
LISP Lists
  • Fundamental to LISP LISt Processing
  • Zero or more elements enclosed by parentheses
  • Typing a list to the listener
  • (this is a list) gt (THIS IS A LIST)
  • Creating a list with functions
  • (list so is this) gt (SO IS THIS)
  • Examples
  • (1 3 5 7), ((2 4 6) 10 (0 8)), (1 this T NIL
    that)
  • The empty list nil ()

12
List Examples
  • (length genes)
  • -gt 4316
  • (first genes)
  • -gt XXX
  • (subseq genes 0 50)
  • -gt ()
  • (nth 3 genes)
  • -gt XXX

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

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

15
LISP Symbols
  • Think of them as words in a dictionary, not
    strings
  • Lisp looks to see if symbol already exists
  • 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
Symbols vs Strings
  • (setq x trp)
  • -gt TRP
  • (eq x trp)
  • -gt T
  • (setq y trp)
  • -gt trp
  • (eq y trp)
  • -gt NIL
  • (equal y trp)
  • -gt T

17
Example Session
  • (setq x (trp arg))
  • gt (TRP ARG)
  • (replace-answer-list x)
  • gt (TRP ARG)
  • (eco)

18
Defining Functions
  • Put function definitions in a file
  • Reload the file when definitions change
  • (defun ltnamegt (ltargumentsgt)
  • code for function )
  • Creates a new operation called ltnamegt
  • Examples
  • (defun square (x)
  • ( x x))
  • (defun message ()
  • (print Hello))
  • (defun test-fn ()
  • 1 2 3 4)

19
Arglist Keywords
  • Are markers in arglist
  • Not themselves argument names, but flag that
    following arguments are different somehow
  • Most common are
  • optional
  • rest
  • key
  • Examples
  • (defun plus5 (x optional (y 5)) ( x y) )
  • (plus5 3) gt 8 (plus5 4 4) gt 8
  • (defun embed (x key (y ltltlt) (z gtgtgt))
    (concatenate string y x z) )
  • (embed foo z ) gt ltltltfoo
  • (defun listall (rest rest-of-args) (sort
    (copy-seq rest-of-args) lt))

20
Problems
  • all-substrates
  • enzymes-of-reaction
  • genes-of-reaction
  • genes-of-pathway
  • monomers-of-protein
  • genes-of-enzyme

21
Example Session
  • (setq x trp)
  • gt trp
  • (get-slot-value x common-name)
  • gt L-tryptophan
  • (setq aas (get-class-all-instances
    Amino-Acids))
  • gt (..)
  • (loop for x in aas count x)
  • gt 20

22
Example Session
  • (loop for x in genes
  • for name (get-slot-value x
    common-name)
  • when (and name (search trp name))
  • collect x))
  • -gt ()
  • (setq rxns (get-class-all-instances
    Reactions))
  • -gt ()
  • (loop for x in rxns
  • when (member-slot-value-p x substrates
    trp)
  • collect x)
  • -gt ()
  • (replace-answer-list )
Write a Comment
User Comments (0)
About PowerShow.com