Symbolic links

From BITS wiki
Jump to: navigation, search
Go back to parent page Introduction to Linux for bioinformatics

Symbolic links

Symbolic links ('symlinks) point to a file, making the file accessible in another directory than where the file is. So you can avoid copying! When the original file is deleted, the symlink is dead. When you remove the symlink, the original file is still present.

The syntax for symbolic links is:

 $ ln -s /home/bits /data/large.fastq /home/bits /Projects/ProjectA/

Tip: when using ln, preferably provide absolute paths. If you want to use relative paths, make sure first going to the directory you want the link to be in, and create the link using a relative path (using '.' and '..' to make the path).

Removing symbolic links as such:

 $ unlink /home/bits /Projects/ProjectA

In contrast, there is also something as a hard link (ln without the -s option). When you delete a hard link, the file to which it referred is gone. So 'ln -s' is mostly used.

Linking data instead of copying

In the Rice Example directory (should be available under your home): download this annotation file into the 'Genome data'/'Annotation' directory. Make a symbolic link to this file in the 'Genome data'/'Sequence' directory. Read the first 10 lines from the symbolic link file.

When you have tried yourself, see the solution.

 
$ cd Rice\ Example/
 ~/Rice Example $ ls
bin  Genome data
 ~/Rice Example $ cd Genome\ data/Annotation/
 ~/Rice Example/Genome data/Annotation $ ls
 ~/Rice Example/Genome data/Annotation $ wget http://rice.plantbiology.msu.edu/pub/data/Eukaryotic_Projects/o_sativa/annotation_dbs/pseudomolecules/version_7.0/all.dir/all.gff3
--2013-10-28 11:45:26--  http://rice.plantbiology.msu.edu/pub/data/Eukaryotic_Projects/o_sativa/annotation_dbs/pseudomolecules/version_7.0/all.dir/all.gff3
           => `all.gff3'
Resolving http://rice.plantbiology.msu.edu (http://rice.plantbiology.msu.edu)... 35.8.196.190
Connecting to http://rice.plantbiology.msu.edu (http://rice.plantbiology.msu.edu)|35.8.196.190|:21... connected.
Logging in as anonymous ... Logged in!
==> SYST ... done.    ==> PWD ... done.
==> TYPE I ... done.  ==> CWD (1) /pub/data/Eukaryotic_Projects/o_sativa/annotation_dbs/pseudomolecules/version_7.0/all.dir ... done.
==> SIZE all.gff3 ... 81498659
==> PASV ... done.    ==> RETR all.gff3 ... done.
Length: 81498659 (78M) (unauthoritative)
 
100%[======================================>] 81,498,659  1.34M/s   in 65s     
 
2013-10-28 11:46:33 (1.20 MB/s) - `all.gff3' saved [81498659]
 
 ~/Rice Example/Genome data/Annotation $ ls ..
Annotation  Sequence
 ~/Rice Example/Genome data/Annotation $ cd ../Sequence/
 ~/Rice Example/Genome data/Sequence $ ln -s ../Annotation/all.gff3 .
 ~/Rice Example/Genome data/Sequence $ ls -l
total 381300
lrwxrwxrwx 1 bits bits 22 Oct 28 11:49 all.gff3 -> ../Annotation/all.gff3
-rw-r--r-- 1 bits bits 390444160 Mar  8  2013 IRGSPb5.fa.masked
-rw-r--r-- 1 bits bits 55 Mar  8  2013 IRGSPb5.fa.masked.gz.md5
 ~/Rice Example/Genome data/Sequence $ head all.gff3 
##gff-version 3
Chr1	MSU_osa1r7	gene	2903	10817	.	+	.	ID=LOC_Os01g01010;Name=LOC_Os01g01010;Note=TBC%20domain%20containing%20protein%2C%20expressed
Chr1	MSU_osa1r7	mRNA	2903	10817	.	+	.	ID=LOC_Os01g01010.1;Name=LOC_Os01g01010.1;Parent=LOC_Os01g01010
Chr1	MSU_osa1r7	exon	2903	3268	.	+	.	ID=LOC_Os01g01010.1:exon_1;Parent=LOC_Os01g01010.1
Chr1	MSU_osa1r7	exon	3354	3616	.	+	.	ID=LOC_Os01g01010.1:exon_2;Parent=LOC_Os01g01010.1
Chr1	MSU_osa1r7	exon	4357	4455	.	+	.	ID=LOC_Os01g01010.1:exon_3;Parent=LOC_Os01g01010.1
Chr1	MSU_osa1r7	exon	5457	5560	.	+	.	ID=LOC_Os01g01010.1:exon_4;Parent=LOC_Os01g01010.1
Chr1	MSU_osa1r7	exon	7136	7944	.	+	.	ID=LOC_Os01g01010.1:exon_5;Parent=LOC_Os01g01010.1
Chr1	MSU_osa1r7	exon	8028	8150	.	+	.	ID=LOC_Os01g01010.1:exon_6;Parent=LOC_Os01g01010.1
Chr1	MSU_osa1r7	exon	8232	8320	.	+	.	ID=LOC_Os01g01010.1:exon_7;Parent=LOC_Os01g01010.1

Introduction: symbolic links to easily install manually applications

If a package is not available via a package manager, manual installation might be an option. I put manually applications in /opt. Next, I link them to a correct location on our system, usually /usr/local/bin. Below you have some examples of this, which you can try out yourself.

If you want to manually install apps, /opt is the advised directory. However, only the administrator ('root') can access /opt.

You can check that the /opt directory belongs to root with
ls -l /opt

To be able to copy and write stuff into /opt, we need root permissions. To do so, precede your commands with sudo, as exemplified in the next exercise below. When we do that, our password will first be asked. Next, the command is executed with root permissions. In this way, we can edit contents in root-owned directories! You are a sudoer!


Transpose, a tool to transpose

Transpose is an extremely convenient text tool to transpose tabular data. We will use it later. The code is hosted on SourceForge.



Go back to parent page Introduction to Linux for bioinformatics