Connect with us

Algorithms

Genetic Algorithm: Explanation and Perl Code

Published

on

When it comes to bioinformatics algorithms, Genetic algorithms top the list of most used and talked about algorithms in bioinformatics. Understanding the Genetic algorithm is important not only because it helps you to reduce the computational time taken to get a result but also because it is inspired by how nature works.

In this article, you will learn how a genetic algorithm works, the basic concept behind it and we will also write a program to illustrate the concepts. You can skip the explanation if you already know the basic concepts of Genetic Algorithm

Genetic Algorithm was developed by John Holland. It uses the concepts of Natural Selection and Genetic Inheritance and tries to mimic the biological evolution. It falls under the category of algorithms known as Evolutionary Algorithms. It can be used to find a solution to the hard problems where we don’t know much about the search space.

Let us understand how a genetic algorithm works. For this, let us consider a cancer-associated gene expression matrix. This matrix contains all the known genes found in human being and their level of expression.

For a given problem, the genetic algorithm works by maintaining a set of candidate solutions and then applies three operators over them – Selection, Recombination, and Mutation, which are collectively known as the stochastic operators.

  • Selection: In nature, if an organism is adapted to the environment, its population will grow relative to its quality of adaptation. This is referred to as selection. It means if a solution meets the conditional constraints, it is replicated at a rate which is proportional to the relative quality.
  • Recombination: In nature, two similar chromosomes of the surviving individual exchange genes during sexual reproduction in a process known as Crossing Over. In GA we decompose two distinct solutions and randomly mix their parts to form novel solutions
  • Mutation: Random changes in an existing chromosome may lead to some fitter individual. This concept is utilized to randomly perturbs a candidate solution
1. produce an initial population of individuals
2. evaluate the fitness of all individuals
3. while termination condition not met do
4.    select fitter individuals for reproduction
5.    recombine between individuals
6.    mutate individuals
7.    evaluate the fitness of the modified individuals
8.    generate a new population
9. End while

Have a look at the Genetic Algorithm illustrated in the diagram below to understand it more clearly.
Genetic Algorithm Diagram

The program

We are going to implement the Genetic Algorithm and write a program in Perl for it. Although not purely applicable to a real-life problem, it should be sufficient to familiarize you with the Genetic Algorithm.

Suppose that you had a set of Gene expression data. The data is for all 25000 genes in the human genome and you want to find out what are the five values among all 25000 values whose sum can give you the highest number.

For the purpose of this program we will require four subroutines:

  • Generate: It will generate chromosomes containing 5 values(specified in variable $GeneNumberConstraint) selected at random at positions
  • Mutate: It mutates a chromosome at random position with a random value less than specified in $HighestMutationValue
  • Survival Check: It checks if the newly formed chromosome is viable. i.e. It has a value that is up to a minimum specification. (Checking for fitness)
  • Recombine: It will form new combinations from the existing chromosome by crossing them over with each other.

The Code

If you wish, you can download the Perl code on GitHub https://github.com/bioinformaticsreview
/geneticalgorithm

So here is the final code implementing Genetic Algorithm in Perl:

# Written by Tariq Abdullah
# Author, Bioinformatics Review
# [email protected]
# www.bioinformaticsreview.com

$CurrentHighest=0;

@GeneExpressionData = (1,3,8,5,2,4,46,6,78,7,9,9
,0,1,1,1,5,59,9,97,7,6,5,45
,4,3,23,2,22,2,2,4,5,5,6,54);
@SolutionSpace = ();
$HighestMutationValue = 110;
$GeneNumberConstraint = 5;
$InitialThreshold  = 10;
$genes	= scalar @GeneExpressionData;
@chromosome = ();
 $sum = 0;
$steps= 10;

print "The Total Genes are: $genes\n";

generate();
$steps = 10;

for($p=0;$p<=$steps;$p++){
 generate();
 SurvivalCheck();
 mutate();
 SurvivalCheck();
 recombine();
 SurvivalCheck();
}


print "\n\n Genetic Algorithm Result
\n\n\n\t\tHighest Detected: $CurrentHighest in $steps Steps\n\n";


sub mutate{
 $randpos = int(rand($gene));
 $n = int(rand($HighestMutationValue));
 $chromosome[$randpos] = $n;
 print "\n Mutation Took Place in Chromosome @chromosome ";
}

sub recombine
{
  print "\nRecombining\n\n";
		
  @chromosome1 = $SolutionSpace[int rand($p)];
  @chromosome2 =  $SolutionSpace[int rand($p)];
  print "Random Sequence Chromosome from Solution Space: @chromosome1 and @chromosome2";
  for($i=0; $i<=$GeneNumberConstraint/2; $i++){ my $random_number = int(rand(3)) + 1; $pos1 = int(rand($GeneNumberConstraint)); $pos1 = int(rand($GeneNumberConstraint)); $swap = $chromosome1[$pos1]; $chromosome1[$pos1] = $chromosome2[$pos2]; $chromosome2[$pos2] = $swap; } print "The Recombination led to @chromosome"; @chromosome = (); @chromosome = @chromosome1; } sub SurvivalCheck{ $sum = 0; foreach $val (@chromosome){ $sum += $val; } if($sum>$CurrentHighest){
   $CurrentHighest = $sum;
   push @SolutionSpace, @chromosome;
   print "\nIndividual is alive! \nCurrent Highest Expression: $CurrentHighest";		return 1;
 }

 else{
  print "\nSpecies Didn't Survive! \n"; 
  return 0;
 }
	
}

sub generate{
 @chromosome = ();
 for($i=1;$i<=$GeneNumberConstraint;$i++){
  $n = int(rand($genes));
  push @chromosome, $GeneExpressionData[$n];
  $sum += $GeneExpressionData[$n];		
 }
	
 print "\n\n\nGenerated Chromosome: @chromosome \n";
}


That’s all! Feel free to comment and discuss if you have any confusion. Like this article? Share it.. ha?

Tariq is founder of Bioinformatics Review and CEO at IQL Technologies. His areas of expertise include algorithm design, phylogenetics, MicroArray, Plant Systematics, and genome data analysis. If you have questions, reach out to him via his homepage.

Advertisement
Click to comment

You must be logged in to post a comment Login

Leave a Reply

Algorithms

MOCCA- A New Suite to Model cis- regulatory Elements for Motif Occurrence Combinatorics

Published

on

MOCCA- A New Suite to Model cis- regulatory Elements for Motif Occurrence Combinatorics

cis-regulatory elements are DNA sequence segments that regulate gene expression. cis-regulatory elements consist of some regions such as promoters, enhancers, and so on. These regions consist of specific sequence motifs. (more…)

Continue Reading

Algorithms

vs_Analysis.py: A Python Script to Analyze Virtual Screening Results of Autodock Vina

Dr. Muniba Faiza

Published

on

VS-Analysis: A Python Script to Analyze Virtual Screening Results of Autodock Vina

The output files obtained as a result of virtual screening (VS) using Autodock Vina may be large in number. It is difficult or quite impossible to analyze them manually. Therefore, we are providing a Python script to fetch top results (i.e., compounds showing low binding affinities). (more…)

Continue Reading

Algorithms

How to search motif pattern in FASTA sequences using Perl hash?

Dr. Muniba Faiza

Published

on

Here is a simple Perl script to search for motif patterns in a large FASTA file with multiple sequences.

(more…)

Continue Reading

Algorithms

How to read fasta sequences from a file using PHP?

Published

on

Here is a simple function in PHP to read fasta sequences from a file. (more…)

Continue Reading

Algorithms

How to read fasta sequences as hash using perl?

Published

on

This is a simple Perl script to read a multifasta file as a hash. (more…)

Continue Reading

Algorithms

BETSY: A new backward-chaining expert system for automated development of pipelines in Bioinformatics

