1 Introduction to computers and programming Laurent Falquet, Basel, October 2006 Swiss Institute of Bioinformatics Swiss EMBnet node LF Basel October 2006 Summary of the week • Monday Intro computers & programming Intro Unix Tutorial Unix • Tuesday Intro Perl I Variables, loops, conditions… Intro Regexp • Wednesday Intro Perl II Reference, subroutines, packages, modules… • Wednesday Object Oriented programming BioPerl • Thursday EMBOSS Database indexing BLAST • Friday Test HTML & cgi-bin Finish exercises Users questions
21
Embed
Introduction to computers and programming - … · Introduction to computers and programming Laurent Falquet, Basel, ... Source code •Instructions Statement, ... whirlwind of a
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
1
Introduction to computers andprogramming
Laurent Falquet, Basel, October 2006Swiss Institute of BioinformaticsSwiss EMBnet node
LF Basel October 2006
Summary of the week
• Monday Intro computers &
programming Intro Unix Tutorial Unix
• Tuesday Intro Perl I
Variables, loops,conditions…
Intro Regexp• Wednesday
Intro Perl II Reference, subroutines,
packages, modules…
• Wednesday Object Oriented
programming BioPerl
• Thursday EMBOSS Database indexing BLAST
• Friday Test HTML & cgi-bin Finish exercises Users questions
2
LF Basel October 2006
Content
• Hardware• Information storage
RAM, ROM HD, DVD
• Display Images Characters (fonts)
• File system/type Encryption Compression
• Network Protocols Packets
• Programming Algorithm Pseudocode Flowchart
• Languages• Source code
Example
LF Basel October 2006
The computer
3
LF Basel October 2006
Internally
LF Basel October 2006
The connections
4
LF Basel October 2006
Information storage
• 1 bit• 8 bits• 16 bits• 32 bits• 64 bits
• bit (1 or 0)• byte (octet) (28)• word (216)• double (232)• long double (264)
Encoding information on a fixed element of length n with abase b gives bn non-redundant possibilities
• Data structures Variable List Array Hash Pointers Objects
LF Basel October 2006
Source code (2)
• Statement, blocks One or more
instructions for theprocessor
• Affectation Change to a variable
• Operator affect one or more
variable + * - / AND OR
NOT…
• Variable A region in memory
that can be modified Exists in different
types Scalar, char, numeric,
boolean List, array Hash Combination->data
structure
18
LF Basel October 2006
Source code (3)
• Loops Allow the computer
to repeat blocks• Tests
Decide what to do• Subroutines
Programs frequentlycalled (functions)
• Comments The most important
lines of the sourcecode…
• Pointers Reference to region
in memory (address)• Objects
Combination of dataand code
LF Basel October 2006
Example: a text to treat
« Noon rings out. A wasp, making an ominous sound, a sound akin to a klaxonor a tocsin, flits about. Augustus, who has had a bad night, sits up blinking andpurblind. Oh what was that word (is his thought) that ran through my brain allnight, that idiotic word that, hard as I'd try to pun it down, was always just aninch or two out of my grasp - fowl or foul or Vow or Voyal? - a word in a quizzwhich, by association, brought into play an incongruous mass and magma ofnouns, idioms, slogans and sayings, a confusing, amorphous outpouring which Isought in vain to control or turn off but which wound around my mind awhirlwind of a cord, a whiplash of a cord, a cord that would split again andagain, would knit again and again, of words without communication or anypossibility of combination, words without pronunciation, signification ortranscription but out of which, notwithstanding, was brought forth a flux, acontinuous, compact and lucid flow: an intuition, a vacillating frisson ofillumination as if caught in a flash of lightning or in a mist abruptly rising tounshroud an obvious sign - but a sign, alas, that would last an instant only tovanish for good. »
Gilbert Adair
19
LF Basel October 2006
Result…
a=97b=15c=26d=35f=23g=32h=44i=90j=1k=5l=33m=17
n=91o=104p=15q=1r=43s=59t=77u=52v=4w=31x=2y=13z=2
Do you see any problem??
Try with this:« The quick brown fox, jumpsover the lazy dog. »
LF Basel October 2006
Flowchart
20
LF Basel October 2006
Source code example
#!/usr/bin/perl -w # essential line of all perl scripts
$filename = "avoid.txt"; # affect « avoid.txt » to the variable $filename
# open the file, or exitopen(FILE, $filename) || die "Cannot open file ‘$filename’\n\n";@text = <FILE>; # add each line of the file to an arrayclose FILE;
foreach $line (@text) { # read one line from the array into $line and repeat for each line@table = split(//,$line); # read each character of the line in an arraywhile ($char=pop(@table)) { # read one character of the array 'table' and repeat for all
$char =~ s/[^a-z]//; # keep only the alphabetical character a to zif ($char) { # check if the character exists and execute the block
$count{$char}++; # if yes, increment by one the hash 'count'}
}}
# print each character and its number of occurence one per lineforeach $c (keys %count) {