26
@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

@input=; @seq=(); for($i=0; $i

  • Upload
    vondra

  • View
    32

  • Download
    1

Embed Size (px)

DESCRIPTION

Reverse FASTA sequence. @input=; @seq=(); for($i=0; $i/) ){ push @seq, split(//, $line); } - PowerPoint PPT Presentation

Citation preview

Page 1: @input=; @seq=(); for($i=0; $i

@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

Page 2: @input=; @seq=(); for($i=0; $i

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

Page 3: @input=; @seq=(); for($i=0; $i

Debugger

On Unix: “perldoc perldebug”

Invoke Perl with the -d switch:perl –d your_code.pl arg1 arg2 …

Page 4: @input=; @seq=(); for($i=0; $i

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

Page 5: @input=; @seq=(); for($i=0; $i

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.

Page 6: @input=; @seq=(); for($i=0; $i

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

Page 7: @input=; @seq=(); for($i=0; $i

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

Page 8: @input=; @seq=(); for($i=0; $i

Debugger (6)

W expr Add a global watch-expression.

Page 9: @input=; @seq=(); for($i=0; $i

Associative Arrays (Hashes)

• Keys are strings

• For each unique key there is one element (data)

Array - $color[1]=“green”;

Assoc. Array- $color{“green”}=1;

Page 10: @input=; @seq=(); for($i=0; $i

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;

Page 11: @input=; @seq=(); for($i=0; $i

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

Page 12: @input=; @seq=(); for($i=0; $i

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};

}

Page 13: @input=; @seq=(); for($i=0; $i

Associative Arrays (5)

# this sorts the %table hash by # value instead of key

@sorted = sort { $table{$b} <=> $table{$a} } keys %table;

Page 14: @input=; @seq=(); for($i=0; $i

Associative Arrays (5)

Page 15: @input=; @seq=(); for($i=0; $i

Associative Arrays (Hashes) (6)

#Exists function

if(exists $assray{“circle”}){

}

#delete function (according to key)

delete $assray{“circle”};

Page 16: @input=; @seq=(); for($i=0; $i

Associative Arrays (7)

defined $i;

defined $hash{$key}; # is not the same as exists( $hash{$key} )

undef $bar{'blurfl'}; # Compare to: delete $bar{'blurfl'};

Page 17: @input=; @seq=(); for($i=0; $i

Nested Data Structures

•Lists of Lists (arrays of arrays)

•Hashes of Arrays

•Arrays of Hashes

•Hashes of Hashes

Page 18: @input=; @seq=(); for($i=0; $i

Lists of Lists

my @lol;

while( <> ){

@tmp= split; #split /\s/, $_;

push @lol, [ @tmp ];

}

print $lol[ $i ][ $j ];

push @lol, @tmp ;

Page 19: @input=; @seq=(); for($i=0; $i

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 ];

Page 20: @input=; @seq=(); for($i=0; $i

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";

}

Page 21: @input=; @seq=(); for($i=0; $i

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” ] ];

Page 22: @input=; @seq=(); for($i=0; $i

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 ];

}

Page 23: @input=; @seq=(); for($i=0; $i

Hashes of Arrays

my %hoa=(

color => [ “red”, “white”, “green” ],

lang => [ “perl”],

record => [ “list”, “of”, “lists” ]

);

$hoa{ “another” } = [ @array ];

print $hoa{ “color” }[0];

Page 24: @input=; @seq=(); for($i=0; $i

Arrays of Hashes

my @hoa=(

{

color => “red”,

lang => “perl”

},

{

color => “green”,

lang => “c++”

}

);

print $hoa[0]{ “color” };

$hoa[0] = { %hash };

Page 25: @input=; @seq=(); for($i=0; $i

Hashes of Hashes

my %hoa=(

record1 => {

color => “red”,

lang => “perl”

},

record2 => {

color => “green”,

lang => “c++”

}

);

print $hoa{“record1”}{ “color” };

$hoa{“newrecord”} = { %hash };

Page 26: @input=; @seq=(); for($i=0; $i

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]