#!/usr/bin/perl use strict; use Getopt::Long; use Data::Dumper; my ($optInput1, $optInput2); GetOptions ('i=s' => \$optInput1, 't=s' => \$optInput2); open (IN, "<", $optInput1)|| die "$!"; open (IN1, "<", $optInput2)|| die "$!"; my %hash_pos; # set my intervals while (){ chomp; /^([^\t]*)\t([^\t]*)\t([^\t]*)/; $hash_pos{$1}->{$2}->{$3} =0; } close IN1; my %hash_stop; my $p =0; my $id = ""; #count tags per interval while(my $t = ){ chomp($t); if ($t =~/#(.*)\s/){ $p=0; $id = $1; %hash_stop = (); next; } $p++; # sometimes the first column is set to 0 $t =~/^(\d+)\t(\d+)/; # set start and stop boundaries for each interval # if start position has been reached if(exists $hash_pos{$id}->{$p}){ foreach my $o (keys %{$hash_pos{$id}->{$p}}){ $hash_stop{$p}->{$o}=1; } } # foreach interval count ++ if tag == 1 foreach my $keyu (keys %hash_stop){ foreach my $key (keys %{$hash_stop{$keyu}}){ $hash_pos{$id}->{$keyu}->{$key}++ if $2 eq '1'; # if end reached you are don with this # delete it from the hash_stop delete($hash_stop{$keyu}->{$key}) if $p == $key; } } } close IN; print Dumper(\%hash_pos);