Unix capstone exercise¶
Ths capstone exercise covers essentially all of the Unix commands you need to develop your bioinformatics piepliens. If you can do this exercise without too much difficulty, you are ready to process raw RNA-seq data!
But don’t be discouraged if you find this difficutl - unless you have quite a lot of previous programming experience, this exerise is likely to be challenging.
General hints:
Use
pwdliberally to check that you are in the right directoryEach command should execute almost instantly - if not, something is problay wrong with your command
Commands in Jupyter can appear to “hang” when there is an error - try the command in a terminal to see what’s wrong
Remember to configure so that you get a warning with unbound variabels
Use variables liberally - if a name is used more than once, it should probably be assinged to a variable
There is no restriction on using any search engine or reviewing previous notebooks
Make two directories
dataandresults. Check that the directories were created.
Hint:
You can list just directories with
ls -d */
[1]:
In
data, create the filesexpt-1,expt-2,epxt-3, each with 5 rows of 3 random numbers between 0 and 9 (inclusive) separated by tabs. When done, display the contents of each file.
Hint:
Create 3 for loops
the first to create a file,
the next to append a row of numbers, and add a newline
and the third to generate the numbers in the row.
You can generate random integers in Unix by repeatedly capturing the value of the special variable
$RANDOM.Initialize the
RANDOMvariable with the seed42.The arithmetic modulo opertor is
%(gives remainder after diviison)The tab character is represented by the string
\tThe argument
-netoechomeans do not emit a newline, evaluate specail characaters like\tYou can generate sequences of numbers using brace expansion or
seqArithmetic operatinons are evaluated like this $((1+2))
[2]:
Create an
MD5SUMfile containing the checksums of the contents withinexpt-1,expt-2, andepxt-3. Show the contents of theMD5SUMfile.
Hint:
md5sumneeds a list of files as arguments
[3]:
Create a
data.tar.gzfile containing all the contents of thedatadirectory
[4]:
Move
data.tar.gzto theresultsdirectory and recreate the original files
[5]:
Create a new file
expt-sum.txtinresultswith 3 lines showing the sum of the numbers in the 1st, 2nd and 3rd columns over all 3expt-xfiles. That is, the first row ofexpt-sum.txtcontains the sum of the 1st column ofexpt-1,expt-2, andexpt-3and so on. Use globbing to get the filesexpt-1,expt-2, andexpt-3.
Hint:
Remember the
cutcommandUse a double for loop
The outer loop selects a file
The inner loop sums up the numbers in the appropriate column of the file
[6]:
Delete the
dataandreultsdirectory recursively
[7]: