Monday, November 5, 2018

Music Search using Google Assistant in Android

Google Assistant

The Google Assistant app allows you to quickly access your smartphone assistant by pressing and holding down your home button or by simply saying, “Ok Google.” It can open your smartphone apps by passing system commands to your Android operating system.

Google is a world's most popular search engine. It is highly famous for keyword search, and image search. Google's voice recognition feature allows searching music or videos by matching the sound. This feature can be simply accessed from Android smartphones through Google Assistant by entering the keywords (or voice) “(What|Find|What's|etc.)” and “(Song)”. For example, “what song”. This is a simple tutorial for searching music from Google through Google Assistant.

Accessing Google Assistant

Download Google Assistant app from Google Play Store, if you do not have in your smartphone. Open the Google Assistant app and press the keypad icon. Now enter the keyword “what song” and play the music.

Google Assistant Music Search

Google Assistant Music Match

Google Assistant displays the list(s) of matching music (song) and/or video (movie).

Google Assistant Music Match

Sunday, October 7, 2018

NCBI BLAST Graphical Summary using HTML/CSS

NCBI BLAST Color Key

This is a simple tutorial for designing a webpage for displaying the graphical summary of biological sequence alignment similar to the output of the NCBI BLAST+ program using HTML and CSS languages. In this tutorial, I have given few example hits (in bars) that match all range of bit scores (mentioned by color key).

NCBI BLAST Graphical Summary

NCBI BLAST is a most popular bioinformatics framework for finding local similarity between two or more biological sequences. It addresses a fundamental problem in bioinformatics research. The heuristic algorithm it uses is much faster than other approaches, such as calculating an optimal alignment. This emphasis on speed is vital to making the algorithm practical on the huge genome databases currently available, although subsequent algorithms can be even faster.

In NCBI BLAST, the graphic is an overview of the database sequences aligned to the query sequence. These are represented horizontal bars colored coded by score and showing the extent of the alignment on the query sequence. Separate aligned regions on the same database sequence are connected by a thin grey line. Mousing over an alignment shows the database sequence title. Clicking the line link to the sequence alignment itself in the Alignments section of the result.

Source Code

HTML: index.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>NCBI Blast Result</title>
  <link rel="stylesheet" type="text/css" href="css/style.css" media="screen">
</head>
<body>
  <div id="graphic" class="hidden shown" style="zoom: 1;">
    <div id="grapArea">
      <div id="grBlastHits">
        <div id="df">Mouse over to see the title, click to show alignments</div>

        <div id="clkey">
          <div class="clKeyTl"> Color key for alignment scores</div>

          <div class="leftGr masterLen">
            <div class="clkey">
              <span class="black ck"></span><span class="cl">&lt;40</span>
            </div>
            <div class="clkey">
              <span class="blue ck"></span><span class="cl">40-50</span>
            </div>
            <div class="clkey">
              <span class="green ck"></span><span class="cl">50-80</span>
            </div>
            <div class="clkey">
              <span class="purple ck"></span><span class="cl">80-200</span>
            </div>
            <div class="clkey">
              <span class="red ck"></span><span class="cl">&gt;=200</span>
            </div>
          </div>

          <div class="grQuery leftGr masterLen"><span>Query</span></div>

          <div class="leftGr grpos"> 
            <div class="scale" style="margin-left:0px"></div>
            <div class="scale" style="margin-left:90px"></div>
            <div class="scale" style="margin-left:90px"></div>
            <div class="scale" style="margin-left:90px"></div>
            <div class="scale" style="margin-left:90px"></div>
            <div class="scale" style="margin-left:90px"></div>
          </div>

          <div class="leftGr grpos"> 
            <div class="sdg" style="margin-left: 0px; width: 10px;">1</div>
            <div class="sdg" style="margin-left: 72px; width: 20px;">70</div>
            <div class="sdg" style="margin-left: 72px; width: 30px;">140</div>
            <div class="sdg" style="margin-left: 62px; width: 30px;">210</div>
            <div class="sdg" style="margin-left: 62px; width: 30px;">280</div>
            <div class="sdg" style="margin-left: 62px; width: 30px;">350</div>
          </div>

          <div class="leftGr grpos"> 
            <div style="width:17px;" class="h4 white"></div>
            <div class="purple">
              <a title="Structure of Benzoate Coa Ligase" class="graphSeq h4" href="#" style="width:154px;"></a>
            </div>
            <div style="width:13px;" class="h1 grey"></div>
            <div class="purple">
              <a title="Structure of Benzoate Coa Ligase" class="graphSeq h4" href="#" style="width:153px;"></a>
            </div>
            <div style="width:14px;" class="h1 grey"></div>
            <div class="purple">
              <a title="Structure of Benzoate Coa Ligase" class="graphSeq h4" href="#" style="width:148px;"></a>
            </div>
          </div>
          
          <div class="leftGr grpos"> 
            <div class="red">
              <a title="Mycobacterium Tuberculosis Ftsz" class="graphSeq h4" href="#" style="width:500px;"></a>
            </div>
          </div>

          <div class="leftGr grpos">
            <div style="width:27px;" class="h4 white"></div>
            <div class="purple">
              <a title="Structure of N-terminal domain" class="graphSeq h4" href="#" style="width:170px;"></a>
            </div>
            <div style="width:1px;" class="h6 black"></div>
            <div class="purple">
              <a title="Structure of N-terminal domain" class="graphSeq h4"  href="#" style="width:166px;"></a>
            </div>
            <div style="width:1px;" class="h6 black"></div>
            <div class="purple">
              <a title="Structure of N-terminal domain" class="graphSeq h4"  href="#" style="width:135px;"></a>
            </div>
          </div>
          
          <div class="leftGr grpos"> 
            <div class="red">
              <a title="Cell Division Protein" class="graphSeq h4" href="#" style="width:500px;"></a>
            </div>
          </div>

          <div class="leftGr grpos"> 
            <div class="red">
              <a title="GTP-bound, double-stranded" class="graphSeq h4" href="#" style="width:500px;"></a>
            </div>
          </div>

          <div class="leftGr grpos"> 
            <div class="red">
              <a title="Structure of a Cell Division" class="graphSeq h4" href="#" style="width:413px;"></a>
            </div>
          </div>

          <div class="leftGr grpos"> 
            <div style="width:9px;" class="h4 white"></div>
            <div class="red">
              <a title="Ftsz B. Subtilis" class="graphSeq h4" href="#" style="width:490px;"></a>
            </div>
          </div>

          <div class="leftGr grpos"> 
            <div style="width:33px;" class="h4 white"></div>
            <div class="red">
              <a title="Structure of Ftsz:mciz Complex" class="graphSeq h4" href="#" style="width:379px;"></a>
            </div>
          </div>

          <div class="leftGr grpos"> 
            <div style="width:33px;" class="h4 white"></div>
            <div class="red">
              <a title="Bacillus Subtilis Ftsz" class="graphSeq h4" href="#" style="width:379px;"></a>
            </div>
          </div>

          <div class="leftGr grpos"> 
            <div style="width:8px;" class="h4 white"></div>
            <div class="red">
              <a title="Staphylococcus Aureus" class="graphSeq h4" href="#" style="width:405px;"></a>
            </div>
          </div>

          <div class="leftGr grpos"> 
            <div class="red">
              <a title="Homo sapiens chromosome 11" class="graphSeq h4" href="#" style="width:114px;"></a>
            </div>
            <div style="width:1px;" class="h6 black"></div>
            <div class="purple">
              <a title="Homo sapiens chromosome 11" class="graphSeq h4" href="#" style="width:174px;"></a>
            </div>
            <div style="width:1px;" class="h6 black"></div>
            <div class="red">
              <a title="Homo sapiens chromosome 11" class="graphSeq h4" href="#" style="width:2px;"></a>
            </div>
            <div style="width:1px;" class="h6 black"></div>
            <div class="red">
              <a title="Homo sapiens chromosome 11" class="graphSeq h4" href="#" style="width:207px;"></a>
            </div>
          </div>
          
          <div class="leftGr grpos"> 
            <div style="width:7px;" class="h4 white"></div>
            <div class="red">
              <a title="Staphylococcal Aureus Complex" class="graphSeq h4" href="#" style="width:490px;"></a>
            </div>
          </div>

          <div class="leftGr grpos"> 
            <div style="width:80px;" class="h4 white"></div>
            <div class="green">
              <a title="Structure of Luciferase Enzyme" class="graphSeq h4" href="#" style="width:86px;"></a>
            </div>
            <div style="width:81px;" class="h1 grey"></div>
            <div class="green">
              <a title="Structure of Luciferase Enzyme" class="graphSeq h4" href="#" style="width:86px;"></a>
            </div>
            <div style="width:80px;" class="h1 grey"></div>
            <div class="green">
              <a title="Structure of Luciferase Enzyme" class="graphSeq h4" href="#" style="width:86px;"></a>
            </div>
          </div>
          
          <div class="leftGr grpos"> 
            <div style="width:7px;" class="h4 white"></div>
            <div class="red">
              <a title="Staphylococcus Aureus" class="graphSeq h4" href="#" style="width:490px;"></a>
            </div>
          </div>

          <div class="leftGr grpos"> 
            <div style="width:8px;" class="h4 white"></div>
            <div class="red">
              <a title="Staphylococcus R29a Mutant" class="graphSeq h4" href="#" style="width:405px;"></a>
            </div>
          </div>

          <div class="leftGr grpos"> 
            <div style="width:8px;" class="h4 white"></div>
            <div class="red">
              <a title="Staphylococcus Aureus Gdp-form" class="graphSeq h4" href="#" style="width:405px;"></a>
            </div>
          </div>

          <div class="leftGr grpos"> 
            <div style="width:8px;" class="h4 white"></div>
            <div class="red">
              <a title="Staphylococcus Aureus Ftsz" class="graphSeq h4" href="#" style="width:405px;"></a>
            </div>
          </div>

          <div class="leftGr grpos"> 
            <div style="width:33px;" class="h4 white"></div>
            <div class="red">
              <a title="S. aureus FtsZ GTP" class="graphSeq h4" href="#" style="width:380px;"></a>
            </div>
          </div>

          <div class="leftGr grpos"> 
            <div style="width:33px;" class="h4 white"></div>
            <div class="red">
              <a title="S. aureus FtsZ F138A" class="graphSeq h4" href="#" style="width:380px;"></a>
            </div>
          </div>

          <div class="leftGr grpos"> 
            <div style="width:7px;" class="h4 white">
            </div><div class="red">
              <a title="Staphylococcus Mutant" class="graphSeq h4" href="#" style="width:490px;"></a>
            </div>
          </div>

          <div class="leftGr grpos"> 
            <div style="width:7px;" class="h4 white"></div>
            <div class="red">
              <a title="1 Angstrom Resolution Structure" class="graphSeq h4" href="#" style="width:415px;"></a>
            </div>
          </div>

          <div class="leftGr grpos"> 
            <div style="width:7px;" class="h4 white"></div>
            <div class="red">
              <a title="S. aureus T7 Mutant" class="graphSeq h4" href="#" style="width:490px;"></a>
            </div>
          </div>

          <div class="leftGr grpos"> 
            <div style="width:33px;" class="h4 white"></div>
            <div class="red">
              <a title="Staphylococcus Aureus semet" class="graphSeq h4" href="#" style="width:380px;"></a>
            </div>
          </div>

          <div class="leftGr grpos"> 
            <div style="width:28px;" class="h4 white"></div>
            <div class="red">
              <a title="Structure of Sula:ftsz" class="graphSeq h4" href="#" style="width:384px;"></a>
            </div>
          </div>

          <div class="leftGr grpos"> 
            <div style="width:28px;" class="h4 white"></div>
            <div class="red">
              <a title="Pseudomonas Aeruginosa Gdp" class="graphSeq h4" href="#" style="width:472px;"></a>
            </div>
          </div>

          <div class="leftGr grpos"> 
            <div style="width:3px;" class="h4 white"></div>
            <div class="red">
              <a title="FtsZ, T7 mutated, T. maritima" class="graphSeq h4" href="#" style="width:409px;"></a>
            </div>
          </div>

          <div class="leftGr grpos"> 
            <div style="width:11px;" class="h4 white"></div>
            <div class="red">
              <a title="FtsZ W319Y mutant" class="graphSeq h4" href="#" style="width:414px;"></a>
            </div>
          </div>

          <div class="leftGr grpos"> 
            <div style="width:11px;" class="h4 white"></div>
            <div class="red">
              <a title="FtsZ GMPCPP soak I213" class="graphSeq h4" href="#" style="width:414px;"></a>
            </div>
          </div>

          <div class="leftGr grpos"> 
            <div style="width:11px;" class="h4 white"></div>
            <div class="red">
              <a title="Cell-Division Protein" class="graphSeq h4" href="#" style="width:414px;"></a>
            </div>
          </div>

          <div class="leftGr grpos"> 
            <div style="width:28px;" class="h4 white"></div>
            <div class="red">
              <a title="Aquifex Aeolicus Ftsz" class="graphSeq h4" href="#" style="width:401px;"></a>
            </div>
          </div>

          <div class="leftGr grpos"> 
            <div style="width:17px;" class="h4 white"></div>
            <div class="blue">
              <a title="4-chlorobenzoyl-coa Ligase" class="graphSeq h4" href="#" style="width:104px;"></a>
            </div>
            <div style="width:62px;" class="h1 grey"></div>
            <div class="blue">
              <a title="4-chlorobenzoyl-coa Ligase" class="graphSeq h4" href="#" style="width:105px;"></a>
            </div>
            <div style="width:62px;" class="h1 grey"></div>
            <div class="blue">
              <a title="4-chlorobenzoyl-coa Ligase" class="graphSeq h4" href="#" style="width:104px;"></a>
            </div>
          </div>
          
          <div class="leftGr grpos"> 
            <div style="width:45px;" class="h4 white"></div>
            <div class="blue">
              <a title="Methanosaeta Thermophila" class="graphSeq h4" href="#" style="width:419px;"></a>
            </div>
          </div>

          <div class="leftGr grpos"> 
            <div style="width:49px;" class="h4 white"></div>
            <div class="black">
              <a title="Cetz2 Haloferax Volcanii" class="graphSeq h4" href="#" style="width:252px;"></a>
            </div>
          </div>

          <div class="leftGr grpos"> 
            <div style="width:13px;" class="h4 white"></div>
            <div class="black">
              <a title="Cetz1 Haloferax Volcanii" class="graphSeq h4" href="#" style="width:236px;"></a>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</body>
</html>

CSS: style.css
body {
  margin: 0;
  padding: 0 0 10px;
  color: #333;
  font: 83%/1.5 arial, tahoma, verdana, sans-serif;
}

p { margin: 0 0 1.75em }

#graphic {
  text-align: center;
  margin: auto;
  padding: 0 0 10px;
}

#clkey {
  background-color: White;
  border: 1px solid black;
  padding-bottom: 1em;
  width: 610px;
  padding-right:1em;
}

.grQuery {
  clear: left;  
  font-family: verdana;
  font-size: 11px;
  font-weight: bold;
  height: 12px;  
  vertical-align: text-top;  
  background-color: #58c7c7; 
  color: black;
}
.grQuery.leftGr.masterLen > span {
  display: inline-block;
  margin-top: -4px;
}

.leftGr.grpos {
  clear: left;
}

.leftGr {
  margin-left: 70px;  
}

.leftGr.grpos > img {
  float: left;
}

.leftGr.grpos div {
  margin-bottom: 5px;
}
.leftGr.grpos div {
  float: left;
}

.grSpace, .grH, .h4 {
  height: 4px;
}

.h6 {
  height: 6px;
}
.h1 {
  height: 1px;
}

.graphSeq {
  display: inline-block;
}
.grey {
  background-color: #808080;
  margin-top: 2px;
}

.black {
  background-color: Black;
  margin-top: -1px;
}

.purple {
  background-color:Fuchsia;
}

.white {
  background-color:white;    
}
.green {
  background-color:lime;
}
.red {
  background-color: red;
}

.blue {
  background-color: blue;
}

.sdg {
  float: none;
  font-family: verdana;
  font-size: 1.1em;
  height: 13px;
  margin-bottom: 1em;
  margin-top: -7px;
  padding-bottom: 1em;
  width: 10px;
}

