Workshop on Genomics 2024
Mercè Montoliu Nerín
January 9th,2024
What is UNIX?
powerful
multi-user
Operating system
multitasking
Why is it important for
bioinformatics?
Handling large
Facilitates sharing and datasets and running
reproducing analyses analyses efficiently
Efficiency
and
speed
Using scripts
Access to powerful
to automate
tools and applications
repetitive tasks
The terminal
Make it comfortable to work in
■ Resize the window
■ Change the font size
■ Open multiple terminal windows (or tabs)
■ Make sure you have the right combination
of colours that work for you.
The terminal
File system organization
/home/Merce
/home/Merce/Genomics
Paths - Absolute vs Relative
Absolute paths
/home/Merce
/home/Merce/Genomics
/home/Merce/bin
. refers to our current location
.. refers to the location above us
Paths - Absolute vs Relative
Absolute paths
/home/Merce
/home/Merce/Genomics
/home/Merce/bin
You are here! Absolute: /home/Merce
Relative: ./
. refers to our current location
.. refers to the location above us ./Genomics
Paths - Absolute vs Relative
Absolute paths
/home/Merce
/home/Merce/Genomics
/home/Merce/bin
You are here! Absolute: /home/Merce
Relative: ./
. refers to our current location
.. refers to the location above us ./bin
Paths - Absolute vs Relative
Absolute paths
/home/Merce
/home/Merce/Genomics
/home/Merce/bin
You are here! Absolute: /home/Merce/Genomics
Relative: ./
. refers to our current location
.. refers to the location above us ..
Paths - Absolute vs Relative
Absolute paths
/home/Merce
/home/Merce/Genomics
/home/Merce/bin
You are here! Absolute: /home/Merce/Genomics
Relative: ./
. refers to our current location
.. refers to the location above us ../bin
Paths - Absolute vs Relative
Absolute paths
/home/Merce
/home/Merce/Genomics
/home/Merce/bin
You are here!
. refers to our current location
.. refers to the location above us How do we refer to this directory?
Paths - Absolute vs Relative
Absolute paths
/home/Merce
/home/Merce/Genomics
/home/Merce/bin
You are here!
. refers to our current location
.. refers to the location above us ../../User2
File system navigation
pwd - where am I? cd - change directory
File system navigation
pwd - where am I?
/home/Merce
cd - change directory
> cd /home/Merce/Genomics
> cd ./Genomics
File system navigation
pwd - where am I?
/home/Merce/Genomics
cd - change directory
> cd /home/Merce
> cd ../
File system visualization
ls - shows you the contents the
directory you are in
> ls
> ls .
> ls ./
> ls ../
��
Create, copy, move, and remove files
and folders
"Unix was not designed
mkdir - create new directory
to stop its users from
cp - copy file
doing stupid things, as
mv - move file or directory that would also stop
rm - remove file them from doing clever
things." - Doug Gwyn
Symbolic links
ln -s /path/to/file link
create a symlink of file
> ln -s /home/Merce/Genomics/Data/seq.fastq \
Data Analyses
/home/Merce/Genomics/Analyses/Analysis1/
If we are already inside the folder Analysis1: seq.fastq
Analysis1 Analysis2
> ln -s /home/Merce/Genomics/Data/seq.fastq .
seq.fastq seq.fastq
Manual
man command - manual of the command
> man ls 🏴🏳🏴🏳
ls -l formatted list
ls -h “human” formatted list
ls -lh combination of flags
stdin, stdout, stderr
command stdin if it works: prints in our terminal the stdout
if it fails: prints in our terminal the stderr
command stdin > stdout if it works: stdout is redirected to a file
if it fails: prints in our terminal the stderr
command2 stdin2 > stdout stdout is redirected to a file and rewrites its
contents
command2 stdin2 >> stdout stdout is redirected to a file and appended
after its contents
stdin, stdout, stderr
command stdin if it works: prints in our terminal the stdout
if it fails: prints in our terminal the stderr
command file1 > output.txt if it works: stdout is redirected to a file
stdin stdout if it fails: prints in our terminal the stderr
command2 file2 > output.txt stdout is redirected to a file and rewrites its
stdin stdout contents
command2 file2 >> output.txt stdout is redirected to a file and appended
stdin stdout after its contents
stdin, stdout, stderr
command file1 2> errors.txt if it works: prints in our terminal the stdout
stdin stderr if it fails: stderr is redirected to a file
command file1 &> output.txt redirects both stdout and stderr to a file
stdin stdout&stderr
command file1 > output.txt 2> errors.txt redirects both stdout and stderr to a
stdin stdout stderr separate file each.
Explore file content
wc - word count (-l lines, -c characters, -w words)
less - visualize file contents in your terminal screen (press q to exit)
cat - prints contents of your file as standard output in your terminal
head - visualize the first 10 lines of a file
tail - visualize the last 10 lines of a file
A bit more advanced file-handling
commands
cat - prints contents of your file as standard output in your terminal
redirect to a command concatenate files
cat fileA | command > output.txt cat fileA fileB >> fileC
cat fileA > fileC
cat fileB >> fileC
A bit more advanced file-handling
commands
sort - puts in certain order a series of lines in our file
sort -r fileA sorts in reverse order
sort -n fileA sorts lines in fileA numerically
sort -k 2 fileA sort fileA by column 2
sort -k 2nr fileA sort fileA by column 2, numerically and in reverse order
sort -V fileA sort lines in fileA numerically natural.
sort -u fileA sort lines and removes duplicates -> sort fileA | uniq
A bit more advanced file-handling
commands
Are these two files different?
diff - can tell us if there are differences between two files
diff -q fileA fileB
“Files fileA and fileC differ”
diff fileA fileB
prints differences
A bit more advanced file-handling
commands
Splitting a file
split - split a given file into multiple files (default 1000)
split -l 20 fileA
produce x number of files from fileA, each containing 20 lines.
cut - extract specific parts of a file
cut -c 2 fileA
extract specific columns from a file
Text editors
Nano - The simpler option of text editor. All commands within the nano
text editor are given by pressing the Control-key, usually represented as ^
^S save current file
^O save to (a different file)
^X exit from nano
Text editors
Vim - a highly configurable text editor built to make creating and changing
any kind of text very efficient
i start insert mode (you can start typing after where your cursor is)
ESC exits insert mode (also Ctrl + C)
:w save file without exiting
:q exit file (if there are unsaved changes, it fails)
:wq save and exit
:q! exit without saving changes
Text editors
emacs - a text editor characterized by its extensibility and configurability.
Some essential commands commands get activated by typing Control + X,
then the command (while holding the control key), but there is a wide
range of key combinations to be used to move and edit the text
Ctrl + x + s save file
Ctrl + x + c exit editor (if not saved, it ask if you want to save, then type
"yes")
What my family and friends What my supervisor thinks I do
think I do
What I actually do
Cheat-sheet
Cheat-sheet
Rubber duck
Now it is your turn to practice!
And become each other’s ducks!