Title: Perl
1Reverse FASTA sequence
_at_inputltgt _at_seq() for(i0 ilt input
i) lineinputi chomp line
if(line /\s/ and i ! input)
next if(! (line /gt/) ) push
_at_seq, split(//, line) if( (line
/gt/) or (i input)) new sequence
print previous sequence if(seq gt0 )
print reverse (_at_seq), "\n\n"
if(i ! input) _at_seq()
print line, "\n" print header
2Packages
3Debugger
On Unix perldoc perldebug
Invoke Perl with the -d switch perl d
your_code.pl arg1 arg2
4Debugger (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
5Debugger (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. ltCRgt
Repeat last n or s command.
6Debugger (4)
r Continue until the return from the current
subroutine. c linesub 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
7Debugger (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 gt 30 b 237 count237 lt 11 b 33 /pattern/i
8Debugger (6)
W expr Add a global watch-expression.
9Associative Arrays (Hashes)
- Keys are strings
- For each unique key there is one element (data)
Array - color1green Assoc. Array-
colorgreen1
10Associative 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 gt 1,
refresh gt ctrl-alt-del,
search gt google) _at_list assray
11Associative Arrays (Hashes) (3)
assray (one gt 1,
refresh gt ctrl-alt-del,
search gt google) _at_assray_keys keys
assray _at_assray_values values assray the
keys and values are in corresponding
order keys_num keys assray returns
3 remember Perl is context dependent
12Associative Arrays (Hashes) (4)
assray (one gt 1, refresh gt
ctrl-alt-del, search gt
google) while ( (key, value) each
(assray) ) print key gt value
\n access elements in sorted order foreach
key (sort keys assray) value
assraykey
13Associative Arrays (5)
this sorts the table hash by value instead
of key _at_sorted sort
tableb ltgt tablea keys table
14Associative Arrays (5)
15Associative Arrays (Hashes) (6)
Exists function if(exists assraycircle)
delete function (according to key) delete
assraycircle
16Associative Arrays (7)
defined i defined hashkey is not the
same as exists( hashkey ) undef
bar'blurfl' Compare to delete
bar'blurfl'
17Nested Data Structures
- Lists of Lists (arrays of arrays)
- Hashes of Arrays
- Arrays of Hashes
- Hashes of Hashes
18Lists of Lists
my _at_lol while( ltgt ) _at_tmp split split /\s/,
_ push _at_lol, _at_tmp print lol i j
push _at_lol, _at_tmp
19Lists of Lists (2)
my _at_lol( red, white, green ,
perl, list, of, lists ) print
lol 0 1 print lol 0 1 print
lol 0 -gt 1 but not print lol-gt 0 1
20Lists of Lists (3)
my _at_lol( red, white, green , perl,
list, of, lists )
print _at_lol ARRAY(0x80d5010) ARRAY(0x80d5070)
ARRAY(0x80d5094)
foreach list (_at_lol) print "_at_list \n"
foreach (_at_lol) print "_at__ \n"
21Lists of Lists (4)
my _at_lol( red, white, green , perl,
list, of, lists )
my rlol red, white, green ,
perl, list, of, lists
print _at_lol ARRAY(0x80d5010) ARRAY(0x80d5070)
ARRAY(0x80d5094) print rlol ARRAY(0x80d4eb4)
lol01 rlol-gt01 lol0-gt1 rlol-gt0
-gt1
22Lists of Lists (5)
foreach ( 0..9 ) _at_array split /\s/,
ltgt lol _ _at_array wrong, _at_array size
assignment
foreach ( 0..9 ) _at_array split /\s/,
ltgt lol _ _at_array
foreach ( 0..9 ) _at_array split /\s/,
ltgt lol _ \_at_array wrong, assignment of
reference to a local value
23Hashes of Arrays
my hoa( color gt red, white, green ,
lang gt perl, record gt list,
of, lists )
hoa another _at_array
print hoa color 0
24Arrays of Hashes
my _at_hoa( color gt red, lang gt
perl , color gt green, lang gt
c )
print hoa0 color hoa0 hash
25Hashes of Hashes
print hoarecord1 color
hoanewrecord hash
my hoa( record1 gt color gt red,
lang gt perl , record2 gt
color gt green, lang gt c )
26HomeWork
(a) Compute the percentage of nucleotides/amino-ac
ids. 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