#df {
  background-color: #ffffcc;
  display: inline-block;
  margin-bottom: 0.2em;
  margin-left: -1.5em;
  margin-top: -0.2em;
  padding: 0 3px;
  width: 326px;
}

#grBlastHits {
  display:inline-block;
}
.scale {
  width: 2px;
  height: 10px;
  background-color: black;
}

.clkey {
  display: inline-block;
  float: left;
  font-family: verdana;
  font-size: 13px;
  margin-bottom: 0.5em;
  width: 20%;
  text-align: left;
}

.clKeyTl {
  font-family: verdana;
  font-weight: bold;
  margin-bottom: 3px;
}

.masterLen {
  width: 500px;
}
.ck {
  display: inline-block;
  height: 1em;
  width: 1em;
}
.cl {
  display: inline-block;
  margin-left: 0.2em;
  vertical-align: 2px;
}

Thursday, October 4, 2018

ATCG Content of Multiple Gene Sequences using C++

ATCG Content Output

This is a simple tutorial for computing ATCG contents of multiple gene sequences using the classes, objects, and members in C++. In this tutorial, I have used Dev C++ v5.11 software for compiling the C++ program.

Program Design

A. Define a class to represent a gene sequence data. Include the following members:

  1. Data members:
    • Gene name
    • Gene ID
    • Length
    • A, T, G, C content
  2. Member functions:
    • To read data for a gene
    • To compute A, T, G, C content
    • To display all the details of a gene
