#!/usr/bin/perl use 5.010; use strict; use warnings; open BLOCKS,'blocks.txt'; open START,'start.txt'; open STOP,'stop.txt'; open NP,'np.txt'; open TRIPLET,'>triplet.txt'; my @blocks=; my @start=; my @stop=; my @np=; chomp @blocks; chomp @start; chomp @stop; chomp @np; my $i; my $index=0; my $first; my $second; my $third; my $a=0; my $b=1; my $c=3; my $flag; for($i=0;$i<(scalar(@blocks));$i++) { if($blocks[$index]=~m/^\d.+/) { if ($blocks[$a]=~m/^\d.+/ and $blocks[$b]=~m/^\d.+/ and $blocks[$c]=~m/^\d.+/) { if($np[$a] eq $np[$b] || $np[$a] eq $np[$b] || $np[$b] eq $np[$c]) { if ($np[$a] eq $np[$b]) { $flag=$np[$a]; print TRIPLET "$start[$a]\t$stop[$a]\t$np[$a]\t$flag\n"; print TRIPLET "$start[$b]\t$stop[$b]\t$np[$b]\t$flag\n"; print TRIPLET "$start[$c]\t$stop[$c]\t$np[$c]\t$flag\n"; } else { $flag=$np[$c]; print TRIPLET "$start[$a]\t$stop[$a]\t$np[$a]\t$flag\n"; print TRIPLET "$start[$b]\t$stop[$b]\t$np[$b]\t$flag\n"; print TRIPLET "$start[$c]\t$stop[$c]\t$np[$c]\t$flag\n"; } } else { #ambigious data print TRIPLET "$start[$a]\t$stop[$a]\t$np[$a]\t$np[$a]\n"; print TRIPLET "$start[$b]\t$stop[$b]\t$np[$b]\t$np[$b]\n"; print TRIPLET "$start[$c]\t$stop[$c]\t$np[$c]\t$np[$c]\n"; } elsif ($blocks[$a]=~m/^\d.+/ && $blocks[$b]=~m/^\d.+/) { if($np[$a] eq $flag || $np[$a] eq $flag) { print TRIPLET "$start[$a]\t$stop[$a]\t$np[$a]\t$flag\n"; print TRIPLET "$start[$b]\t$stop[$b]\t$np[$b]\t$flag\n"; } else { print TRIPLET "$start[$a]\t$stop[$a]\t$np[$a]\t$np[$a]\n"; print TRIPLET "$start[$b]\t$stop[$b]\t$np[$b]\t$np[$b]\n"; } } else { print TRIPLET "$start[$a]\t$stop[$a]\t$np[$a]\t$np[$a]\n"; } } else { print TRIPLET "$blocks[$index]\n"; } $index++; $a=+2; $b=+2; $c=+2; } close BLOCKS; close START; close STOP; close NP; close TRIPLET; exit;