Introduction to LISP Programming of Pathway Tools Queries and Updates.

Slides:



Advertisements
Similar presentations
CS 63 LISP Philip Greenspun's Tenth* Rule of Programming:
Advertisements

Lisp. Versions of LISP Lisp is an old language with many variants Lisp is alive and well today Most modern versions are based on Common Lisp LispWorks.
C-LISP. LISP 2 Lisp was invented by John McCarthy in 1958 while he was at the Massachusetts Institute of Technology (MIT).John McCarthyMassachusetts Institute.
Scheme in Scheme. Why implement Scheme in Scheme  Implementing a language is a good way to learn more about programming languages  Interpreters are.
Functional Programming. Pure Functional Programming Computation is largely performed by applying functions to values. The value of an expression depends.
1 Programming Languages and Paradigms Lisp Programming.
Lambda Calculus and Lisp PZ03J. Lambda Calculus The lambda calculus is a model for functional programming like Turing machines are models for imperative.
CS 355 – PROGRAMMING LANGUAGES Dr. X. Apply-to-all A functional form that takes a single function as a parameter and yields a list of values obtained.
Lisp – Introduction יעל נצר מערכות נבונות סמסטר ב' תשס"ו.
CS Lecture 03 Outline Sed and awk from previous lecture Writing simple bash script Assignment 1 discussion 1CS 311 Operating SystemsLecture 03.
Introduction to Artificial Intelligence Lisp Ruth Bergman Fall 2002.
CMSC 471 LISP. Why Lisp? Because it’s the most widely used AI programming language Because it’s good for writing production software (Graham article)
TES3111 October 2001 Artificial Intelligence LISP.
JavaScript, Third Edition
CSE S. Tanimoto Introduction 1 LISP Lisp is worth learning for the profound enlightenment experience you will have when you finally get it; that.
LISP A brief overview. Lisp stands for “LISt Process” –Invented by John McCarthy (1958) –Simple data structure (atoms and lists) –Heavy use of recursion.
COMP 205 – Week 11 Dr. Chunbo Chu. Intro Lisp stands for “LISt Process” Invented by John McCarthy (1958) Simple data structure (atoms and lists) Heavy.
Lisp and Scheme I. Versions of LISP LISP is an acronym for LISt Processing language Lisp is an old language with many variants – Fortran is the only older.
LISP 1.5 and beyond A very quick tour. Data Atoms (symbols) including numbers – All types of numbers including Roman! (well, in the early days) – Syntactically.
Allegro CL Certification Program Lisp Programming Series Level I Session Overview of Common Lisp.
Input/Output Chapters 7 & 9. Output n Print produces output > (print 100) n It also returns the value it printed –that’s where the second 100 came.
Basic Lisp CIS 479/579 Bruce R. Maxim UM-Dearborn.
1 Lisp Functions –Built-in functions –Defining functions –Function Evaluation and Special Forms defun, if Control statements –Conditional if, cond –Repetition.
Functional Programming in Scheme
Introduction to Scheme Lectures on The Scheme Programming Language, 2 nd Ed. R. Kent Dybvig.
Artificial Intelligence IES 503 Asst. Prof. Dr. Senem Kumova Metin.
Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
Basic LISP Programming Common LISP follows the algorithm below when interacting with users: loop read in an expression from the console; evaluate the expression;
Introducing Python CS 4320, SPRING Lexical Structure Two aspects of Python syntax may be challenging to Java programmers Indenting ◦Indenting is.
Predicates, Functions and Files "I suppose I should learn Lisp, but it seems so foreign." - Paul Graham, Nov 1983.
LISP Data Types Functional Programming Academic Year Alessandro Cimatti
Introduction to LISP. Lisp Extensible: It lets you define new operators yourself Lisp programs are expressed as lisp data structures –You can write programs.
Python Primer 1: Types and Operators © 2013 Goodrich, Tamassia, Goldwasser1Python Primer.
UMBC CMSC Common Lisp II. UMBC CMSC Input and Output Print is the most primitive output function > (print (list 'foo 'bar)) (FOO BAR) The.
Copyright © 2003 ProsoftTraining. All rights reserved. Perl Fundamentals.
Lisp and Scheme I. Versions of LISP LISP is an acronym for LISt Processing language Lisp is an old language with many variants – Fortran is the only older.
1 Lecture 9 Shell Programming – Command substitution Regular expressions and grep Use of exit, for loop and expr commands COP 3353 Introduction to UNIX.
Milos Hauskrecht (PDF) Hieu D. Vu (PPT) LISP PROGARMMING LANGUAGE.
SRI International Bioinformatics 1 The Structured Advanced Query Page Mario Latendresse Tomer Altman Bioinformatics Research Group SRI International March,
Basic Scripting & Variables Yasar Hussain Malik - NISTE.
SRI International Bioinformatics 1 The Structured Advanced Query Page Tomer Altman Mario Latendresse Bioinformatics Research Group SRI International April.
Shell Scripting September 27, 2004 Class Meeting 6, Part II * Notes adapted by Lenwood Heath from previous work by other members of the CS faculty at Virginia.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
LISP LISt Processing. History & Overview b b One of the oldest high level programming languages. b b First developed in 1958 by John McCarthy. b b Later.
1 Outline Review Introduction to LISP Symbols and Numbers Lists Writing LISP Functions LISPWorks.
Constructing Complex Queries in Pathway Tools using Emacs, Lisp, and Perl Randy Gobbel, Ph.D. May 14, 2003
Artificial Intelligence and Lisp Lecture 6 LiU Course TDDC65 Autumn Semester,
CS 330 Class 7 Comments on Exam Programming plan for today:
Section 15.4, 15.6 plus other materials
Ruby: An Introduction Created by Yukihiro Matsumoto in 1993 (named after his birthstone) Pure OO language (even the number 1 is an instance of a class)
LISP LISt Processing.
LISP A brief overview.
CSE S. Tanimoto Introduction
Modern Programming Languages Lecture 20 Fakhar Lodhi
CSE S. Tanimoto Introduction
Lisp and Scheme I.
Allegro CL Certification Program
Lisp: Using Functions as Data
Python Primer 1: Types and Operators
LISP A brief overview.
C Programming Getting started Variables Basic C operators Conditionals
CSE S. Tanimoto Introduction
LISP LISt Processing.
Lisp: Using Functions as Data
LISP LISt Processing.
Modern Programming Languages Lecture 18 Fakhar Lodhi
Common Lisp II.
Lisp.
Allegro CL Certification Program
CSE 3302 Programming Languages
Presentation transcript:

Introduction to LISP Programming of Pathway Tools Queries and Updates

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

SRI International Bioinformatics LISP and GFP References 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 l l

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)

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)

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)

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

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)

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

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) -> (…………….)

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 ()

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

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)

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

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

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

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

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 () )

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 ]]]) ==> <<<foo]]] l (defun listall (&rest rest-of-args) (sort (copy-seq rest-of-args) #<))

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

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

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 *)