Dr. Muniba Faiza

Published

on

Bioinformatics analyses have become long and difficult as it involves a large number of steps implemented for data processing. Bioinformatics pipelines are developed to make this process easier, which on one hand automate a specific analysis, while on the other hand, are still limited for investigative analyses requiring changes to the parameters used in the process. (more…)

Continue Reading

Algorithms

Algorithm and workflow of miRDB

Published

on

As mentioned in the previous article, Micro RNAs (miRNAs) are the short endogenous RNAs (~22 nucleotides) and originate from the non-coding RNAs [1], produced in single-celled eukaryotes, viruses, plants, and animals [2]. They play significant roles in various biological processes such as degradation of mRNA [3]. Several databases exist storing a large amount of information about miRNAs, one of such databases miRBase [4] was explained in the previous article, today we will explain the algorithm of miRDB [5,6], another database for miRNA target prediction. (more…)

Continue Reading

Algorithms

miRBase: Explained

Dr. Muniba Faiza

Published

on

Micro RNAs (miRNAs) are the short endogenous RNAs (~22 nucleotides) and originate from the non-coding RNAs [1], produced in single-celled eukaryotes, viruses, plants, and animals [2]. miRNAs are capable of controlling homeostasis [2] and play significant roles in various biological processes such as degradation of mRNA and post-translational inhibition through complementary base pairing [3].  (more…)

Continue Reading

Algorithms

Prediction of biochemical reactions catalyzed by enzymes in humans

Dr. Muniba Faiza

Published

on

There are many biological important enzymes which exist in the human body, one of them is Cytochrome P450 (CyP450) enzymes which are mostly considered in drug discovery due to their involvement in the majority (75%) of drug metabolism [1]. Therefore, various in-silico methods have been applied to predict the possible substrates of CyP 450 enzymes [2-4]. Recently, an in-silico model has been developed to predict the potential chemical reactions mediated by the enzymes present in humans including CyP450 enzymes [5]. (more…)

Continue Reading

Algorithms

A new high-level Python interface for MD simulation using GROMACS

Published

on

The roots of the molecular simulation application can be traced back to physics where it was applied to simplified hard-sphere systems [1]. This field of molecular simulation study has gained a lot of interest since then and applied to perform simulations to fold small protein at multi-microsecond scale [2-4], predict functional properties of receptors and to capture the intermediate transitions of the complex [5], and to study the movement and behavior of ligand in a binding pocket and also to predict interactions between receptors and ligands [6,7]. (more…)

Continue Reading

Algorithms

Machine learning in prediction of ageing-related genes/proteins

Dr. Muniba Faiza

Published

on

Ageing has a great impact on human health, when people’s age advance towards 80 years, approximately half of the proteins in the body get damaged through oxidation. The chemical degradations occurring in our body produce energy by the consumed food via oxidation in the presence of oxygen. (more…)

Continue Reading

Algorithms

Simulated sequence alignment software: An alternative to MSA benchmarks

Dr. Muniba Faiza

Published

on

In our previous article, we discussed different multiple sequence alignment (MSA) benchmarks to compare and assess the available MSA programs. However, since the last decade, several sequence simulation software have been introduced and are gaining more interest. In this article, we will be discussing various sequence simulating software being used as alternatives to MSA benchmarks. (more…)

Continue Reading

Algorithms

Benchmark databases for multiple sequence alignment: An overview

Dr. Muniba Faiza

Published

on

Multiple sequence alignment (MSA) is a very crucial step in most of the molecular analyses and evolutionary studies. Many MSA programs have been developed so far based on different approaches which attempt to provide optimal alignment with high accuracy. Basic algorithms employed to develop MSA programs include progressive algorithm [1], iterative-based [2], and consistency-based algorithm [3]. Some of the programs incorporate several other methods into the process of creating an optimal alignment such as M-COFFEE [4] and PCMA [5]. (more…)

Continue Reading

