1 / 26

@input=<>; @seq=(); for($i=0; $i<= $#input; ++$i){ $line=$input[$i]; chomp $line;

Reverse FASTA sequence. @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); }

vondra
Download Presentation

@input=<>; @seq=(); for($i=0; $i<= $#input; ++$i){ $line=$input[$i]; chomp $line;

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. Reverse FASTA sequence @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 } } }

  2. Utilities.pm some.pl 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; use Utilities; Utilities::checkInput(“for check”); print $Utilities::path; my $path=“/locale/”; #local definition Packages

  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. • <CR> • 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 isomitted, 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.

  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” ] ); my $rlol=[ [ “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];

  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 ]; } foreach ( 0..9 ){ @array = split /\s/, <>; $lol[ $_ ]= \@array; #wrong, assignment of reference to a local value }

  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 print $hoa{“record1”}{ “color” }; $hoa{“newrecord”} = { %hash }; my %hoa=( record1 => { color => “red”, lang => “perl” }, record2 => { color => “green”, lang => “c++” } );

  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]

More Related