B. Write a main program to test the program by reading n gene sequences data.

Source Code

/* Computing ATCG Content of Multiple Gene Sequences */
#include <iostream>
#include <iomanip>
#include <conio.h>
#include <string.h>
#include <stdlib.h>

class gene {
  char r, gene_name[20][20], gene_seq[20][200], gene_id[20][20], id[20];
  int gene_length, a, t, c, g, o, n, i, j, m, substr_eq, substr_rem;
  std::string seq, s;
  
  public:
    void get_sequence();
    void find_length();
    void find_atcg();
};

void gene::get_sequence() {
  system("cls");
  std::cout << "\n+---------------------------------------------------+";
  std::cout << "\n| Computing ATCG Content of Multiple Gene Sequences |";
  std::cout << "\n+---------------------------------------------------+\n";
  std::cout << "\nHow many sequence? ";
  std::cin >> n;
  for (i = 0; i < n; i++) {
    std::cout << "\nEnter the Details of Gene " << i+1 << ":\n\n";
    std::cout << "Enter the Gene Name: ";
    std::cin >> gene_name[i];
    std::cout << "Enter the Gene ID: ";
    std::cin >> gene_id[i];
    std::cout << "Enter the Gene Sequence: ";
    std::cin >> gene_seq[i];
    strupr(gene_seq[i]);
  }
}
  
