#!/usr/bin/perl use strict; use warnings; use LWP::Simple; use Data::Dumper; my $sequence="GGCGCAACGCTGAGCAGCTGGCGCGTCCCGCGCGGCCCCAGTTCTGCGCAGCTTCCCGAGGCTCCGCACCAGCCGCGCTTCTGTCCGCCTGCAGGGCATT"; ############ Make hash of rejected length ############### my $input = "fragments.txt"; my %split; open (my $infile, "<", $input) or die "Cannot open file '$input' for reading: $!"; build_hash($_) while <$infile>; close ($infile) or die "Cannot close file '$input': $!"; build_hash(length($sequence) + 1); sub build_hash{ use feature 'state'; state $old = 0; state $cnt = 1; my ($line) = @_; my $gap = $line - $old; my $start = $old + 1; my $end = ($gap > 2) ? $line - 1 : $start; $split{$cnt++} = [$start .. $end] if $gap >= 2; $old = $line; } ############# Write HTML file ############################# #my $header; open (AA, ">fragments.html") or die "Cannot open file:$!"; print AA <<"EndOfHTML";
EndOfHTML
#print AA "$header\n";
my $red = '';
my $span = '';
my $brk = qq{
\n};
for (my $pos=1;$pos<=length($sequence);$pos++){
my $FLAG=0;my @temp=();
foreach my $k(sort {$a <=> $b} keys %split){
my @pos=@{$split{$k}};
my $p1 =$pos[0];
my $p2 =$pos[$#pos];
if($pos == $p1){
push (@temp, $red);
for(my $p=$p1;$p<=$p2;$p++){
my $s=substr($sequence,$p-1,1);
push (@temp,$s);
if($p==int($p/50)*50){
push (@temp, $brk);
}
$FLAG=1; $pos++;
}
push (@temp, $span);
}
}
if($FLAG ==0){
my $s=substr($sequence,$pos-1,1);
print AA "$s";
}
else{
printf AA join("",@temp);
}
if($pos==int($pos/50)*50){
printf AA "$brk";
}
}
print AA <<"EndOfHTML";
EndOfHTML
close (AA);