chr1 3204563 3661775 -
chr1 3204563 3600000 -
chr1 3204500 3660000 -
chr1 3204000 3204001 -
chr1 3204563 3760000 -
better illustrates the point. There are 3 instances where I should get a positive result for the first line in DB.out. However, rather than counting the number of times a hit occurs, the line from DB.out is printed 3 times (each with the count value of "1"):
Xkr4 chr1 3204562 3661779 - 3 457.217 1
Xkr4 chr1 3204562 3661779 - 3 457.217 1
Xkr4 chr1 3204562 3661779 - 3 457.217 1
I also added a step to reset the count to zero for each loop leaving:
my @file1 = ();
open(FILE, @ARGV[0]) ||
die ("could not open file @ARGV[0]\n");
while (my $line = <FILE>) {
chomp $line;
my ($chr, $start, $stop) = split(/\t/, $line);
push @file1, [$chr, $start, $stop];
}
close FILE;
open(FILE, @ARGV[1])||die ("could not open file @ARGV[1]\n");
while(<FILE>){
($Gene,$Chrom,$ModStart,$ModEnd,$Strand,$ExonCount,$SizeKB)= s
+plit;
foreach my $line (@file1){
$Count = 0;
my ($chr, $start, $stop) = @$line;
if ($chr eq $Chrom && $start gt $ModStart && $end lt $ModE
+nd){
$Count++;
print ("$Gene\t$Chrom\t$ModStart\t$ModEnd\t$Strand\t$ExonC
+ount\t$SizeKB\t$Count\n")
}
}
}
How do I get it to change the number to 3, and not print 3 times? |