Perl variables

In any programming language we need to store information, an to retrieve it when needed. Perl has three types of variables:

  • scalar – they can store numbers or text (strings).
  • array – they are ordered lists of scalar.
  • hashes – they are unordered lists of values with a “label” called name.

Scalar are identified by the ‘$’ character. You can assign a value to a scalar with the ‘=’:

$age = 15;
$name = 'Larry';
$age = $age+1;        # an more compact alternative is $age++, if you have to add 1
$combine1 = "$name is $age";
$combine2 = '$name is $age';
print "Double quotes:  $combine1\n";
print "Sinngle quotes: $combine2\n;"

This small script has two assignation, a number and a string. Then we increment the $age variable by 1.
Note that for numbers we don’t use any quote, while for string we use single quotes or double quotes. The difference – as mentioned – is that double quotes are interpreted and substitute $name with the content of the variable itself.

Arrays are list of strings. To create a new array the syntax is a list of comma separated scalars enclosed by round brackets:

@array = ('first', 'second', 15, 16);

each element of the array has an index starting from 0, thus the last element of the array in the example has index 3. As each element of the array is a scalar, we refer to it with the “$” sign, specifying the index:

$firstElement = $array[0];

A special variable is created by Perl and contains the index of the last element:

$lastindex = $#array;

Thus:

$lastElement = $array[$#array];

Finally hashes are unordered lists of couples of scalar: one is the key and has an associated value.  We’ll see hashes in detail in lesson2.

(in Italian) c’è un buon tutorial su array ed hash in questo sito, valido anche per altri argomenti ovviamente… vi consiglio il corso completo come lettura serale ;).

Tagged , , , ,

Perl: Hello World!

Here you are the code of our very first script we made in lesson1:

#!/usr/bin/perl
 
$yourname = 'George';
print "Hello world!\n";
print "and hello $yourname too!\n";

Remember that if you want to add comments they should be preceded by the # character. The very first line is an instruction for the shell rather than for Perl, but at the moment just remember to add it.

Each instruction has to end with a “;”.

\n is the special way to add a new-line.

Do you remember the difference between double quotes and single quotes?

 

Tagged ,

HTML: Hello World!

HTML is the very simple language to format web pages. We used HTML as a first use of “simple text” files and our text editor.

Here i report a simple example very similar to the one covered during the first lesson.

<html>
<body>
<h1>Hello World!</h1>
<p>My first paragraph. Another <strong>great</strong> paragraph!</p>
</body>
</html>

 

If you want to test some HTML code without having to create a new text file you can try this website.

Tagged ,

A “primer” on Genome Assembly

During our first lesson we had a brief overview of the sequencing strategy used for Nannochloropsis.

First, a whole genome shotgun approach was used to have a first draft (see picture below). In particular we used the Roche 454 machine that provides reads ~500bp long, and we assembled them with the Newbler package.

As we saw both read length and sequence coverage affects the quality of the assembly. In particular repeated regions make the assembly program to “break” the sequence. This happens if the length of the repeated region is longer than the single fragments (reads) sequenced. Repeated regions collapse in the same contig, that will have a higher coverage (approximately n-times the average, where n is the number of repeats in the genome).

Continue reading

Tagged , , ,

First class lesson: project overview and first Perl script!

Lesson date: March 8th, 2012

We discussed the project goal: a program to design primers for genome finishing.

We introduced the three main tools of the bioinformaticisists: scripting languages, relational databases and HTML for web interfaces.

You were suggested to download and install a programming editor, with syntax highlighting and other advanced features usually lacking on simpler editors and to install Perl if you use Windows.

 Download slides

Tagged

Installing and testing Perl

Installing Perl

If you have Linux or Mac OS X you have Perl installed by default. For Windows users there are different package to choose from, but a long used and tested is ActiveState Perl. Choose the X_86 version for Windows.
Download and execute the package following the instructions. You can watch this YouTube video to have and idea: the installation process is quite straightforward.

Installing a text editor

  • Under Linux you can use Gedit (in Ubuntu is under Application -> Accessories -> Text Editor). Kate is good as well.
  • Under Mac OS X you can download Text Wrangler, that is available for free at the App Store.
  • Under Windows you can use Crimson Editor.

Testing Perl

Open a shell terminal. (Under Windows hit Start, then choose “Run…” and type cmd in the text input, then hit Enter).

Type the “perl -v” command, without quotes, and hit enter. Is it working?

Tagged ,

Welcome to the Genomics practicals blog (and wiki)

Dear students,

welcome to this blog. This is the reference website for the practical course of Genomics, that – as you already know – focuses on genome finishing, both from the bioinformatics side and the wet lab side.

This blog will contain lessons and protocols, but also open questions and polls. A course calendar is online.

Please, register to this blog and start commenting on posts to answer question and – of course – feel free to ask some!

We’ll publish polls from time to time (the first is here, left column!)… We’d love to hear your voice (clicks..)!

Stay tuned,

Andrea & Elisa

PS: Beside this blog we also opened a Wiki, and we’ll tell you how to use it… Consider that the wiki is your open space, and populating it is.. up to you 🙂