This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to compute the AT/GC ratio for an e.coli sequence in a fasta file?

Last week I started a course in computing for ecology/evolution and am very new to this. We've been asked to compute the AT/GC ratio within an e.coli FASTA file. However, we have to do this just in the mac terminal, without using shell scripting or python. It has to be done using single line solutions piped together. I've been searching online for hours but I'm still totally lost, can anyone give me any advice? Thank you so much!

sequencing fasta

There are going to be many ways to do this. Another hint, on top of Mensur's answer, is that AWK's gsub function returns the number of matches made. Check up online what its doing, and then try to adapt it to work with your Escherichia coli FASTa file, whose sequence may be spread across multiple lines:

echo "CCGCATGCAAGCTAGCTGACTGACTGACTGACTAGCTATGC" | \
  awk '{
    print "A bases:\t"gsub(/A/,"",$0);
    print "T bases:\t"gsub(/T/,"",$0);
    print "G bases:\t"gsub(/G/,"",$0);
    print "C bases:\t"gsub(/C/,"",$0)}'

A bases:    10
T bases:    9
G bases:    10
C bases:    12

You may also have to deal with masked bases, and upper- and lower-case bases.

Another approach using grep :)

grep -v ">" fastafile |grep -o . |sort |uniq -c

1 answer

Count how many times As and Ts appear in your FASTa file (excluding first line) and divide the sum of those two numbers by total number of all ACGT letters. Maybe this search will help. You can try using tr or sed instead of awk.

Log in to answer this question.