r 於微陣列數據分析 - bioinformatics analysis in perl -
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 PresentationTRANSCRIPT
R 於微陣列數據分析-Bioinformatics analysis in Perl-
教師 : 黃宣誠 老師助教 : 林振慶E-mail: [email protected]
Outline
07/26
Syntax
Perl BasicsData StructureSubroutinePackage Installation and Searching
07/31Regular Expression
Advanced PerlData ParsingID Mapping
08/02 Biological Network ImplementationFunctional Enrichment
Perl Basics
Perl Installation
• http://www.activestate.com/activeperl
SyntaxLook of perl
Variables
• $var– scalar
• @var – array
• %var– hash
• ;• #
Control Flow (Condition)
• if(condition1)• elsif(condition2)• else• unless(condition1)• else• Ternary operator - ?– $a = ($b > 5) ? “yes” : “no”;
True or False
• False– 0– ‘0’ 、” 0” 、’’、””– undef– Undefined value
• True– others
Control Flow (Loop)
• while (condition)• until (condition)• for(condition)• foreach(array)• last and next– last: exit this loop– next: ignore below statements
Data StructureThe pivot part of perl
Scalar
• $– $A = 55;– $B = “55”;– $C = ‘Hello Perl!\n’;– $D = “Hello Perl!\n”– $E = \$A;– +, -, *, /, %, **,
• <STDIN>
Array
• @–@Empty = ();–@A = (1, 2, 3); @B = (‘a’, ‘b’, ‘c’);– $A[0] == 1– $A[0] = 4;–@A == (4, 2, 3)–@C = (@A, @B);
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
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
SubroutineObject-oriented
Functions
• Array– push, pop, reverse
• Hash– keys, delete, exists, reverse
• String– substr, index, length
• rand, int
Subroutine
sub subroutine_name{
statements in subroutine;return something/nothing;
}
#call subroutine$return_value = &subroutine_name(parameters);
Subroutine
sub ADD{
($lo, $ro) = @_;return $lo + $ro;
}
print &ADD(3, 5);
Subroutine
$max_value = &Max(3, 5);sub Max{
($lo, $ro) = @_;my $bigger = ($lo >= $ro) ? $lo:$ro;return $bigger;
}
Subroutine
• Call by value– 傳值給 subroutine ,實際上變數並沒有被傳進
subroutine– 在 subroutine 中是用另一個 local variable 來存傳進來的值
• Call by reference– 傳位址給 subroutine ,所以變數被以位址的方式傳進 subroutine 中– 在 subroutine 中是用另一個 local variable 來存傳進來的位址
Subroutine (call by value)
@initial = (3, 5);@answer = &exchange(@initial);sub exchange{
reverse @_;return @_;
}
Subroutine (call by reference)
&exchange(\@initial);sub exchange{
(my $add) = @_;reverse @$add;return;
}
rand & int
• rand– 亂數函式– rand; # 隨機回傳一個 0~1 之間的數– rand(100); # 隨機回傳一個 0~100 之間的數
• int– 整數函式– int(15.44332521122323211554) # 回傳 15– int(rand(50)) # 隨機回傳一個 0~50 之間的整數
Recursive• Permutation
– 0! = 1, N! = N * (N-1)!Sub Permutation{
my $n = $_[0];if($_[0] == 0){return 1;}else{return $n * Permutation($n- 1);}
}
Perl PackagePPM & CPAN
PPM
• Perl Package Manager
CPAN
• Comprehensive Perl Archive Network
Homework
Debug Mode
• perl -d test.pl– 小明媽有 500 元– 小明有 100 元– 媽媽給小明 45 元
• 媽媽跟小明分別剩多少錢 ?
– 小明跟雜貨店老闆買了兩本 20 元的筆記本、三隻 7 元的鉛筆,一瓶 15 元的輕鬆小品• 小明剩多少錢• 老闆入賬多少錢
• 請輸出每一個步驟的金額以及其對應的記憶體位址
Homeworks
• 要求使用者輸入一正整數,並做輸入檢查,然後判斷它是奇數或偶數。• 分別印出 1 到 100 中的偶數跟奇數
– 先印全部的奇數再換行印全部的偶數,數字間用空白分隔• 用 iterative 方式印出 Fibonacci 數列的前 50 個數
– Fibonacci 數列: F(0) == F(1) == 1 ,之後,數列中每個數是前兩個數之和, F(n) = F(n-1) + F(n-2)
• 寫出漢諾塔的程式 (recursive)– 若有四個銅環,請問需搬動幾次。– 請將搬動過程 print 出來。