CommandSets: Shell Scripting for Bioinformatics - Printable Version +- Biotechnology Forums (https://www.biotechnologyforums.com) +-- Forum: Biotechnology Discussion (https://www.biotechnologyforums.com/forum-1.html) +--- Forum: Bioinformatics (https://www.biotechnologyforums.com/forum-5.html) +--- Thread: CommandSets: Shell Scripting for Bioinformatics (/thread-4690.html) |
CommandSets: Shell Scripting for Bioinformatics - SunilNagpal - 06-19-2014 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}}' <filename> Number of Columns and Rows in a matrix awk '{print NF}' <filename> (For Columns) awk '{print NR}' <filename> (For Rows) Print Even and Odd Numbered Columns and Rows in a matrix awk '{NR%2==0}' <filename> For Even Rows awk '{NR%2==1}' <filename> For odd Rows awk '{NF%2==0}' <filename> For Even Columns awk '{NF%2==1}' <filename> 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. |