Skip to main content

Introduction to Bioinformatics Algorithm Partial Digest source code in Perl

Partial Digest Problem :
Its a common known problem in bio-informatics where chunk of DNA with deferent length is given.Our work is to find out in what position this chunk is cut-up.I completed this problem by backtracking in Perl language where multiple solution can be found.The code is given here.You should first understand the problem than use this code.(For your good)I use Introduction to Bio-informatics Algorithm Book as reference.

*************************************************************************************


use strict;
use warnings;

main(@ARGV);

sub main
{

    # here value is the  set of piece which cut from entire length  and flag use for just check which piece used and which
    # piece not used before and unsed is counter for how much piece are not  used still now , inti is the starting point and
    # end is end point of entire length  and at the end point are the array which contain still now how much point we have
    # and whose are they, for  every dfs function or subrutine have  the necessary information to get the solution and it also
    # able to find multiple solution because it always main base case a trach its possible way

    my @value = (2,2,3,3,4,5,6,7,8);
    my @flag = (0,0,0,0,0,0,0,0,0);
    my @points ;
    push(@points,0);
    push(@points,10);
    my $unused  = 9;
    my $inti = 0;
    my $end = 10;
    dfs(\@value,\@points,\@flag,$unused,$inti,$end);

}


sub dfs
{

    my ($temp_value,$temp_points,$temp_flag,$unused,$inti,$end) = @_;
    my @value = @{$temp_value};
    my @points = @{$temp_points};
    my @flag = @{$temp_flag};
    my $current_point = 0 ;my $i;my $j;my $k;my $len;my $len2;my $cur;my $cnt ; my $check;
   
   
    # unused ==0 is the base case for the backtrack , here i know for every state we have only two candidate
    # so if we code two dfs one after another then we can handle this  easily so below i did this
   
    if($unused==0)
    {   
        print "here found a solution \n";
        @points = sort(@points);
        print "@points\n";
    }
   
    else
    {
   
        $len = scalar @value;
        for($i=$len-1; $i>=0;--$i)
        {
            if($flag[$i]==0)
            {
                $cur=$value[$i];
                last;
            }
        }
       
        $current_point =  $end - $cur;

        $cnt=0;
        $len= scalar @points;
        $len2=scalar @value;
        for($i=0;$i<$len;++$i)
        {
            $check = 0;
            for($j=0;$j<$len2;++$j)
            {
                if( (abs($current_point-$points[$i])==$value[$j]) && $flag[$j]==0)
                {
                    $check=1;
                    last;
                }
            }
            if($check==1)
            {
                ++$cnt;
            }
        }
       
        if($cnt==$len)
        {
       
            my @ommit;
            $len= scalar @points;
            $len2=scalar @value;
            for($i=0;$i<$len;++$i)
            {
                for($j=0;$j<$len2;++$j)
                {
                    if( (abs($current_point-$points[$i])==$value[$j]) && $flag[$j]==0)
                    {
                        $flag[$j]=1;
                        push(@ommit,$value[$j]);
                        last;
                    }
                }
            }
           
           
            #first dfs;
           
            push(@points,$current_point);
            dfs(\@value,\@points,\@flag,$unused-$len,$inti,$end);
            pop(@points);
           
           
            $len= scalar @ommit;
            $len2=scalar @value;
            for($i=0;$i<$len;++$i)
            {
                for($j=0;$j<$len2;++$j)
                {
                    if( $ommit[$i]==$value[$j] && $flag[$j]==1)
                    {
                        $flag[$j]=0;
                        last;
                    }
                }
            }
        }
       
       
        $current_point = $cur;
        $cnt=0;
        $len= scalar @points;
        $len2=scalar @value;
        for($i=0;$i<$len;++$i)
        {
            $check = 0;
            for($j=0;$j<$len2;++$j)
            {
                if( (abs($current_point-$points[$i])==$value[$j]) && $flag[$j]==0)
                {
                    $check = 1;
                    last;
                }
            }
            if($check==1)
            {
                ++$cnt;
            }
        }
       
        if($cnt==$len)
        {
           
            my @ommit;
            $len= scalar @points;
            $len2=scalar @value;
            for($i=0;$i<$len;++$i)
            {
                for($j=0;$j<$len2;++$j)
                {
                    if( (abs($current_point-$points[$i])==$value[$j]) && $flag[$j]==0)
                    {
                        $flag[$j]=1;
                        push(@ommit,$value[$j]);
                        last;
                    }
                }
            }
           
           
            # second dfs ;
           
            push(@points,$current_point);
            dfs(\@value,\@points,\@flag,$unused-$len,$inti,$end);
            pop(@points);
           
            $len= scalar @ommit;
            $len2=scalar @value;
            for($i=0;$i<$len;++$i)
            {
                for($j=0;$j<$len2;++$j)
                {
                    if( $ommit[$i]==$value[$j] && $flag[$j]==1)
                    {
                        $flag[$j]=0;
                        last;
                    }
                }
            }
        }
    }

}




Comments

  1. Great information about on Introduction to Bioinformatics Algorithm Partial Digest source code in Perl. Thanks for shearing about this I thinks its very hopeful post and very important post for us. I'm glad you enjoyed the post.Keep sharing such useful informations. So informative blog, thanks for providing valuable information.
    bioinformatics information

    ReplyDelete

Post a Comment

Popular posts from this blog

UDP server client in c

Server #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <stdio.h> #include <unistd.h> #include <errno.h> #include <string.h> #include <stdlib.h> int main() {         int sock;         int addr_len, bytes_read;         char recv_data[1024],send_data[1024];         struct sockaddr_in server_addr , client_addr;         if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {             perror("Socket");             exit(1);         }         server_addr.sin_family = AF_INET;         server_addr.sin...

My favourite writer Humayun Ahmed

There is none who can replace him.At least the standard which he create in is life time in the running literature it never be replaceable.The new generation which is all the time busy in playing PC games,chatting ,bands etc. only his writing makes them to take a glance on the literature.For example Himu and Misir ali all the time keep them on track by anti-logic and logic.They also have show-down on the novel.I myself read all of the books of Himu and Misir ali and wait for the new one to come every year.Now I have to wait for life time. Except books he makes our dirty film industry pure by his heart warming ,well versed film.Following him many new producer try to make well and good film (not the dirty one) .He also contribute our drama by his dashing drama's. In writing except romance ,logic ,anti-logic ,he also write many science fiction.His brother Sir Dr. Md. Zafar Iqbal is the man who started science fiction in bangla. The list of books: Selected novels • Lilaboti (2...

[ASTERIK] configure: error: *** uuid support not found (this typically means the uuid development package is missing)

ISSUE: Build error on Asterik , when you want test webrtc feature :) checking for uuid_generate_random in -luuid... no checking for uuid_generate_random in -le2fs-uuid... no checking for uuid_generate_random... no configure: error: *** uuid support not found (this typically means the uuid development package is missing) Fix: This issue arises due to missing of UUID generator specified by rfc4122 . +Linux sudo apt-get install uuid-dev  @Unix yum -y install libuuid-devel Asterik comes with lots of helpful script available on - asterisk/contrib/scripts/ folder of your ASTERIK source. So just use the following command on UNIX console to run the asterik pre-requisite script. contrib/scripts/install_prereq install And you are done! configuring. Now -- Make Asterik.