r 於微陣列數據分析 - bioinformatics analysis in perl -

30
R 於於於於於於於於 -Bioinformatics analysis in Perl- 於於 : 於於於 於於 於於 : 於於於 E-mail: [email protected]

Upload: ringo

Post on 23-Feb-2016

107 views

Category:

Documents


0 download

DESCRIPTION

R 於微陣列數據分析 - Bioinformatics analysis in Perl -. 教師 : 黃宣誠 老師 助教 : 林振慶 E-mail: [email protected]. Outline. Perl Basics. Perl Installation. http://www.activestate.com/activeperl. Look of perl. Syntax. Variables. $ var scalar @ var array % var hash ; #. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: R 於微陣列數據分析 - Bioinformatics analysis in  Perl -

R 於微陣列數據分析-Bioinformatics analysis in Perl-

教師 : 黃宣誠 老師助教 : 林振慶E-mail: [email protected]

Page 2: R 於微陣列數據分析 - Bioinformatics analysis in  Perl -

Outline

07/26

Syntax

Perl BasicsData StructureSubroutinePackage Installation and Searching

07/31Regular Expression

Advanced PerlData ParsingID Mapping

08/02 Biological Network ImplementationFunctional Enrichment

Page 3: R 於微陣列數據分析 - Bioinformatics analysis in  Perl -

Perl Basics

Page 4: R 於微陣列數據分析 - Bioinformatics analysis in  Perl -

Perl Installation

• http://www.activestate.com/activeperl

Page 5: R 於微陣列數據分析 - Bioinformatics analysis in  Perl -

SyntaxLook of perl

Page 6: R 於微陣列數據分析 - Bioinformatics analysis in  Perl -

Variables

• $var– scalar

• @var – array

• %var– hash

• ;• #

Page 7: R 於微陣列數據分析 - Bioinformatics analysis in  Perl -

Control Flow (Condition)

• if(condition1)• elsif(condition2)• else• unless(condition1)• else• Ternary operator - ?– $a = ($b > 5) ? “yes” : “no”;

Page 8: R 於微陣列數據分析 - Bioinformatics analysis in  Perl -

True or False

• False– 0– ‘0’ 、” 0” 、’’、””– undef– Undefined value

• True– others

Page 9: R 於微陣列數據分析 - Bioinformatics analysis in  Perl -

Control Flow (Loop)

• while (condition)• until (condition)• for(condition)• foreach(array)• last and next– last: exit this loop– next: ignore below statements

Page 10: R 於微陣列數據分析 - Bioinformatics analysis in  Perl -

Data StructureThe pivot part of perl

Page 11: R 於微陣列數據分析 - Bioinformatics analysis in  Perl -

Scalar

• $– $A = 55;– $B = “55”;– $C = ‘Hello Perl!\n’;– $D = “Hello Perl!\n”– $E = \$A;– +, -, *, /, %, **,

• <STDIN>

Page 12: R 於微陣列數據分析 - Bioinformatics analysis in  Perl -

Array

• @–@Empty = ();–@A = (1, 2, 3); @B = (‘a’, ‘b’, ‘c’);– $A[0] == 1– $A[0] = 4;–@A == (4, 2, 3)–@C = (@A, @B);

Page 13: R 於微陣列數據分析 - Bioinformatics analysis in  Perl -

Array operator• pop @A : Pick up an element from the end of array• push @A : Add an element to the end of array• shift @A : Pick up an element from the top of array• unshift @A : Add an element to the top of array• @A = @B;• reverse @A• sort @A : follow the order of ASCII code

– sort {$a <=> $b} @A : from small to big– sort {$b <=> $a} @A : from big to small

Page 14: R 於微陣列數據分析 - Bioinformatics analysis in  Perl -

Hash (the soul of Perl)

• %– key => value–%Empty = ();–%A = {“A” => 1, “B” => 2, “C” => 3};– reverse: reverse key and value (unsafe)– keys: return keys of hash as an array– values: return values of hash as an array– exists: check if a key exists in hash (unsafe)– delete: delete one key of hash

Page 15: R 於微陣列數據分析 - Bioinformatics analysis in  Perl -

SubroutineObject-oriented

Page 16: R 於微陣列數據分析 - Bioinformatics analysis in  Perl -