void gene::find_length() {
  again:
  system("cls");
  m = 0;
  std::cout << "\n+---------------------------------------------------+";
  std::cout << "\n| Computing ATCG Content of Multiple Gene Sequences |";
  std::cout << "\n+---------------------------------------------------+\n";
  std::cout << "\nEnter the Gene ID to Compute: ";
  std::cin >> id;
  for (i = 0; i < n; i++) {
    if (strcmpi(id, gene_id[i]) == 0) {
      gene_length = strlen(gene_seq[i]);
      std::cout << "\n\nSequence Name: " << gene_name[i];
      s = gene_seq[i];
      substr_eq = gene_length / 50;
      substr_rem = gene_length % 50;
      if (substr_rem == 0) substr_eq--;
      std::cout << "\n\n\nGene Sequence: \n\n\t";
      for (i = 0; i < substr_eq + 1; i++) {
        for (j = i * 50; j < gene_length && j < (i+1) * 50; j += 1) {
          if ((j + 1) % 10 == 0) {
            std::cout << s[j] << " ";
          } else {
            std::cout << s[j];
          }
        }
        std::cout << "\n\t";
      }
      seq = s;
      std::cout << "\n\nLength of the Sequence: " << gene_length;
      m++;
    }
  }
  if (m == 0) {
    std::cout << "\n\nThe Gene ID Does Not Exists!";
    std::cout << "\n\nDo you want to try again (y/n)? ";
    std::cin >> r;
    if (r == 'y' || r == 'Y') {
      goto again;
    } else {
      getch();
      exit(0);
    }
  }
}
  
