Example 4: Finding GC content

Overview

In this example, you will learn how to highlight all Gs and Cs by capitalizing them, find the total number of Gs, Cs and calculate Percentage GC in a sequence

Example Code

Output

GCaCaGGGtGaaCGtaaCGatGGCtGatCGtataaGtGtGaCtatGGCCGaCaCtGataGaGtCaaCttGaCCatGCaCaGGGtGaaCGtaaCG

%GC is : 0.5

 

Decode

>>Line 10: $sequence=~tr/gc/GC/;

This tr function finds all g and change them into G, and then find all c to change them into C.

>> Line 24: $numberOfG=($sequence=~tr/G/G);

This command returns the total number of G in $sequence.

>>Line 25: $numberOfC=($sequence=~tr/C/C);

This command returns the tatal number of C in $sequence

Exercise Four

>>Write a program that finds the number of As in $sequence. Then change all T in $sequence into A and find the number of As again. Print the results.

$sequence="GCACAGGGTGAACGTAACGATGGCTGATCGTATAAGTGTGACTATGGCCGACACTGATAGAGTCAAC

TTGACCATGCACAGGGTGAACGTAACG ";