#test program to count instances of three-base subsequences

@bases = ("A","T","G","C");
$sequence = "ATTAGACGATTTGCGGGCTCACTAGCC";

#get the length of the sequence

$length_of_sequence = length ($sequence);


#loop over first base of triplet

foreach $b1 (@bases)
        {
        
        #loop over second base
        
        foreach $b2 (@bases)
        
	        {
	
	        #loop over third base

         	foreach $b3 (@bases)

          		{

            		$count=0;

              		#move through the sequence from beginning to end, looking at every triple of bases

               		for ($p=0; $p<$length_of_sequence - 2 ; $p++)
              			{

                                #extract a triple

                                $sub = substr($sequence, $p, 3);
			
			        #compare the current triple

           			if  ( $sub eq $b1.$b2.$b3)

              				{

              				$count=$count+1;

                                        }

               			}

		               #print the count for the particular triple

		               print "The subsequence ".$b1.$b2.$b3." appears in ".$sequence." ".$count." times\n"	;

                        }

                 }

        }