void gene::find_atcg() {
  a = 0, t = 0, c = 0, g = 0, o = 0;
  for (i = 0; i < gene_length; i++) {
    if (seq[i] == 'A') {
      a++;
    } else if (seq[i] == 'T') {
      t++;
    } else if (seq[i] == 'C') {
      c++;
    } else if (seq[i] == 'G') {
      g++;
    } else {
      o++;
    }
  }
  std::cout << "\n\nATCG Content of the Sequence:";
  std::cout << "\n\n\tA = " << std::left << std::setw(6) << a << "T = " << t;
  std::cout << "\n\n\tC = " << std::left << std::setw(6) << c << "G = " << g;
  std::cout << "\n\n\tX = " << o;
}

int main() {
  gene g;
  char rp;
  g.get_sequence();
  agn:
  g.find_length();
  g.find_atcg();
  std::cout << "\n\nDo you want to try another (y/n)? ";
  std::cin >> rp;
  if (rp == 'y' || rp == 'Y') {
    goto agn;
  } else {
    getch();
    exit(0);
  }
}

Input/Output

ATCG Content Input

Monday, September 24, 2018

Biological Sequence Pattern Matching using Perl

Pattern Matching Output

This article is a simple Perl programming tutorial for matching patterns in the biological sequence using regular expressions. In this tutorial, I have used ActiveState Perl 5.24.3 software for compiling the Perl script.

Pattern Matching

In Bioinformatics, string matching or pattern matching is a fundamental and popular method used in a wide range of applications ranging from sequence alignment to functional prediction. Pattern matching is classified into exact pattern matching and approximate pattern matching. The exact pattern matching method does not allow any insertion, deletion, or substitution of characters while matching with the target sequence, whereas the approximate pattern matching method allows with certain limitations. In Computational Biology, a pattern is an expression as a sequence of characters with a defined set of symbolic representation. Example: N{P}-[ST]{P}A(2,3).

Source Code

system('cls');
print "\n+-----------------------------------+";
print "\n| Matching Patterns in the Sequence |";
print "\n+-----------------------------------+\n";
print "\nEnter the sequence:\n\n";
$s = <>; 
chomp($s);
$s =~ s/[^a-zA-Z]//g;
$s = uc($s);
$s1 = $s;
print "\nEnter the search pattern: ";
$q = <>;
chomp($q);
$q = uc($q);
if ($s =~ m/$q/) {
  system('cls');
  print "\nPattern \"$q\" found in the sequence!\n\n\nResult\:\n\n\t";
  $s1 =~ s/$q/1/gi;
  $s1 =~ s/[a-z]/-/gi;
  $s1 =~ s/1/$q/g;
  $x = $s;
  $y = 50;
  $len = length($x);
  $qt = int($len / $y);
  $rm = $len % $y;
  if ($rm == 0 and $qt > 0) { $qt--; }
  for ($i = 0; $i <= $qt; $i++) {
    if ($rm > 0) {
      if ($i == $qt) {
        print substr($s, $i * $y, $rm), "\n\t";
        print substr($s1, $i * $y, $rm), "\n\n\t";
      } else {
        print substr($s, $i * $y, $y), "\n\t";
        print substr($s1, $i * $y, $y), "\n\n\t";
      }
    } else {
      print substr($s, $i * $y, $y), "\n\t";
      print substr($s1, $i * $y, $y), "\n\n\t";
    }
  }
  <>;
} else {
  system('cls');
  print "\nPattern \"$q\" not found in the sequence!\n";
  <>;
}

