30
Introduction to Computational Biology Programming with Matlab

Introduction to Computational Biology

Embed Size (px)

DESCRIPTION

Introduction to Computational Biology. Programming with Matlab. Why Program?. Programming a computer provides: Accuracy Reduce human error Speed and efficiency Processing the human genome manually is impossible Adding all numbers from 1..1000 is a waste of our time Repetition - PowerPoint PPT Presentation

Citation preview

Page 1: Introduction to Computational Biology

Introduction to Computational Biology

Programming with Matlab

Page 2: Introduction to Computational Biology

Why Program?

Programming a computer provides: Accuracy

Reduce human error Speed and efficiency

Processing the human genome manually is impossible Adding all numbers from 1..1000 is a waste of our time

Repetition Same program can be run many times using different

input data Automation

Page 3: Introduction to Computational Biology

Anatomy of a program

Input Instructions OutputData Steps encoded in a

programming languageResults – readable by you or another program

3, 4 Sum 7

GAGCAGACACGTTTTTGGTGGTTTT

GAGCAGACATTTTTTGATTCTGGTTTT

AlignGACAT-TTTTTGATTCTGGTTTT

GACACGTTTTTGG---TGGTTTT|||| |||||| |||||||

Page 4: Introduction to Computational Biology

Computing

A computable task Does it make sense to create a program to solve

my problem? Text Editor

A program that allows you to save text files Emacs (unix), vi (unix), gedit (unix), notepad

(Windows)

Compiler/Interpreter gcc (C), javac (Java), perl (Perl)

Page 5: Introduction to Computational Biology

Strings

“This is a string”

‘This is also a string’

“ACGACTACGACTAGCATCAGCATCAG”

Page 6: Introduction to Computational Biology

vectors

>> v = [3 1]

v =

3 1

Page 7: Introduction to Computational Biology

vectors

>> v = [3 1];

>>

Page 8: Introduction to Computational Biology

Row vectors

>> v = [3 1 7 -21 5 6]

v =

3 1 7 -21 5 6

Page 9: Introduction to Computational Biology

column vectors

>> v = [3 1 7 -21 5 6]'

v =

3 1 7 -21 5 6

Page 10: Introduction to Computational Biology

A new vector

>> v = [1:8]

v =

1 2 3 4 5 6 7 8

Page 11: Introduction to Computational Biology

A new vector with increments of 0.25

>> v = [2:.25:4]

v =

Columns 1 through 7

2.0000 2.2500 2.5000 2.7500 3.0000 3.2500 3.5000

Columns 8 through 9

3.7500 4.0000

Page 12: Introduction to Computational Biology

Accessing vector elements

>> v(1)

ans =

2

Page 13: Introduction to Computational Biology

Basic operations

>> v

v =

0 2 4 6 8

>> v(1:3)?>> v(2:4)?>> v(1:3)-v(2:4)

ans =

-2 -2 -2

Page 14: Introduction to Computational Biology

Basic operations

>> u = [0:-1:-4]

u =

0 -1 -2 -3 -4

>> -2*u

ans =

0 2 4 6 8

Page 15: Introduction to Computational Biology

A matrix: n x n (row x column)

>> A = [ 1 2 3; 3 4 5; 6 7 8]

A =

1 2 3

3 4 5

6 7 8

Page 16: Introduction to Computational Biology

Indexing a matrix

>> A(1:2,3:4)??? Index exceeds matrix dimensions.

>> A(1:2,2:3)

ans =

2 3 4 5

>> A(1:2,2:3)'

ans =

2 4 3 5

A =

1 2 3 3 4 5 6 7 8

Page 17: Introduction to Computational Biology

Vector operations

>> v = [1 2 3]'

v =

1 2 3

>> b = [2 4 6]'

b =

2 4 6

>> v+b

ans =

3 6 9

>> v-b

ans =

-1 -2 -3

Page 18: Introduction to Computational Biology

Plotting

>> v

v =

1

2

3

>> b

b =

2

4

6

>> plot(v,b)

Page 19: Introduction to Computational Biology

Loops>> for j=1:4, jend

j =

1

j =

2

j =

3

j =

4

Page 20: Introduction to Computational Biology

Loops>> v = [1:3:10]

v =

1 4 7 10

>> for j=1:4, v(j) = j;end>> v

v =

1 2 3 4

Page 21: Introduction to Computational Biology

If statements

a = 2;

b = 3;

if (a<b)

j = -1;

end

Page 22: Introduction to Computational Biology

If and elseif statements

a = 4;

b = 3;

if (a<b)

j = -1;

else if (a>b)

j = 2;

end

Page 23: Introduction to Computational Biology

Character arrays

>> c = ’atcg’

Page 24: Introduction to Computational Biology

Example 1: find the complementfunction c = watson_crick(v)

%This is a function m-file for finding the Watson-Crick complement of a %string of nucleotide symbols%%%Author: Winfried Just% Department of Mathematics% Ohio University% Athens, OH 45701% [email protected]%%Date: March 31, 2005

%Input: v - string of letters from the alphabet {a, c, g, t}%Output: c - the string of Watson-Crick complements to the terms of v%

http://www.math.ohiou.edu/~just/bioinfo05/supplements/MLBasicsIV/watson_crick.m

Page 25: Introduction to Computational Biology

Example 1 cont.

function c = watson_crick(v)

for i = 1:length(v) if v(i) == 'a' c(i) = 't'; elseif v(i) == 'c' c(i) = 'g'; elseif v(i) == 'g' c(i) = 'c'; elseif v(i) == 't' c(i) = 'a'; else c(i) = '?'; disp('Non-nucleotide symbol encountered'); end end

Page 26: Introduction to Computational Biology

Run watson_crick

>> watson_crick (’accgatgcttatggatc’)

Page 27: Introduction to Computational Biology

Example 2: find the AUG

function start_codon(v)

%This is a function m-file for finding the position of the first start codon %%%Author: Winfried Just% Department of Mathematics% Ohio University% Athens, OH 45701% [email protected]%%Date: March 31, 2005

%Input: v - string of letters from the alphabet {a, c, g, t}%Output: a message that shows the position of the first % start codon in v%

Page 28: Introduction to Computational Biology

Example 2: find the AUG

function start_codon(v)found = 0; %this variable will tell us when we have found a start codon i = 1; while ~found & i < length(v) - 1 if v(i) == 'a' & v(i+1) == 't' & v(i+2) == 'g' found = 1; disp(['start codon at position ', num2str(i)]) else i = i+1; end end if ~found disp('no start codon found') end

http://www.math.ohiou.edu/~just/bioinfo05/supplements/MLBasicsIV/start_codon.m

Page 29: Introduction to Computational Biology

Run start_codon

>> start_codon(’accgatgcttatggatc’)

Page 30: Introduction to Computational Biology

Examples relevant to biology

Log-log plot http://www.math.ohiou.edu/courses/matla

b/math266a/266A-fitting-logplot.pdf