1 / 30

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

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

ringo
Télécharger la présentation

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

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. R於微陣列數據分析-Bioinformatics analysis in Perl- 教師: 黃宣誠 老師 助教: 林振慶 E-mail: kdragongo@gmail.com

  2. Outline

  3. Perl Basics

  4. Perl Installation • http://www.activestate.com/activeperl

  5. Look of perl Syntax

  6. Variables • $var • scalar • @var • array • %var • hash • ; • #

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

  8. True or False • False • 0 • ‘0’、”0”、’’、”” • undef • Undefined value • True • others

  9. Control Flow (Loop) • while (condition) • until (condition) • for(condition) • foreach(array) • last and next • last: exit this loop • next: ignore below statements

  10. The pivot part of perl Data Structure

  11. Scalar • $ • $A = 55; • $B = “55”; • $C = ‘Hello Perl!\n’; • $D = “Hello Perl!\n” • $E = \$A; • +, -, *, /, %, **, • <STDIN>

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

  13. 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

  14. 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 existsin hash(unsafe) • delete:delete one key of hash

  15. Object-oriented Subroutine

  16. Functions • Array • push, pop, reverse • Hash • keys, delete, exists, reverse • String • substr, index, length • rand, int

  17. Subroutine sub subroutine_name { statements in subroutine; return something/nothing; } #call subroutine $return_value = &subroutine_name(parameters);

  18. Subroutine sub ADD { ($lo, $ro) = @_; return $lo + $ro; } print &ADD(3, 5);

  19. Subroutine $max_value = &Max(3, 5); sub Max { ($lo, $ro) = @_; my $bigger = ($lo >= $ro) ? $lo:$ro; return $bigger; }

  20. Subroutine • Call by value • 傳值給subroutine,實際上變數並沒有被傳進subroutine • 在subroutine中是用另一個local variable來存傳進來的值 • Call by reference • 傳位址給subroutine,所以變數被以位址的方式傳進subroutine中 • 在subroutine中是用另一個local variable來存傳進來的位址

  21. Subroutine (call by value) @initial = (3, 5); @answer = &exchange(@initial); sub exchange { reverse @_; return @_; }

  22. Subroutine (call by reference) &exchange(\@initial); sub exchange { (my $add) = @_; reverse @$add; return; }

  23. rand & int • rand • 亂數函式 • rand; #隨機回傳一個0~1之間的數 • rand(100); #隨機回傳一個0~100之間的數 • int • 整數函式 • int(15.44332521122323211554) #回傳15 • int(rand(50)) #隨機回傳一個0~50之間的整數

  24. Recursive • Permutation • 0! = 1, N! = N * (N-1)! Sub Permutation { my $n = $_[0]; if($_[0] == 0) { return 1; } else { return $n * Permutation($n- 1); } }

  25. PPM & CPAN Perl Package

  26. PPM • Perl Package Manager

  27. CPAN • Comprehensive Perl Archive Network

  28. Homework

  29. Debug Mode • perl -d test.pl • 小明媽有500元 • 小明有100元 • 媽媽給小明45元 • 媽媽跟小明分別剩多少錢? • 小明跟雜貨店老闆買了兩本20元的筆記本、三隻7元的鉛筆,一瓶15元的輕鬆小品 • 小明剩多少錢 • 老闆入賬多少錢 • 請輸出每一個步驟的金額以及其對應的記憶體位址

  30. Homeworks • 要求使用者輸入一正整數,並做輸入檢查,然後判斷它是奇數或偶數。 • 分別印出1到100中的偶數跟奇數 • 先印全部的奇數再換行印全部的偶數,數字間用空白分隔 • 用iterative方式印出Fibonacci 數列的前 50 個數 • Fibonacci 數列:F(0) == F(1) == 1,之後,數列中每個數是前兩個數之和,F(n) = F(n-1) + F(n-2) • 寫出漢諾塔的程式 (recursive) • 若有四個銅環,請問需搬動幾次。 • 請將搬動過程print出來。

More Related