Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a bash script named codoncount that expects a file name on the command lin

ID: 3589839 • Letter: W

Question

Write a bash script named codoncount that expects a file name on the command line. The file is a DNA file, that only contains DNA string with no newline characters or white space characters. The DNA is a sequences of a, c, g and t of length 3n for some n. The bash script must count the number of occurrences of every codon in file, first codon starts at position 1^2, and it must output the number of times each codon appears, sorted in order of decreasing frequency (if there is a tie in frequency it should be broken by sorting in alphabetical order). If it cannot read the file, it must exit with a message "cannot open file".

Ex: DNA string in file DNAfile: aacgtttgtaaccagaactgt, then command

./codoncount DNAfile

Produces this output

3 aac

2 tgt

1 cag

1 gtt

Explanation / Answer

//shell script

#!/bin/sh                                                                                                                                                     

                                                                                                                                                              

if [ $# -eq 0 ] ;                                                                                                                                             

        then echo "Entrer file name as input"                                                                                                                 

        exit 1                                                                                                                                                

fi                                                                                                                                                            

i=$(grep  -o aac $1 | wc -l)                                                                                                                                  

echo -n $i " aac"; echo                                                                                                                                       

i=$(grep  -o tgt $1 | wc -l)                                                                                                                                  

echo -n $i " tgt"  ; echo                                                                                                                                     

i=$(grep  -o  cag $1 | wc -l)                                                                                                                                 

echo -n $i " cag" ; echo                                                                                                                                      

i=$(grep  -o gtt $1 | wc -l)                                                                                                                                  

echo -n $i " gtt" ; echo

------------------------------------------------------------------

//output

.   

sh-4.4$ ./codoncount DNAfile                                                                                                                                  

3  aac                                                                                                                                                        

2  tgt                                                                                                                                                        

1  cag                                                                                                                                                        

1  gtt  

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote