in reply to Re: Hash_of_Hash_Would do it?
in thread Hash_of_Hash_Would do it?

Thank your very much GrandFather,

The code works perfect, but when the gap between two adjacent PIP in the original file is large let's say 16 or more it behaves differently.

Please take a look at the input and output files I have included here. In the output after 949 it has printed three "1"s instead of 8.

I went through the code and I think a condition should be added here. To see if the gap in pip is greater or equal to 16. is my speculation right?

my $first = $pip > 8 ? $pip - 8 : 0; my $last = $pip + 8;
Original CLS_S3_Contig1000 933 10 0.488 CLS_S3_Contig1000 935 9 0.4867 CLS_S3_Contig1000 937 9 0.4989 CLS_S3_Contig1000 939 10 0.503 CLS_S3_Contig1000 943 8 0.3531 CLS_S3_Contig1000 949 8 0.3477 CLS_S3_Contig1000 1060 6 0.1498 CLS_S3_Contig1000 1070 9 0.3885 CLS_S3_Contig1000 1071 8 0.3848 OUTPUT CLS_S3_Contig1000 933 10 0.488 1 CLS_S3_Contig1000 934 1 CLS_S3_Contig1000 935 9 0.4867 1 CLS_S3_Contig1000 936 1 CLS_S3_Contig1000 937 9 0.4989 1 CLS_S3_Contig1000 938 1 CLS_S3_Contig1000 939 10 0.503 1 CLS_S3_Contig1000 940 1 CLS_S3_Contig1000 941 1 CLS_S3_Contig1000 942 1 CLS_S3_Contig1000 943 8 0.3531 1 CLS_S3_Contig1000 944 1 CLS_S3_Contig1000 945 1 CLS_S3_Contig1000 946 1 CLS_S3_Contig1000 947 1 CLS_S3_Contig1000 948 1 CLS_S3_Contig1000 949 8 0.3477 1 CLS_S3_Contig1000 950 1 CLS_S3_Contig1000 951 1 CLS_S3_Contig1000 952 0 CLS_S3_Contig1000 953 0 CLS_S3_Contig1000 954 0 CLS_S3_Contig1000 955 0 CLS_S3_Contig1000 956 0 CLS_S3_Contig1000 957 0

Replies are listed 'Best First'.
Re^3: Hash_of_Hash_Would do it?
by GrandFather (Saint) on Sep 16, 2008 at 00:48 UTC

    It needs a little more work than that. Replace the fake up loop and preceding line with:

    my $lastToAdd = -1; # Fake up present flag for +/- 8 lines around real data for my $pip (0 .. $#$origin) { next if $pip > $lastToAdd and ! defined $origin->[$pip]; if ($pip <= $lastToAdd and ! defined $origin->[$pip]) { @{$origin->[$pip]}[0 .. $numColumns - 1] = ('', $oKey, $pip + 1, ('') x $numColumns); next; } my $first = $pip > 8 ? $pip - 8 : 0; for my $index ($first .. $pip) { next if defined $origin->[$index]; @{$origin->[$index]}[0 .. $numColumns - 1] = ('', $oKey, $index + 1, ('') x $numColumns); } $lastToAdd = $pip + 8; }

    The problem of course is that the finish point needs to be reset each time a new real line is found.


    Perl reduces RSI - it saves typing