Algorithms

ab-initio prediction of protein structure: An introduction

Dr. Muniba Faiza

Published

on

We have heard a lot about the ab-initio term in Bioinformatics, which could be difficult to understand for newbies in the field of bioinformatics. Today, we will discuss in detail what ab-initio is and what are the applicable methods for it. (more…)

Continue Reading

Algorithms

Intrinsically disordered proteins’ predictors and databases: An overview

Published

on

Intrinsically unstructured proteins (IUPs) are the natively unfolded proteins which must be unfolded or disordered in order to perform their functions.  They are commonly referred to as intrinsically disordered proteins (IDPs) and play significant roles in regulating and signaling biological networks [1]. IDPs are also involved in the assembly of signaling complexes and in the dynamic self-assembly of membrane-less nuclear and cytoplasmic organelles [1]. The disordered regions in a protein can be highly conserved among the species in respect of both the composition and the sequence [2]. (more…)

Continue Reading

Algorithms

An introduction to the predictors of pathogenic point mutations

Dr. Muniba Faiza

Published

on

Single nucleotide variation is a change in a single nucleotide in a sequence irrespective of the frequency of the variation. Single nucleotide variants (SNVs) play a very important role in causing several diseases such as the tumor, cancer, etc. Many efforts have been made to identify the SNVs which were initially based on identifying non-synonymous mutations in coding regions of the genomes. (more…)

Continue Reading

Algorithms

SparkBLAST: Introduction

Dr. Muniba Faiza

Published

on

The basic local alignment search tool (BLAST) [1,2] is known for its speed and results, which is also a primary step in sequence analysis. The ever-increasing demand for processing huge amount of genomic data has led to the development of new scalable and highly efficient computational tools/algorithms. For example, MapReduce is the most widely accepted framework which supports design patterns representing general reusable solutions to some problems including biological assembly [3] and is highly efficient to handle large datasets running over hundreds to thousands of processing nodes [4]. But the implementation frameworks of MapReduce (such as Hadoop) limits its capability to process smaller data. (more…)

Continue Reading

Algorithms

Role of Information Theory, Chaos Theory, and Linear Algebra and Statistics in the development of alignment-free sequence analysis

Published

on

By

Sequence alignment is customary to not only find similar regions among a pair of sequences but also to study the structural, functional and evolutionary relationship between organisms. Many tools have been discovered to achieve the goal of alignment of a pair of sequences, separately for nucleotide sequence and amino acid sequence, BLOSSUM & PAM [1] are a few to name. (more…)

Continue Reading

Algorithms

Bioinformatics Challenges and Advances in RNA interference

Published

on

By

 

 

RNA interference is a post-transcriptional gene regulatory mechanism to down-regulate the gene expression either by mRNA degradation or by mRNA translation inhibition. The mechanism involves a small partially complementary RNA against the target gene. To perform the action, it also requires a class of dedicated proteins to process these primary RNAs into mature microRNAs. The guide sequence determines the specificity of the miRNA. Therefore, the knowledge of the guide sequence is crucial for predicting its targets and also exploiting the sequence to create a new regulatory circuit. In this short review, we will briefly discuss the role and challenges in miRNA research for unveiling the target prediction by bioinformatics and to foster our understanding and applications of RNA interference. (more…)

Continue Reading

Algorithms

Systems pharmacology and drug development

Dr. Muniba Faiza

Published

on

Systems pharmacology is an emerging area in the field of medicinal chemistry and pharmacology which utilizes systems network to understand drug action at the organ and organism level. It applies the computational and experimental systems biology approaches to pharmacology, which includes network analyzes at multiple biological organization levels facilitating the understanding of both therapeutic and adverse effects of the drugs. Nearly a decade ago, the term systems pharmacology was used to define the drug action in a specific organ system such as reproductive pharmacology [1], but to date, it has been expanded to different organ and organism levels [2]. (more…)

Continue Reading

LATEST ISSUE

ADVERT