UNIX Course Part III Advanced Operations Andy Hauser LAFUGA Gene Center Munich LMU June, 2016 1
How many sense vs. anti- sense genes are in ecoli? 2
Solutions from last session $ grep 'CDS' | cut -f 7 ecoli_1-7.gtf | sort | uniq -c 2367 + 2198 - $ grep -c "CDS\t.*\t\-" ecoli_1-7.gtf 2198 $ grep -c "CDS\t.*\t\+" ecoli_1-7.gtf 2367 $ grep "CDS\t.*\t\-" ecoli_1-7.gtf | wc -l 2198 $ grep "CDS\t.*\t\+" ecoli_1-7.gtf | wc -l 2367 3
Some other solutions
seq - creating number sequences $ seq 1 5 arguments are range from and to 1 2 3 4 5 $ seq 5 1 also goes form higher to lower 5 4 3 2 1 $ seq 9 2 13 third argument in the middle is step size 9 11 13 $ seq -w 9 11 -w adds padding 0s 09 10 11
paste - join columns $ seq 1 5 > 1to5 $ seq 5 1 > 5to1 $ paste 1to5 5to1 1 5 2 4 3 3 4 2 5 1
tr - transliterate $ echo hello world | tr e a hallo world $ echo hello world | tr ehw aHW Hallo World $ echo hello world | tr a-z A-Z HELLO WORLD
rev - reverse lines $ echo hello world | rev dlrow olleh Hey what do we need that for … ?!?
How to get the reverse complement of a DNA sequence?
How to get the reverse complement of a DNA sequence? $ echo AAAGTAAC | tr AGTC TCAG | rev GTTACTTT
read - a line into a variable $ echo hello world | read myline $ echo $myline hello world
while loop $ while read myline; do echo line: $myline done < 1to5 line: 1 line: 2 line: 3 line: 4 line: 5
for loop $ for i in 1 2 3 4 5; do echo line: $i done line: 1 line: 2 line: 3 line: 4 line: 5
subshells $ echo `cat 1to5` 1 2 3 4 5 $ for i in `cat 1to5`; do echo line: $i done line: 1 line: 2 line: 3 line: 4 line: 5
Regular Expressions • [] one character from set, e.g. [abc] or ranges [a-z] • $ matches line end, e.g. "png$" • ? in shell: any one character • . in grep any one character • * in shell any characters • .* in grep any characters
awk - programming language $ seq 8 12 > 8to12 $ awk '{print length}' 8to12 1 1 2 2 2 $ awk '/1/ {print length}' 8to12 // matches like grep 2 2 2 $ paste 1to5 8to12 1 8 2 9 3 10 4 11 5 12 $ paste 1to5 8to12 | awk '{print $1}' 1 2 3 4 5 $ paste 1to5 8to12 | awk '{print $2}' 8 9 10 11 12
sed - streaming editor $ sed 's/1/2/' 8to12 Many commands. 8 e.g. s/// for replacing text 9 20 21 22 $ sed '/11/s/1/2/' 8to12 lines to act on can be selected with // 8 9 10 21 12 $ sed -n '/11/s/1/2/p' 8to12 21 $ sed -n '/1./s/1/2/p' 8to12 sed takes grep like regular expressions 20 21 22
Recommend
More recommend