Presentation is loading. Please wait.

Presentation is loading. Please wait.

for($i=0; $i<= $#input; ++$i){ $line=$input[$i]; chomp $line; if($line =~ /^\s*$/ and $i != $#input) { next; } if(! ($line =~ />/)

Similar presentations


Presentation on theme: "for($i=0; $i<= $#input; ++$i){ $line=$input[$i]; chomp $line; if($line =~ /^\s*$/ and $i != $#input) { next; } if(! ($line =~ />/)"— Presentation transcript:

1 @input=<>; @seq=(); for($i=0; $i<= $#input; ++$i){ $line=$input[$i]; chomp $line; if($line =~ /^\s*$/ and $i != $#input) { next; } if(! ($line =~ />/) ){ push @seq, split(//, $line); } if( ($line =~ />/) or ($i == $#input)) { #new sequence #print previous sequence if($#seq >0 ){ print reverse (@seq), "\n\n"; } if($i != $#input){ @seq=(); print $line, "\n"; #print header } Reverse FASTA sequence

2 Packages package Utilities; sub checkInput{ my ($input)=@_; … } our $path=“/home/usr/local/”; my $var=“”; #local definition #last evaluated value must be #positive = #successful package load 1; Utilities.pm use Utilities; Utilities::checkInput(“for check”); print $Utilities::path; my $path=“/locale/”; #local definition some.pl

3 Debugger On Unix: “perldoc perldebug” Invoke Perl with the -d switch: perl –d your_code.pl arg1 arg2 …

4 Debugger (2) always displays the line it's about to execute Any command not recognized by the debugger is directly executed (eval'd) as Perl code (for example you can print out some variables). p expr (as “print expr”) x expr - Nested data structures are printed out recursively, unlike the real print function in Perl

5 Debugger (3) s [expr] Single step. Executes until the beginning of another statement, descending into subroutine calls. If an expression is supplied that includes function calls, it too will be single-stepped. n [expr] Next. Executes over subroutine calls, until the beginning of the next statement. If an expression is supplied that includes function calls, those functions will be executed with stops before each statement. Repeat last n or s command.

6 Debugger (4) r Continue until the return from the current subroutine. c [line|sub] Continue, optionally inserting a one-time-only breakpoint at the specified line or subroutine. w [line] List window (a few lines) around the current/[line] line

7 Debugger (5) b subname [condition] b [line] [condition] Set a breakpoint before the given line. If line is omitted, set a breakpoint on the line about to be executed. If a condition is specified, it's evaluated each time the statement is reached: a breakpoint is taken only if the condition is true. Breakpoints may only be set on lines that begin an executable statement. b 237 $x > 30 b 237 ++$count237 < 11 b 33 /pattern/i

8 Debugger (6) W expr Add a global watch-expression.

9 Associative Arrays (Hashes) Keys are strings For each unique key there is one element (data) Array - $color[1]=“green”; Assoc. Array- $color{“green”}=1;

10 Associative Arrays (Hashes) (2) # list of pairs can be transformed into hash (and vice versa) % assray =(“one”, 1, “refresh”, “ctrl-alt-del”, “search”,”google”); #or % assray =(“one” => 1, “refresh” => “ctrl-alt-del”, “search” => ”google”); @list = %assray;

11 Associative Arrays (Hashes) (3) % assray =(“one” => 1, “refresh” => “ctrl-alt-del”, “search” => ”google”); @assray_keys = keys %assray; @assray_values = values %assray; #the keys and values are in corresponding order $keys_num = keys %assray; #returns 3 #remember – Perl is context dependent

12 Associative Arrays (Hashes) (4) % assray =(“one” => 1, “refresh” => “ctrl-alt-del”, “search” => ”google”); while ( ($key, $value) = each (%assray) ){ print “$key => $value \n”; } #access elements in sorted order foreach $key (sort keys %assray){ $value = $assray{$key}; }

13 Associative Arrays (5) # this sorts the %table hash by # value instead of key @sorted = sort { $table{$b} $table{$a} } keys %table;

14 Associative Arrays (5)

15 Associative Arrays (Hashes) (6) #Exists function if(exists $assray{“circle”}){ … } #delete function (according to key) delete $assray{“circle”};

16 Associative Arrays (7) defined $i; defined $hash{$key}; # is not the same as exists( $hash{$key} ) undef $bar{'blurfl'}; # Compare to: delete $bar{'blurfl'};

17 Nested Data Structures Lists of Lists (arrays of arrays) Hashes of Arrays Arrays of Hashes Hashes of Hashes

18 Lists of Lists my @lol; while( <> ){ @tmp= split; #split /\s/, $_; push @lol, [ @tmp ]; } print $lol[ $i ][ $j ]; push @lol, @tmp ;

19 Lists of Lists (2) my @lol=( [ “red”, “white”, “green” ], [ “perl”], [ “list”, “of”, “lists” ] ); print $lol[ 0 ][ 1 ]; print ${ $lol[ 0 ] }[ 1 ]; print $lol[ 0 ]->[ 1 ]; #but not print $lol->[ 0 ][ 1 ];

20 Lists of Lists (3) my @lol=( [ “red”, “white”, “green” ], [ “perl”], [ “list”, “of”, “lists” ]); print “@lol”; ARRAY(0x80d5010) ARRAY(0x80d5070) ARRAY(0x80d5094) foreach $list (@lol){ print "@$list \n"; } foreach (@lol){ print "@$_ \n"; }

21 Lists of Lists (4) my @lol=( [ “red”, “white”, “green” ], [ “perl”], [ “list”, “of”, “lists” ] ); print “@lol”; ARRAY(0x80d5010) ARRAY(0x80d5070) ARRAY(0x80d5094) print $rlol; ARRAY(0x80d4eb4) $lol[0][1]; $rlol->[0][1]; $lol[0]->[1]; $rlol->[0]->[1]; my $rlol=[ [ “red”, “white”, “green” ], [ “perl”], [ “list”, “of”, “lists” ] ];

22 Lists of Lists (5) foreach ( 0..9 ){ @array = split /\s/, <>; $lol[ $_ ]= @array; #wrong, @array size assignment } foreach ( 0..9 ){ @array = split /\s/, <>; $lol[ $_ ]= \@array; #wrong, assignment of reference to a local value } foreach ( 0..9 ){ @array = split /\s/, <>; $lol[ $_ ]= [ @array ]; }

23 Hashes of Arrays my %hoa=( color => [ “red”, “white”, “green” ], lang => [ “perl”], record => [ “list”, “of”, “lists” ] ); $hoa{ “another” } = [ @array ]; print $hoa{ “color” }[0];

24 Arrays of Hashes my @hoa=( { color => “red”, lang => “perl” }, { color => “green”, lang => “c++” } ); print $hoa[0]{ “color” }; $hoa[0] = { %hash };

25 Hashes of Hashes my %hoa=( record1 => { color => “red”, lang => “perl” }, record2 => { color => “green”, lang => “c++” } ); print $hoa{“record1”}{ “color” }; $hoa{“newrecord”} = { %hash };

26 HomeWork (a) Compute the percentage of nucleotides/amino-acids. Input: file(s) in the FASTA format. Output: percentage of sequence symbols. (b) Sort protein/dna sequences according to sequence length. Input: file(s) in the FASTA format. Output: The same sequences (with descriptors) ordered from the longest sequence to the shortest. [use ‘sort’ perl function]


Download ppt "for($i=0; $i<= $#input; ++$i){ $line=$input[$i]; chomp $line; if($line =~ /^\s*$/ and $i != $#input) { next; } if(! ($line =~ />/)"

Similar presentations


Ads by Google