Biotechnology Forums

Full Version: CommandSets: Shell Scripting for Bioinformatics
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello all,

Shell scripting has been an indispensable part of Bioinformatics. Thought to initiate a thread for discussing problems/codes/useful one-liners/anything that can ease the life of the Bioinformaticians!

Here are some of the useful one-liners one can use for various purposes ( assuming actions on tab separated text file):

Transpose of a File :
awk '{ for (i=1; i<=NF; i++) { a[NR,i] = $i }}NF>p { p = NF }END { for(j=1; j<=p; j++) {str=a[1,j];for(i=2; i<=NR; i++){str=str" "a[i,j];}print str}}'

Number of Columns and Rows in a matrix
awk '{print NF}' (For Columns)
awk '{print NR}' (For Rows)


Print Even and Odd Numbered Columns and Rows in a matrix
awk '{NR%2==0}' For Even Rows
awk '{NR%2==1}' For odd Rows
awk '{NF%2==0}' For Even Columns
awk '{NF%2==1}' For Odd Columns


Fastq to Fasta conversion
Use FASTX Toolkit from Hannon Lab: Click Here for the link.

The Magic of !!
Double exclamation is a very useful command in Shell (those who have used it, would agree). Whenever you type !! in your terminal, it will print and execute the Last Shell Command you used on your Linux Terminal. Now this puts forward an array of possibiliies using !!.

Just for an example:
Use !! to add your last used command into any file or even a shell script you want to update.
If I use:
perl abc.pl
and then
!! (it will print following)
perl abc.pl

So, you can do echo !! >> filename (this will append the last used command to your file.

Delete First Line of a File
All you have to do is:
sed '1d' Filename

Delete all lines having a particular string
sed '/STRING/d' Filename

So, these were some of the tips for today. I'll keep it posted. And, let's share tips and problems here.