If you want to refer to a directory in UNIX (and, with little differences, in Windows too) you can use:
- Relative path
- Absolute path
If you want to refer to a directory in UNIX (and, with little differences, in Windows too) you can use:
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.
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!
Today we start playing with our computer: we want to
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) |
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
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.
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
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"; } |
#!/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.