Input/Output

Pattern Matching Input

Sunday, September 23, 2018

Computing Amino Acid Composition using C++

Amino Acid Composition Output

This article explains the simple method to compute composition of amino acids in the protein sequence using C++. In this tutorial, I have used Dev C++ v5.11 software for compiling the C++ program.

Length of the Protein Sequence

Length of the protein sequence is the count (C) of the total number of amino acid characters in the protein sequence.

Let, Protein Sequence (S) = S1S2S3…Sl-1Sl

Where, S ∈ {A, C, D, E, F, G, H, I, K, L, M, N, P, Q, R, S, T, V, W, Y}

Then, l is the length of the protein sequence (S).

Amino Acid Composition of the Protein Sequence

Amino acid composition is the sum of count (C) of each amino acids in the protein sequence.

Count of each amino acids is CA, CC, CD, CE, CF, CG, CH, CI, CK, CL, CM, CN, CP, CQ, CR, CS, CT, CV, CW, and CY.

Source Code

// Computing Composition of Amino Acids in the Protein Sequence
#include <iostream>
#include <iomanip>
#include <string.h>
#include <conio.h>
using namespace std;

struct composition {
  char seq[100];
  int a, c, d, e, f, g, h, i, k, l, m, n, p, q, r, s, t, v, w, y, o;
};

