Our Sponsors

Download BioinformaticsOnline(BOL) Apps in your chrome browser.



Compress and decompress the sequence with perl

  • Public
By Jit 254 days ago
use strict; use warnings; my @char; while (<DATA>) { @char = split //; } comp(\@char); #--------------------- my $com= "r0a3m4a4j0"; my @com = split //, $com; dcomp (\@com); #dcomp sub here sub dcomp { my ($com_ref)=@_; my @com=@$com_ref; my $car; for (my $aa=0; $aa<=$#com; $aa++) { if ($com[$aa]!~ /\D/) { print "$car" x ($com[$aa]);} else {print "$com[$aa]"; $car = "$com[$aa]";} } print "\n"; } #comp sub here sub comp { my ($char_ref)=@_; my @char=@$char_ref; my $cnt=""; for (my $aa=0; $aa<=$#char; $aa++) { if ($char[$aa+1]) { if ($char[$aa] eq $char[$aa+1]) { $cnt++; } elsif ($cnt) { print "$char[$aa]"."$cnt"; undef $cnt;} else {print "$char[$aa]";} } } print "\n"; } __DATA__ raaaammmmmaaaaaj