Browse the Linux filesystem

If you want to refer to a directory in UNIX (and, with little differences, in Windows too) you can use:

  • Relative path
  • Absolute path

Continue reading

Tagged , , , , ,

Lab change: important

Tomorrow we have the second  laboratory.

We will meet in aula B / Piano Rialzato at 14.30 and after a small demonstration we’ll reach together the Computer Room.

Please spread the message!

Try to close a gap

Here you are a simple homework to practice with Primer3 and our genome finishing goal.

Using the information stored in mate-paired reads, we see that the 5′-end of “contig05189” is linked to 3′-end of “contig01316”. Please note the 3′ and 5′ ends are indicated in gray boxes for each connection.

You can see that the path to the 3′ is a little bit more complex.

Continue reading

Tagged ,

Hello_everyone.pl

Now that we know where Perl stores command line parameters (hint: @ARGV), we can revise the original Hello world! script.

1) Write a say_hello.pl script that takes a single argument from command line, that is the name of a person, and then prints “Hello name!”.

2) Write a hello_everyone.pl script that receive as input a list of names, and then print for each name a “Hello name” line.
This means that we want to type a command like this:

perl hello_everyone.pl Lineweaver Burk

and to have, as output:

Hello Lineweaver!
Hello Burk!

3) Write a program hello_count.pl that counts the people to greet and prints the number. This means that we want to type a command like this:

perl hello_everyone.pl Lineweaver Burk 

and to have, as output:

Hello you 2 guys!

First computer lab

Welcome to the Computer Lab #1

From text editor to program execution

Today we start playing with our computer: we want to

  1. start using the shell terminal
  2. start using a programming editor
  3. preparing and executing simple Perl scripts
  4. Make Primer3 design a couple of primers

Continue reading

Tagged

Auto-completing filenames

The shell if filled with shortcuts and tricks, but there a vital feature you can’t miss at all: the auto-completion (see what says Wikipedia about it). In a few words if you start typing a filename or command an you press [Tab] once it will be automatically completed. If more than a file exist that starts with the characters you typed, double [Tab] prints a list of possibilities.

This is much more than a trick: it’s a safe way to check that you are giving the right parameter to your scripts/programs.

If you mis-type a filename (or directory name) you’ll see the error only executing the command.

cd ~
cd Documanti
-bash: cd: Documanti: No such file or directory
 
cd ~
cd Docu[Tab]
cd Documenti (automatically completed)

 

 

Tagged ,

UNIX shell, from simple to complex

We used some very simple commands during our first lab. Let see a new command. This post shows how to use two handy features of the shell: output redirection and program piping.

grep look for a patter into a line, and print it only if the pattern is present in the line. If we have a multifasta file, each header has a “>” sign. If we want to view all headers we can type:

grep ">" multifasta.fa

Output redirection

Most UNIX commands prints their output to screen. If we want to save that output we can use the “>” character:

ls -l > filelist.txt

we won’t see as usual the file listing with this command, because the “>” redirects ls’s output to the filelist.txt file. If we print the file:

cat filelist.txt

we will have a proof.

Program “pipes”

A very useful feature of the UNIX shell is the possibility to send the output of a program to another program. This is done with the pipe character: |.

ls -la | head -n 3

With this command we will see the first three lines of the ls output. Nice?

cat multifasta.fa | grep ">" | wc -l
  • can you guess what happens with this command???
  • can you write a command that prints only files created in march? (answer with comments)
Tagged , , , ,

Second lesson: slides

Today we had an extremely fast introduction to Perl (crash course). In particular we

  • Reviewed variables and learned what hashes are and how to use them
  • Reviewed the for and foreach cycles
  • Introduced the while loop
  • Introduced mathematical and string operators and functions
  • Introduced the if test
  • Saw how to open a file and get parameters (@ARGV).

 Download slides

Tagged

IF statement and Perl operators

See this tutorial for a comprehensive list.

Remember that “=” has to be used only to assign a value to a scalar. To compare two numbers we’ll use the ‘==’ operator, while to compare two strings the ‘eq’ operator.

This script is a shor example:

#!/usr/bin/perl
 
$n1 = 10;
$n2 = $n1;
$n1++;
 
if ($n1 == $n2) {
print "Equal numbers: $n1 = $n2.\n";
} elsif ($n1>$n2) {
print "$n1 is greater than $n2.\n";
} else {
print "$n2 is greater than $n1.\n";
}
Tagged

Reading a (text) file line by line with Perl

#!/usr/bin/perl
 
# Get the filename from the user via command line
$filename = $ARGV[0];
 
# Here we use the open command that reads a file (second parameter)
# and link it to a "handle" (first parameters, conventionally uppercase).
# "||" means "or", that is if open returns false... exit with an error message
open(FILE, "$filename") || die " FATAL ERROR:\n Unable to open \"$file\".\n";
 
# Now we retrieve line by line calling the file handle with < and >.
# Line content is stored in the special scalar "$_"
while (<FILE>) {
  $linecounter++;
  print "$linecounter: $_";
}

to use this script we need to add a parameter to the command line: the filename! eg:

perl script.pl filename.txt

You can find a detailed tutorial on the open command here.

Tagged , ,