Functions

• Array– push, pop, reverse

• Hash– keys, delete, exists, reverse

• String– substr, index, length

• rand, int

Page 17: R 於微陣列數據分析 - Bioinformatics analysis in  Perl -

Subroutine

sub subroutine_name{

statements in subroutine;return something/nothing;

}

#call subroutine$return_value = &subroutine_name(parameters);

Page 18: R 於微陣列數據分析 - Bioinformatics analysis in  Perl -

Subroutine

sub ADD{

($lo, $ro) = @_;return $lo + $ro;

}

print &ADD(3, 5);

Page 19: R 於微陣列數據分析 - Bioinformatics analysis in  Perl -

Subroutine

$max_value = &Max(3, 5);sub Max{

($lo, $ro) = @_;my $bigger = ($lo >= $ro) ? $lo:$ro;return $bigger;

}

Page 20: R 於微陣列數據分析 - Bioinformatics analysis in  Perl -

Subroutine

• Call by value– 傳值給 subroutine ,實際上變數並沒有被傳進

subroutine– 在 subroutine 中是用另一個 local variable 來存傳進來的值

• Call by reference– 傳位址給 subroutine ,所以變數被以位址的方式傳進 subroutine 中– 在 subroutine 中是用另一個 local variable 來存傳進來的位址

Page 21: R 於微陣列數據分析 - Bioinformatics analysis in  Perl -

Subroutine (call by value)

@initial = (3, 5);@answer = &exchange(@initial);sub exchange{

reverse @_;return @_;

}

Page 22: R 於微陣列數據分析 - Bioinformatics analysis in  Perl -

Subroutine (call by reference)

&exchange(\@initial);sub exchange{

(my $add) = @_;reverse @$add;return;

}

Page 23: R 於微陣列數據分析 - Bioinformatics analysis in  Perl -

rand & int

• rand– 亂數函式– rand; # 隨機回傳一個 0~1 之間的數– rand(100); # 隨機回傳一個 0~100 之間的數

• int– 整數函式– int(15.44332521122323211554) # 回傳 15– int(rand(50)) # 隨機回傳一個 0~50 之間的整數

Page 24: R 於微陣列數據分析 - Bioinformatics analysis in  Perl -

Recursive• Permutation

– 0! = 1, N! = N * (N-1)!Sub Permutation{

my $n = $_[0];if($_[0] == 0){return 1;}else{return $n * Permutation($n- 1);}

}

Page 25: R 於微陣列數據分析 - Bioinformatics analysis in  Perl -

Perl PackagePPM & CPAN

Page 26: R 於微陣列數據分析 - Bioinformatics analysis in  Perl -

PPM

• Perl Package Manager

Page 27: R 於微陣列數據分析 - Bioinformatics analysis in  Perl -

CPAN

• Comprehensive Perl Archive Network

Page 28: R 於微陣列數據分析 - Bioinformatics analysis in  Perl -

Homework

Page 29: R 於微陣列數據分析 - Bioinformatics analysis in  Perl -

Debug Mode

• perl -d test.pl– 小明媽有 500 元– 小明有 100 元– 媽媽給小明 45 元

• 媽媽跟小明分別剩多少錢 ?

– 小明跟雜貨店老闆買了兩本 20 元的筆記本、三隻 7 元的鉛筆,一瓶 15 元的輕鬆小品• 小明剩多少錢• 老闆入賬多少錢

• 請輸出每一個步驟的金額以及其對應的記憶體位址

Page 30: R 於微陣列數據分析 - Bioinformatics analysis in  Perl -

Homeworks

• 要求使用者輸入一正整數,並做輸入檢查,然後判斷它是奇數或偶數。• 分別印出 1 到 100 中的偶數跟奇數

– 先印全部的奇數再換行印全部的偶數,數字間用空白分隔• 用 iterative 方式印出 Fibonacci 數列的前 50 個數

– Fibonacci 數列: F(0) == F(1) == 1 ,之後,數列中每個數是前兩個數之和, F(n) = F(n-1) + F(n-2)

• 寫出漢諾塔的程式 (recursive)– 若有四個銅環,請問需搬動幾次。– 請將搬動過程 print 出來。