#!/usr/bin/perl use strict; use warnings; chomp(my @previous = split /\t/, ); my $from = 1; my $to = $previous[2]-9 > 0 ? $previous[2]-9 : 0; # print '0 values' up to 8 less of margin for my $pos ($from..$to) { print join("\t", $previous[1], $pos, '','','0'), "\n"; } $from = $previous[2]-8 > 0 ? $previous[2]-8 : 1; $to = $previous[2]-1; # print margin of '1 values' up to first record for my $pos ($from .. $to) { print join("\t", $previous[1], $pos, '','','1'), "\n"; } # print first record print join("\t", @previous[1..4], '1'), "\n"; my $pos_count = $previous[2]; while () { chomp; my @current= split /\t/; if ($current[1] eq $previous[1]) { if (++$pos_count != $current[2]) { for my $pos ($pos_count .. $current[2]-1) { print join("\t", $current[1], $pos, '','', '1'), "\n"; } } print join("\t", @current[1..4], 1), "\n"; } else { # print '1 values' for margin of 8 past last pos for previous record for my $pos ($previous[2] + 1 .. $previous[2] + 8) { print join("\t", $previous[1], $pos, '','','1'), "\n"; } $from = 1; $to = $current[2]-9 > 0 ? $current[2]-9 : 0; # print '0 values' up to 8 less of margin for current record for my $pos ($from .. $to) { print join("\t", $current[1], $pos, '','','0'), "\n"; } $from = $current[2]-8 > 0 ? $current[2]-8 : 1; $to = $current[2]-1; # print '1 values' up to current record for my $pos ($from .. $to) { print join("\t", $current[1], $pos, '','','1'), "\n"; } print join("\t", @current[1..4], 1), "\n"; } $pos_count = $current[2]; @previous = @current; } # after last record printed, print out margin of 8 more for my $pos ($previous[2] + 1 .. $previous[2] + 8) { print join("\t", $previous[1], $pos, '','','1'), "\n"; } __DATA__ CLS_S3_Contig100_st CLS_S3_Contig100 53 10 0.3717 CLS_S3_Contig100_at CLS_S3_Contig100 55 11 0.4321 CLS_S3_Contig100_st CLS_S3_Contig100 57 10 0.3223 CLS_S3_Contig100_at CLS_S3_Contig100 59 11 0.4055 CLS_S3_Contig100_st CLS_S3_Contig100 61 11 0.4511 CLS_S3_Contig100_at CLS_S3_Contig100 63 11 0.474 CLS_S3_Contig10031_st CLS_S3_Contig10031 53 12 0.5548 CLS_S3_Contig10031_st CLS_S3_Contig10031 57 10 0.4871 CLS_S3_Contig10031_st CLS_S3_Contig10031 61 12 0.547 CLSS3627.b1_F19.ab1 CLS_S3_Contig10031 62 11 0.5129 CLSS3627.b1_F19.ab1 CLS_S3_Contig10031 64 11 0.5789