#!/usr/bin/perl use strict; use warnings; use Data::Dumper; #Load in the previously generated ontology file. open (FINALDATA, "MotifRandomOntologies.txt") || die "Couldnt open the data file"; open (MYFILE, '>>MotifFrequencies.txt'); my %ontCatCount; my @operon1; my @operon2; my @operon3; my %freqMain; while (){ chomp; if(/\[([.\d\s]+)\]\s+\[([.\d\s]+)\]\s+\[([.\d\s]+)\]/){ my %freq; my %freq2; my %freq3; #print "* $1 + $2 + $3* \n"; @operon1 = split(/ /,$1); @operon2 = split(/ /,$2); @operon3 = split(/ /,$3); #print " @operon1 "; #create a hash table with MultiFun values. foreach (@operon1){ #next if ($freq{$_}) if(!$freq{$_}){ $freq{$_}++; # print "$_ "; } } # print " +++ "; foreach (@operon2){ #next if ($freq{$_}) #print $_ , " "; if(!$freq2{$_}){ $freq2{$_}++; # print "$_ "; } } # print " +++ "; foreach (@operon3){ #next if ($freq{$_}) #print $_ , " "; if(!$freq3{$_}){ $freq3{$_}++; # print "$_ "; } } #print $_ , "\n"; #At this point we have one set of frequencies for one motif. We can #transfer these to the big frequency table. foreach my $t (sort (keys (%freq))){ $freqMain{$t}++; } foreach my $t (sort (keys (%freq2))){ $freqMain{$t}++; } foreach my $t (sort (keys (%freq3))){ $freqMain{$t}++; } #Test this line has been properly assessed. undef %freq; undef %freq2; undef %freq3; } else{ /#([\w\d]+)\s+([\w\d]+)\s+([\w\d]+)/; my $filename = "$1$2$3"; print MYFILE $filename, "********\n"; print $filename, "********\n"; #First construct a hash table for the test network frequencies. #Now we can do the sums for each file and clear the freqMain hash too. foreach my $t (sort (keys (%freqMain))){ print MYFILE "$t $freqMain{$t} \n"; #print "$t $freqMain{$t} \n"; } undef %freqMain; my %freqMain; } #print "\n"; } close(MYFILE);