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

Comments

Most Popular Posts

TNEB Bill Calculator

TNEB Bill Calculator (New)

Technical Questions