int main() {
  system("cls");
  composition comp, *ptr;
  comp.a = 0, comp.c = 0, comp.d = 0, comp.e = 0, comp.f = 0, comp.g = 0,
  comp.h = 0, comp.i = 0, comp.k = 0, comp.l = 0, comp.m = 0, comp.n = 0,
  comp.p = 0, comp.q = 0, comp.r = 0, comp.s = 0, comp.t = 0, comp.v = 0,
  comp.w = 0, comp.y = 0, comp.o = 0;
  int i, j, length, substr_eq, substr_rem;
  cout << "\nFinding Composition of Amino Acid(s):-\n";
  cout << "\nEnter the Raw Protein Sequence: ";
  cin >> comp.seq;
  strupr(comp.seq);
  length = strlen(comp.seq);
  system("cls");
  string s = comp.seq;
  substr_eq = length / 50;
  substr_rem = length % 50;
  if (substr_rem == 0) substr_eq--;
  cout << "\n\n\nQuery Sequence: \n\n\t";
  for (i = 0; i < substr_eq + 1; i++) {
    for (j = i * 50; j < length && j < (i+1) * 50; j += 1) {
      if ((j + 1) % 10 == 0) {
        cout << s[j] << " ";
      } else {
        cout << s[j];
      }
    }
    cout << "\n\t";
  }
  cout << "\nLength of the Sequence: " << length << endl;
  cout << "\nComposition of Amino Acids: \n\n";
  ptr = &comp;
  for (i = 0; i < length; i++) {
    if ((comp.seq[i] == 'a') || (comp.seq[i] == 'A')) {
      comp.a++;
    } else if ((comp.seq[i] == 'c') || (comp.seq[i] == 'C')) {
      comp.c++;
    } else if ((comp.seq[i] == 'd') || (comp.seq[i] == 'D')) {
      comp.d++;
    } else if ((comp.seq[i] == 'e') || (comp.seq[i] == 'E')) {
      comp.e++;
    } else if ((comp.seq[i] == 'f') || (comp.seq[i] == 'F')) {
      comp.f++;
    } else if ((comp.seq[i] == 'g') || (comp.seq[i] == 'G')) {
      comp.g++;
    } else if ((comp.seq[i] == 'h') || (comp.seq[i] == 'H')) {
      comp.h++;
    } else if ((comp.seq[i] == 'i') || (comp.seq[i] == 'I')) {
      comp.i++;
    } else if ((comp.seq[i] == 'k') || (comp.seq[i] == 'K')) {
      comp.k++;
    } else if ((comp.seq[i] == 'l') || (comp.seq[i] == 'L')) {
      comp.l++;
    } else if ((comp.seq[i] == 'm') || (comp.seq[i] == 'M')) {
      comp.m++;
    } else if ((comp.seq[i] == 'n') || (comp.seq[i] == 'N')) {
      comp.n++;
    } else if ((comp.seq[i] == 'p') || (comp.seq[i] == 'P')) {
      comp.p++;
    } else if ((comp.seq[i] == 'q') || (comp.seq[i] == 'Q')) {
      comp.q++;
    } else if ((comp.seq[i] == 'r') || (comp.seq[i] == 'R')) {
      comp.r++;
    } else if ((comp.seq[i] == 's') || (comp.seq[i] == 'S')) {
      comp.s++;
    } else if ((comp.seq[i] == 't') || (comp.seq[i] == 'T')) {
      comp.t++;
    } else if ((comp.seq[i] == 'v') || (comp.seq[i] == 'V')) {
      comp.v++;
    } else if ((comp.seq[i] == 'w') || (comp.seq[i] == 'W')) {
      comp.w++;
    } else if ((comp.seq[i] == 'y') || (comp.seq[i] == 'Y')) {
      comp.y++;
    } else {
      comp.o++;
    }
  }
  cout << "\n" << setw(23) <<  "Alanine, " << "A  =  " << ptr->a;
  cout << "\n" << setw(23) <<  "Cysteine, " << "C  =  " << ptr->c;
  cout << "\n" << setw(23) <<  "Aspartate, " << "D  =  " << ptr->d;
  cout << "\n" << setw(23) <<  "Glutamate, " << "E  =  " << ptr->e;
  cout << "\n" << setw(23) <<  "Phenylalanine, " << "F  =  " << ptr->f;
  cout << "\n" << setw(23) <<  "Glycine, " << "G  =  " << ptr->g;
  cout << "\n" << setw(23) <<  "Histidine, " << "H  =  " << ptr->h;
  cout << "\n" << setw(23) <<  "Isoleucine, " << "I  =  " << ptr->i;
  cout << "\n" << setw(23) <<  "Lysine, " << "K  =  " << ptr->k;
  cout << "\n" << setw(23) <<  "Leucine, " << "L  =  " << ptr->l;
  cout << "\n" << setw(23) <<  "Methionine, " << "M  =  " << ptr->m;
  cout << "\n" << setw(23) <<  "Asparagine, " << "N  =  " << ptr->n;
  cout << "\n" << setw(23) <<  "Proline, " << "P  =  " << ptr->p;
  cout << "\n" << setw(23) <<  "Glutamine, " << "Q  =  " << ptr->q;
  cout << "\n" << setw(23) <<  "Arginine, " << "R  =  " << ptr->r;
  cout << "\n" << setw(23) <<  "Serine, " << "S  =  " << ptr->s;
  cout << "\n" << setw(23) <<  "Threonine, " << "T  =  " << ptr->t;
  cout << "\n" << setw(23) <<  "Valine, " << "V  =  " << ptr->v;
  cout << "\n" << setw(23) <<  "Tryptophan, " << "W  =  " << ptr->w;
  cout << "\n" << setw(23) <<  "Tyrosine, " << "Y  =  " << ptr->y;
  cout << "\n" << setw(23) <<  "UnKnown, " << "X  =  " << ptr->o;
  getch();
}

Input/Output

Amino Acid Composition Input